Anda di halaman 1dari 23

Operating System

OS is an interface between user and the hardware


It provides facilities for:
task management
task communication
hardware management (e.g. memory, devices) for security, efficiency,
robustness..
interface to user
RTOS is special OS for which task management is done on a specified
schedule and constraints.
Real Time Operating Systems: Schedule and Constraints
Deadline and response time requirements for tasks
Precedence between the tasks
Rate of execution
Mutual exclusion
What do we mean by Real Time
Hard RT: failure to execute a task on a schedule is catastrophic
Pre-runtime analysis / preparation to provide runtime guarantees
All requirement know before hand.
Firm RT: executing after the schedule is not useful
Soft RT: executing after the schedule degrades the performance
runtime changes for some kind of best effort quality of service (QoS)
Task Scheduler
runs at specific points in time: system calls, interrupts, signals, clock
interrupts
decides on which program to run next
manages data structure that store information about task states and their
execution statistics.

Schedulers
Guaranteed or best effort
Static or Dynamic
Preemptive or non-preemptive
Single or multi-processor
Central or distributed.
Task Model
Periodic task occurs with a periodic hard dealine
Aperiodic tasks have soft or no dealine
Sporadic tasks occur sporadically but with hard deadlines

Worst Case Execution Time (WCET) is used when exec. time are not known
tasks may have precedence between them
tasks can have fixed or dynamic priority over its execution time.
Comparing schedulers
Assume fixed set of n tasks with given periods (= deadlines) and WCETs
the tasks are independent, context switch cost is ignored.
A scheduler is called optimal (w.r.t. feasibility) if it can find a schedule
whenever it exists
Schedulers can also be compared on Lateness:

or on total completion time / makespan:

this is more of a performance metric.


Timeline Scheduling or Cyclic Executives
Everything is know about tasks, there are no pririties
Time divided into major cycle: LCM of periods of the tasks
Major cycles divided into minor cycles: composed of time units given to
tasks
all tasks periods should be multiple of minor cycle
Fully deterministic static planning
Consider tasks Ta, Tb, Tc, Td, Te, Tf with periods and execution times (p, e)
given respectively by: (10, 2), (10, 3), (20, 4), (20, 2), (20, 2), (40, 1) Find a
schedule for it.
Cyclic Executives:

Utilisation is not 100%: preemption can be used.


Tasks are considered as functions and share the address space
No sporadic or aperiodic tasks are allowed
Schedules can be stored in tables and different tables can be used for
different modes
Precedence constraints can be put on tasks
Cyclic Executives:
Very simple and predictable system
Validation and testing with high confidence. Easier certification.
Historically used in most safety critical system
No races conditions, deadlocks etc.
May need recalculation on minor changes in task parameters.
A good schedule needs significant computation
If tasks are dependent then problem in scheduling
Priority based scheduling: Rate Monotonic
Liu and Leyland (1973)
peremptive, fixed priority
rate of a task is inverse of its period
Assign higher priority to those with higher rates
At each decision point execute a task with highest priority, preempting if
another was running
Find a schedule for the following two tasks:
Rate Monotonic scheduling
Optimal with respect to feasibility for fixed priority scheduling
Consider when a non-RM schedule is feasible for two tasks.
Rate Monotonic scheduling: Schedulibility Tests

False negatives False positives

A common parameter used for schedulibility test is process utilisation:

For RM scheduling a sufficient condition for feasible schedule is:


Rate Monotonic scheduling: Schedulibility Tests
Example 1 (Sufficient):T1 (20, 7), T2 (50, 10), T3 (30, 5)
Example 2 (not necessary): T1 (80, 40), T2 (40, 10), T3 (20, 5)
RM scheduling may not give a feasible schedule even if the processor is
idle for some time.
Consider T1 (2, 1), T2 (3, 1). What happens if e1 or e2 change? Can p1 or
p2 be reduced?
In such cases:
optimise code to get WCETs smaller
increase periods for some tasks
In general RM scheduling is easy to implement and analyse. Used often in
RT systems.
Priority based scheduling: Earliest Deadline First
Horn (1974)
Preemptive, dynamic priorites
Supports arrival of tasks
Assign higher priority to those with closest deadlines
At each decision point execute a task with highest priority, preempting if
another was running
Minimizes maximum lateness:
Earliest Deadline First: Examples
Find a schedule for the following two tasks (p, e): (20, 5), (12, 10)

A feasible schedule is possible iff utilisation is less than 1

Is an EDF schedule possible for tasks: (5, 2), (7, 4)?


RM vs. EDF scheduling
EDF generally provides better utilisation (100% compared to a statistical
88% for RM)
EDF supports arrival of tasks which is not possible with RM
RM scheduling is easier to implement
EDF results in lesser preemptions, lowering context switch times
consider scheduling of (4, 1), (8, x) with EDF and RM
EDF also is more robust w.r.to changes in parameters
In case of overlaod, RM scheduling behaves better.
Least Laxity First (LLF)
Laxity = deadline - remaining computation time
Preemptive, dynamic
Assign the processor to the task with least laxity
Optimal w.r.t feasibility
Consider a LLF schedule for two tasks (8, 5), (7, 2)
Least Laxity First (LLF) may provide better utilisation on multiprocessors
Consider two processors, and 3 tasks: (10, 5), (10, 5), (12, 8)
Compare EDF and LLF schedules for these tasks.
Tasks with precedence
A precedence graph is provided:

Lawler's algorithm: latest deadline first (LDF), static scheduling


Start at the end, choose task on which no other task depends, and has
latest deadline
Tasks with precedence: supporting task arrival
Modified EDF: EDF*
Use modified deadlines:

For the example considered:


d1' = 1, d2' = 2, d3' = 4, d4' = 3, d5' = 5, d6' = 6.
Priority Inversion
A high-priority task is blocked while unrelated lower-priority tasks execute
Priority Inheritance Protocol
Sha et al. (1990)
When a task blocks attempting to acquire a lock, then the task that holds
the lock inherits the priority of the blocked task
Some deadlocks can be avoided by priorities
Sha et al. (1990) gave priority ceiling protocol
Every lock or semaphore is assigned a priority ceiling equal to the priority
of the highest-priority task that can lock it

Anda mungkin juga menyukai