Processes and operating systems z Operating systems 2000

  • Slides: 24
Download presentation
Processes and operating systems z. Operating systems. © 2000 Morgan Kaufman Overheads for Computers

Processes and operating systems z. Operating systems. © 2000 Morgan Kaufman Overheads for Computers as Components

Operating systems z. The operating system controls resources: ywho gets the CPU; ywhen I/O

Operating systems z. The operating system controls resources: ywho gets the CPU; ywhen I/O takes place; yhow much memory is allocated. z. The most important resource is the CPU itself. y. CPU access controlled by the scheduler. © 2000 Morgan Kaufman Overheads for Computers as Components

Process state z A process can be in one of three states: yexecuting on

Process state z A process can be in one of three states: yexecuting on the CPU; yready to run; ywaiting for data. executing gets CPU preempted needs data gets data ready waiting needs data © 2000 Morgan Kaufman gets data and CPU Overheads for Computers as Components

Operating system structure z. OS needs to keep track of: yprocess priorities; yscheduling state;

Operating system structure z. OS needs to keep track of: yprocess priorities; yscheduling state; yprocess activation record. z. Processes may be created: ystatically before system starts; ydynamically during execution. © 2000 Morgan Kaufman Overheads for Computers as Components

Embedded vs. generalpurpose scheduling z. Workstations try to avoid starving processes of CPU access.

Embedded vs. generalpurpose scheduling z. Workstations try to avoid starving processes of CPU access. y. Fairness = access to CPU. z. Embedded systems must meet deadlines. y. Low-priority processes may not run for a long time. © 2000 Morgan Kaufman Overheads for Computers as Components

Time quanta z. Quantum: unit of time for scheduling. © 2000 Morgan Kaufman Overheads

Time quanta z. Quantum: unit of time for scheduling. © 2000 Morgan Kaufman Overheads for Computers as Components

Priority-driven scheduling z. Each process has a priority. z. CPU goes to highest-priority process

Priority-driven scheduling z. Each process has a priority. z. CPU goes to highest-priority process that is ready. z. Priorities determine scheduling policy: yfixed priority; ytime-varying priorities. © 2000 Morgan Kaufman Overheads for Computers as Components

Priority-driven scheduling example z. Rules: yeach process has a fixed priority (1 highest); yhighest-priority

Priority-driven scheduling example z. Rules: yeach process has a fixed priority (1 highest); yhighest-priority ready process gets CPU; yprocess continues until done or wait state. z. Processes y. P 1: priority 1, execution time 10 y. P 2: priority 2, execution time 30 y. P 3: priority 3, execution time 20 © 2000 Morgan Kaufman Overheads for Computers as Components

Priority-driven scheduling example P 3 ready t=18 P 2 ready t=0 P 1 ready

Priority-driven scheduling example P 3 ready t=18 P 2 ready t=0 P 1 ready t=15 P 2 0 P 1 10 20 P 2 30 P 3 40 60 50 time © 2000 Morgan Kaufman Overheads for Computers as Components

The scheduling problem z. Can we meet all deadlines? y. Must be able to

The scheduling problem z. Can we meet all deadlines? y. Must be able to meet deadlines in all cases. z. How much CPU horsepower do we need to meet our deadlines? © 2000 Morgan Kaufman Overheads for Computers as Components

Process initiation disciplines z. Periodic process: executes on (almost) every period. z. Aperiodic process:

Process initiation disciplines z. Periodic process: executes on (almost) every period. z. Aperiodic process: executes on demand. z. Analyzing aperiodic process sets is harder--must consider worst-case combinations of process activations. © 2000 Morgan Kaufman Overheads for Computers as Components

Timing requirements on processes z. Period: interval between process activations. z. Initiation interval: reciprocal

Timing requirements on processes z. Period: interval between process activations. z. Initiation interval: reciprocal of period. z. Initiation time: time at which process becomes ready. z. Deadline: time at which process must finish. © 2000 Morgan Kaufman Overheads for Computers as Components

Timing violations z. What happens if a process doesn’t finish by its deadline? y.

Timing violations z. What happens if a process doesn’t finish by its deadline? y. Hard deadline: system fails if missed. y. Soft deadline: user may notice, but system doesn’t necessarily fail. © 2000 Morgan Kaufman Overheads for Computers as Components

Example: Space Shuttle software error z. Space Shuttle’s first launch was delayed by a

Example: Space Shuttle software error z. Space Shuttle’s first launch was delayed by a software timing error: y. Primary control system PASS and backup system BFS. y. BFS failed to synchronize with PASS. y. Change to one routine added delay that threw off start time calculation. y 1 in 67 chance of timing problem. © 2000 Morgan Kaufman Overheads for Computers as Components

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

Interprocess communication z. Interprocess communication (IPC): OS provides mechanisms so that processes can pass data. z. Two types of semantics: yblocking: sending process waits for response; ynon-blocking: sending process continues. © 2000 Morgan Kaufman Overheads for Computers as Components

IPC styles z. Shared memory: yprocesses have some memory in common; ymust cooperate to

IPC styles z. Shared memory: yprocesses have some memory in common; ymust cooperate to avoid destroying/missing messages. z. Message passing: yprocesses send messages along a communication channel---no common address space. © 2000 Morgan Kaufman Overheads for Computers as Components

Shared memory z. Shared memory on a bus: CPU 1 © 2000 Morgan Kaufman

Shared memory z. Shared memory on a bus: CPU 1 © 2000 Morgan Kaufman memory Overheads for Computers as Components CPU 2

Race condition in shared memory z. Problem when two CPUs try to write the

Race condition in shared memory z. Problem when two CPUs try to write the same location: y. CPU 1 reads flag and sees 0. y. CPU 2 reads flag and sees 0. y. CPU 1 sets flag to one and writes location. y. CPU 2 sets flag to one and overwrites location. © 2000 Morgan Kaufman Overheads for Computers as Components

Atomic test-and-set z. Problem can be solved with an atomic test -and-set: ysingle bus

Atomic test-and-set z. Problem can be solved with an atomic test -and-set: ysingle bus operation reads memory location, tests it, writes it. z. ARM test-and-set provided by SWP: ADR r 0, SEMAPHORE LDR r 1, #1 GETFLAG SWP r 1, [r 0] BNZ GETFLAG © 2000 Morgan Kaufman Overheads for Computers as Components

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

Critical regions z. Critical region: section of code that cannot be interrupted by another process. z. Examples: ywriting shared memory; yaccessing I/O device. © 2000 Morgan Kaufman Overheads for Computers as Components

Semaphores z. Semaphore: OS primitive for controlling access to critical regions. z. Protocol: y.

Semaphores z. Semaphore: OS primitive for controlling access to critical regions. z. Protocol: y. Get access to semaphore with P(). y. Perform critical region operations. y. Release semaphore with V(). © 2000 Morgan Kaufman Overheads for Computers as Components

Message passing z. Message passing on a network: CPU 1 CPU 2 message ©

Message passing z. Message passing on a network: CPU 1 CPU 2 message © 2000 Morgan Kaufman Overheads for Computers as Components

Process data dependencies z One process may not be able to start until another

Process data dependencies z One process may not be able to start until another finishes. z Data dependencies defined in a task graph. z All processes in one task run at the same rate. © 2000 Morgan Kaufman Overheads for Computers as Components P 1 P 2 P 3 P 4

Other operating system functions z. Date/time. z. File system. z. Networking. z. Security. ©

Other operating system functions z. Date/time. z. File system. z. Networking. z. Security. © 2000 Morgan Kaufman Overheads for Computers as Components