Presentation is loading. Please wait.

Presentation is loading. Please wait.

Processes and operating systems

Similar presentations


Presentation on theme: "Processes and operating systems"— Presentation transcript:

1 Processes and operating systems
© 2000 Morgan Kaufman Overheads for Computers as Components

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

3 Overheads for Computers as Components
RTOS Real-time operating systems (RTOSs),which are OSs that provide facilities for satisfying real-time requirements. A RTOS allocates resources using algorithms that take real time into account. General-purpose OSs, in contrast, generally allocate resources using other criteria like fairness. Trying to allocate the CPU equally to all processes without regard to time can easily cause processes to miss their deadlines. © 2000 Morgan Kaufman Overheads for Computers as Components

4 MULTIPLE TASKS AND MULTIPLE PROCESSES
Most embedded systems require functionality and timing that is too complex to embody in a single program. We break the system into multiple tasks in order to manage when things happen. Basic abstractions that will be manipulated by the RTOS to build multirate systems . Tasks and Processes Multirate Systems Timing Requirements on Processes CPU Metrics Process State and Scheduling Some Scheduling Policies Running Periodic Processes © 2000 Morgan Kaufman Overheads for Computers as Components

5 Overheads for Computers as Components
Designing a telephone answering Machine: define recording a phone call and operating the user’s control panel as distinct tasks, because they perform logically distinct operations and they must be performed at very different rates. These different tasks are part of the system’s functionality © 2000 Morgan Kaufman Overheads for Computers as Components

6 Overheads for Computers as Components
A process is a single execution of a program. If we run the same program two different times, we have created two different processes. Each process has its own state that includes not only its registers but all of its memory. In some OSs, the memory management unit is used to keep each process in a separate address space. In others, particularly lightweight RTOSs, the processes run in the same address space. Processes that share the same address space are often called threads. To be more precise, task can be composed of several processes or threads © 2000 Morgan Kaufman Overheads for Computers as Components

7 Overheads for Computers as Components
the separation of an application into tasks may be reflected in the program structure, consider how we would build a stand-alone compression unit based on a compression algorithm this device is connected to serial ports on both ends. The input to the box is an uncompressed stream of bytes. The box emits a compressed string of bits on the output serial line, based on a predefined compression table. Such a box may be used, for example, to compress data being sent to a modem. © 2000 Morgan Kaufman Overheads for Computers as Components

8 Overheads for Computers as Components
© 2000 Morgan Kaufman Overheads for Computers as Components

9 Overheads for Computers as Components
The program’s need to receive and send data at different rates—for example, the program may emit 2 bits for the first byte and then 7 bits for the second byte a more elegant solution is to create a queue of output bits, with those bits being removed from the queue and sent to the serial port in 8-bit sets. if we spend too much time in packaging and emitting output characters, we may drop an input character. asynchronous input- compression mode button- Sampling the button’s state- button-handling routine- illustrates how requirements on timing and execution rate can create major problems in programming © 2000 Morgan Kaufman Overheads for Computers as Components

10 Overheads for Computers as Components
Multirate Systems Implementing code that satisfies timing requirements is even more complex when multiple rates of computation must be handled. Multirate embedded computing systems are very common,including automobile engines, printers,and cell phones. In all these systems,certain operations must be executed periodically,and each operation is executed at its own rate © 2000 Morgan Kaufman Overheads for Computers as Components

11 Timing Requirements on Processes
Processes can have several different types of timing requirements imposed on them by the application. The timing requirements on a set of processes strongly influence the type of scheduling that is appropriate. two important requirements on processes: release time and deadline. The release time is the time at which the process becomes ready to execute; this is not necessarily the time at which it actually takes control of the CPU and starts to run. © 2000 Morgan Kaufman Overheads for Computers as Components

12 Overheads for Computers as Components
© 2000 Morgan Kaufman Overheads for Computers as Components

13 Overheads for Computers as Components
The period of a process is the time between successive executions. The process’s rate is the inverse of its period. © 2000 Morgan Kaufman Overheads for Computers as Components

14 Overheads for Computers as Components
illustrates process execution in a system with four CPUs. The various execution instances of program P1 have been subscripted to distinguish their initiation times. In this case, the initiation interval is equal to onefourth of the period. It is possible for a process to have an initiation rate less than the period even in single-CPU systems. If the process execution time is significantly less than the period, it may be possible to initiate multiple copies of a program at slightly offset times. © 2000 Morgan Kaufman Overheads for Computers as Components

15 Overheads for Computers as Components
© 2000 Morgan Kaufman Overheads for Computers as Components

16 Overheads for Computers as Components
What happens when a process misses a deadline? The practical effects of a timing violation depend on the application—the results can be catastrophic in an automotive control system, where as a missed deadline in a multimedia system may cause an audio or video glitch. © 2000 Morgan Kaufman Overheads for Computers as Components

