RT+Linux +Training 10
-
Upload
kartikakraze -
Category
Documents
-
view
228 -
download
0
Transcript of RT+Linux +Training 10
-
8/8/2019 RT+Linux +Training 10
1/41
RT LinuxRT Linux
A Real Time Approach of Linux A Real Time Approach of Linux
-
8/8/2019 RT+Linux +Training 10
2/41
W hatW hat isis realreal--time?time?
Correctness of output depends on timingCorrectness of output depends on timingas well as resultas well as result
Hard vs. soft realHard vs. soft real- -timetime
Are W indows and Linux real Are W indows and Linux real- -time?time?
-
8/8/2019 RT+Linux +Training 10
3/41
Real time IntroductionReal time IntroductionDefinitionsDefinitions
Real Time SystemReal Time System is one where theis one where thecorrectness of a computation is acorrectness of a computation is afunction of both the result of thefunction of both the result of thecomputation and the time at which thecomputation and the time at which thecomputation is deliveredcomputation is delivered
Soft RTSoft RT occasionally allowed tooccasionally allowed tomiss deadlines (eg. Updating a videomiss deadlines (eg. Updating a videodisplay)display)H ard RTH ard RT M eeting the deadline isM eeting the deadline isabsolutely critical (eg. Rocketabsolutely critical (eg. Rocketcontroller)controller)
-
8/8/2019 RT+Linux +Training 10
4/41
Typical RTSTypical RTS
-
8/8/2019 RT+Linux +Training 10
5/41
RTOS Vs. GPOSRTOS Vs. GPOS
RTOSRTOSneeds deterministic timing behavior needs deterministic timing behavior
W orks under worst case assumptionsW orks under worst case assumptions
GPOSGPOShigh throughput and fairnesshigh throughput and fairness
Optimizes for the average caseOptimizes for the average case
Hence, the design objectives of the OSs are differentHence, the design objectives of the OSs are different
-
8/8/2019 RT+Linux +Training 10
6/41
Incompatibility withIncompatibility with
Timesharing SystemsTimesharing SystemsTimesharing systems try to optimizeTimesharing systems try to optimizeaverage case but RT systems mustaverage case but RT systems mustconsider worst case.consider worst case.Contradictory design goals for the twoContradictory design goals for the two what is good for the average case tendswhat is good for the average case tendsto deteriorate the worst case. A classicto deteriorate the worst case. A classicexample is virtual memory and demandexample is virtual memory and demandpaging.paging.
-
8/8/2019 RT+Linux +Training 10
7/41
Two Types of Real Time OSTwo Types of Real Time OS
Hard Real TimeHard Real TimeM eeting the deadlineM eeting the deadlineis absolutely criticalis absolutely critical
E.g. Rocket controller E.g. Rocket controller
Soft Real TimeSoft Real TimeOccasionallyOccasionallyallowed to missallowed to missdeadlinesdeadlines
E.g. Updating aE.g. Updating avideo displayvideo display
So what happens in the case a Hard Real Time Systemdoes not meet a deadline?
Failure!
-
8/8/2019 RT+Linux +Training 10
8/41
Hard versus SoftHard versus Soft
HARD:HARD: miss a deadline and youre in trouble!miss a deadline and youre in trouble!(planes, trains, factory control, nuclear facilities, ...)(planes, trains, factory control, nuclear facilities, ...)SOFT:SOFT: try to meet deadlines, but if not, system stilltry to meet deadlines, but if not, system still
works, although with degraded performanceworks, although with degraded performance(multimedia, thermostat, ...)(multimedia, thermostat, ...)F IRM :F IRM : late results are worthless, but you are not inlate results are worthless, but you are not introubletrouble
-
8/8/2019 RT+Linux +Training 10
9/41
-
8/8/2019 RT+Linux +Training 10
10/41
Why RTOS?
Interactive embedded systems require realtime schedulingSome legacy OS can provide some of thisfunctionality BUT they are too big to run onan embedded systems
-
8/8/2019 RT+Linux +Training 10
11/41
Real Time OS problemReal Time OS problem
A RTOS needs to be fast and predictable: so itA RTOS needs to be fast and predictable: so itneeds to be small and precisely designed.needs to be small and precisely designed.
Modern RT applications need networking stacks,Modern RT applications need networking stacks,GUI, databases, file systems, developmentGUI, databases, file systems, developmentenvironments, web servers, and so on: So theenvironments, web servers, and so on: So theoperating system needs to have many featuresoperating system needs to have many features H ard to estimate service time.H ard to estimate service time.
Both requirements are hardly satisfied at the sameBoth requirements are hardly satisfied at the sametime.time.
-
8/8/2019 RT+Linux +Training 10
12/41
D esirable Real-Time Kernel Features
MultitaskingPriority-based preemptive scheduling
Inter-task synchronization and communicationSemaphores, mailboxes, event-flags ...Basic memory managementInterrupt handling
Timer handling, time managementImplementable on small deeply embedded systems
-
8/8/2019 RT+Linux +Training 10
13/41
Defects In Linux As An RTOSDefects In Linux As An RTOS
-
8/8/2019 RT+Linux +Training 10
14/41
Rea l ti e I tr ti Rea l ti e I tr ti Li x as g RT pl a tf r Li x as g RT pl a tf r
Excellent stability and efficiencyExcellent stability and efficiencySource code availabilitySource code availability
Active license, and substantial user base. Active license, and substantial user base.Linux can run on the most widely availableLinux can run on the most widely availablecomputerscomputersLinux has all features of a modern UN IX system:Linux has all features of a modern UN IX system:(X W indow, graphical user interface toolkits,(X W indow, graphical user interface toolkits,
networking, databases, programming languages,networking, databases, programming languages,debuggers, and a variety of applications).debuggers, and a variety of applications).It is embeddable and is able to perform efficientlyIt is embeddable and is able to perform efficientlyusing relatively small amounts of RA M and other using relatively small amounts of RA M and other computer resources.computer resources.
-
8/8/2019 RT+Linux +Training 10
15/41
-
8/8/2019 RT+Linux +Training 10
16/41
Defects of LinuxDefects of Linux
Linux scheduling algorithms are not designed for realLinux scheduling algorithms are not designed for real- -time tasks.time tasks.
Linux scheduling is unpredictable.Linux scheduling is unpredictable.
Linux Timer resolution is coarse, 10 ms.Linux Timer resolution is coarse, 10 ms.
Linux Kernel is NonLinux Kernel is Non- -preemptible .preemptible .
Linux disables interrupts used for coarseLinux disables interrupts used for coarse- -grainedgrained
synchronization.synchronization.Linux uses virtual memory.Linux uses virtual memory.
Linux reorders requests for efficiency (e.g., for disk I/O).Linux reorders requests for efficiency (e.g., for disk I/O).
-
8/8/2019 RT+Linux +Training 10
17/41
Can Linux provide realCan Linux provide real- -time guarantees?time guarantees?---- No!!No!!
L inuxL inuxnonnon- -preemptible kernelpreemptible kernel
A system call might take long time to complete A system call might take long time to complete
C oarse timer resolutionC oarse timer resolutionTasks can be released only withTasks can be released only with 10ms10ms precisionprecisionV irtual memoryV irtual memory
Introduces unpredictable amount of delaysIntroduces unpredictable amount of delaysV ariable priorityV ariable priority
Each task is assigned a priority which varies over the time;Each task is assigned a priority which varies over the time;this is to achieve fairnessthis is to achieve fairness
-
8/8/2019 RT+Linux +Training 10
18/41
Unpredictable schedulingUnpredictable scheduling depends on systemdepends on systemload.load.Time resolutionTime resolutionNonNon--preemptible kernelpreemptible kernelDisabling of interrupt during critical sectionsDisabling of interrupt during critical sectionsUse of virtual memoryUse of virtual memory
Rea l tim e Introd ctionWhy is Lin x Uns it ab le for H a rd RT ?
-
8/8/2019 RT+Linux +Training 10
19/41
Real Time LinuxReal Time Linux- - An AnIntroductionIntroduction
-
8/8/2019 RT+Linux +Training 10
20/41
W hat is RTLinux ? ..W hat is RTLinux ? ..
To support hard real timeTo support hard real timeapplications, the Linuxapplications, the Linuxkernel is modified bykernel is modified byintroducing a layer introducing a layer between the hardwarebetween the hardwareand the standard Linuxand the standard Linuxkernel.kernel.RTRT--Linux is a hard realLinux is a hard real- -
time kernel that runstime kernel that runsLinux or BSD as an idleLinux or BSD as an idletask, whenever there aretask, whenever there areno realno real- -time demands.time demands.
-
8/8/2019 RT+Linux +Training 10
21/41
RTRT--LinuxLinux Add iti a l l aye r b e tw een Li nu x Add iti na l l aye r b e tw een Li nu x k e r ne l an d h a r d w a r e.k e r ne l an d h a r d w a r e.
Sm a ll r ea l ti m e k e r ne l e xi s t s withSm a ll r ea l ti m e k e r ne l e xi s t s withLi nu x k e r ne l .Li nu x k e r ne l .
RT RT- - Li nu x i s mo d u l e o ri en t e d .Li nu x i s mo d u l e o ri en t e d .
Dec o u pl es th e m ec h an i s m s o f r ea l Dec o u pl es th e m ec h an i s m s o f r ea l - - ti m e k e r ne l fr om th e g ene r a l p u rp o se ti m e k e r ne l fr om th e g ene r a l p u rp o se k e r ne l .k e r ne l .
-
8/8/2019 RT+Linux +Training 10
22/41
POS IX 1003.1b StandardPOS IX 1003.1b StandardFor soft RT features in UN IX For soft RT features in UN IX It requires the followingIt requires the following
Preemptive priority schedulingPreemptive priority schedulingLocking of virtual pages into memoryLocking of virtual pages into memoryRealReal--time signalstime signalsImproved IPCImproved IPCImproved timers
Improved timersLinux only partially conforms to the above.Linux only partially conforms to the above.
(mlock and setsched system calls)(mlock and setsched system calls)
-
8/8/2019 RT+Linux +Training 10
23/41
RT Li nu x I n tr o d uc ti o nRT Li nu x I n tr o d uc ti o nG o a l sG o a l s
Achieve hard RT performance. Achieve hard RT performance.High level of timer precision in scheduling.High level of timer precision in scheduling.To provide low interrupt latency.To provide low interrupt latency.Customized scheduling.Customized scheduling.M inimal changes to the Linux kernel so that theM inimal changes to the Linux kernel so that thefull range of OS services are available.full range of OS services are available.
-
8/8/2019 RT+Linux +Training 10
24/41
RTRT--Linux is developed and supported byLinux is developed and supported byFS M LabsFS M Labs . RT. RT--Linux began life as a researchLinux began life as a researchproject at the New M exico Institute of project at the New M exico Institute of
Technology (N M T). RTTechnology (N M T). RT- -Linux is an openLinux is an open- -sourcesourceproduct. RTproduct. RT- -LinuxLinux--specific components arespecific components arereleased under the GPL, and Linux componentsreleased under the GPL, and Linux componentsreleased under the standard Linux license. Thereleased under the standard Linux license. The
source code is freely distributed.source code is freely distributed.
RT Li nu x I n tr o d uc ti o nRT Li nu x I n tr o d uc ti o nBac kgr o un d Bac kgr o un d
-
8/8/2019 RT+Linux +Training 10
25/41
The mostThe most- -current stable version of RTLinuxcurrent stable version of RTLinuxV3.0, offers a POS IX style applicationV3.0, offers a POS IX style applicationprogramming interface (AP I), runs on x86,programming interface (AP I), runs on x86,PowerPC and Alpha processors and supportsPowerPC and Alpha processors and supportsS M P (x86 and PPC).S M P (x86 and PPC).
RT Li nu x I n tr o d uc ti o nRT Li nu x I n tr o d uc ti o nBac kgr o n d Bac kgr o n d - - C o n t C o n t
-
8/8/2019 RT+Linux +Training 10
26/41
RTRT--Linux a version of the Linux OperatingLinux a version of the Linux OperatingSystem, its a hard realSystem, its a hard real- -time operating systemtime operating systemthat runs Linux as its lowest priority executionthat runs Linux as its lowest priority execution
thread.thread.The Linux thread is made completelyThe Linux thread is made completelypreemptible so that real time threads andpreemptible so that real time threads andinterrupt handlers are never delayed by noninterrupt handlers are never delayed by non- -realreal
time operationstime operationsPrevents disabling of interrupts by Linux.Prevents disabling of interrupts by Linux.
RT Li nu x I n tr o d uc ti o nRT Li nu x I n tr o d uc ti o n A ppr o ac h A ppr o ac h
-
8/8/2019 RT+Linux +Training 10
27/41
R T Li nu x I n tr o d uc ti o nR T Li nu x I n tr o d uc ti o nS tr uc t u r eS tr uc t u r e
Linux Process 1 Linux Process 2
Linux Kernel An RT - Process
Real Time Kernel
-
8/8/2019 RT+Linux +Training 10
28/41
RealReal--time tasks in RTtime tasks in RT- -Linux canLinux cancommunicate with Linux processes viacommunicate with Linux processes viashared memory or using a F IFO. Thus, realshared memory or using a F IFO. Thus, real- -time applications can make use of all thetime applications can make use of all thepowerful, nonpowerful, non- -realreal--time services of Linux,time services of Linux,including:including:
NetworkingNetworking
GraphicsGraphicsW indowing systemsW indowing systemsData analysis packagesData analysis packagesLinux device drivers, andLinux device drivers, and
Standard POSIX
API.Standard POS
IXAP
I.
RT Li nu x I n tr o d uc ti o nRT Li nu x I n tr o d uc ti o n A ppr o ac h A ppr o ac h C o n t C o n t
-
8/8/2019 RT+Linux +Training 10
29/41
Real Time LinuxReal Time Linux
Real time LinuxReal time LinuxProject:Project:
UT IM EUT IM ERTRT--Linux PlatformLinux PlatformKurt PlatformKurt PlatformRED LinuxRED Linux
RTA IRTA ILinux /RK(fromLinux /RK(fromM ac /RK)M ac /RK)
Embedded LinuxEmbedded LinuxProjectsProjects
M iniRTLM iniRTLExtension to RTExtension to RTLinuxLinux
ELKS ProjectELKS ProjectHAHA--Linux (HighLinux (High
Availability) Availability)VM E Linux ProjectVM E Linux Project
-
8/8/2019 RT+Linux +Training 10
30/41
RTLinux FeaturesRTLinux Features
RealReal--time scheduling algorithm.time scheduling algorithm.Predictable delays.Predictable delays.
By its small size and limited operations.By its small size and limited operations.
Finer timer resolution.Finer timer resolution.Preemptible kernel.Preemptible kernel.
The RTLinux executive is itself nonpreemptible.The RTLinux executive is itself nonpreemptible.Its routine are very small and fast, this does not cause bigIts routine are very small and fast, this does not cause big
delays.delays.Interrupts from Linux are disabled.Interrupts from Linux are disabled.
No virtual memory.No virtual memory.
-
8/8/2019 RT+Linux +Training 10
31/41
A rchitecture of RT Linux
-
8/8/2019 RT+Linux +Training 10
32/41
-
8/8/2019 RT+Linux +Training 10
33/41
Linux KernelLinux Kernel
System libraries
Device drivers L inux kernel
Hardware
I/O Hardware Interrupts
User Processes
-
8/8/2019 RT+Linux +Training 10
34/41
-
8/8/2019 RT+Linux +Training 10
35/41
RTRT--Linux: Design CriteriaLinux: Design Criteria
To provide timing reliability to the LinuxTo provide timing reliability to the LinuxKernel.Kernel.
Linux Kernel is unpredictable becauseLinux Kernel is unpredictable becauseof:of:
Scheduling algorithms (maximize throughput)Scheduling algorithms (maximize throughput)Device Drivers.Device Drivers.Uninterruptible System Calls.Uninterruptible System Calls.Use of interrupt disabling procedures.Use of interrupt disabling procedures.
-
8/8/2019 RT+Linux +Training 10
36/41
W hen is Hard RealW hen is Hard Real- -TimeTimeneeded?needed?
Hard vs. Soft RealHard vs. Soft Real- -TimeTimeHard RT always guarantees exact timingHard RT always guarantees exact timing
Hard RealHard Real- -Time applicationsTime applicationsClosedClosed- -loop control systemsloop control systemsStimulus /response systemsStimulus /response systems
ExamplesExamples
Robotics, AnimatronicsRobotics, AnimatronicsIndustrial equipmentIndustrial equipmentNeural, fuzzy and adaptive systemsNeural, fuzzy and adaptive systems
However:However:Hard RealHard Real- -Time extensions can degrade OSTime extensions can degrade OSperformance of non timeperformance of non time- -critical applicationscritical applications
-
8/8/2019 RT+Linux +Training 10
37/41
RTLinux: The Real Time LinuxRTLinux: The Real Time Linux
GoalsGoalsmaintain compatibility with GNU /Linuxmaintain compatibility with GNU /Linux
handle tasks with hardhandle tasks with hard- -real time constrainsreal time constrainssimplicity and reliability of the RTsimplicity and reliability of the RTtradeoff: ease of usetradeoff: ease of use
Approach Approachrealreal--time microkerneltime microkernelLinux kernel is running as lowest priority task inLinux kernel is running as lowest priority task inthe realthe real- -time scheduletime schedulerealreal--time applications are written as microkerneltime applications are written as microkernelmodulesmodules
microkernel is transparent to regular applicationmicrokernel is transparent to regular application
-
8/8/2019 RT+Linux +Training 10
38/41
RTLinux: M icrokernelRTLinux: M icrokernel
M icrokernelM icrokernelIS a thin layer of IS a thin layer of abstractionabstraction
PROV IDES anPROV IDES aninterface for hardwareinterface for hardwareinterrupts and AP I for interrupts and AP I for realreal--time taskstime tasksM ED I ATES requestsM ED I ATES requeststo /from hardwareto /from hardware
-
8/8/2019 RT+Linux +Training 10
39/41
RTLinux: M icrokernel (cont.)RTLinux: M icrokernel (cont.)
ComponentsComponentsProcessor clock controlProcessor clock control
RealReal--Time scheduler Time scheduler POS IXPOS IX --like interface to device driverslike interface to device driversRealReal--Time F IFOsTime F IFOsShared memory buffersShared memory buffersPOS IXPOS IX --like IPClike IPC
Blocking mutexesBlocking mutexesSemaphoresSemaphores
SourceSource- -level debugger supportlevel debugger supportSerial port interfaceSerial port interface
-
8/8/2019 RT+Linux +Training 10
40/41
RTLinux: M icrokernel DetailsRTLinux: M icrokernel Details
Scheduler Scheduler Preemptive, priority basedPreemptive, priority based
Hardware context switch isHardware context switch isnot not
usedusedReason: saves too much state, not fast enoughReason: saves too much state, not fast enoughStack is used insteadStack is used instead
RT kernel handles hardware interruptsRT kernel handles hardware interrupts
Linux thread does not directly receive themLinux thread does not directly receive themW hen Linux wants to disable interruptsW hen Linux wants to disable interruptsThe microkernel stops passing them to the LinuxThe microkernel stops passing them to the LinuxthreadthreadHowever, realHowever, real- -time tasks can receive themtime tasks can receive them
-
8/8/2019 RT+Linux +Training 10
41/41