Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
RTOSRTOS
CharacteristicsCharacteristicsTime constraintsTime constraints
S h d liS h d liSchedulingScheduling
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari
RealReal--Time SystemsTime Systems
Definition of real-time system“ l h h h f “A real-time system is one in which the correctness of the computation not only depends on the logical correctness of the computation, but also on the time pat which the result is computed. If the timing constraints of the system are not met, system failure is said to have occurred”s sa d to ave occu ed
Tasks or processes attempt to control or react to external events occuring in “real time”RT processes must be able to keep up events
Hard Real Time: timing violation produces a disasterS ft R l Ti ti i g i l ti d i bl b t Soft Real Time: timing violations are undesirable but not catastrophic
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 22 --
RTOSRTOS
A Real-Time Operating System (RTOS)Is just one element of a complete real-time systemMust provide sufficient functionality to enable the
ll l ti t t t it i toverall real-time system to meet its requirementsShould ensure that all time critical events are handled as quickly and efficiently as possibleas quickly and efficiently as possible
RTOS are characterized by these main featuresDeterministic behaviourDeterministic behaviourResponsivenessUser controlReliability and fail-soft operation
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 33 --
RTOS: DeterminismRTOS: Determinism
Operations are performed at fixed, predetermined times or within predetermined time intervalsConcerned with
How long the operating system delays before acknowledging an interruptWhether the system has sufficient capacity to handle Whether the system has sufficient capacity to handle all requests within required time
RTOS should show minimum interrupt latencyRTOS should show minimum interrupt latencyTypical measure:
Max delay to start ISR with highest priorityRT: 1µs - 1msNon-RT: 10ms - 100 ms
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 44 --
RTOS: ResponsivenessRTOS: Responsiveness
How long, after acknowledgment, the operating system takes to service the interruptIncludes the time to begin execution of the ISR
If a context switch is necessary, the delay is longer than an ISR executed within the context of the current processcurrent process
Includes the amount of time to perform the interrupt, depending also on the specific hardware p , p g pDepends on the possible ISR nesting and if ISRs can be interrupted
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 55 --
RTOS: User controlRTOS: User control
Much broader in RTOS than in ordinary O.S.User should be able to
Specify paging or process swappingDecide which processes must reside in main memoryEstablish the rights of processes
d l kFine-grained control over task prioritiesSelect algorithms for disks scheduling...
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 66 --
RTOS: ReliabilityRTOS: Reliability
In the application domain of RTOS, degradation of performances may have catastrophic consequencesperformances may have catastrophic consequences
Attempt either to fix the problem or minimize its effects while continuing to rungGraceful degradation can be not enough
Fail-softAbility to fail in such a way to preserve as much data and capability as possible
E g multiple attempts to improve data consistencyE.g., multiple attempts to improve data consistency
StabilityThe system adopts policies such that the most critical y p phigh priority tasks execute first, even if some needs of less important tasks can be not always met
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 77 --
RTOS: Typical featuresRTOS: Typical features
Low cost, small sizeManagement of at least 20 tasksHave minimum interrupt latencyD t i i ti ti ti f ll k l iDeterministic execution time for all kernel servicesProvide at least the following services
Allow tasks to be dynamically created and deletedAllow tasks to be dynamically created and deletedProvide semaphore management services and IPCAllow time delays and timeouts on kernel servicesyManagement of special alarmsUse of special file to accumulate data at a fast ratePreemptive priority-based scheduling with fast context switch
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 88 --
Time constraintsTime constraints
Computational activities in a real-time system generally have timing constraints
computation time
ready scheduled completed deadline
time
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 99 --
Time constraintsTime constraints
The "ready" event may bePeriodic
Tasks: Overall activityJ b I t ti ti i di id ll h d l d Jobs: Instantiations or individually scheduled computations of the task. A task is a stream of jobs
Aperiodic but predictablepe od c but p ed ctableUnpredictable
The "computation time" may beFixed in durationVariableUnpredictable
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1010 --
DeadlinesDeadlines
DeadlinesHard
The computation must be completed by the deadline time or a fatal error will occurtime or a fatal error will occur
SoftThe deadline may just be a recommendation or The deadline may just be a recommendation or preference for completion of the computation
A "Value Function"Indicates the criticality of a deadlineIndicates the value that the completion of a task
t ib t t th ll l f th tcontributes to the overall value of the system
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1111 --
DeadlinesDeadlines
In a non real-time system the time by which a task is completed does not influence the overall value –or quality – of the systemTh l f ti i th f ll iThe value function is the following
V
tR0
tR
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1212 --
DeadlinesDeadlines
Catastrophic effect Hard Deadline
V V
tR0
-∞ tR0
D D
Ramped Hard Deadline Soft Deadline
V V
tR0
D tR0
D
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1313 --
tR D tR D
PreemptionPreemption
A computation or task is preemptable if it can be interrupted (suspended) when another more critical task needs to be executedA t ti bA computation can be
PreemptablePreemptable with one or more non preemptible Preemptable with one or more non-preemptible critical regionsNon-preemptableNon preemptable
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1414 --
PreemptionPreemption
IRQpreemption completed
Task 1
time
Task 2
IRQno preemption completedno preemption completed
Task 1
time
Task 2
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1515 --
time
SchedulingScheduling
The heart of a RTOS is the short-term schedulerNot crucial
Fairness, Minimum average response time, …
C i lCrucialAll hard-RT tasks must complete by their deadlineAs many soft-RT tasks as possible should also complete As many soft-RT tasks as possible should also complete meeting their deadlines
Most RTOSs are unable to deal with deadlinesDesigned to be as responsive as possible to RT tasks
When deadline approaches, RT tasks can be quickly h d l dscheduled
This approach requires deterministic response time sometimes below milliseconds
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1616 --
sometimes below milliseconds
SchedulingScheduling
In a Round Robin non-preemptive schedulerThe RT task is appended at the end of the ready queue
Wait for its next timeslice
Th d l b t bl f RT li tiThe delay can be unacceptable for RT applications
Request for RT Task
ticks
Task 1 Task 2 Task 3 Task N RT Task Task 1
Scheduling time
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1717 --
Scheduling time
SchedulingScheduling
Priority driven non-preemptive schedulerRT tasks have higher priorityA RT task is scheduled when the current task T
Is blocked, orRuns to completion (even if with low priority)
The RT is added at the head of the ready queueThe RT is added at the head of the ready queuePossible delay of seconds, unacceptable for real-time
Request for RT Task
Task T RT Task Task N
Scheduling time
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1818 --
Scheduling time
SchedulingScheduling
Priority driven preemptive on preemption pointsPreemption can only take place at the end of some regular intervalsI th i tIn those points
The highest priority task is scheduledIncluding kernel tasksIncluding kernel tasks
Delays in the order of some ms, adequate for some applications not for more demanding ones
Request for RT Task
RT Task Task T (resumed)
Scheduling time
Task T
preemptionpoints
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 1919 --
Scheduling timep
SchedulingScheduling
Immediate preemptive schedulingThe service to the interrupt is almost immediate
Apart from the case OS is executing a critical region
S h d li d l f ll d t 100 lScheduling delays fall down to 100 µs, or lessA minimum amount of time is nevertheless required to save the context and to switch to the new contextsave the context and to switch to the new context
Good for critical systems
Request for RT Task
RT Task Task T (resumed)
Scheduling time
Task T
preemptionpoints
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2020 --
Scheduling timep
Factors influencing schedulingFactors influencing scheduling
Schedulability analysisYes/NoStatic/dynamic
The result of the analysis can beA clear scheduling
l f ll f k d hA "plan" to follow at run-time for task dispatching
Classes of algorithmsS i bl d iStatic table-drivenStatic priority-driven preemptiveDynamic planning basedDynamic planning-basedDynamic best-effort
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2121 --
Static tableStatic table--drivendriven
Through a static feasibility analysis of schedule, determines at run time when a task must begin determines, at run-time, when a task must begin execution
Applicable to periodic tasksApplicable to periodic tasksAnalysis inputs
Periodic arrival timeExecution timePeriodic ending deadlineR l ti i it f h t kRelative priority of each task
Predictable but inflexible approachAny change in the requirements of tasks imply the Any change in the requirements of tasks imply the computation of a new schedule
Example: Earliest-deadline first
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2222 --
Static priorityStatic priority--driven preemptivedriven preemptive
Uses standard priority-driven preemptive schedulerStatic analysis is performed
No schedule is drawn-upAssigns priorities to tasksIn RT systems depends on time constraints associated to tasksto tasks
Example: Rate Monotonic
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2323 --
Dynamic planningDynamic planning--basedbased
Feasibility is determined at run-time Rather then offline
A task is accepted for execution If and only if it is feasible to meet its time constraints
Before its execution An attempt is made to create a schedule including previous tasks and the new oneThe deadline of the extended task set must be metThe deadline of the extended task set must be met
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2424 --
Dynamic bestDynamic best--efforteffort
Used in many commercial RT systems lEasy to implement
No feasibility analysis is performedTypically the tasks are aperiodic and no static Typically, the tasks are aperiodic and no static scheduling analysis is possible
When a task arrivesThe system assign a priority based on its characteristics
E.g., based on earliest deadlinesE.g., based on earliest deadlinesThe system tries to meet deadlines and aborts any started process whose deadline is missed
il h k i l d ( d dli i ) i i Until the task is completed (or deadline arrives), it is unknown if time constraints will be met
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2525 --
Deadline schedulingDeadline scheduling
Real-time applications are not concerned with speed but with completing tasksPriorities
Provide a crude tool Do not capture the requirement of completion or initiation at the most valuable timeinitiation at the most valuable time
Other deadline related information should be taken into accountinto account
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2626 --
Deadline scheduling: Deadline scheduling: Other informationOther informationOther informationOther information
Ready time h h k d f Time at which task is ready for execution
For periodic task it is a sequence of times Known in advanceKnown in advance
Starting/completion deadlineTypical RT application have either deadlines, but not yp pp ,both
Processing timeI it i li dIn some cases it is suppliedIn others cases the operating system measures an exponential averagep g
Resource requirementsIn addition to microprocessor
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2727 --
Deadline scheduling: Deadline scheduling: Other informationOther informationOther informationOther information
PriorityMeasures relative importance of tasksHard-RT tasks have “absolute” priority
Subtask structureTask possibly decomposed in
M d b k h l i h h d RT d dliMandatory subtasks: the only with hard RT deadlinesOptional subtasks: all other subtasks
…
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2828 --
Design issuesDesign issues
Which task to schedule next?For a given preemption strategy, scheduling tasks with the earliest deadline minimizes the fraction of tasks that miss their deadlines tasks that miss their deadlines
True for single and multiprocessor configurations
What sort of preemption is allowed?What sort of preemption is allowed?When starting deadlines are given, non-preemptive scheduler makes senseThe RT task has the responsibility to block itself afterexecuting the critical portion, allowing starting other RT d dliRT deadlines
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 2929 --
Example: Periodic tasksExample: Periodic tasks
A system collects and processes data from two sensors, A and BDeadlines:
A must be read every 20 msB must be read every 50 ms
P i ti (i l di OS h d) Processing time (including OS overhead): Processing data from A requires 10 msP i g d t f B i 25 Processing data from B requires 25 ms
The system makes scheduling decision every 10 ms
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3030 --
Example: Periodic tasksExample: Periodic tasks
Process Arrival time Execution time DeadlineA(1) 0 10 20A(2) 20 10 40A(2) 20 10 40A(3) 40 10 60A(4) 60 10 80… … … …… … … …
B(1) 0 25 50B(2) 50 25 100… … … …
B(1) deadline
B(1) deadline
A(1) deadline
A(2) deadline
A(3) deadline
A(4) deadline
A(5) deadline
A(6) deadline
time
Task A
Task B
0 10 20 30 40 50 60 70 80 90 100 110 120
A(1)
B(1)
A(2) A(3) A(4) A(5) A(6) A(7)
B(2) B(3)
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3131 --
time0 10 20 30 40 50 60 70 80 90 100 110 120
Example: Periodic tasksExample: Periodic tasks
Fixed priority schedulingTask A has priority Task B may miss some deadlines
A(1) B(1) A(2) A(3) A(4) A(5) A(6) A(7)B(2) B(3)B(1) B(2) B(2)B(3)
time0 10 20 30 40 50 60 70 80 90 100 110 120
B(1) is not rescheduled sinceits deadline has been reached
d ll h b l d
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3232 --
and will thus be violated
Example: Periodic tasksExample: Periodic tasks
Fixed priority schedulingTask B has priority Task A may miss some deadlines
B(1) A(2) A(3) A(5)B(2) B(3)
time0 10 20 30 40 50 60 70 80 90 100 110 120
A(1) missed deadline A(4) missed deadline
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3333 --
Example: Periodic tasksExample: Periodic tasks
Earliest deadline first with preemptionCompletion deadlines are consideredAt any preemption point the scheduler gives priority t th t k ith th li t d dlito the task with the earliest deadlineAll task can meet their deadlines
A(1) B(1) A(2) A(3) A(4) A(5) A(6) B(3)B(1) B(2)B(2)
time0 10 20 30 40 50 60 70 80 90 100 110 120
All task can be scheduled within their completion deadlines
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3434 --
Example: Aperiodic tasksExample: Aperiodic tasks
Five tasks All tasks have an execution time of 20 msArrival times are unknown Starting deadlines are considered
A B C D EA B C D E
AB C DE
time0 10 20 30 40 50 60 70 80 90 100 110 120
C
Arrival timesArrival times
Starting deadlines
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3535 --
Example: Aperiodic tasksExample: Aperiodic tasks
Earliest deadline firstStarting deadlines are unknown before the task becomes ready for schedulingS h d l th d t k ith th li t d dli Schedule the ready task with the earliest deadline and let the task run to completion
A B C D E
AB C DE
A E DC
time0 10 20 30 40 50 60 70 80 90 100 110 120
B missed deadline Tasks D and E are readyTask E has earliest deadline
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3636 --
Example: Aperiodic tasksExample: Aperiodic tasks
Earliest deadline with unforced idle timesPossible if deadlines are know before the task is ready
Schedule the eligible task with the earliest deadline L t th t k t l tiLet the task run to completion
Elegible tasks may not be ready Processor remains idle even though ready tasks existProcessor remains idle even though ready tasks exist
A B C D E
AB C DE
B E DC A
time0 10 20 30 40 50 60 70 80 90 100 110 120
Tasks A, D and E are readyTask E has earliest deadline
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3737 --
Example: Aperiodic tasksExample: Aperiodic tasks
First-Come, First-Serve (FCFS)Tasks are ordered based on their arrival timesTasks are served if their starting deadline is metTasks B and E do not meet their deadlines
A B C D EE missed deadline
AB C DE
DCA
time0 10 20 30 40 50 60 70 80 90 100 110 120
Tasks D and E are ready, with D coming firstTask D is served
B missed deadline
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3838 --
Rate Monotonic SchedulingRate Monotonic Scheduling
Each task has A period T An execution time C for each occurrence
In uniprocessor systems C < T
lProcessor Utilization is U = C/T (<100%)
ti
Period
Task P P P Ptime
ExecutionTime
IdleTime
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 3939 --
Rate Monotonic SchedulingRate Monotonic Scheduling
Assigns priorities to tasks On the basis of their periodsShortest period task has highest priority
High Highest priority
y
g
Highest rate
Highest priority
Prio
rity
Rate (Hz)
Low
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 4040 --
Rate Monotonic SchedulingRate Monotonic Scheduling
A measure of a the effectiveness of a periodic scheduling algorithm is its capability to meet deadlinesC id N t k ith Consider N tasks with
A fixed period Ti
A fixed execution time CA fixed execution time Ci
To meet all deadlines, the processor utilizations of individual tasks must not exceeds the available individual tasks must not exceeds the available computational power
N C∑=
≤N
i i
i
TC
1
1
C. Brandolese, W. FornaciariC. Brandolese, W. Fornaciari -- 4141 --