Process Scheduling for RTS - PowerPoint PPT Presentation

About This Presentation
Title:

Process Scheduling for RTS

Description:

Process Scheduling for RTS RTS Scheduling Approach RTS typically control multiple parameters concurrently Eg. Flight Control System Speed, altitude, inclination etc.. – PowerPoint PPT presentation

Number of Views:221
Avg rating:3.0/5.0
Slides: 29
Provided by: HMe98
Category:
Tags: rts | process | scheduling | unix

less

Transcript and Presenter's Notes

Title: Process Scheduling for RTS


1
Process Scheduling for RTS
2
RTS Scheduling Approach
  • RTS typically control multiple parameters
    concurrently
  • Eg. Flight Control System
  • Speed, altitude, inclination etc..
  • Options
  • Use a single process
  • Simple/limited approach but can be dangerous
  • No OS required
  • Use multiple processes
  • More complex but more robust
  • Use threads
  • Light weight relative to processes

3
Cyclic Executive Approach
  • Single Process
  • while(1)
  • Task 1
  • Task 2
  • ..
  • ..
  • Task n
  • Encapsulate all tasks within single infinite loop

4
Cyclic Executive
  • Ok for very well defined / periodic tasks with
    bounded execution times
  • Need to ensure that tasks cannot block and halt
    all others
  • May need to slow it down to meet particular task
    reqds
  • Eg. Above example will run as fast as processor
    can handle tasks
  • Possible Strategy
  • Run as fast as required by highest freq task
  • Use lower harmonics for remaining tasks
  • Eg. Highest freq Task is 100 Hz
  • Other tasks at 50Hz, 25 Hz etc
  • Possible use counters to control sequence
  • Possible use of timers to sleep
  • Limited scope for aperiodic tasks eg. Interrupts
  • Hardware specific?very limited portability

5
Cyclic Executive
  • AS Example
  • Cyclic executive approach
  • Each AS station handles well defined tasks
  • Execution time of each task precisely known
  • Task schedule customised s.t.total task runtime
    will facilitate/meet response time
  • Slack time in each cycle built in for interrupt
    processing
  • If total task time exceeded repeatedly, timeout
    fault

6
Multiple Process Approach
  • Each process is much more simple as handling a
    small subset of overall system
  • Overall system
  • More robust and reliable
  • More scalable
  • Can run on multiprocessor machine
  • Modular
  • Process code more portable
  • Protected
  • Each process operates in isolation with dedicated
    memory ? less risk of overall system failure
  • Downside
  • Requires an OS to schedule multiple processes
  • More memory reqd for process overhead
  • Communication between processes has to be
    explicitly done (advantage!)

7
Multiple Process
  • Generic Process States
  • Dormant Process created but not eligible to
    execute
  • Ready Process released and eligible to execute
    but not doing so
  • May be preempted
  • May have been blocked for resources ? move to
    ready
  • May have reached end of timeslice
  • Executing Process being executed
  • Suspended (Blocked) Process waiting for resource
    to be freed or self-suspended
  • Terminated Process finished execution

8
Process State Diagram
Pre-empt or Timeslice allocated
Executing
Blocked/ Self suspended
Resource freed
Blocked
Preempted, timeslice up
Ready
Resource freed
Process terminated
Schedule Task
Terminated
Dormant
9
Scheduling for RTS
  • Fundamental OS function
  • More critical for RTS
  • Allocating resources and scheduling tasks to
    ensure that deadlines are met
  • Schedule is feasible iff all the tasks start
    after their release time and complete before
    their deadlines
  • Scheduling Policy may be determined
  • Pre-run-time
  • Schedule created offline
  • Not unlike Cyclic Executive approach
  • Run-time
  • Schedule determined online as tasks arrive
  • Needs to be done quickly!

10
Scheduling for RTS
  • Static versus Dynamic Priority
  • Static Priority Scheduling Alg.
  • Task priority does not change
  • Rate Monotonic Alg.
  • Dynamic Priority Scheduling Alg.
  • Priority can change over time
  • Earliest Deadline First (EDF)
  • Preemptive versus non-preemptive
  • Preemptive Schedule
  • Task can be preempted by other tasks
  • Penalty of context switches
  • Non preemptive
  • Task runs to completion unless blocked over
    resource

