running real time tasks in linux x86 and arm
play

Running Real-Time Tasks in Linux (x86 and ARM) - PowerPoint PPT Presentation

Running Real-Time Tasks in Linux (x86 and ARM) Sisu Xi CSE 467S, Spring, 04/14/2014 Real-Time Tasks Task: a sequence of jobs


  1. ¡ Running ¡Real-­‑Time ¡Tasks ¡ ¡ in ¡Linux ¡(x86 ¡and ¡ARM) ¡ Sisu ¡Xi ¡ CSE ¡467S, ¡Spring, ¡04/14/2014 ¡

  2. Real-­‑Time ¡Tasks ¡ Ø Task: ¡a ¡sequence ¡of ¡jobs ¡ Period ¡ q Worst ¡case ¡execuEon ¡Eme ¡ q Deadline ¡(usually ¡equals ¡period) ¡ q Ø Scheduler ¡ StaEc ¡priority: ¡RM ¡ 15 0 5 10 Time q schedulable deadline miss Dynamic ¡priority: ¡EDF ¡ q A real time task with period of 5, PreempEve ¡vs. ¡non-­‑preempEve ¡ q execution time of 2, and deadline of 4 1. ¡Periodically ¡triggered ¡tasks? ¡ 3. ¡Scheduler ¡setup? ¡ 2. ¡Worst ¡case ¡execu7on ¡7me? ¡ 4. ¡Deadline ¡miss? ¡ 2 ¡

  3. 1. ¡Periodically ¡Triggered ¡Task ¡ Ø Video ¡decoding, ¡sensor ¡processing, ¡etc. ¡ hTp://www.cse.wustl.edu/~xis/programs/period_task.c ¡ Ø struct sigaction sa; … sa.sa_sigaction = work; sigaction(SIGRTMIN, &sa, NULL); … struct sigevent timer_event; timer_event.sigev_signo = SIGRTMIN; … timer_create(CLOCK_REALTIME, &timer_event, &timer); timer_settime(timer, TIMER_ABSTIME, &timerspec, NULL); … Ø Many ¡other ¡approaches, ¡see ¡pointers ¡ 3 ¡

  4. 2. ¡Workload ¡for ¡Tasks ¡– ¡Setup ¡ ¡ Ø Minimize ¡interference/uncertainEes ¡ Turn ¡off ¡unnecessary ¡services ¡ q • Bluetooth, ¡network, ¡graphic, ¡etc ¡ Fix ¡CPU ¡frequency ¡ q • CPU ¡frequency ¡scaling ¡ hTps://wiki.archlinux.org/index.php/CPU_Frequency_Scaling ¡ • CPU ¡frequency ¡governors ¡ hTp://www.mjmwired.net/kernel/DocumentaEon/cpu-­‑freq/ governors.txt ¡ ¡ • Disable ¡in ¡BIOS ¡(SpeedStep ¡for ¡Intel, ¡PowerNow ¡for ¡AMD) ¡ • Set ¡to ¡Performance/Custom/PowerSave ¡ ls ¡/sys/devices/system/cpu/cpu0/cpufreq/ ¡ § echo ¡performance ¡> ¡/sys/devices/system/cpu/cpu0/cpufreq/ § governors ¡ 4 ¡

  5. 2. ¡Workload ¡for ¡Tasks ¡– ¡Programs ¡ ¡ Ø Simulated ¡workload ¡ WCET ¡benchmarks ¡ q hTp://www.mrtc.mdh.se/projects/wcet/benchmarks.html ¡ SNU ¡real-­‑Eme ¡benchmarks ¡ q hTp://www.cprover.org/goto-­‑cc/examples/snu.html ¡ MiBench ¡benchmarks ¡hTp://www.eecs.umich.edu/mibench/ ¡ q Video ¡player: ¡“Sod ¡Real-­‑Time ¡on ¡MulEprocessors: ¡Are ¡Analysis-­‑ q Based ¡Scheduler ¡Really ¡Worth ¡It?” ¡[RTSS’11] ¡ hTps://wiki.litmus-­‑rt.org/litmus/PublicaEons ¡ CPU ¡intensive ¡workload ¡ q • Measure ¡workload ¡for ¡1 ¡ms, ¡then ¡scale ¡to ¡any ¡milliseconds ¡workload ¡ • Note: ¡need ¡to ¡tune ¡for ¡each ¡individual ¡machine ¡ 5 ¡

  6. 3. ¡Scheduler ¡Setup ¡– ¡Basic ¡ ¡ Ø ParEEoned ¡run ¡queue, ¡holds ¡pending ¡jobs ¡ hTp://oreilly.com/catalog/linuxkernel/chapter/ch10.html ¡ ¡ Ø Two ¡classes, ¡would ¡always ¡schedule ¡RT ¡class ¡first ¡ RT ¡class: ¡staEc ¡priority, ¡1 ¡(lowest) ¡to ¡99 ¡(highest) ¡ q • SCHED_FIFO, ¡SCHED_RR ¡ • Can ¡be ¡used ¡to ¡implement ¡staEc ¡priority ¡(like ¡rate ¡monotonic) ¡ • SCHED_DEADLINE ¡since ¡Linux ¡3.14 ¡ • Reserve ¡5% ¡for ¡other ¡classes ¡ /proc/sys/kernel/sched_rt_period_us ¡ ¡ ¡ ¡ ¡1000000 ¡ § /proc/sys/kernel/sched_rt_runEme_us ¡ ¡ ¡ ¡950000 ¡ § Non-­‑RT ¡class: ¡SCHED_OTHER ¡with ¡Complete ¡Fair ¡Scheduler ¡ q 6 ¡

  7. 3. ¡Scheduler ¡Setup ¡– ¡Preemptive ¡ ¡ Ø Scheduler ¡is ¡triggered ¡every ¡HZ ¡quantum ¡ Ø cat ¡/boot/config-­‑* ¡| ¡grep ¡CONFIG_HZ ¡ For ¡most ¡desktops, ¡value ¡is ¡1000. ¡Ecked ¡every ¡1ms ¡ q For ¡arm ¡processors, ¡value ¡is ¡usually ¡100. ¡Ecked ¡every ¡10 ¡ms ¡ q Ø CONFIG_NO_HZ ¡= ¡y ¡ ¡ Ø CONFIG_HIGH_RES_TIMERS ¡= ¡y ¡ hTp://elinux.org/High_ResoluEon_Timers ¡ ¡ Ø Can ¡recompile ¡kernel ¡to ¡change ¡these ¡values ¡ 7 ¡

  8. 3. ¡Scheduler ¡Setup ¡– ¡Priorities ¡ ¡ ¡ Ø chrt ¡command ¡(can ¡also ¡check ¡task ¡prioriEes) ¡[link] ¡ sudo ¡chrt ¡–f ¡–p ¡99 ¡4800 ¡ ¡ ¡ ¡ ¡# ¡pid ¡4800 ¡with ¡priority ¡99 ¡and ¡fifo ¡ q Ø sched_scheduler ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡[link] ¡ ¡ ¡ #include <sched.h> int main() { … struct sched_param sched; sched.sched_priority = 99; if (sched_setscheduler(getpid(), SCHED_FIFO, &sched) < 0) { exit(EXIT_FAILURE); } … } 8 ¡

  9. 3. ¡Scheduler ¡Setup ¡– ¡AfJinities ¡ Ø taskset ¡command ¡(can ¡also ¡check ¡task ¡affiniEes) ¡ ¡[link] ¡ sudo ¡taskset ¡-­‑c ¡2,3 ¡4800 ¡ ¡ ¡ ¡ ¡# ¡pid ¡4800 ¡runs ¡on ¡cores ¡2-­‑3 ¡ q Ø sched_setaffinity ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡[link] ¡ #include <sched.h> int main() { … unsigned long mask = 1; if (sched_setaffinity(getpid(), sizeof(mask), &mask) < 0) { exit(EXIT_FAILURE); } … } 9 ¡

  10. 4. ¡Measure ¡Deadline ¡Miss ¡ Ø geymeofday() ¡ ¡ ¡[link] ¡ return ¡struct ¡Emeval, ¡includes ¡tv_sec ¡and ¡tv_usec ¡ q not ¡ok ¡for ¡measuring ¡overhead ¡on ¡standard ¡kernel ¡configuraEon ¡ q Ø rdtsc ¡ ¡ ¡ ¡[link] ¡ read ¡CPU ¡cycles ¡directly ¡(need ¡to ¡fix ¡CPU ¡frequency) ¡ q cat ¡/proc/cpuinfo ¡to ¡get ¡CPU ¡frequency ¡ q on ¡a ¡3.33GHZ ¡CPU, ¡Ecks ¡3,330,000,000 ¡Emes ¡per ¡second ¡ q • 3 ¡Eck ¡equals ¡1ns ¡ • if ¡you ¡use ¡rdtsc ¡to ¡record ¡Eme, ¡pay ¡aTenEon ¡to ¡this ¡value ¡ • cat ¡/proc/cpuinfo ¡ ¡ ¡ ¡ ¡# ¡get ¡CPU ¡frequency ¡ • cat ¡/sys/devices/system/clocksource/clocksource0 ¡# ¡get ¡current ¡clock ¡ 10 ¡

  11. Demo ¡ Ø /proc/cpuinfo ¡ Ø /proc/sys/kernel/sched_rt_* ¡ Ø /sys/devices/system/clocksource/clocksource0/ ¡ Ø /sys/devices/system/cpu/cpufreq ¡ Ø /sys/devices/system/cpu/cache/ ¡ Ø /boot/config* ¡ Ø /dev/shm ¡ Ø Compile ¡demo ¡task ¡(g++ ¡period_task.c ¡-­‑lrt) ¡ 11 ¡

  12. Raspberry ¡Pi ¡ Ø ARM ¡based ¡Linux ¡box ¡ ¡ Ø Model ¡B ¡($35) ¡ 700 ¡MHz, ¡single ¡core ¡ q 512 ¡MB ¡RAM ¡ q 12 ¡

  13. Raspberry ¡Pi ¡– ¡CPU ¡ ¡ Ø cat ¡/proc/cpuinfo ¡ ARMv6 ¡compaEble ¡processor ¡rev ¡7 ¡(v61) ¡ q Ø ls ¡/sys/devices/system/cpu/cpu0/cpufreq/ ¡ cur, ¡max, ¡min ¡freq ¡ q scaling_governor ¡ q Ø uname ¡–a ¡ Linux ¡raspberrypi ¡3.6.11+ ¡#371 ¡PREEMPT ¡Thu ¡Feb ¡7 ¡16:31:35 ¡GMT ¡ q 2013 ¡armv6l ¡GNU/Linux ¡ Linux ¡Preempt-­‑RT ¡patch: ¡hTps://rt.wiki.kernel.org ¡ q • Minimize ¡scheduling ¡latency ¡ 13 ¡

  14. Raspberry ¡Pi ¡– ¡Clock ¡ Ø /sys/devices/system/clocksource/clocksource0/ available_clocksource ¡ stc, ¡sodware ¡simulated ¡clock, ¡Ecked ¡every ¡1 ¡microseconds ¡ q Ø cat ¡/proc/config.gz ¡| ¡gzip ¡–d ¡| ¡grep ¡HZ ¡ CONFIG_NO_HZ ¡= ¡y ¡ ¡ ¡ ¡ ¡# ¡when ¡idle, ¡Eckles ¡to ¡save ¡energy ¡ q CONFIG_HZ ¡= ¡100 ¡# ¡Eck ¡every ¡10 ¡ms ¡ q 14 ¡

  15. Raspberry ¡Pi ¡– ¡Summary ¡ Ø Single ¡core ¡processor: ¡no ¡need ¡to ¡set ¡cpu_masks ¡ Ø Fixed ¡frequency: ¡no ¡need ¡to ¡change ¡frequency ¡governor ¡ Ø No ¡rdtsc ¡ Need ¡to ¡record ¡Eme ¡using ¡other ¡funcEons ¡calls ¡like ¡geymeofday, ¡ q clock_geyme(), ¡etc ¡ Minimum ¡Eme ¡resoluEon ¡provided ¡is ¡1 ¡microseconds ¡via ¡stc ¡ q Default ¡scheduling ¡Eck ¡is ¡10 ¡ms ¡(compared ¡to ¡1 ¡ms ¡on ¡Desktop) ¡ q Ø Comes ¡with ¡Preempt-­‑RT ¡patch ¡by ¡default ¡ Less ¡scheduling ¡latency, ¡more ¡responsive ¡to ¡I/O ¡tasks ¡ q 15 ¡

  16. Demo ¡ ¡ Ø /sys/devices/system/clocksource/clocksource0/ available_clocksource ¡ Ø /proc/config.gz ¡| ¡gzip ¡–d ¡| ¡grep ¡HZ ¡ Ø /sys/devices/system/cpu/cpu0/cpufreq/ ¡ Ø /proc/cpuinfo ¡ Ø uname ¡–a ¡ Ø Compile ¡demo ¡task ¡ ¡ No ¡rdtsc, ¡need ¡to ¡replace ¡with ¡geymeofday() ¡ q 16 ¡

  17. Note: ¡Be ¡careful ¡with ¡serial ¡cable! ¡ 17 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend