View
225
Download
0
Category
Preview:
Citation preview
8/12/2019 Embedded Systems Unit III
1/78
8/12/2019 Embedded Systems Unit III
2/78
SITE 2
8/12/2019 Embedded Systems Unit III
3/78
SITE 3
Example: engine control Tasks:
spark control crankshaft sensing
fuel/air mixture oxygen sensor filter
enginecontroller
8/12/2019 Embedded Systems Unit III
4/78
SITE 4
Task graphs Tasks may have data
dependencies---mustexecute in certain order.
Task graph showsdata/controldependencies betweenprocesses.
Task : connected set ofprocesses.
Task set : One or moretasks.
P3
P1 P2
P4
P5
P6
task 1 task 2
task set
8/12/2019 Embedded Systems Unit III
5/78
SITE 5
Communication between tasks Task graph assumes that
all processes in each taskrun at the same rate,tasks do notcommunicate.
In reality, some amount ofinter-task communicationis necessary. Its hard to require
immediate response formulti-rate communication.
MPEGsystem
layer
MPEG
audio
MPEG
video
8/12/2019 Embedded Systems Unit III
6/78
SITE 6
8/12/2019 Embedded Systems Unit III
7/78
SITE 7
8/12/2019 Embedded Systems Unit III
8/78
SITE 8
8/12/2019 Embedded Systems Unit III
9/78
SITE 9
8/12/2019 Embedded Systems Unit III
10/78
8/12/2019 Embedded Systems Unit III
11/78
SITE 11
8/12/2019 Embedded Systems Unit III
12/78
SITE 12
8/12/2019 Embedded Systems Unit III
13/78
SITE 13
8/12/2019 Embedded Systems Unit III
14/78
SITE 14
Buggy cooperative multitasking system
Void process 1 ()
{If(input 1==0)
{
subA();
}
Else
{
subB();Switch();S
}
}
8/12/2019 Embedded Systems Unit III
15/78
SITE 15
Process2 ()
{
X =global 1; // global 1 is input to the process
While(x
8/12/2019 Embedded Systems Unit III
16/78
SITE 16
8/12/2019 Embedded Systems Unit III
17/78
SITE 17
8/12/2019 Embedded Systems Unit III
18/78
SITE 18
8/12/2019 Embedded Systems Unit III
19/78
SITE 19
8/12/2019 Embedded Systems Unit III
20/78
SITE 20
Processes and operatingsystems
Scheduling policies: RMS; EDF.
Scheduling modeling assumptions.
8/12/2019 Embedded Systems Unit III
21/78
SITE 21
Rate monotonic scheduling RMS (Liu and Layland): widely-used,
analyzable scheduling policy. Analysis is known as Rate Monotonic
Analysis (RMA).
8/12/2019 Embedded Systems Unit III
22/78
SITE 22
RMA model All process run on single CPU. Zero context switch time.
No data dependencies betweenprocesses. Process execution time is constant.
Deadline is at end of period. Highest-priority ready process runs.
8/12/2019 Embedded Systems Unit III
23/78
SITE 23
Rate-monotonic analysis Response time : time required to finish
process. Critical instant : scheduling state that gives
worst response time. Critical instant occurs when all higher-
priority processes are ready to execute.
8/12/2019 Embedded Systems Unit III
24/78
SITE 24
RMS priorities Optimal (fixed) priority assignment:
shortest-period process gets highest priority; priority inversely proportional to period; break ties arbitrarily.
No fixed-priority scheme does better.
8/12/2019 Embedded Systems Unit III
25/78
SITE 25
RMS CPU utilization, contd. RMS cannot use 100% of CPU, even with
zero context switch overhead. Must keep idle cycles available to handle
worst-case scenario. However, RMS guarantees all processes
will always meet their deadlines.
8/12/2019 Embedded Systems Unit III
26/78
SITE 26
RMS implementation Efficient implementation:
scan processes; choose highest-priority active process.
8/12/2019 Embedded Systems Unit III
27/78
SITE 27
8/12/2019 Embedded Systems Unit III
28/78
SITE 28
8/12/2019 Embedded Systems Unit III
29/78
SITE 29
8/12/2019 Embedded Systems Unit III
30/78
SITE 30
8/12/2019 Embedded Systems Unit III
31/78
SITE 31
8/12/2019 Embedded Systems Unit III
32/78
SITE 32
8/12/2019 Embedded Systems Unit III
33/78
SITE 33
8/12/2019 Embedded Systems Unit III
34/78
SITE 34
8/12/2019 Embedded Systems Unit III
35/78
SITE 35
E li d dli fi
8/12/2019 Embedded Systems Unit III
36/78
SITE 36
Earliest-deadline-firstscheduling
EDF : dynamic priority scheduling scheme. Process closest to its deadline has highest
priority. Requires recalculating processes at every
timer interrupt.
8/12/2019 Embedded Systems Unit III
37/78
SITE 37
EDF analysis EDF can use 100% of CPU. But EDF may fail to miss a deadline.
8/12/2019 Embedded Systems Unit III
38/78
SITE 38
EDF implementation On each timer interrupt:
compute time to deadline; choose process closest to deadline.
Generally considered too expensive to usein practice.
8/12/2019 Embedded Systems Unit III
39/78
SITE 39
8/12/2019 Embedded Systems Unit III
40/78
SITE 40
8/12/2019 Embedded Systems Unit III
41/78
SITE 41
EARLIEST DEADLINE FIRST SCHEDULING
CONSIDER THE FOLLOWING PROCESSES
PROCESS EXECUTION TIME PERIOD
P1 1 3
P2 1 4
P3 2 5
8/12/2019 Embedded Systems Unit III
42/78
SITE 42
P1=3,1 P2=4,1 P3=5,3
TIME RUNNING PROCESS DEADLINE
0 P11 P2
2 P3 P1
3 P3 P24 P1 P3
5 P2 P1
6 P17 P3 P2
8 P3 P1
9 P1 P3
8/12/2019 Embedded Systems Unit III
43/78
SITE 43
P1=3,1 P2=4,1 P3=5,3
TIME RUNNING PROCESS DEADLINE
10 P2
11 P3 P1,P2
12 P3 P1
13 P1 P2
14 P2 P1,P3
15 P1 P2
16 P2
17 P3 P1
18 P3 P1
8/12/2019 Embedded Systems Unit III
44/78
SITE 44
Fixing scheduling problems What if your set of processes is
unschedulable? Change deadlines in requirements. Reduce execution times of processes. Get a faster CPU.
8/12/2019 Embedded Systems Unit III
45/78
SITE 45
Priority inversion Priority inversion : low-priority process
keeps high-priority process from running. Improper use of system resources can
cause scheduling problems: Low-priority process grabs I/O device. High-priority device needs I/O device, but
cant get it until low -priority process is done. Can cause deadlock.
8/12/2019 Embedded Systems Unit III
46/78
SITE 46
8/12/2019 Embedded Systems Unit III
47/78
SITE 47
8/12/2019 Embedded Systems Unit III
48/78
SITE 48
Solving priority inversion Give priorities to system resources. Have process inherit the priority of a
resource that it requests. Low-priority process inherits priority of device
if higher.
8/12/2019 Embedded Systems Unit III
49/78
SITE 49
Data dependencies Data dependencies
allow us to improveutilization.
Restrict combination ofprocesses that can runsimultaneously.
P1 and P2 cant run
simultaneously.
P1
P2
8/12/2019 Embedded Systems Unit III
50/78
SITE 50
Context-switching time Non-zero context switch time can push
limits of a tight schedule. Hard to calculate effects---depends on
order of context switches. In practice, OS context switch overhead is
small (hundreds of clock cycles) relative tomany common task periods (ms ms).
8/12/2019 Embedded Systems Unit III
51/78
SITE 51
Interprocess communication
Interprocess communication (IPC ): OSprovides mechanisms so that processescan pass data.
Two types of communications: blocking : sending process waits for response; non-blocking : sending process continues.
8/12/2019 Embedded Systems Unit III
52/78
SITE 52
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 commonaddress space.
8/12/2019 Embedded Systems Unit III
53/78
SITE 53
Shared memory
Shared memory on a bus:
CPU 1 CPU 2memory
R di i i h d
8/12/2019 Embedded Systems Unit III
54/78
SITE 54
Race condition in sharedmemory
Problem when two CPUs try to write thesame location: CPU 1 reads flag and sees 0. CPU 2 reads flag and sees 0. CPU 1 sets flag to one and writes location. CPU 2 sets flag to one and overwrites
location.
8/12/2019 Embedded Systems Unit III
55/78
SITE 55
8/12/2019 Embedded Systems Unit III
56/78
SITE 56
8/12/2019 Embedded Systems Unit III
57/78
SITE 57
Critical regions
Critical region : section of code that cannotbe interrupted by another process.
Examples: writing shared memory; accessing I/O device.
8/12/2019 Embedded Systems Unit III
58/78
SITE 58
8/12/2019 Embedded Systems Unit III
59/78
SITE 59
8/12/2019 Embedded Systems Unit III
60/78
SITE 60
8/12/2019 Embedded Systems Unit III
61/78
SITE 61
8/12/2019 Embedded Systems Unit III
62/78
SITE 62
8/12/2019 Embedded Systems Unit III
63/78
SITE 63
Message passing
Message passing on a network:
CPU 1 CPU 2
message message
message
8/12/2019 Embedded Systems Unit III
64/78
SITE 64
8/12/2019 Embedded Systems Unit III
65/78
SITE 65
Process data dependencies
One process may notbe able to start untilanother finishes.
Data dependenciesdefined in a taskgraph .
All processes in onetask run at the samerate.
P1 P2
P3
P4
INTERPROCESS COMMUNICATION MECHANISMSSIGNALS POSIX
8/12/2019 Embedded Systems Unit III
66/78
SITE 66
SIGNALS POSIX
Signal Description
SIGABRT Abnormal termination signal such asissued by the abort() function.
SIGALRM Timeout signal such as issued by thealarm() function.
SIGHUP Death of session leader, or hangupdetected on controlling terminal.
SIGILL Detection of an invalid hardwareinstruction. Note that if a second faultoccurs while your process is in a signalhandler for this fault, the process will beterminated.
SIGINT Interactive attention signal ( Break ).
SIGKILL Termination signal should be used onlyfor emergency situations. This signalcannot be caught or ignored .
SIGPIPE Attempt to write on a pipe with noreaders.
SIGQUIT Interactive termination signal.
INTERPROCESS COMMUNICATION MECHANISMSSIGNALS
http://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/a/abort.htmlhttp://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/a/alarm.htmlhttp://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/a/alarm.htmlhttp://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/a/abort.html8/12/2019 Embedded Systems Unit III
67/78
SITE 67
SIGNALS
Signal Description
SIGSEGV
Detection of an invalid memory reference.Note that if a second fault occurs whileyour process is in a signal handler for thisfault, the process will be terminated.
SIGSTOP Stop process (the default).Thi s signal
cannot be caught or ignored . SIGSYS Bad argument to system call.
SIGTERM Termination signal.
SIGUSR1 Reserved as application-defined signal 1.
SIGUSR2 Reserved as application-defined signal 2.
SIGWINCH Window size changed.
8/12/2019 Embedded Systems Unit III
68/78
SITE 68
CPU power consumption Most modern CPUs are designed with
power consumption in mind to somedegree.
Power vs. energy: heat depends on power consumption; battery life depends on energy consumption.
8/12/2019 Embedded Systems Unit III
69/78
SITE 69
CMOS power consumption Voltage drops : power consumption
proportional to V 2. Toggling : more activity means more
power. Leakage : basic circuit characteristics; can
be eliminated by disconnecting power.
8/12/2019 Embedded Systems Unit III
70/78
SITE 70
CPU power-saving strategies Reduce power supply voltage. Run at lower clock frequency. Disable function units with control signals
when not in use. Disconnect parts from power supply when
not in use.
8/12/2019 Embedded Systems Unit III
71/78
SITE 71
low power features Parallel execution units---longer idle shutdowntimes. Multiple data widths:
16-bit ALU vs. 40-bit ALU. Instruction caches minimizes main memory
accesses. Power management:
Function unit idle detection. Memory idle detection.
8/12/2019 Embedded Systems Unit III
72/78
SITE 72
Power management styles Static power management : does not
depend on CPU activity. Example: user-activated power-down mode.
Dynamic power management : based onCPU activity. Example: disabling off function units.
8/12/2019 Embedded Systems Unit III
73/78
SITE 73
Power optimization Power management : determining how
system resources are scheduled/used tocontrol power consumption.
OS can manage for power just as itmanages for time.
OS reduces power by shutting down units. May have partial shutdown modes.
Power management and
8/12/2019 Embedded Systems Unit III
74/78
SITE 74
gperformance
Power management and performance areoften at odds.
Entering power-down mode consumes energy, time.
Leaving power-down mode consumes energy, time.
Simple power management
8/12/2019 Embedded Systems Unit III
75/78
SITE 75
p p gpolicies
Request-driven : power up once request isreceived. Adds delay to response.
Predictive shutdown : try to predict how
long you have before next request. May start up in advance of request in
anticipation of a new request. If you predict wrong, you will incur additional
delay while starting up. Ex :- pagers
8/12/2019 Embedded Systems Unit III
76/78
SITE 76
Probabilistic shutdown Assume service requests are probabilistic. Optimize expected values:
power consumption; response time.
Simple probabilistic: shut down after timeTon , turn back on after waiting for T off .
Advanced Configuration and
8/12/2019 Embedded Systems Unit III
77/78
SITE 77
gPower Interface
ACPI : open standard for powermanagement services.
Hardware platform
devicedrivers
ACPI BIOS
OS kernel
applications power
management
8/12/2019 Embedded Systems Unit III
78/78
ACPI global power statesFive basic global power states
G3: mechanical off G2: soft off
S1: low wake-up latency with no loss of context S2: low latency with loss of CPU/cache state S3: low latency with loss of all state except memory S4: lowest-power state with all devices off
G1: sleeping state G0: working state Legacy state
Recommended