11
Task Characteristics Ti
  • Precedence Constraints
  • Other tasks reqd before task Ti can run
  • Release Time
  • of task Ti ri
  • Phase Fi
  • of task Ti release time of 1st instance of
    task Ti
  • Execution time ei
  • of task Ti time (worst case) for task to
    complete
  • Period pi
  • interval between consecutive instances of task
    Ti (presuming periodic)
  • Absolute Deadline Di
  • instant by which task must be complete
  • Relative Deadline di
  • .. Relative to release time ri

12
Task Characteristics Ti
pi
di
ei
Di
ri
Fi
13
Simplifications
  • All tasks are periodic
  • Relative deadline is equal to period
  • No precedence constraints
  • No task has any non-preemptible sections
  • Cost of preemption is zero
  • Non CPU resources are infinite eg. Memory / I/O
  • ? limited use in the real world!

14
Rate Monotonic Scheduling
  • Run time scheduling, Static priority and
    Preemptive
  • Priority inversely related to period
  • Eg. Given task Ti and Tj where pi lt pj
  • Priority of task Ti greater than Tj
  • Scheduling decision made when
  • Current task execution complete
  • New task released
  • Recall In real world, RTS tasks with higher freq
    typically require shortest response times and are
    the most critical
  • Recall task Ti utilisation ui ei / pi
  • Overall CPU Utilisation U

15
RM Example
All Tasks released at time 0
Priority T1 gt T2 gt T3 Overall U
0.9 Sequence 1st inst Task 1 runs to
completion 1st inst Task 2 runs to completion 1st
inst Task 3 runs for 1 unit ..at Eu4, Task 1
released ? preempts Task 3 2nd inst Task 1 runs
to completion ..at Eu 5, Task 2 released 2nd
inst Task 2 runs to completion 1st inst Task 3
runs for 1 unit .. At Eu 8, Task 1 released
? preempts Task3 3rd inst Task 1 runs to
completion 1st inst Task 3 runs for 1 unit ..
At Eu 10, 3rd inst of Task 2 released ?
preempts 3 .. At Eu 15, 1st inst Task 3
completes.. CPU idle Eu 18-20 At Eu 20, all 3
tasks released .. Cycle repeats
Task e p u
T1 1 4 0.25
T2 2 5 0.4
T3 5 20 0.25
1 2 2 3 1 2 2 3 1 3 2 2 1 3 3
2 1 2 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20 Execution Units Eu
16
RM Scheduling
  • General schedulability test
  • If overall CPU utilisation U lt n(21/n -1)
  • where n no of tasks
  • RM will definitely produce feasible schedule
  • However
  • RM may produce feasible schedule where
  • U gt n(21/n -1)
  • i.e. Sufficient but not necessary condition
  • Recall Example CPU U 0.9 but still schedulable
  • Depends on particular task characteristics
  • May need to perform further schedulability
    analysis
  • As Task no increases, bound ? 69

17
Utilisation Bound for RM Alg.
1
0.83
0.78
0.69
0.73
Bound
8
1
2
3
4
5
6
10
No of Tasks
18
RM Schedulability Analysis
  • Eg. Taskset T1 T2 T3 T4 where
  • p1 lt p2 lt p3 lt p4
  • Task 1
  • Highest priority.. never preempted
  • Will run immediately once released
  • For Task1 to be feasibly scheduled
  • Only condition is that e1 lt p1
  • Include Task 2
  • Can only preempted by Task 1
  • Will be executed iff can find sufficient time e2
    over period 0, p2
  • Say Task 2 completes at time t within 0, p2
  • How many times did Task 1 run over 0,t ?
  • Each iteration must also complete in this
    interval 0,t

19
RM Schedulability Analysis
  • Over interval 0,t, Task 1 completes
  • Must satisfy condition
  • t e2 e1
  • Need to find t over interval 0, p2
  • Only need to check this when new instances of
    task 1 are released
  • Find integer k such that
  • k p1 gt k e1 e2
  • k p1 lt p2

20
RM Schedulability Analysis
  • Include Task 3
  • Can be preempted by Task 1 and 2
  • Need to find t over 0,p3 such that
  • Need to check only at multiples of p1 and/or p2
  • Similar analysis for Task 4
  • Can be preempted by Task 1,2,3

21
RM Schedulability Analysis
  • General Rule
  • Wi(t)
  • total work carried out by tasks T1T2T3... Ti
    initiated in interval 0,t
  • If Wi(t) lt t , then schedule is feasible
  • ?(Wi(t) / t) lt 1
  • Wi(t) only changes at finite no of points when
    tasks are released
  • Points defined by

