processes and operating systems zpriority-driven scheduling zscheduling policies: yrms; yedf....

44
Processes and operating systems Priority-driven scheduling Scheduling policies: RMS; EDF. Interprocess communication. Operating system performance. Power management.

Upload: sherman-newman

Post on 02-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Processes and operating systems

Priority-driven schedulingScheduling policies:

RMS; EDF.

Interprocess communication.Operating system performance.Power management.

Page 2: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Embedded vs. general-purpose scheduling

Workstations try to avoid starving processes of CPU access. Fairness = access to CPU.

Embedded systems must meet deadlines. Low-priority processes may not run for a

long time.

Page 3: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Priority-driven scheduling

Each process has a priority.CPU goes to highest-priority process

that is ready.Priorities determine scheduling

policy: fixed priority; time-varying priorities.

Page 4: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Priority-driven scheduling example

Rules: each process has a fixed priority (1 highest); highest-priority ready process gets CPU; process continues until done.

Processes P1: priority 1, execution time 10 P2: priority 2, execution time 30 P3: priority 3, execution time 20

Page 5: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Priority-driven scheduling example

time

P2 ready t=0 P1 ready t=15

P3 ready t=18

0 3010 20 6040 50

P2 P2P1 P3

Page 6: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Metrics

How do we evaluate a scheduling policy: Ability to satisfy all deadlines. CPU utilization---percentage of time devoted

to useful work. Scheduling overhead---time required to

make scheduling decision. Algorithm

Rate-monotonic scheduling (RMS)Earliest deadline first(EDF)

Page 7: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Rate monotonic scheduling

RMS (Liu and Layland): widely-used, analyzable scheduling policy.

Analysis is known as Rate Monotonic Analysis (RMA).

Page 8: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

RMA model

All process run on single CPU periodly .

Zero context switch time.No data dependencies between

processes.Process execution time is constant.Deadline is at end of period.Highest-priority ready process runs.

Page 9: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Process parameters

Ti is computation time of process i; i is period of process i.

period i

Pi

computation time Ti

Page 10: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

RMS priorities

Optimal (fixed) priority assignment:shortest-period process gets highest

priority;

Page 11: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

RMS example

time

0 5 10

P2 period

P1 period

P1

P2

P1 P1

Page 12: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Example

Process Execution time

period

P1 1 4

P2 2 6

P3 3 12Priority: P1,P2,P3

Need:

hyperperiod :12 length

executing P1-3times, P2-2times, P3-1times

Page 13: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

0 12108642

P1

P2

P3

CPU utilization: (1*3+2*2+3*1)/12=83.3%

Page 14: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Another Example

Process Execution time

period

P1 2 4

P2 3 6

P3 3 12Need: hyperperiod :12 length

executing P1-3times, P2-2times, P3-1times

P1-3times-6cpu unit cycles; P2-2times-6cpu unit cycles

P3-1time-3cpu unit cycles; sum=15 cpu unit cycles, but hyperperiod is 12 unit cycles.

No schedule algorithm!

Page 15: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

RMS CPU utilization

Utilization for n processes is

i Ti / i

As number of tasks approaches infinity, maximum utilization approaches 69%.

Page 16: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

RMS CPU utilization, cont’d.

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.

Page 17: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Earliest-deadline-first scheduling ( EDF)

EDF: dynamic priority scheduling scheme.

Process closest to its deadline has highest priority.

Requires recalculating processes at every timer interrupt.

Page 18: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

EDF analysis

EDF can use 100% of CPU.But EDF may fail to miss a deadline.

Page 19: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

ProcessTime period

P1 1 3P2 1 4P3 2 5

Time RP deadline 0 P1 d(P2)=3,d(P3)=41 P2 d(P3)=32 P3 d(P1)=3,d(P3)=23 P3 d(P1)=2,d(P2)=44 P1 d(P2)=3,d(P3)=55 P2 d(P1)=3,d(P3)=46 P1 d(P3)=37 P3 d(P3)=2, d(P2)=48 p3 d(P2)=3, d(P1)=39 P1 d(P2)=2, d(P3)=510 P2 d(P3)=411 P3 d(P1)=3,d(P3)=3,d(P2)=412 P1 d(P3)=2,d(P2)=313 P3 d(P2)=2,d(P1)=314 P2 d(P1)=2,d(P3)=515 P1 d(P2)=4,d(P3)=4

Page 20: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

