610 likes | 809 Views
3. Operating System Organization. Purpose of an OS. Coordinate Use of the Abstractions. Processes. The Abstractions. Create the Abstractions. OS Requirements. Provide resource abstractions Process abstraction of CPU/memory use Address space
E N D
3 Operating SystemOrganization Operating Systems: A Modern Perspective, Chapter 3
Purpose of an OS Coordinate Use of the Abstractions Processes The Abstractions Create the Abstractions Operating Systems: A Modern Perspective, Chapter 3
OS Requirements • Provide resource abstractions • Process abstraction of CPU/memory use • Address space • Thread abstraction of CPU within address space • Resource abstraction • “Anything a process can request that can block the process if it is unavailable” • NT uses “object abstraction” to reference resources • File abstraction of secondary storage use Operating Systems: A Modern Perspective, Chapter 3
DOS -- Resource Abstraction Only Program Program Libraries Program OS Services ROM Routines Processor(s) Main Memory Devices Operating Systems: A Modern Perspective, Chapter 3
OS Requirements (cont) • Provide resource abstractions • Manage resource sharing • Time/space-multiplexing • Exclusive use of a resource • Isolation • Managed sharing Operating Systems: A Modern Perspective, Chapter 3
Process Process Process Program Program Program State State State Abstraction & Sharing Libraries • OS Services • Abstraction • Manage sharing ROM Routines Processor(s) Main Memory Devices Operating Systems: A Modern Perspective, Chapter 3
OS Design Constraints • Performance • Protection and security • Correctness • Maintainability • Commercial factors • Standards and open systems Operating Systems: A Modern Perspective, Chapter 3
Performance • The OS is an overhead function should not use too much of machine’s resources • Minimum functionality is to implement abstractions • Additional function must be traded off against performance • DOS: one process • UNIX: low level file system Operating Systems: A Modern Perspective, Chapter 3
Protection & Security • Multiprogramming resource sharing • Therefore, need software-controlled resource isolation • Security policy: Sharing strategy chosen by computer’s owner • Protection mechanism: Tool to implement a family of security policies Operating Systems: A Modern Perspective, Chapter 3
Correctness & Maintainability • Security depends on correct operation of software trusted vs untrusted software • Maintainability relates to ability of software to be changed • If either is sufficiently important, can limit the function of the OS • Guiding a manned spaceship • Managing a nuclear reactor Operating Systems: A Modern Perspective, Chapter 3
Device Management Device-Independent Part Device-Dependent Part Device-Dependent Part Device-Dependent Part … Device Device Device Operating Systems: A Modern Perspective, Chapter 3
Process, Thread, and Resource Management Thread Abstraction Process Abstraction Generic Resource Manager Multiprogramming Other … Primary Memory Abstract Resources Processor Operating Systems: A Modern Perspective, Chapter 3
Memory Management Isolation & Sharing Virtual Memory Block Allocation Process Manager Primary Memory Storage Devices Operating Systems: A Modern Perspective, Chapter 3
Exclusive Access to a Resource Processor Process A Process B A’s Protected Object Supervisor Program Operating Systems: A Modern Perspective, Chapter 3
Processor Modes • Mode bit: Supervisor or User mode • Supervisor mode • Can execute all machine instructions • Can reference all memory locations • User mode • Can only execute a subset of instructions • Can only reference a subset of memory locations Operating Systems: A Modern Perspective, Chapter 3
Kernels • The part of the OS critical to correct operation (trusted software) • Executes in supervisor mode • The trap instruction is used to switch from user to supervisor mode, entering the OS Operating Systems: A Modern Perspective, Chapter 3
Supervisor and User Memory User Space User Process Supervisor Process Supervisor Space Operating Systems: A Modern Perspective, Chapter 3
send(…, A, …); receive(…, B, …); send/receive receive(…A, …); … send(…, B, …); Procedure Call and Message Passing Operating Systems call(…); trap return; Operating Systems: A Modern Perspective, Chapter 3
System Call Using the trap Instruction … fork(); … Trap Table Kernel fork() { … trap N_SYS_FORK() … } sys_fork() sys_fork() { /* system function */ … return; } Operating Systems: A Modern Perspective, Chapter 3
A Thread Performing a System Call User Space Kernel Space Thread fork(); sys_fork() { } Operating Systems: A Modern Perspective, Chapter 3
File Manager Memory Manager Device Manager Basic Operating System Organization Process, Thread & Resource Manager Processor(s) Main Memory Devices Operating Systems: A Modern Perspective, Chapter 3
The UNIX Architecture Interactive User Libraries Commands Application Programs … OS System Call Interface Trap Table Device Driver • Monolithic Kernel Module • Process Management • Memory Management • File Management • Device Mgmt Infrastructure Device Driver … Driver Interface Device Driver Operating Systems: A Modern Perspective, Chapter 3
Microkernel Organization Process Process Libraries Process User Supervisor Server Server Server Device Drivers Microkernel Processor(s) Main Memory Devices Operating Systems: A Modern Perspective, Chapter 3
Windows NT Organization Process Process T T Process T T T T Libraries T T T Process Management Memory Management File Management Device Mgmt Infrastructure Subsystem Subsystem Subsystem User Supervisor I/O Subsystem NT Executive NT Kernel Hardware Abstraction Layer Processor(s) Main Memory Devices Operating Systems: A Modern Perspective, Chapter 3
Monitoring the Kernel Process Process T Task Manager T Process T T T T Libraries T T T pview pstat Subsystem Subsystem Subsystem User Supervisor I/O Subsystem NT Executive NT Kernel Hardware Abstraction Layer Processor(s) Main Memory Devices Operating Systems: A Modern Perspective, Chapter 3
4 ComputerOrganization Operating Systems: A Modern Perspective, Chapter 4
Stored Program Computers and Electronic Devices Pattern Jacquard Loom Variable Program Stored Program Device Fixed Electronic Device Operating Systems: A Modern Perspective, Chapter 4
Assembly Language ; Code for a = b + c load R3,b load R4,c add R3,R4 store R3,a ; Code for d = a - 100 load R4,=100 subtract R3,R4 store R3,d Program Specification Source int a, b, c, d; . . . a = b + c; d = a - 100; Operating Systems: A Modern Perspective, Chapter 4
Machine Language 10111001001100…1 10111001010000…0 10100111001100…0 10111010001100…1 10111001010000…0 10100110001100…0 10111001101100…1 Machine Language Assembly Language ; Code for a = b + c load R3,b load R4,c add R3,R4 store R3,a ; Code for d = a - 100 load R4,=100 subtract R3,R4 store R3,d Operating Systems: A Modern Perspective, Chapter 4
The von Neumann Architecture Central Processing Unit (CPU) Arithmetical Logical Unit (ALU) Control Unit (CU) Address Bus Data Bus Device Primary Memory Unit (Executable Memory) Operating Systems: A Modern Perspective, Chapter 4
The ALU load R3,b load R4,c add R3,R4 store R3,a Right Operand Left Operand R1 R2 . . . Rn Functional Unit Status Registers Result To/from Primary Memory Operating Systems: A Modern Perspective, Chapter 4
load R3,b load R4,c add R3,R4 store R3,a Fetch Unit 10111001001100…1 10111001010000…0 10100111001100…0 10111010001100…1 3050 PC Decode Unit IR load R4, c Execute Unit Control Unit Control Unit 3046 3050 3054 3058 Primary Memory Operating Systems: A Modern Perspective, Chapter 4
Control Unit Operation • Fetch phase: Instruction retrieved from memory • Execute phase: ALU op, memory data reference, I/O, etc. PC = <machine start address>; IR = memory[PC]; haltFlag = CLEAR; while(haltFlag not SET) { execute(IR); PC = PC + sizeof(INSTRUCT); IR = memory[PC]; // fetch phase }; Operating Systems: A Modern Perspective, Chapter 4
1234 98765 read 1. Load MAR with address 2. Load Command with “read” 3. Data will then appear in the MDR Primary Memory Unit 0 MAR 1 2 MDR Command 1234 98765 Read Op: n-1 Operating Systems: A Modern Perspective, Chapter 4
Device manager • Program to manage device controller • Supervisor mode software Abstract I/O Machine The Device-Controller-Software Relationship Application Program Software in the CPU Device Controller Device Operating Systems: A Modern Perspective, Chapter 4
busy done 0 0 idle 0 1 finished 1 0 working 1 1 (undefined) Device Controller Interface . . . busy done Error code . . . Command Status Data 0 Data 1 Logic Data n-1 Operating Systems: A Modern Perspective, Chapter 4
Performing a Write Operation while(deviceNo.busy || deviceNo.done) <waiting>; deviceNo.data[0] = <value to write> deviceNo.command = WRITE; while(deviceNo.busy) <waiting>; deviceNo.done = TRUE; • Devices much slower than CPU • CPU waits while device operates • Would like to multiplex CPU to a different process while I/O is in process Operating Systems: A Modern Perspective, Chapter 4
… … … Ready Processes Ready Processes Ready Processes CPU CPU Device Device I/O Operation Uses CPU CPU-I/O Overlap CPU Device Operating Systems: A Modern Perspective, Chapter 4
Determining When I/O is Complete CPU Interrupt Pending Device Device Device • CPU incorporates an “interrupt pending” flag • When device.busy FALSE, interrupt pending flag is set • Hardware “tells” OS that the interrupt occurred • Interrupt handler part of the OS makes process ready to run Operating Systems: A Modern Perspective, Chapter 4
memory[1] contains the address of the interrupt handler Control Unit with Interrupt (Hardware) PC = <machine start address>; IR = memory[PC]; haltFlag = CLEAR; while(haltFlag not SET) { execute(IR); PC = PC + sizeof(INSTRUCT); IR = memory[PC]; if(InterruptRequest) { memory[0] = PC; PC = memory[1] }; Operating Systems: A Modern Perspective, Chapter 4
Interrupt Handler (Software) interruptHandler() { saveProcessorState(); for(i=0; i<NumberOfDevices; i++) if(device[i].done) goto deviceHandler(i); /* something wrong if we get to here … */ deviceHandler(int i) { finishOperation(); returnToScheduler(); } Operating Systems: A Modern Perspective, Chapter 4
A Race Condition saveProcessorState() { for(i=0; i<NumberOfRegisters; i++) memory[K+i] = R[i]; for(i=0; i<NumberOfStatusRegisters; i++) memory[K+NumberOfRegisters+i] = StatusRegister[i]; } PC = <machine start address>; IR = memory[PC]; haltFlag = CLEAR; while(haltFlag not SET) { execute(IR); PC = PC + sizeof(INSTRUCT); IR = memory[PC]; if(InterruptRequest && InterruptEnabled) { disableInterupts(); memory[0] = PC; PC = memory[1] }; Operating Systems: A Modern Perspective, Chapter 4
Revisiting the trap Instruction (Hardware) executeTrap(argument) { setMode(supervisor); switch(argument) { case 1: PC = memory[1001]; // Trap handler 1 case 2: PC = memory[1002]; // Trap handler 2 . . . case n: PC = memory[1000+n];// Trap handler n }; • The trap instruction dispatches a trap handler routine atomically • Trap handler performs desired processing • “A trap is a software interrupt” Operating Systems: A Modern Perspective, Chapter 4
Direct Memory Access Primary Memory Primary Memory CPU CPU Controller Controller Device Device Operating Systems: A Modern Perspective, Chapter 4
Addressing Devices Primary Memory Primary Memory Memory Addresses Device 0 Device 0 Memory Addresses Device 1 Device 1 Device Addresses Device n-1 Device n-1 Operating Systems: A Modern Perspective, Chapter 4
Polling I/O … // Start the device … While((busy == 1) || (done == 1)) wait(); // Device I/O complete … done = 0; Software busy done … while((busy == 0) && (done == 1)) wait(); // Do the I/O operation busy = 1; … Hardware Operating Systems: A Modern Perspective, Chapter 4
Fetch-Execute Cycle with an Interrupt while (haltFlag not set during execution) { IR = memory[PC]; PC = PC + 1; execute(IR); if (InterruptRequest) { /* Interrupt the current process */ /* Save the current PC in address 0 */ memory[0] = PC; /* Branch indirect through address 1 */ PC = memory[1]; } } Operating Systems: A Modern Perspective, Chapter 4
Detecting an Interrupt CPU InterruptRequest flag Device Device Device Operating Systems: A Modern Perspective, Chapter 4