Multitasking and Scheduling of Real Time Processes, Some Strategies
Multitasking and Scheduling of Real Time Processes, Some Strategies
The following is a list of common scheduling practices and disciplines (ref Wikipedia):
Wewilldiscussa
fewoftheseinmore
details
Scheduling of RT processes
An absolute requirement in hard Real-Time systems
is that deadlines are met! Missing a deadline may
have catastrophic consequences. This requirement
is the baseline for true RT Operating Systems!
In soft Real-Time systems deadlines may however
occasionally be missed without leading to
acatastropy. For such such applications standard
OSs can be used (Windows, Linux, etc)
Since Linux is popular in many embedded systems, let us have a
quick look at some of its characteristics
Scheduling in Linux
A web search on Linux scheduling will give
numerous hits, not least on hacker-type and/or RealTime improvements of the scheduler.
The following pages on Linux 2.6.8.1 have been copied from
http://josh.trancesoftware.com/linux/linux_cpu_scheduler.pdf
in 2007, a reference which is no longer available
Linux 2.6.8.1
1/2
Linux2.6.8.1Schedulerstaticpriorities:
Alltaskshasastaticpriority,thenicevalue.Thenicevaluesrangefrom
20to19,thehighervaluebeinglowerpriority(nicer).
Linux 2.6.8.1
2/2
VxWorks multitasking
Multitasking provides the fundamental mechanism
for an application to control and react to multiple,
discrete real-world events. The VxWorks real-time
kernel, wind, provides the basic multitasking
environment. Multitasking creates the appearance of
many threads of execution running concurrently
when, in fact, the kernel interleaves their execution
on the basis of a scheduling algorithm. Each
apparently independent program is called a task.
Each task has its own context, which is the CPU
environment and system resources that the task
sees each time it is scheduled to run by the kernel.
On a context switch, a task's context is saved in the
task control block (TCB). A task's context includes:
T.B. Skaali, Department of Physics, University of Oslo
10
VxWorks multitasking
Task context:
11
12
13
14
Whatfollowsaresomepagesonschedulingfrom
thebookbyBurns&Wellings,withafewadd
ons.
15
Scheduling
Standard Notation
B
C
D
I
J
N
P
R
T
U
a-z
Process-Based Scheduling
Rate-monotonic scheduling
Theorem:
25
Period, T
25
60
42
105
75
Priority, P
5
3
4
1
2
Note,onlyrelativepriorityvaluesarerelevant
Utilisation-Based Analysis
Ci
1/ N
U
N (2
1)
i 1 Ti
Liu and Layland
U 0.69 as N
Utilization Bounds
N
1
2
3
4
5
10
Utilization bound
100.0%
82.8%
78.0%
75.7%
74.3%
71.8%
Process Set A
Process Period ComputationTime Priority Utilization
T
C
P
U
a
b
c
50
40
30
12
10
10
1
2
3
0.24
0.25
0.33
10of12
10of10
10of10
10of10
Preempted
10of10
Executing
10
20
30
40
50
60
Time
Note!Processchasthehighestpriority
Process Set B
Process Period ComputationTime Priority Utilization
T
C
P
U
a
b
c
80
40
16
32
5
4
1
2
3
0.400
0.125
0.250
Process Set C
Process Period ComputationTime Priority Utilization
T
C
P
U
a
b
c
80
40
20
40
10
5
1
2
3
0.50
0.25
0.25
5of40
20of40
25of40
10of10
5of5
10of10
5of5
10
40of40
20
5of5
30
40
5of5
50
60
70
Time
Note!Processchasthehighestpriority
80
1
i 1 T
i
N
Response-Time Analysis
Here task i's worst-case response time, R, is calculated
first and then checked (trivially) with its deadline
R D
i
i
Ri Ci I i
5of40
b
c
interference
20of40
10of10
5of5
40of40
10of10
5of5
10
25of40
20
5of5
30
40
5of5
50
60
70
Note!Processchasthehighestpriority
80
Calculating R
During R, each higher priority task j will execute a number of
times:
Ri
Number of Releases
Tj
The ceiling function gives the smallest integer greater than the fractional
number on which it acts. So the ceiling of 1/3 is 1, of 6/5 is 2, and of 6/3 is 2.
Ri
Cj
Tj
jhp ( i ) T
j
Where hp(i) is the set of tasks with priority higher than task i
Solve by forming a recurrence relationship:
win 1
win
Ci
Cj
jhp ( i )
Tj
0
1
2
n
w
,
w
,
w
,...,
w
The set of values i i i
i ,.. is monotonically non decreasing
When win win 1 the solution to the equation has been found, wi0
must not be greater that Ri (e.g. 0 or Ci )
win : Ci
loop
n 1
calculate new wi
n 1
n
if wi wi then
Ri win
exit value found
end if
n 1
if wi Ti then
exit value not found
end if
n := n + 1
end loop
end loop
ImplementedintheFYS4220VxWorksprogramFPS_analysis.c
Process Set D
Process
a
b
c
Period
T
7
12
20
ComputationTime
C
3
3
5
Priority
P
3
2
1
wb0 3
Ra 3
3
w 3
36
7
1
b
6
w 3
36
7
Rb 6
2
b
wc0 5
5
5
wc1 5
3
3 11
7
12
11
11
wc2 5
3
3 14
7
12
14
3
wc3 5
14
12 3 17
17
17
w 5
3
3 20
7
12
20
20
5
wc 5
3
3 20
7
12
Rc 20
4
c
41
42
43
44
80
40
20
40
10
5
1
2
3
80
15
5
WCET Finding C
Most analysis techniques involve two distinct activities.
VxWorks timexLib
timexLib
NAME
timexLib - execution timer facilities
ROUTINES
timexInit( ) - include the execution timer library
timexClear( ) - clear the list of function calls to be timed
timexFunc( ) - specify functions to be timed
timexHelp( ) - display synopsis of execution timer facilities
timex( ) - time a single execution of a function or functions
timexN( ) - time repeated executions of a function or group of functions
timexPost( ) - specify functions to be called after timing
timexPre( ) - specify functions to be called prior to timing
timexShow( ) - display the list of function calls to be timed
DESCRIPTION
This library contains routines for timing the execution of programs, individual
functions, and groups of functions. The VxWorks system clock is used as a time
base. Functions that have a short execution time relative to this time base can
be called repeatedly to establish an average execution time with an acceptable
percentage of error.
49
Sporadic Processes
General Guidelines
Rule 1 all processes should be schedulable using
average execution times and average arrival rates
Rule 2 all hard real-time processes should be
schedulable using worst-case execution times and worstcase arrival rates of all processes (including soft)
Aperiodic Processes
Priority Inversion
Process
a
b
c
d
Priority
1
2
3
4
Execution Sequence
EQQQQE
EE
EVVE
EEQVE
Release Time
0
2
2
4
10
12
14
Executing
Preempted
Blocked
16
18
Priority Inheritance
If process p is blocking process q, then p runs with q's
priority. In the diagram below, q corresponds to d, while
both a and c can be p
Process
d(q)
c
b
a
0
10
12
14
16
18
POSIX
POSIX
Other Facilities
POSIX allows: