Betriebssysteme ws2000/2001
Operating Systems Principles
Design and Implementation Policies and Mechanisms
S 2004 CS325 1
Textbook: L.Bic and A.C Shaw: "Operating Systems Principles"
Other references:
• A.S. Tanenbaum, „Modern Operating Systems“, Prentice-Hall
• Other references – see web site: cs.nmt.edu/~cs325
S 2004 CS325 2
Prof. H. D. Clausen 1 Betriebssysteme ws2000/2001
Simple hardware configuration
control CPU data addres s
controller controller
main memory device_1 device_2 user IO subsystem
S 2004 CS325 3
Typical hardware configuration
main CPU memory
IOC IOC/PPU
controller controller controller controller
device device device
S 2004 CS325 4
Prof. H. D. Clausen 2 Betriebssysteme ws2000/2001
Processor performance
This chart plots relative performance as measured by the SPECint benchmarks with base of one being a VAX 11/780.
S 2004 CS325 5
Memory cost
Prices of DRAMs (from 16K bits to 64M bits) over time in 1977 dollars. S 2004 CS325 6
Prof. H. D. Clausen 3 Betriebssysteme ws2000/2001
API application program application support API SVC SysCall systems programs
kernel programs SW CISC driver programs RISC HW
S 2004 CS325 7
Principle of abstraction
• Higher-level function: – Read( file, logical_block, main_memory )
• Lower-level functions – Calculate position of logical_block on the disk; – Move Read/Write head to corresponding track; – Check for „seek“ errors; – Read physical block; – Check for „read“ errors; – Copy block to main_memory;
S 2004 CS325 8
Prof. H. D. Clausen 4 Betriebssysteme ws2000/2001
Principle of abstraction
extended machine read
Calc_pos Mov_RWhd Functions = “virtual” ReadPhysBlk CopyBlkToMe instructions m
ChckReadErr ChckSeekErr
driver basic machine
HW machine instructions
S 2004 CS325 9
“Logical Design”
• Logical -> “virtual” machine • Real -> “physical” machine
• Design principles – – “policy”, strategy – plan of action --- design – “mechanism”, tactics, approach --- implementation • Example: waiting queue – Logical organization: FIFO, priority, some scheduling scheme – Physical organization: linked list, doubly linked list, circular list, array, heap, …
S 2004 CS325 10
Prof. H. D. Clausen 5 Betriebssysteme ws2000/2001
„Timesharing“ – time slicing
1 1
2
4
3
S 2004 CS325 11
Real and virtual memory logical real (virtual) (physial)
mapping
S 2004 CS325 12
Prof. H. D. Clausen 6 Betriebssysteme ws2000/2001
Real and virtual memory
logical (virtual) real (physial)
The ideal situation: each The real situation: each process (executing memory system is composed program) has its own of a hierarchy of storage address space ranging from components (cache, fast and 0 to a max_size. big memory…). The total No access from/to other storage is divided into address spaces is allowed. segments, pages and access/ transfer pieces – proper Special hardware support (paging, access and protection is a base and limimt registers, address serious problem. mapping hardware (MMU) alleviate the task of the operating system.
S 2004 CS325 13
Virtual, logical und physical devices
control data
virtual device
log. device 1 log. device 2
Driver_1 Driver_2
phys. phys. device 1 device 2
S 2004 CS325 14
Prof. H. D. Clausen 7 Betriebssysteme ws2000/2001
interfaces and Virtual machines
Operating System kernel
virtual machine = logical machine + manager
logical machine = physical maschine + driver
S 2004 CS325 15
Virtual Machines
Processes Processes Processes
Kernel_1 Kernel_2 Kernel_3
Virtual Machine
Hardware
S 2004 CS325 16
Prof. H. D. Clausen 8 Betriebssysteme ws2000/2001
Example Virtual Machine
Processes Processes Processes
OS_1 OS _2 OS _3
Virtual Machine (VM/370)
Hardware
S 2004 CS325 17
System Configuration
secondary storage tape/C terminal printer D
controller controller controller controller
controller netw.interf. CPU memory
S 2004 CS325 18
Prof. H. D. Clausen 9 Betriebssysteme ws2000/2001
structural organization
application programs user_1 user_2 user_n
user- mode System-Libraries file- (protected) (functions) system
OS-kernel system- mode (priviledged)
Hardware Plattform
S 2004 CS325 19
structural organization
• Monolithic systems: one big collection of routines, all run in privileged mode; • Structured systems: higher-level functions run in user mode, lower-level functions are combined into a privileged kernel; • Micro-kernel systems: only the hardware-drivers and a few critical components (thread management, inter- process communication, synchronization) run in kernel mode – everything else runs in user mode.
S 2004 CS325 20
Prof. H. D. Clausen 10 Betriebssysteme ws2000/2001
Software structure
User 1 User 2 . . . User n
(Graphical)(Graphical) User User Interface Interface
Applic.-Applic.- utility-utility- SW-SW- Applic.-Applic.- progr.progr. 1 1 programprogram tooltool progr.progr. n n System Calls MaschinenPOSIX OperatingOperating System System FunctionsFunctions code VM OperatingOperating System System KernelKernel HardwareHardware
S 2004 CS325 21
„von Neumann Architecture“
Memory contains:
Adress • data and Data (results) of next instruction • programs
instructions data (commands)
Control unit control- ALU signals
This principle was invented by J. P. Eckert and J. W. Mauchly but published first as an abstract concept by John von Neumann. Similar ideas were developed by Konrad Zuse and Schreyer.
S 2004 CS325 22
Prof. H. D. Clausen 11 Betriebssysteme ws2000/2001
Fetch-Execute Cycle
REPEAT IR := Mp[PC]; PC := PC+1 IF (FC == JpClass) THEN PC := Operand jumps ELSE other Execute (IR) operations END_IF; UNTIL cpu_HALT;
S 2004 CS325 23
von Neumann Architecture (SISD)
memory Mp contains: ALU Adress of • data and dat next instruction • programs
instruction
Program Counter PC instruction register IR
FCMod Operand
modifier Adress, direct function code Operand
S 2004 CS325 24
Prof. H. D. Clausen 12 Betriebssysteme ws2000/2001
Interrupt Mechanism
IF (IRQ_i == 1) THEN save PC; PC := IRLoc_i ELSE IR := Mp[PC]; PC := PC+1
IF (FC == JpClass) THEN PC := Operand ELSE Execute (IR);
END_IF
END_IF // Interrupt
S 2004 CS325 25
„basic instruction cycle with interrupts“ nxnynz This transition is triggered by the interrupt nnn_i
nxnyni
This location is saved by the interrupt hardware or the handler This transition is executed by the interrupt software. handler (driver) command “RTI”
S 2004 CS325 26
Prof. H. D. Clausen 13 Betriebssysteme ws2000/2001
Software Structure
User 1 User 2 . . . User n
(Graphical)(Graphical) User User Interface Interface–– „shell“ „shell“
applicationapplication 1 1 UtilityUtility i i ToolTool k k applicationapplication n n
System Calls (SVC) Operating System Functions and Services
Operating System kernel Hardware
S 2004 CS325 27
OS Functions
• Process management
• File management5
• Input/Output
• Networking
• Utility services
S 2004 CS325 28
Prof. H. D. Clausen 14 Betriebssysteme ws2000/2001
Simple batch system – memory allocation
FF….FF free space
-data User program - code
Operating system 0
S 2004 CS325 29
Bootstrap Loader task: load a small initial program into memory and start it. This process is also called „deadstart“, „coldstart“, „bootstrap“; it must be supported by a hardware “initial load” function.
Press_Load: FOR i := 0 TO 79 DO Read(M[i]); END_FOR; GOTO (M[0]);
S 2004 CS325 30
Prof. H. D. Clausen 15 Betriebssysteme ws2000/2001
Bootstrap
0 1 79 LA1 n1 Absolute Code (Program/Data) LA2 n2 Absolute Code (Program/Data)
LA3 n3 Absolute Code (Program/Data)
......
E_A 0
Entry_Address = start of execution ( PC := E_A; go! )
S 2004 CS325 31
Bootstrap In a second/third phase the minimal program can read and sub- sequently start a bigger program - e.g. a more powerful loader or the kernel of an executive system (Exec, Monitor program,0 OS)1 79 LA n Absolute Code (Program/Data)
Load address
LOOP: FOR i := 0 TO 79 DO Read(M[r+i]) END_FOR; LA := M[r]; n := M[r+1]; IF n==0 THEN GOTO LA; FOR i := 0 TO n-1 DO M[LA+i] := M[r+2+i] END_FOR; END_LOOP; S 2004 CS325 32
Prof. H. D. Clausen 16 Betriebssysteme ws2000/2001
Bootstrap Loader
3 loading stages
Operating system Main memory
S 2004 CS325 33
Bootstrap Loader II
1 2 Initially a HW program (ROM) reads the first sector of the boot disk with the “Partition Table”; then it reads the bootblock of the active partition.
3
All other steps are identical to the simple boot process.
S 2004 CS325 34
Prof. H. D. Clausen 17 Betriebssysteme ws2000/2001
Early Programming
• Use of the „bare machine“
• Certain instruction sequences which appear frequently are arranged into subroutines
• Subroutines which are commonly used are organized into a library
for application programming a symbolic notation is introduced - > Assembler FC „64“ = „jmp“
• Address managment is alleviated by introducing symbolic names and automatic relocation at translation and loading time
S 2004 CS325 35
Early Programming
• Binding (linkage edit) und Loading are delegated to special programs. (linkage editor, loader)
• Execution is supervised and controlled by a „Monitor“ program (Exec).
• Additional service programs (utilities) are provided: editor, compiler, SortMerge programs
• Control cards and a „Job Control Language“ (JCL) permit user control of „job“ execution
• all systems and utility programs comprise the operating software; the machine-oriented programs lower layers form the operating system proper.
S 2004 CS325 36
Prof. H. D. Clausen 18 Betriebssysteme ws2000/2001
protected user mode
kernel unprotected = privileged mode
bare hardware
S 2004 CS325 37
Multiprogramming systeme - memory allocation
user job_n
User job_2
user job_1
operating system Jan 26
S 2004 CS325 38
Prof. H. D. Clausen 19 Betriebssysteme ws2000/2001
CPU and I/O Activities Interrupt Aktivität Interrupt
CPU
I/O
Zeit t
S 2004 CS325 39
I/O Overlap (Multiprogramming / Multitasking) Interrupt Aktivität Interrupt Process 2 CPU Process 1 CPU Process 1
I/O I/O Process 1
Zeit t
S 2004 CS325 40
Prof. H. D. Clausen 20 Betriebssysteme ws2000/2001
Runtime Organization - Service Invocation
• Subroutine/Coroutine – Single thread of execution
• Message Passing – Multiple threads – Logical / virtual – Physical / real
S 2004 CS325 41
Memory Protection
job_n
< Limitregister job_2 >= Basisregister job_1 User Mode Kernel Mode Operating system privilegierte Instruktionen
S 2004 CS325 42
Prof. H. D. Clausen 21 Betriebssysteme ws2000/2001
Protection - Kernel/User Mode
job_n
< Limitregister job_2 >= Baseregister job_1 UserPrivileged Mode KernelInstructions Mode operating system privilegierte Instruktionen
S 2004 CS325 43
Types of Operating Systems
• simple Batch Systems • Timesharing Systems • Workstation / PC Systems • Multiprocessor-/Parallel-systems • Real Time Systems • Process Control Systems • Embedded Systems • Signal processing systems • Distributed Systems • Networked Systems
S 2004 CS325 44
Prof. H. D. Clausen 22 Betriebssysteme ws2000/2001
Monolithic System
P_1 User programs P_n
Proc-Call; Call; SVC; Branch; Send/Receive; Return;
Operating System
Interrupt
HW System
S 2004 CS325 45
Process-Oriented System
User communication System process u_i s_j process
Kernel Call Return;
Operating System Kernel
Interrupt
HW System
S 2004 CS325 46
Prof. H. D. Clausen 23 Betriebssysteme ws2000/2001
Object-Oriented System
User System object o_i object capability o_j
Kernel Call Return;
Operating System Kernel
Interrupt
HW System
S 2004 CS325 47
Future?
• “current efforts to secure the PC´s traditionally open architecture will either lead – to an unwieldy system that tries to employ impenetrable membranes, encrypted buses and tamper resistant memory, or – To an inferior solution that fails to thwart dishonest users and limits backup and interoperability “ • “investing in proven architectural improvements such as guarded pointers and data tags (capabilities) is a more cost effective and long overdue alternative”
S 2004 CS325 48
Prof. H. D. Clausen 24 Betriebssysteme ws2000/2001
Yet another quote…
“The world of software production has dramatically changed during the last decades from pure assembler programming to procedural programming to object-oriented programming. Each step raised the level of abstraction and increased programmer productivity. Operating systems, on the other hand, remained largely unaffected by this process. … there is a growing divergence between application programming and operating system programming. To close this semantic gap between the applications and the OS interface a large market of middleware systems has emerged over the last years. While these systems hide the ancient nature of operating systems, they introduce many layers of indirection with several performance problems. While previous object-oriented operating systems demonstrated that it is possible and beneficial to use object-orientation, they also made it apparent that it is a problem when implementation technology (object orientation) and protection mechanism (address spaces) mismatch.”
S 2004 CS325 49
Not a pretty picture …
Application Application program program API
Middleware
KI
Operating System
Hardware
S 2004 CS325 50
Prof. H. D. Clausen 25 Betriebssysteme ws2000/2001
CPU und I/O activity – (a) instruction waits
I/O I/O routine I/O instruction routine I/O CPU instruction
idleI/O device idle I/O
time t
S 2004 CS325 51
I/O and CPU Overlapping
aktiv READY 1 1 1 CPUinaktividle
Command Interrupt READY aktiv
I/Oinaktividle
S 2004 CS325 52
Prof. H. D. Clausen 26 Betriebssysteme ws2000/2001
CPU und I/O activity – (b) parallel I/O with polling
I/O I/O routine routine
CPU test test test test test test restart restart busy device idleI/O device idle
time t
S 2004 CS325 53
CPU und I/O activity – (c) device interrupts CPU
I/O I/O routine routine
CPU restart restart interrupt device interrupt interrupt busy idleI/O device idle
time t
S 2004 CS325 54
Prof. H. D. Clausen 27 Betriebssysteme ws2000/2001
The basic structure of protection rings (Multics)
S 2004 CS325 55
XINU
Is Not Unix !
Douglas Comer: Operating System Design – the XINU Approach (LSI-11, Pentium)
S 2004 CS325 56
Prof. H. D. Clausen 28 Betriebssysteme ws2000/2001
Design Principles
• Functionality vs. form • components – composition - aggregation • Concentrate on basic design elements and functions (the logical level, not implementation aspects ??) • Follow the KISS principle: (keep it simple, stupid!) • Aside: implementation principles: – Use HL implementation languages! – Compilers need to efficiently exploit the HW (JIT) – Exploit efficient basic methods, e.g. * Fast context switching (address space) * Highly efficient IPC * Efficient process/thread switching and RPC
S 2004 CS325 57
Layered Structure
User_1 User_2 User_n
CompilerEditor Programm
System services Hard- ware
System kernel
Hardware
S 2004 CS325 58
Prof. H. D. Clausen 29 Betriebssysteme ws2000/2001
Layered Systems
• Layer – a collection of functions which are closely coupled and at the same hierarchical level • hierarcal level - corresponds to a certain level of abstraction • abstraction – extraction of the essential (logical) characteristic features of a real (physical) machine and definition of an abstract (logical) machine • The services are made available by “system calls” (SVCs) in form of standardized functions at APIs [API - application program interface, SAP - service access point ]
S 2004 CS325 59
“virtualization”
Layer 3
Processing – Processing - Processing - step step step Java
Layer 2
Java-VM
Layer 1
e.g. Pentium time
S 2004 CS325 60
Prof. H. D. Clausen 30 Betriebssysteme ws2000/2001
HAL and virtual machines
• A Hardware Abstraction Layer (HAL) is an attempt to map the physical characteristics of hardware onto a more abstract and general logical machine. • A virtual machine offers to the user a certain interface which generates the illusion of a “real” machine. • The different layers of an operating system can be seen as virtual machines of increasingly higher abstraction. • Different virtual machines can coexist in one real system at the same level and in multiprogramming mode. • The „Java VM“ supports specifically the concepts and structure of the high-level programming system Java; this (should) guarantee the portability of applications (and late binding/dynamic loading as well as JIT compiling).
S 2004 CS325 61
Goals
• Design goals – “elegant and clean” • Implementation goals – “efficient and compact”
• 2 competing views: – Top-down – goal oriented (deductive) – Bottom-up – tool oriented (inductive) • Common goal: both approaches concentrate on the kernel – Micro – kernel – Exo – kernel • *** the kernel design and implementation is the *** real problem
S 2004 CS325 62
Prof. H. D. Clausen 31 Betriebssysteme ws2000/2001
Cont.
• The common elements are: – Improved protection mechanisms to support “trusted systems” – Highly efficient set of basic elements (functions, primitives, objects) – Extensibility I.e. the capability to dynamically load additional OS components such as e.g. drivers in a “safe and secure” mode
S 2004 CS325 63
Mach
User 1 User 2 . . .
user Interface to Memory Terminal File mode system calls and functions Management I/O System
kernel Micro-kernel: Scheduler, Interprocess Communic. Basic I/O mode
HardwareHardware
S 2004 CS325 64
Prof. H. D. Clausen 32 Betriebssysteme ws2000/2001
Windows NT Struktur
Logon OS/2 Win16 WIN32 MSDOS POSIX proc. applic. applic. applic. applic. applic. security OS/2 Win16 MSDOS POSIX Subsyst. Subsyst. VDM VDM Subsyst. Win32 user Subsyst. mode
Executive - Systemdienste Object Process Memory Security Local Proc. I/O Manager Manager Manager Manager Calls kernel Manager (Mikro) Kernel mode Hardware Abstraction Layer
HardwareHardware
S 2004 CS325 65
Prof. H. D. Clausen 33