300 likes | 464 Views
Processes and Operating System. Dankook University 2004.11.27. 목차. 목차. 1. 2. 3. 4. 5. 6. 7. 8. 9. Introduction Multiple Tasks and Multiple Processes Processes Context Switching Operating Systems Scheduling Policies Interprocess Communication Mechanisms
E N D
Processes and Operating System Dankook University 2004.11.27
목차 목차 1. 2. 3. 4. 5. 6. 7. 8. 9. Introduction Multiple Tasks and Multiple Processes Processes Context Switching Operating Systems Scheduling Policies Interprocess Communication Mechanisms Evaluating Operating System Performance Power Optimization Strategies for Processes
1. Introduction Introduction Process abstraction Switching contexts between programs Real-time operation systems (RTOS) Interprocess communication Performance analysis and Power consumption A telephone answering machine designFocus on .. This chapter studies the two fundamental abstractions – the process and the operation system These two abstractions let us switch the state of the processor between multiple tasks. The process clearly defines the state of an executing program,while the operating system provides the mechanism for switching execution between the process.
Serial line Serial line Uncompressed data Compressor Compressed data Compressor Character Bit queue Compression Table 2. Multiple Tasks and Multiple Processes Multiple Tasks and Multiple Processes Example – telephone answering machine – recording a phone call, operating the user’s control panel Valuable data rate Asynchronous input (button control penal) String of byte String of bit
Spark plug Engine Controller Crankshaft position 2. Multiple Tasks and Multiple Processes Multirate Systems Must be executed periodically, and each operation is executed as its own rate Automobile Engine, printers, telephone PBXsAsynchronous input Engine speed 에 따라서 피스톤의 움직임과 스파크가 변함.
2. Multiple Tasks and Multiple Processes Early Multitasking Technology: The Co-Routine What is import in this example is the structure of the jumps between the co-routines Coroutine은 부프로그램 간에 상호호출로 제어를 옮길때 수행이 끝나기 전에 호출한 프로그램으로 제어를 되돌려주는 부프로그램 개념. 즉 상호 coroutine 으로 호출하는 부프로그램들은 동일한 위치에서 서로 교대로 호출로 인하여 실행이 일시 정지된 위치에서 실행을 재개시키도록 제어를 돌리는 실행구조.보통 부프로그램은 호출 프로그램에 종속되어 실행이 완료되면, 호출 프로그램으로 복귀하고 동시에 부프로그램의 지역적인 자료는 소멸되나, coroutine 의 경우에는 이와 달리 서로 대등한 입장에 있기 때문에 복귀하는 것이 아니라, 서로 중단된 위치로부터 재개되고 지역자료도 그대로 보존된다. Not enough to help us construct complex program with significant timing properties. It is hard to trace through the flow of control between co-routines when the system is built from three or more co-routine
ADR r14, co2a ADR r0, a LDR r1, [ro] ADD r1, #5 STR r1, [r0] ADR r13, co1b MOV r15, r14 ADR r3, w LDR r4, [r3] STR r4, r0 ADR r13,co2b MOV r15, r13 Co2a Co1a ADR r3, x LDR r4,[r3] ADR r5, y STR r4, r5 ADR r13, co2c MOV r15, r13 Co1b ADR r3, b LDR r4,[r3] BNE r4, #2 ADR r13, colc MOV r15, r14 Co1b Co2c… … Colc… … Co-routine 2 Co-routine 1 2. Multiple Tasks and Multiple Processes Early Multitasking Technology: The Co-Routine 서브 프로그램의 수행이 완전히 종료되기 전에 호출할 수 있는 서브 프로그램 일부분만이 수행하고 제어를 반환 재호출시 제어가 반환된 곳에서 수행 재개 호출 프로그램과 피호출 프로그램은 동등한 관계
PC Process 3 data, Code Process 2 data, Code Registers CUP Process 1 data, Code Process 3 activation record Process 2 activation record Process 1 activation record 3. Processes Processes The process lets us organize executable code into similarly manageable units. A process is simply a unique execution of a program. A process is defined by both its code and data. The data set – CPU register, main memory (the process’s result may be stored in both)
3. Processes Processes Childid = fork(); If ( childid==0 ){/*must be the child*/ /* do child process here */ } Childid = fork(); If ( childid==0 ){/*must be the child*/ execv{“mychild”,childargs); perror(“execl”); exit(1); } Else {/*is the parent*/ parent_stuff();/*execute parent functionality*/ wait(&cstatus); exit(0); } Childid = fork(); If ( childid==0 ){/*must be the child*/ execv{“mychild”,childargs); perror(“execv”); exit(1); }
If (x>2) sub1(y); Else sub2(y,z); cswitch(); proca(a,b,c); Proc_date(r,s,t) cswitch(); If(val1==3) abc(val2); Rst(val3); save_state(current); P= choose_process(); Load_and_go(p); Process 2 Process 1 Scheduler 4. Context Switching Cooperative Multitasking 문맥 : 커널이 관리하는 태스크의 자원과 수행 환경 집합 The mechanism for moving the CPU form one executing process to another In a cooperative multitasking system, on process give up the CPU to another voluntarily Look like procedure call but it dose not immediately return to the caller Similar to the co-routine , difference is that rather than directly calling the other process, we use the scheduler to determine which process runs next.(more flexibility in choosing the order in which processes run The process states are store in process activation records in main memory
4. Context Switching Cooperative Multitasking CPU를 필요로 한다면 필요한 시간을 알리기 위해 대기 행렬(Queue :큐) 에 메시지를 제출 프로세스는 어떤 다른 프로세스가 통제가 필요한지를 알아보기 위해 정기적으로 대기행렬을 확인 이 때 메시지가 확인되면, 이 통제 프로세스는 실행을 중단하고 다른 프로세스가 실행을 시작 언제 프로세스가 대기 행렬을 체크할 것인가에 대한 일정한 표준이 없다 몇몇 프로세스들은 보다 많은 CPU 시간을 사용해야함
Interrupt Timer CPU 4. Context Switching Preemptive Multitasking The interrupt mechanism is designed to save state and the invisibly return control to an executing program. (force the CPU)
5. Operating Systems Operating Systems Allocating resources in the computing system Scheduling the CPU is the most important job Scheduling processes to meet performance requirements 자원 관리자 (Resource Manager) 응용에게 자원에 대한 서비스 제공 (Computing Environment)
Executing Chosen to run Needs data Gets data, CPU ready Preempted Ready Waiting Received data Needs data Scheduling state of a process Process P2 data arrival Execution time Priority P1 data arrival P3 data arrival P1 1 10 P2 2 30 P3 3 20 P2 P1 P2 P3 0 10 20 30 40 50 60 5. Operating Systems Process State and Scheduling Priority-Driven Scheduling
5. Operating Systems Operating System Structure The process activation record can be generalized to include all the following data required by theoperating system to run the process:* Process priority* Process scheduling state* starting address of the process
Deadline Deadline P1 P1 time Initiating event Deadline time Initiating event Aperiodic process P1 Period Periodic process initiated at start of period time Initiating event Period Periodic process initiated by event 5. Operating Systems Timing Requirements on Processes
CUP1 P1i P1i+4 P1i P1i+4 CUP2 P1i P1i+4 CUP3 P1i P1i+4 CUP4 time A sequence of processes with a high initiation rate 5. Operating Systems Timing Requirements on Processes
CPU1 Shared location CPU2 Memory BUS 5. Operating Systems Interprocess Communication A process can send a communication in one of two ways – blocking or nonbloking Blocking – waiting state , Nonblocking – continue execution Major style – shared memory and message passing There must be a flag that tells one CPU when the data from the other CPU are ready. 메모리의 일부분을 모든 프로세서가 접근할 수 있도록 할당
Size info Buffer CPU UART In UART out Memory 5. Operating Systems Interprocess Communication Elastic Buffer as Shared Memory
msg msg P1 P2 CPU1 CPU2 Audio P3 System Video Message passing communication P4 Communication among processes at different rates Data dependencies among processes 5. Operating Systems Interprocess Communication
6. Scheduling Policies Rate-Monotonic Scheduling (RMS) • A scheduling policy defines how processes are selected for promotion from the ready state tothe running state. • 공평성(fairness) : 기아 상태(starvation)가 되는 태스크가 없어야 된다. 효율성(efficiency) : 태스크 선택 과정이 빠르게 수행되어야 한다. 응답 시간(response time) vs 처리율(throughput) • RMS is static scheduling policy because it assigns fixed priorities to process. • All processes run periodically on a single CPU • Context switching time is ignored • There are no data dependencies between processes • The execution time for a process is constant. • All deadlines are at the ends of their periods. • The highest-priority ready process is always selected for execution • 프로세스가 일으키는 이벤트들의 발생 주기에 비례해 각 프로세스의 priority를 준다
Process Process Period Period Execution time Execution time P1 P1 1 2 4 4 P2 P2 3 2 6 6 P3 P3 3 3 12 12 12 0 10 6 8 2 4 6. Scheduling Policies Rate-Monotonic Scheduling (RMS)
6. Scheduling Policies Earliest-Deadline-First Scheduling Classic, Dynamic pre-emptive 스케줄링 우선순위가 고정됨 - 태스크 할당 주기를 기준으로 고정된 우선순위 할당- 가장 짧은 주기의 태스크가 가장 높은 우선순위를 가짐- 디스크 패처는 항상 가장 높은 우선 순위의 태스크를 디스패치
6. Scheduling Policies RMS versus EDF Get a fast CUP. That will reduce execution times without changing the periods, giving youlower utilization. This will require you to redesign the hardware, but this is often feasiblebecause you are rarely using the fastest CPU available. Redesign the processes to take less execution time. This requires knowledge of the code andmay or may not be possible. Rewrite the specification to change the deadlines. This is unlikely to be feasible, but may bein a few cases where some of the deadlines were initially made tighter than necessary.
Task Deadline P1 P3 T1 10 T2 8 P2 Task rates P1 P2 P1 Task graph Process CPU time P1 2 Process Deadline Execution time P2 P2 1 P1 1 4 P1 P3 4 P2 2 6 time Execution times 0 10 6 8 2 4 6. Scheduling Policies Data Dependencies and Scheduling
7. Interprocess Communication Mechanisms Signals A signal is analogous to an interrupt, but it is entirely a software creation. A signal is generated by a process and transmitted to another process by the operating system.
8. Evaluating Operating System Performance Evaluating Operating System Performance
9. Power Optimization Strategies for Processes Power Optimization Strategies for Processes Two kinds of power management mechanisms: static and dynamic. Aviding a power-down mode can cost unnecessary power. Computation history를 기반으로 idle time의 주기를 예상하고 power와 responsiveness의 측면에서 idle time의 예상 주기가 shutdown의 cost를 justify하면 process가 미리 정한 예상주기 만큼 shutdown된다. Algorithm이 경험적인 결과의 분석으로부터 wait 간격의 길이를 미리 예측한다. 이 Predictive system shutdown 방식은 계산할 때 많은 에너지 감소를 가져온다. 그러나, 실제로는 Shutdown과 연관된 time and power overhead로 인해 이러한 reduction이 쉽지 않다.
Power manager Commands Observations Service Provider Service Requestor Queue Request Architecture of a power-managed system 9. Power Optimization Strategies for Processes Power Optimization Strategies for Processes
Applications Kernel ACPI driver AML interpreter Power Management Device derivers ACPI ACPI tables ACPI registers ACPI BIOS Hardware platform The advanced Configuration and Power Interface and its relationship to a complete system 9. Power Optimization Strategies for Processes Power Optimization Strategies for Processes ACPI 는 한마디로 운영체제에서 컴퓨터의 전원을 관리할수 있도록 만들어주는 바이오스와 운영체제의 인터페이스라고 할수 있다.