800 likes | 941 Views
Chapitre 10 Systèmes d’exploitation et synchronisation de processus. Operating System model. Operating. Application. Hardware. System. Interactive usage. Batch Processing. Absolute Binary Loader. Central Memory. s3,t4. s3,t4. ABL. Command Interpreter. Central Memory. chess.
E N D
Chapitre 10 Systèmes d’exploitation et synchronisation de processus
Operating System model Operating Application Hardware System
Absolute Binary Loader Central Memory s3,t4 s3,t4 ABL
Command Interpreter Central Memory chess s3,t4 Fmgr. Cmnd.Int. ABL
Organizes data on disk Hides the details of physical files Offers standardized file organizations Sequential Random Access Indexed Sequential Maintains File Directories File Manager
chess Cmnd.Int. Fmgr. ABL Command Interpreter
Monoprogramming Process States task completed active I/O completion activation start I/O Blocked (busy wait) load waiting for cpu
Control by Command Interpreter Cmnd Interpreter Program X Start User Pgm Return to CMND.INT
Interrupt Handler Based System Command interpreter User program Interrupt handler File manager A.B.L.
Efficient people can be working on several tasks in an interleaved fashion. Several programs kept in central memory Need for memory management Programs protected against each other Selection process for entering central memory CPU works alternatively for different programs Need for CPU scheduling I/O managed by Operating System (spooling) Communication facilities between programs Multitasking
Efficient people can be working on several tasks in an interleaved fashion. Several programs kept in central memory Need for memory management Programs protected against each other Selection process for entering central memory CPU works alternatively for different programs Need for CPU scheduling I/O managed by Operating System (spooling) Communication facilities between programs Multitasking
Fixed Partitions Physical Memory
Automatic Relocation + Physical Memory Base Register
Memory Segmentation Segment d Segment a Segment c Physical Memory Segment b
Efficient people can be working on several tasks in an interleaved fashion. Several programs kept in central memory Need for efficient memory management Programs protected against each other Selection process for entering central memory CPU works alternatively for different programs Need for CPU scheduling I/O managed by Operating System (spooling) Communication facilities between programs Multitasking
Active Process Switch P1 P0 Save state into PCB0 Reload state from PCB1 Context switch overhead Save state into PCB1 Reload state from PCB0
Process context Contents of registers Memory space & Memory Management tables One program can contain many processes No protection required Could share memory space Fast process switching Lightweight processes sharing memory space Threads Threads
Efficient people can be working on several tasks in an interleaved fashion. Several programs kept in central memory Need for memory management Programs protected against each other Selection process for entering central memory CPU works alternatively for different programs Need for CPU scheduling I/O managed by Operating System (spooling) Communication facilities between programs Multitasking
Manual selection (starting an application under Windows) Automatic selection based on priorities Based on the Round Robin algorithm Virtual memory reduces considerably the importance of job scheduling. Job SchedulerSelects the programs to be loaded in Central Memory
Preempted tasks after t seconds Input queue Completed tasks Central memory New tasks Round Robin
Efficient people can be working on several tasks in an interleaved fashion. Several programs kept in central memory Need for memory management Programs protected against each other Selection process for entering central memory CPU works alternatively for different programs Need for CPU scheduling I/O managed by Operating System (spooling) Communication facilities between programs Multitasking
Multitasking Process States task completed active preemption start I/O activation load waiting for cpu I/O completion (interrupt) blocked swap out
Non-preemptive Scheduling: Priorities are compared whenever the active program blocks itself a clock tick occurs (typically every 10 mS) Preemptive Scheduling Priorities are continuously compared. Process SchedulerAll programs have a priority and the one waiting with the highest priority becomes active.
Process Priorities active -1 +1 p = p0 waiting for cpu blocked +1
Efficient people can be working on several tasks in an interleaved fashion. Several programs kept in central memory Need for memory management Programs protected against each other Selection process for entering central memory CPU works alternatively for different programs Need for CPU scheduling I/O managed by Operating System (spooling) Communication facilities between programs Multitasking
Program A Program B Program C Program D Output Spooling
Efficient people can be working on several tasks in an interleaved fashion. Several programs kept in central memory Need for memory management Programs protected against each other Selection process for entering central memory CPU works alternatively for different programs Need for CPU scheduling I/O managed by Operating System (spooling) Communication facilities between programs Multitasking
LOOP REPEAT UNTIL full; v := v + 1 END LOOP REPEAT UNTIL call; write(v); v := 0 END Concurrency& shared variablesExample : Rainfall recorder (1) P1 P2
MOV v,D1 ADI D1,1 MOV D1,v MVI D2,0 MOV D2,v Concurrency& shared variablesExample : Rainfall recorder (2) v := v + 1 v := 0 t
LOOP REPEAT UNTIL full; v := v + 1 END LOOP REPEAT UNTIL call; write(v); v := 0 END Critical SectionsExclusive access to shared variables P1 P2
Mutual exclusion Only one process in its critical section Progress When processes compete to enter their C.S. no other processes can influence the choice the choice can not be postponed indefinitely Bounded waiting The number of times a process can enter its C.S. while another is waiting is bounded Critical Sections
Software implementation: The Deckers Algorithm Hardware implementation On any computer: Test & Set bit Swap bit On monoprocessors: Disabling of interrupts Fundamental mechanism:The critical section
… … … REPEAT UNTIL free; free := FALSE; (* use shared variable *) free := TRUE; … … … Critical SectionBoolean Reservation
VAR turn : pturn,qturn; … … … REPEAT UNTIL pturn; (* use shared variable *) turn := qturn; … … … Critical SectionTurn Indicator
VAR pneed,qneed : Boolean; … … … pneed := TRUE; REPEAT UNTIL NOT qneed; (* use shared variable *) pneed := FALSE; … … … Critical SectionDouble reservation
VAR pneed,qneed:BOOLEAN;turn:pturn,qturn; … pneed := TRUE; WHILE qneed DO IF turn = qturn THEN pneed:=FALSE; REPEAT UNTIL turn = pturn; pneed := TRUE END END; (* use shared resource *) pneed := FALSE; turn := qturn; ... Deckers Algorithm
Software implementation: The Deckers Algoritm Hardware implementation On any computer: Test & Set bit Swap bit On monoprocessors: Disabling of interrupts Fundamental mechanism:The critical section
PROCEDURE TestAndSet (VAR X:BOOLEAN):BOOLEAN; VAR temp:BOOLEAN: BEGIN temp := X; X := TRUE; RETURN temp END TestAndSet; Test & SetTo be implemented in Hardware as one indivisible operation !!!
Lock is a common BOOLEAN variable ... LOOP REPEAT UNTIL NOT TestAndSet(Lock); Critical Section Lock := FALSE; Remainder of loop END Critical Section with Test & Set No bounded waiting !
PROCEDURE Swap (VAR X,Y:BOOLEAN); VAR temp:BOOLEAN; BEGIN temp := X; X := Y; Y := temp END Swap; SwapTo be implemented in Hardware as one indivisible operation !!!
Lock is a common BOOLEAN variable, initially FALSE Each process has a local boolean variable Key ... LOOP Key := TRUE; REPEAT Swap(lock,key); UNTIL Key = FALSE; Critical Section Lock := FALSE; Remainder of loop END Critical Section with Swap No bounded waiting !
Common variables: Waiting : ARRAY[0..n-1] OF BOOLEAN; Lock : BOOLEAN; i : 0 .. n-1; Variables specific for each process: Key : BOOLEAN; j : 0 .. n-1; Critical Sectionwith bounded waiting
LOOP Trying to access the Critical Section; Critical Section; Rearranging priorities; Remainder Section END Critical Sectionwith bounded waiting Overall Outline of Process i
Waiting[i] := TRUE; Key := TRUE; WHILE Waiting[i] AND Key DO Key := TestAndSet(Lock) END; Waiting[i] := FALSE; Critical Sectionwith bounded waiting Trying to access the Critical Section