22
RM Schedulability Analysis
i ei pi
1 20 100
2 30 150
3 80 210
4 100 400
  • Consider Task set
  • Check points
  • W1 100
  • W2 100,150
  • W3 100,150,200.210
  • W4 100,150,200,210,300,400

23
RM Schedulability Analysis
  • Task 1 is RM Schedulable iff
  • e1lt100 (True)
  • Task 1/2 is RM Schedulable iff
  • e1 e2 lt 100 or .(True)
  • 2 e1 e2 lt 150 . (True)
  • Task 1/2/3 is RM Schedulable iff
  • e1 e2 e3 lt 100 or . (False)
  • 2 e1 e2 e3 lt 150 or .. (True)
  • 2 e1 2e2 e3 lt 200 or (True)
  • 3 e1 2e2 e3 lt 210 . (True)

24
RM Schedulability Analysis
  • Task 1/2/3/4 is RM Schedulable iff
  • e1 e2 e3 e4 lt 100 or . (False)
  • 2e1 e2 e3 e4 lt 150 or .. (False)
  • 2e1 2e2 e3 e4 lt 200 or (False)
  • 3e1 2e2 e3 e4 lt 210 or . (False)
  • 3e1 2e2 2e3 e4 lt300 or . (False)
  • 4e1 3e2 2e3 e4 lt400 . (False)
  • Task 4 not RM schedulable
  • Can also plot results
  • Check whether Wi(t) falls on or below Wi(t) t
    line

25
RM Schedulability Analysis
  • Wi(t)
  • W1
  • Interval 0,100
  • W1(t) e1 20
  • W2 checkpoints100,150
  • Interval 0,100 W2(t)
  • 20(1) 30(1) 50
  • Interval 0,150 W(t)
  • 20(2) 30(1) 70

26
RM Schedulability Analysis
  • W3 checkpoints100,150,200,210
  • W3(t)
  • Interval 0,100
  • W3(t) 20(1) 30(1) 80(1) 130
  • Interval 0,150
  • 20(2) 30(1) 80(1) 150
  • Interval 0,200
  • 20(2) 30(2) 80(1) 180
  • Interval 0,210
  • 20(3) 30(2) 80(1) 200

27
RM Schedulability Analysis
W1
W2
100
100
Wi(t) t
70
50
20
100
150
100
Time
Time
28
RM Schedulability Analysis
W3
W4
430
Wi(t) t
210
200
Wi(t) t
?
180
150
130
100
200
150
400
Time
Time
29
RM Schedulability Analysis
  • Sporadic Tasks
  • So far have only considered periodic tasks
  • ? unrealistic
  • Can view sporadic task as infrequent periodic
    task if can specify
  • Minimum interarrival time between release of
    successive sporadic tasks
  • Maximum execution time
  • If so, can set these as highest priority relative
    to true periodic tasks
  • ? Simply treat as additional task in RM analysis

30
Earliest Deadline First (EDF)
  • Dynamic priority and preemptable
  • Ready task whose absolute deadline is the
    earliest given highest priority
  • Task priorities are reevaluated when tasks
    released/completed
  • EDF is an optimal uniprocessor sched alg
  • If all tasks are periodic
  • Task 1n CPU U
  • If U lt1, then task set is EDF schedulable

