Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Embedded Systems
6 - Operating Systems
RMR2012
tc
he
RMR2012
t up rr g te in in andl h
Process state
executing
preempted
gets data
ready
needs data
waiting
RMR2012
RMR2012
RMR2012
Hardware
Hardware
System
System Components
RMR2012
Typical OS Conguration
Priority-driven scheduling
Each process has a priority. CPU goes to highest-priority process that is ready. Priorities determine scheduling policy:
xed priority;
Maths is not everything
RMR2012
time-varying priorities.
Rules:
each process has a xed priority (1 highest); highest-priority ready process gets CPU; process continues until done.
P2 ready t=0 P3 ready t=18 P1 ready t=15
P2
0
Maths is not everything
P1
10 20
P2
30 40
P3
50
time 60
P1: priority 1, execution time 10 P2: priority 2, execution time 30 P3: priority 3, execution time 20
RMR2012
RMR2012
Periodic process: executes on (almost) every period. Aperiodic process: executes on demand. Analyzing aperiodic process sets is harder---must consider worst-case combinations of process activations.
RMR2012
Period: interval between process activations. Initiation interval: reciprocal of period. Initiation time: time at which process becomes ready.
Maths is not everything
RMR2012
RMR2012
A real-time system is any information processing system which has to respond to externally generated input stimuli within a finite and specified period
the correctness depends not only on the logical result but also the time it was delivered failure to respond is as bad as the wrong response!
Maths is not everything
RMR2012
14
Flow meter
Processing
Valve
RMR2012
15
Timing violations
RMR2012
Interface
Data Logging
Operators Console
Operator Interface
Real-Time Computer
RMR2012
17
Characteristics of a RTS
RMR2012
18
Characteristics of a RTS
we need to be able to predict with condence the worst case response times for systems; efciency is important but predictability is essential
RMR2012
19
RMR2012
Synchronisation and Communication The correct behaviour of a concurrent program depends on synchronisation and communication between its processes Synchronisation: the satisfaction of constraints on the
interleaving of the actions of processes (e.g. an action by one process only occurring after an action by another)
Data communication is usually based upon either shared variables or message passing.
RMR2012
21
Interprocess communication
Interprocess communication (IPC): OS provides mechanisms so that processes can pass data. Two types of semantics:
blocking: sending process waits for response;
Maths is not everything
RMR2012
IPC styles
Shared memory:
processes have some memory in common; must cooperate to avoid destroying/missing messages.
Message passing:
processes send messages along a communication channel---no common address space.
Maths is not everything
RMR2012
Shared memory
CPU 1
CPU 2
RMR2012
RMR2012
Atomic test-and-set
RMR2012
Critical regions
Critical region: section of code that cannot be interrupted by another process. Examples:
writing shared memory; accessing I/O device.
Maths is not everything
RMR2012
Semaphores
RMR2012
Semaphores
A semaphore is a non-negative integer variable that apart from initialization can only be acted upon by two procedures P (or WAIT) and V (or SIGNAL) WAIT(S) If the value of S > 0 then decrement its value by one; otherwise delay the process until S > 0 (and then decrement its value). SIGNAL(S) Increment the value of S by one. WAIT and SIGNAL are atomic (indivisible).
Maths is not everything
Two processes both executing WAIT operations on the same semaphore cannot interfere with each other and cannot fail during the execution of a semaphore operation
RMR2012
29
Condition synchronisation
process P1; (* waiting process *) statement X; wait (consyn) statement Y; end P1;
process P2; (* signalling proc *) statement A; signal (consyn) statement B; end P2;
RMR2012
30
Mutual Exclusion
(* mutual exclusion *) var mutex : semaphore; (* initially 1 *)
process P1; statement X wait (mutex); statement Y signal (mutex); statement Z end P1;
process P2; statement A; wait (mutex); statement B; signal (mutex); statement C; end P2;
RMR2012
31
Deadlock
Two processes are deadlocked if each is holding a resource while waiting for a resource held by the other
type Sem is ...; X : Sem := 1; Y : Sem := 1; task A; task body A is begin ... Wait(X); Wait(Y); ... end A; task B; task body B is begin ... Wait(Y); Wait(X); ... end B;
RMR2012
32
Livelock
Two processes are livelocked if each is executing but neither is able to make progress.
type Flag is (Up, Down); Flag1 : Flag := Up; task A; task body A is begin ... while Flag1 = Up loop null; end loop; ... end A; task B; task body B is begin ... while Flag1 = Up loop null; end loop; ... end A;
RMR2012
33
A binary semaphore (MUTEX) only takes the value 0 and 1; the signalling of a semaphore which has
the value 1 has no effect - the semaphore retains the value 1
A general semaphore can be implemented by two binary semaphores and an integer. With a quantity semaphore the amount to be decremented by WAIT (and incremented by SIGNAL) is given as a parameter; e.g. WAIT (S, i)
RMR2012
34
RMR2012
35
One process may not be able to start until another finishes. Data dependencies defined in a task graph.
P1
P2
P3 P4
RMR2012
Process P1
send message
Maths is not everything
RMR2012
time
time
Variations in the process synchronisation model arise from the semantics of the send operation Asynchronous (or no-wait) (e.g. POSIX)
Requires buffer space. What happens when the buffer is full?
Process P2
receive message
RMR2012
time
time
receive message
RMR2012
time
time
Process P2
receive message
RMR2012
void move_arm(int D, int P); #define DEFAULT_NBYTES 4 int nbytes = DEFAULT_NBYTES; #define MQ_XPLANE "/mq_xplane" #define MQ_YPLANE "/mq_yplane" #define MQ_ZPLANE "/mq_zplane" #define MODE . . . /* mode info /* names of message queues */ -- message queue name -- message queue name -- message queue name for mq_open */
RMR2012
41
RMR2012
42
Now the main program which creates the controller processes and passes the appropriate coordinates to them:
void (*C)(dimension dim) = &controller; int main(int argc, char **argv) { mqd_t mq_xplane, mq_yplane, mq_zplane; struct mq_attr ma; /* queue attributes */ int xpid, ypid, zpid; char buf[DEFAULT_NBYTES]; /* set message queues attributes*/ ma.mq_flags = 0; /* No special behaviour */ ma.mq_maxmsg = 1; ma.mq_msgsize = nbytes; mq_xplane = MQ_OPEN(MQ_XPLANE, O_CREAT|O_EXCL, MODE, &ma); mq_yplane = ...; mq_zplane = ...;
RMR2012
43
RMR2012
44
Message passing
CPU 1 message
2008 Wayne Wolf
Maths is not everything
RMR2012