operating system organization
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
Slide 3-1
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Slide 3-2
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
3Operating SystemOrganization
Slide 3-3
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Purpose of an OS
The Abstractions
Create the Abstractions
Coordinate Useof the AbstractionsProcesses
Slide 3-4
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-5
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
DOS -- Resource Abstraction Only
Processor(s) Main Memory Devices
Program
Program
Program
OS Services
Libraries
ROM Routines
Slide 3-6
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-7
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Abstraction & Sharing
Processor(s) Main Memory Devices
Libraries
ROM Routines
ProgramState
Process
ProgramState
Process
ProgramState
Process
OS Services • Abstraction• Manage sharing
Slide 3-8
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
OS Design Constraints
• Performance• Protection and security• Correctness• Maintainability• Commercial factors• Standards and open systems
Slide 3-9
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-10
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-11
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-12
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Device Management
Device-IndependentPart
Device-DependentPart
Device …Device Device
Device-DependentPart
Device-DependentPart
Slide 3-13
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Process, Thread, and Resource Management
…Processor
PrimaryMemory
AbstractResources
Multiprogramming
ThreadAbstraction
ProcessAbstraction Generic
ResourceManager
Other
Slide 3-14
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Memory Management
PrimaryMemory
ProcessManager
BlockAllocation
VirtualMemory
Isolation &Sharing
StorageDevices
Slide 3-15
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Exclusive Access to a Resource
Process A
SupervisorProgram
A’s ProtectedObject
Processor
Process B
Slide 3-16
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-17
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-18
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Supervisor and User Memory
UserSpace
SupervisorSpace
UserProcess
SupervisorProcess
Slide 3-19
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Procedure Call and Message Passing Operating Systems
call(…);
trap
return;
send(…, A, …);receive(…, B, …);
receive(…A, …); …send(…, B, …);
send/receive
Slide 3-20
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
System Call Using the trap Instruction
…fork();…
fork() {…trap N_SYS_FORK()…}
sys_fork()
sys_fork() {/* system function */ … return;}
KernelTrap Table
Slide 3-21
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
A Thread Performing a System Call
User Space Kernel Space
fork();
sys_fork() {
}
Thread
Slide 3-22
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Basic Operating System Organization
Processor(s) Main Memory Devices
Process, Thread &Resource Manager
MemoryManager
DeviceManager
FileManager
Slide 3-23
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Libraries Commands
Device Driver
The UNIX ArchitectureInteractive User
ApplicationPrograms
OS System Call Interface
Device Driver
Device Driver
Driv
er In
terf
ace
…Monolithic Kernel Module• Process Management• Memory Management• File Management• Device Mgmt Infrastructure
Trap Table
…
Slide 3-24
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Microkernel Organization
Device DriversMicrokernel
Processor(s) Main Memory Devices
Libraries
Process
Process
Process
Server Server Server
User
Supervisor
Slide 3-25
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Windows NT Organization
Processor(s) Main Memory Devices
Libraries
ProcessProcess
Process
SubsystemUser
Supervisor
Subsystem Subsystem
Hardware Abstraction LayerNT Kernel
NT ExecutiveI/O Subsystem
TT
TT
TT T T
T
Process ManagementMemory ManagementFile ManagementDevice Mgmt Infrastructure
Slide 3-26
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3
Monitoring the Kernel
Processor(s) Main Memory Devices
Libraries
ProcessProcess
Process
Subsystem Subsystem Subsystem
Hardware Abstraction LayerNT Kernel
NT ExecutiveI/O Subsystem
TT
TT
TT T T
TTaskManager
pview
pstat
Supervisor
User
Slide 3-27
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Slide 3-28
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
4ComputerOrganization
Slide 3-29
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Stored Program Computers and Electronic Devices
Pattern
Fixed Electronic Device
Variable Program
Stored Program Device
Jacquard Loom
Slide 3-30
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Program Specification
int a, b, c, d;. . .a = b + c;d = a - 100;
Source
; 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
Assembly Language
Slide 3-31
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Machine 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
Assembly Language
10111001001100…110111001010000…010100111001100…010111010001100…110111001010000…010100110001100…010111001101100…1
Machine Language
Slide 3-32
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
The von Neumann Architecture
Control Unit(CU)
Central Processing Unit (CPU)
Device
Address BusData Bus
Arithmetical Logical Unit(ALU)
Primary Memory Unit(Executable
Memory)
Slide 3-33
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
The ALU
R1R2
Rn
. . .
Status RegistersFunctional Unit
Left Operand
Right Operand
Result
To/from Primary Memory
load R3,bload R4,cadd R3,R4store R3,a
Slide 3-34
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Control Unit
3046305030543058
Primary Memory
Fetch Unit
Decode Unit
Execute Unit
PC
IR
Control Unit
load R3,bload R4,cadd R3,R4store R3,a
10111001001100…110111001010000…010100111001100…010111010001100…1load R4, c
3050
Slide 3-35
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Control Unit Operation
PC = <machine start address>;IR = memory[PC];haltFlag = CLEAR;while(haltFlag not SET) { execute(IR); PC = PC + sizeof(INSTRUCT); IR = memory[PC]; // fetch phase};
• Fetch phase: Instruction retrieved from memory
• Execute phase: ALU op, memory data reference, I/O, etc.
Slide 3-36
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Primary Memory Unit
MAR
MDR
Command
012
n-1
1234 98765Read Op:
1234
1. Load MAR with address
read
2. Load Command with “read”
98765
3. Data will then appear in the MDR
Slide 3-37
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
The Device-Controller-Software Relationship
Application Program
Device Controller
Device
Softw
are
in th
e C
PU
Abstract I/O Machine
• Device manager• Program to manage device controller• Supervisor mode software
Slide 3-38
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Device Controller Interface
Command Status Data 0
Data 1
Data n-1Logic
busy done Error code . . .. . .busy done 0 0 idle 0 1 finished 1 0 working 1 1 (undefined)
Slide 3-39
Copyright © 2004 Pearson Education, Inc. 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
Slide 3-40
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
CPU-I/O Overlap
CPU
Device
…
Rea
dy P
roce
sses
CPU
Device
…
Rea
dy P
roce
sses
I/O Operation
CPU
Device
…
Rea
dy P
roce
sses
Uses CPU
Slide 3-41
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Determining When I/O is Complete
CPU
Device Device Device
Interrupt Pending
• 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
Slide 3-42
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
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]};
memory[1] contains the address of the interrupt handler
Slide 3-43
Copyright © 2004 Pearson Education, Inc. 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();}
Slide 3-44
Copyright © 2004 Pearson Education, Inc. 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]};
Slide 3-45
Copyright © 2004 Pearson Education, Inc. 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”
Slide 3-46
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Direct Memory Access
PrimaryMemory
CPU
Controller
Device
PrimaryMemory
CPU
Controller
Device
Slide 3-47
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Addressing Devices
PrimaryMemory
Device 0
Device 1
Device n-1
PrimaryMemory
Device 0
Device 1
Device n-1
Dev
ice A
ddre
sses
Mem
ory
Add
ress
es
Mem
ory
Add
ress
es
Slide 3-48
Copyright © 2004 Pearson Education, Inc. 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;
…while((busy == 0) && (done == 1)) wait();// Do the I/O operationbusy = 1;…
busy done
Soft
war
eH
ardw
are
Slide 3-49
Copyright © 2004 Pearson Education, Inc. 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]; }}
Slide 3-50
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Detecting an Interrupt
CPU
Device Device Device
InterruptRequest flag
Slide 3-51
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
The Interrupt Handler
Interrupt_Handler{ saveProcessorState(); for (i=0; i<Number_of_devices; i++) if (device[i].done == 1) goto device_handler(i); /* Something wrong if we get here */}
Slide 3-52
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Disabling Interrupts
if(InterruptRequest && InterruptEnabled) {/* Interrupt current process */ disableInterrupts(); memory[0] = PC; PC = memory[1];}
Slide 3-53
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
The Trap Instruction Operation
SMode
TrustedCode
trap
User Supervisor
Branch Table
2
3
1
Slide 3-54
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Intel System Initialization
ROM
CMOS
RAM
Boot DevicePOST
BIOS
Boot Prog
Loader
OS…Hardware Process
Data Flow
Power Up
Slide 3-55
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Bootstrapping
Bootstrap loader (“boot sector”)
Primary Memory
1
0x0001000
Fetch Unit
Decode Unit
Execute Unit
0000100
…
PC
IR
BIOS loader 0x0000100
Slide 3-56
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
BootstrappingBootstrap loader (“boot sector”)
Primary Memory
Loader
1
2
Fetch Unit
Decode Unit
Execute Unit
0001000
…
PC
IR
BIOS loader 0x00001000x0001000
0x0008000
Slide 3-57
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
BootstrappingBootstrap loader (“boot sector”)
Primary Memory
Loader
OS
12
3Fetch Unit
Decode Unit
Execute Unit
0008000
…
PC
IR
BIOS loader 0x00001000x0001000
0x0008000
0x000A000
Slide 3-58
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
Bootstrapping
Bootstrap loader (“boot sector”)
Primary Memory
Loader
OS
12
3
4. Initialize hardware5. Create user environment6. …
Fetch Unit
Decode Unit
Execute Unit
000A000
…
PC
IR
BIOS loader 0x00001000x0001000
0x0008000
0x000A000
Slide 3-59
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
A Bootstrap Loader Program
FIXED_LOC: // Bootstrap loader entry pointload R1, =0load R2, =LENGTH_OF_TARGET
// The next instruction is really more like // a procedure call than a machine instruction// It copies a block from FIXED_DISK_ADDRESS// to BUFFER_ADDRESS
read BOOT_DISK, BUFFER_ADDRESSloop: load R3, [BUFFER_ADDRESS, R1]
store R3, [FIXED_DEST, R1]incr R1bleq R1, R2, loopbr FIXED_DEST
Slide 3-60
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
A Pipelined Function Unit
Function UnitOperand 1Operand 2
Result
Operand 1Operand 2
Result
(a) Monolithic Unit
(b) Pipelined Unit
Slide 3-61
Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 4
A SIMD MachineALU Control
Unit
ALU ControlUnit
ALU
ALU
ALU
…
(a) Conventional Architecture
(b) SIMD Architecture