Preempt_rt realtime patch

Download Preempt_rt realtime patch

Post on 16-Apr-2017

745 views

Category:

Software

3 download

Embed Size (px)

TRANSCRIPT

<p>Missing points from last presentationWhich modifications doneDetailed configuration optionsChange realtime support run time or statically?Statically, you need to compile the realtime patched kernel with CONFIG_PREEMPT_RT_FULL=y to support realtime.Linux kernel API documentshttps://www.kernel.org/doc/htmldocs/kernel-api/Operating system designScheduling Other approaches to Linux realtimeXenomaiRTLinuxRTAIextra: does other mobile operating systems provide realtime capability?android osfirefox os#will be covered later</p> <p>#</p> <p>Preempt_rt researchEmre Can Kucukoglueckucukoglu@gmail.com28.08.14</p> <p>When does real-time Linux come into embedded development?Hard real time requirementsmissing a deadline is a total system failure.strict deadlineto control something thatwill end up killing people if something goes wrong.eg. nuclear systems, pacemakers, avionics</p> <p>#</p> <p>When does real-time Linux come into embedded development?Soft real time requirementsmaximizing the number of deadlines met, minimizing the lateness of tasks and maximizing the number of high priority tasks meeting their deadlines.violation of constraints results in degraded quality, but the system can continue to operate.eg. Live audio-video systems</p> <p>#</p> <p>When does real-time Linux come into embedded development?Firm real time requirementsinfrequent deadline misses are tolerable usefulness of a result is zero after its deadlineeg. forecast systems</p> <p>#</p> <p>Preempt_rt: Hard real time"Hard" real-time softwarefor robotics, stock exchanges (imkb)...has been used on computers that have gone into space.#</p> <p>Preempt_rt: Hard realtimefasterresponse timesremoves all unbounded latencieslinux kernel is filled with unbounded latencies non-deterministic behavioreg. unfair reader writer locksreaders can continually take the lockbounded latency: eg. fair reader writer locknew readers will block if there's a writer waiting</p> <p>#</p> <p>Advantage over other rt linux implementationspreempt_rt makes linux itself real-time, others create a small microkernel that runs like a hypervisor linux kernel runs as a tasknot really linux:rt tasks must be modified to communicate with microkernel</p> <p>#</p> <p>Main configurationNo Preemptionlittle scheduling overheadnever schedule unless a function explicitly calls schedule()eg. Servers</p> <p>#</p> <p>Main configurationVoluntary Preemptionschedule only at preemption pointsreduce the maximum latency of reschedulingproviding faster application reaction at the cost of slightly lower throughput.Implementation: might_sleep()calls might_resched(); calls _cond_resched()</p> <p>#</p> <p>Main configurationPreemptible Kernelexcept within spin_locks andpreempt_disable(); /* preemption is disabled */ preempt_enable();every spin_lock acts like a single global lock WRT preemption.</p> <p>#</p> <p>Main configurationPreemptible Kernel (Basic RT)to debug PREEMPT_RT_FULLto learn that problem is mutexes or notenables parts of the PREEMPT_RT options, without sleeping spin_locksit will probably go away</p> <p>#</p> <p>Fully Preemptible Kernelinterrupts run as threadsability to modify the priorities of interrupts user space tasks can run at even a higher priority than interrupts.remove disabling of interruptsneeded for kernel preemptionconversion of spin_locks into mutexesspin_locks side effectdisabling preemptionpriority inheritance for all locks</p> <p>linux kernel</p> <p>Main configuration#</p> <p>Sleeping spin_lockif task is blocked go to sleepmutexesthreaded interrupts neededotherwise miss interruptif not-threaded (not-prioritized) interrupts spin_locks changed to mutexesmust not be in atomic paths preempt_disable()local_irq_save(flags): disable interrupt on the current processor and prior to which it saves current interrupt state into flags.#</p> <p>raw_spin_lockcreation of non-preemptible sectionssame as current mainline spin_locksshould only be used for scheduler, rtmutex implementation, debugging/tracing infrastructure and for timer interrupts</p> <p>#</p> <p>Non-Thread IRQstimer interruptIRQF_TIMER flagflag for timer interruptsIRQF_NO_THREAD flagExplicitly marking interrupt as not be a thread</p> <p>#</p> <p>Threaded Interruptsdriver wants handler as threadrequest_threaded_irq(irq, handler, thread_fn, irqflags, devname, dev_id)same as request_irq() with the addition of the thread_fnhandlercalled in hard interrupt contextcheck whether the interrupt originates from the device. If yes it needs to disable the interrupt on the device and return IRQ_WAKE_THREAD IRQ_WAKE_THREAD will wake up the handler thread and run thread_fnif null, must have thread_fnthreadirqscommandline parameterforces all interrupts to run threadedexcept IRQF_NO_THREADmostly a debug option to allow retrieving better debug data from crashing interrupt handlers.</p> <p>#</p> <p>Critical sections &amp; disabling interruptslocal_irq_disable()disables local interrupt deliveryshould not be used since:what it's protecting?spin_lock_irqsave(lock, flags)disables interrupts before taking the spinlock; the previous interrupt state is stored in flags. If you are absolutely sure nothing else might have already disabled interrupts, you can use spin_lock_irq insteadpreempt_rt does not disable interruptsshould be used since:spin_lock_irqsave labeling what its protecting</p> <p>#</p> <p>Critical sections &amp; disabling interruptsAvoid usinglocal_irq_save()preempt_disable()get_cpu_var() since it calls preempt_disable() for per_cpu variablesper_cpu variables can be manipulated without explicit lockingrwlocksWrites must wait for unknown amount of readersUseget_cpu_light()local_lock[_irq[save]](var)get_local_var(var)#</p> <p>preempt_rt primitives and methodshttp://lwn.net/Articles/146861/Locking PrimitivesPer-CPU VariablesInterrupt HandlersMiscellaneous methods#</p> <p>Understanding fileshttps://www.kernel.org/pub/linux/kernel/projects/rt/patch-x.xx.xx-rty.patchx: linux kernel, y: patch. x-y pairs are one-to-one.patches-x.xx.xx-rty~ 300 patcheseg. ata-Do-not-disable-interrupts-in-ide-code-for-preemp.patchide-Do-not-disable-interrupts-for-PREEMPT-RT.patchcore-Do-not-disable-interrupts-on-RT-in-kernel-users.patchcomments in code: Use the local_irq_*_nort variants to reduce latencies in RT. The codeis serialized by the locks. No need to disable interrupts....</p> <p>#</p>