31
EDF Example
All Tasks released at time 0
Overall U 0.9 Sequence 1st inst Task 1 runs 1st
as earliest deadline of 4 1st inst Task 2 runs to
completion 1st inst Task 3 runs for 1 unit
..note Deadline is 20 ..at Eu4, Task 1 rel.
? preempy Task 3 as deadline is 8 2nd inst Task
1 runs to completion ..at Eu 5, Task 2
released 2nd inst Task 2 runs to completion as
deadline is 10 1st inst Task 3 runs for 1 unit
.. At Eu 8, Task 1 released ? preempts
Task3 3rd inst Task 1 runs to completion 1st inst
Task 3 runs for 1 unit .. At Eu 10, Task 2 rel..
Preempts task 3 as deadline is 15 .. At Eu 12,
Task 1 runs as deadline 16 lt 20 At Eu 15 Task 2
released and runs with deadline 20 At Eu 16 Task
1 rel with deadline 20 ? no preemption
Task e p u
T1 1 4 0.25
T2 2 5 0.4
T3 5 20 0.25
1 2 2 3 1 2 2 3 1 3 2 2 1 3 3
2 2 1 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20 Execution Units Eu
32
EDF Example
All Tasks released at time 0
Overall U 0.93 Sequence 1st inst Task 1 runs
1st as earliest deadline of 3 1st inst Task 2
runs to completion .. At Eu3, 2nd inst Task 1
rel runs as deadline is 6 1st inst Task 3 runs
..at Eu5, Task 2 rel. ? doesnt preempt Task
3 as deadline is also 10 .. Task 3
completes .. At Eu 6, Task 1 released deadline
9 ?runs .. At Eu 7 Task 2 runs to completion
.. At Eu 9, Task 1 rel ? deadline 12 ..runs
.. At Eu 10, Task 3 rel. deadline 20, Task 2
also rel with deadline 15 ?Task 2 runs ..
At Eu 15, Task 1 and 2 released with deadlines
16,20 ? Task 1 runs .. At Eu16, Task 2
runs .. At Eu 18 Task 1 rel with deadline 21
but Task 3 has deadline 20 ? Task 3 runs
Task e p u
T1 1 3 0.33
T2 2 5 0.4
T3 2 10 0.2
1 2 2 1 3 3 1 2 2 1 2 2 1 3 3
1 2 2 3 3 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20 Execution Units Eu
33
EDF vs RM
  • With RM, priorities fixed
  • Lowest period tasks guaranteed proc time
  • Only higher period tasks will miss deadlines
  • In overload conditions, same lower priority tasks
    lose out
  • Bound on CPU utilisation must be considered
  • EDF, dynamic priority
  • More flexible.. Less predictable
  • All tasks may miss deadlines
  • Schedulable if CPU U lt1
  • May react poorly to overload condition

34
Conventional OS Scheduling
  • Time Sharing Emphasis
  • Balance needs of interactive and CPU intensive
    traffic
  • Complex alg
  • Constantly adjust process priority
  • CPU intensive processes lose priority as they run
  • As a process waits, priority is increased ? will
    get CPU slot sooner
  • Unix command nice
  • nice -20 process_high_priority
  • nice 20 process_low_priority
  • nice will work but underlying sched alg unchanged
  • Windows RealTime Threads
  • Somewhat equivalent

35
POSIX.4 RT Scheduling
  • Defines two main scheduling policies
  • SCHED_FIFO and SCHED_RR
  • Each have attributes
  • Also have SCHED_OTHER
  • Currently a single attribute priority
  • struct sched_param
  • int sched_priority
  • Eg. Could implement EDF by extending structure to
    include
  • struct timespec sched_deadline
  • struct timespec sched_timerequired

36
POSIX.4 RT Scheduling
  • SCHED_FIFO
  • Simple priority based preemptive scheduler
  • Most common in RTS
  • FIFO used to schedule processes within each
    priority level
  • If no other process exists at higher priority,
    process runs until complete
  • Next process at that priority (if present) then
    allocated CPU
  • Highest priority process guaranteed processor
    time

37
POSIX.4 RT Scheduling
  • SCHED_RR
  • Round robin used to timeslice among processes at
    same priority level
  • System provided timeslice
  • Use for lower priority tasks

38
POSIX.4 RT Scheduling
  • Setting scheduling policy and attribute
  • include ltsched.hgt
  • struct sched_param scheduling_parameters
  • int scheduling_policy
  • int i
  • scheduling_parameters.sched_priority17
  • isched_setscheduler(getpid( ),SCHED_FIFO,
    scheduling_parameters)
  • getpid( ) used to determine process ID
  • Process set to FIFO, priority 17

39
POSIX.4 RT Scheduling
  • Process priority ranges differ among OS
  • Need this info before setting priority level
  • int sched_rr_min, sched_rr_max
  • int sched_fifo_min, sched_fifo_max
  • sched_rr_minsched_get_priority_min(SCHED_RR)
  • sched_rr_maxsched_get_priority_max(SCHED_RR)
  • sched_fifo_minsched_get_priority_min(SCHED_FIFO)
  • sched_fifo_maxsched_get_priority_max(SCHED_FIFO)
  • Eg. 256 priority levels
  • FIFO range 128-255
  • RR range 0-127

40
POSIX.4 RT Scheduling
  • Eg.
  • includeltsched.hgt
  • int i
  • struct sched_param my_sched_params
  • // determine max FIFO priority level
  • my_sched_params.sched_priority
    sched_get_priority_max(SCHED_FIFO)
  • // Set priority
  • isched_setparam(getpid (),my_sched_params)
Write a Comment
User Comments (0)
About PowerShow.com