EDF implementation

On each timer interrupt: compute time to deadline; choose process closest to deadline.

Generally considered too expensive to use in practice.

Page 21: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Fixing scheduling problems

What to do if your set of processes is unschedulable? Change deadlines in requirements. Reduce execution times of processes. Get a faster CPU.

Page 22: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

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

can’t get it until low-priority process is done.Can cause deadlock.

Page 23: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Solving priority inversion

Set the highest priority to the low-priority process

After executing this process, restore the low priority.

Page 24: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Data dependencies

Data dependencies allow us to improve utilization. Restrict

combination of processes that can run simultaneously.

P1 and P2 can’t run simultaneously.

P1

P2

Page 25: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

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 to many common task periods (ms – s).

Page 26: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Interprocess communication(进程间通讯 )

Interprocess communication (IPC): OS provides mechanisms so that processes can pass data.

Two types of semantics: Blocking(阻塞) : sending process

waits for response; non-blocking(非阻塞) : sending

process continues.

Page 27: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

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.

Page 28: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Shared memory

Shared memory on a bus:

CPU I/O

devicememory

Page 29: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Race condition in shared memory

Problem when CPU and I/O device try to write the same location: CPU reads flag and sees 0. I/O reads flag and sees 0. CPU sets flag to one and writes

location. I/O sets flag to one and overwrites

location.

Page 30: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Atomic test-and-setProblem is solved by an atomic test-and-set:

single bus operation reads memory location, tests it, writes it.

ARM test-and-set provided by SWP: ADR r0,SEMAPHORE

LDR r1,#1

GETFLAG SWP r1,r1,[r0]

CMP r1, #0

BNZ GETFLAG

HASFLAG … …

Page 31: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Critical regions

Critical region: section of code that cannot be interrupted by another process.

Examples: writing shared memory; accessing I/O device.

Page 32: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Semaphores

Semaphore: OS primitive for controlling access to critical regions.

Protocol: Get access to semaphore with P(). Perform critical region operations. Release semaphore with V().

Page 33: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Message passing

Message passing on a network:

CPU 1 CPU 2

message message

message

Page 34: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Evaluating RTOS performance

Simplifying assumptions: Context switch costs no CPU time,. We know the exact execution time of

processes. WCET/BCET don’t depend on context

switches.

Page 35: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Scheduling and context switch overhead

Process Execution time

deadline

P1 3 5

P2 3 10

With context switch overhead of1, no feasible schedule.2TP1 + TP2 = 2*(1+3)+(1+3)=12

Page 36: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Process execution time

Process execution time is not constant.

Extra CPU time can be good.Extra CPU time can also be bad:

Next process runs earlier, causing new preemption.

Page 37: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Processes and caches

Processes can cause additional caching problems. Even if individual processes are well-

behaved, processes may interfere with each other.

Worst-case execution time with bad behavior is usually much worse than execution time with good cache behavior.

Page 38: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Effects of scheduling on the cache

Process WCET Avg. CPU time

P1 8 6

P2 4 3

P3 4 3

Schedule 1 (LRU cache):

Schedule 2 (half of cache reserved for P1):

Each process use half cache. Every repeating, all cache can use.

Page 39: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Power optimization

Power management: determining how system resources are scheduled/used to control power consumption.

OS can manage for power just as it manages for time.

OS reduces power by shutting down units. May have partial shutdown modes.

Page 40: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Power management and performance

Power management and performance are often at odds.

Entering power-down mode consumes energy, time.

Leaving power-down mode consumes energy, time.

Page 41: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Simple power management policies

Request-driven: power up once request is received. 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.

Page 42: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Probabilistic shutdown

Assume service requests are probabilistic.

Optimize expected values: power consumption; response time.

Simple probabilistic: shut down after time Ton, turn back on after waiting for Toff.

Page 43: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

Advanced Configuration and Power Interface(ACPI)

ACPI: open standard for power management services.

Hardware platform

devicedrivers

ACPI BIOS

OS kernel

applications

powermanagement

Page 44: Processes and operating systems zPriority-driven scheduling zScheduling policies: yRMS; yEDF. zInterprocess communication. zOperating system performance

ACPI global power states

G3: mechanical offG2: soft off

S1: low wake-up latency with loss of contextS2: low latency with loss of CPU/cache stateS3: low latency with loss of all state except memoryS4: lowest-power state with all devices off

G1: sleeping stateG0: working state