17 Overheads for Computers as Components
The order of execution of processes may be constrained when the processes pass data between each other. Following Figure shows a set of processes with data dependencies among them. Before a process can become ready,all the processes on which it depends must complete and send their data to it. The data dependencies define a partial ordering on process execution—P1 and P2 can execute in any order (or in interleaved fashion) but must both complete before P3, and P3 must complete before P4. All processes must finish before the end of the period. © 2000 Morgan Kaufman Overheads for Computers as Components

18 Overheads for Computers as Components
The data dependencies must form a directed acyclic graph (DAG)—a cycle in the data dependencies is difficult to interpret in a periodically executed system. A set of processes with data dependencies is known as a task graph. we will consider a component of the task graph (a set of nodes connected by data dependencies) as a task and the complete graph as the task set. Figure also shows a second task with two processes. The two tasks ({P1, P2, P3, P4} and {P5, P6}) have no timing relationships between them. © 2000 Morgan Kaufman Overheads for Computers as Components

19 Overheads for Computers as Components
communication among processes of different rates is very common. Figure illustrates the communication required among three elements of an MPEG audio/video decoder. Data come into the decoder in the system format, which multiplexes audio and video data. Multirate communication is necessarily one way—for example, the system process writes data to the video process, but a separate communication mechanism must be provided for communication from the video process back to the system process. © 2000 Morgan Kaufman Overheads for Computers as Components

20 CPU Metrics The initiation time is the time at which a process actually starts executing on the CPU. The completion time is the time at which the process finishes its work. The most basic measure of work is the amount of CPU time expended by a process. The CPU time of process i is called Ci . Note that the CPU time is not equal to the completion time minus initiation time; several other processes may interrupt execution. The total CPU time consumed by a set of processes is Utilization is the ratio of the CPU time that is being used for useful computations to the total available CPU time.

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

22 Operating system structure
OS needs to keep track of: process priorities; scheduling state; process activation record. Processes may be created: statically before system starts; dynamically during execution. © 2000 Morgan Kaufman Overheads for Computers as Components

23 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. © 2000 Morgan Kaufman Overheads for Computers as Components

24 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. © 2000 Morgan Kaufman Overheads for Computers as Components

25 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 © 2000 Morgan Kaufman Overheads for Computers as Components

26 Priority-driven scheduling example
P3 ready t=18 P2 ready t=0 P1 ready t=15 P2 P1 P2 P3 10 20 30 40 50 60 time © 2000 Morgan Kaufman Overheads for Computers as Components

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

28 Process initiation disciplines
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. © 2000 Morgan Kaufman Overheads for Computers as Components

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

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

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

32 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. © 2000 Morgan Kaufman Overheads for Computers as Components

33 Overheads for Computers as Components
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. © 2000 Morgan Kaufman Overheads for Computers as Components

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

35 Race condition in shared memory
Problem when two CPUs try to write the same 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. © 2000 Morgan Kaufman Overheads for Computers as Components

36 Overheads for Computers as Components
Atomic test-and-set Problem can be solved with 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] BNZ GETFLAG © 2000 Morgan Kaufman Overheads for Computers as Components

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

38 Overheads for Computers as Components
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(). © 2000 Morgan Kaufman Overheads for Computers as Components

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

40 Process data dependencies
One process may not be able to start until another finishes. Data dependencies defined in a task graph. All processes in one task run at the same rate. P1 P2 P3 P4 © 2000 Morgan Kaufman Overheads for Computers as Components

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

42 Some Scheduling Policies
A scheduling policy defines how processes are selected for promotion from the ready state to the running state. Every multitasking OS implements some type of scheduling policy. Choosing the right scheduling policy not only ensures that the system will meet all its timing requirements, but it also has a profound influence on the CPU horsepower required to implement the system’s functionality. © 2000 Morgan Kaufman Overheads for Computers as Components

43 Overheads for Computers as Components
Schedulability means whether there exists a schedule of execution for the processes in a system that satisfies all their timing requirements. Utilization is one of the key metrics in evaluating a scheduling policy. Our most basic requirement is that CPU utilization be no more than 100% since we can’t use the CPU more than 100% of the time. © 2000 Morgan Kaufman Overheads for Computers as Components

44 Overheads for Computers as Components
When we evaluate the utilization of the CPU, we generally do so over a finite period that covers all possible combinations of process executions. For periodic processes, the length of time that must be considered is the hyperperiod, which is the least-common multiple of the periods of all the processes. The complete schedule for the least-common multiple of the periods is sometimes called the unrolled schedule © 2000 Morgan Kaufman Overheads for Computers as Components

45 Overheads for Computers as Components
© 2000 Morgan Kaufman Overheads for Computers as Components


Download ppt "Processes and operating systems"

Similar presentations


Ads by Google