operating systems principles design and implementation ...cs325/osp_01.pdf · os_1 os _2 os _3...
TRANSCRIPT
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 1
S 2004 CS325 1
Operating Systems PrinciplesOperating Systems Principles
Design and Implementation Design and Implementation Policies and Mechanisms Policies and Mechanisms
S 2004 CS325 2
Textbook: L.Bic and A.C Shaw: Textbook: L.Bic and A.C Shaw: "Operating Systems Principles""Operating Systems Principles"
Other references:
• A.S. Tanenbaum, „Modern Operating Systems“, Prentice-Hall
• Other references – see web site: cs.nmt.edu/~cs325
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 2
S 2004 CS325 3
Simple hardware configurationSimple hardware configuration
control
CPU dataaddress
mainmemory
controller controller
device_1 device_2
IO subsystem
user
S 2004 CS325 4
Typical hardware configurationTypical hardware configuration
CPUmain
memory
controller
device
IOC
controller controller
device
IOC/PPU
controller
device
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 3
S 2004 CS325 5
Processor performanceProcessor performance
This chart plots relative performance as measured by the SPECint benchmarks with base of one being a VAX 11/780.
S 2004 CS325 6
Memory costMemory cost
Prices of DRAMs (from 16K bits to 64M bits) over time in 1977 dollars.
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 4
S 2004 CS325 7
application supportAPI
CISC
RISC
SysCall
systems programs
kernel programs
driver programsSW
HW
application program
SVC
API
S 2004 CS325 8
Principle of abstractionPrinciple 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;
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 5
S 2004 CS325 9
Principle of abstractionPrinciple of abstraction
HW
driver
read
Calc_pos Mov_RWhd
ChckSeekErrChckReadErr
ReadPhysBlk CopyBlkToMem
Functions = “virtual” instructions
machine instructions
basic machine
extended machine
S 2004 CS325 10
“Logical Design”“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, …
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 6
S 2004 CS325 11
„Timesharing“ „Timesharing“ –– ttime ime sslicinglicing
1
2
1
3
4
S 2004 CS325 12
Real and virtual memoryReal and virtual memorylogical
(virtual)real
(physial)
mapping
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 7
S 2004 CS325 13
Real and virtual memoryReal and virtual memory
logical (virtual) real (physial)
The ideal situation: each process (executing program) has its own address space ranging from 0 to a max_size. No access from/to other address spaces is allowed.
The real situation: each memory system is composed of a hierarchy of storage components (cache, fast and big memory…). The total storage is divided into segments, pages and access/ transfer pieces – proper access and protection is a serious problem.
Special hardware support (paging, base and limimt registers, address mapping hardware (MMU) alleviate the task of the operating system.
S 2004 CS325 14
Virtual,Virtual, logicallogical und und physicalphysical devicesdevices
virtual device
control data
log. device 1 log. device 2
phys. device 1
phys. device 2
Driver_1 Driver_2
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 8
S 2004 CS325 15
interfacesinterfaces andand VirtualVirtual machinesmachines
virtual machine = logical machine + manager
logical machine = physical maschine +driver
Operating Systemkernel
S 2004 CS325 16
Virtual MachinesVirtual Machines
Hardware
Virtual Machine
Kernel_1 Kernel_2 Kernel_3
Processes Processes Processes
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 9
S 2004 CS325 17
Example Example VirtuVirtuaal Machinel Machine
Hardware
Virtual Machine (VM/370)
OS_1 OS _2 OS _3
Processes Processes Processes
S 2004 CS325 18
System ConfigurationSystem Configuration
CPUmemory
controller
terminal
controllercontroller
secondary storage
controller
controller
printertape/C
D
netw.interf.
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 10
S 2004 CS325 19
structural organization structural organization
user_1 user_2 user_napplication programs
System-Libraries (functions)
OS-kernel
Hardware Plattform
file-system
user-mode
(protected)
system-mode
(priviledged)
S 2004 CS325 20
structural organizationstructural 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.
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 11
S 2004 CS325 21
Operating System KernelOperating System Kernel
SoftwareSoftware strustruccturturee
(Graphical) User Interface(Graphical) User Interface
Applic.-progr. 1Applic.-progr. 1
User 1
utility-programutility-
programSW-tool
SW-tool
Applic.-progr. nApplic.-progr. n
User 2 User n
Operating System FunctionsOperating System Functions
HardwareHardware
SystemCalls
Maschinencode
. . .
VM
POSIX
S 2004 CS325 22
„von Neumann Architecture“„von Neumann Architecture“
Memory contains:
• data and
• programs
instructions(commands)
Control unit ALU
data
control-signals
Data (results)Adress of next instruction
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.
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 12
S 2004 CS325 23
FetchFetch--Execute CycleExecute Cycle
REPEATIR := Mp[PC];PC := PC+1IF (FC == JpClass) THEN
PC := OperandELSE
Execute (IR)END_IF;
UNTIL cpu_HALT;
jumps
other operations
S 2004 CS325 24
von Neumann Architecture (SISD)von Neumann Architecture (SISD)
memory Mp contains:
• data and
• programs
instruction
Program Counter PC instruction register IR
Adress of next instruction
ALUdat
FC OperandMod
Adress, direct Operandfunction code
modifier
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 13
S 2004 CS325 25
Interrupt MechanismInterrupt Mechanism
ELSE
IF (FC == JpClass) THEN PC := Operand
ELSE Execute (IR);
END_IF
save PC; PC := IRLoc_i
IF (IRQ_i == 1) THEN
IR := Mp[PC]; PC := PC+1
END_IF // Interrupt
S 2004 CS325 26
„basic instruction cycle with interrupts“„basic instruction cycle with interrupts“nxnynz
nnn_i
nxnyni
This transition is triggered by the interrupt
This transition is executed by the interrupthandler (driver) command “RTI”
This location is saved by the interrupthardware or the handler software.
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 14
S 2004 CS325 27
Software StructureSoftware Structure
(Graphical) User Interface – „shell“(Graphical) User Interface – „shell“
application 1application 1
User 1
Utility iUtility i Tool kTool k application napplication n
User 2 User n
Operating System kernel
Hardware
System Calls (SVC)
. . .
Operating SystemFunctions and Services
S 2004 CS325 28
OS Functions OS Functions
• Process management
• Memory management
• File management5
• Input/Output
• Networking
• Utility services
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 15
S 2004 CS325 29
Simple batch system Simple batch system –– memory allocationmemory allocation
Operating system
- data
User program- code
free space
0
FF….FF
S 2004 CS325 30
Bootstrap LoaderBootstrap Loadertask: 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]);
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 16
S 2004 CS325 31
BootstrapBootstrap
Entry_Address = start of execution ( PC := E_A; go! )
LA1 Absolute Code (Program/Data)n1
10 79
LA2 Absolute Code (Program/Data)n2
LA3 Absolute Code (Program/Data)n3
E_A 0
.. ........
S 2004 CS325 32
BootstrapBootstrapIn a second/third phase the minimal program can read and sub- sequently start a bigger program - e.g. a more powerfulloader or the kernel of an executive system (Exec, Monitor program, OS)
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;
LA
Load address
Absolute Code (Program/Data)n
10 79
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 17
S 2004 CS325 33
Bootstrap Loader Bootstrap Loader
3 loading stages
Operating system Main memory
S 2004 CS325 34
Bootstrap Loader IIBootstrap Loader IIInitially a HW program (ROM) reads the firstsector of the boot disk with the “Partition Table”; then it reads the bootblock of the active partition.
All other steps are identical to the simple boot process.
1 2
3
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 18
S 2004 CS325 35
Early ProgrammingEarly 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 36
Early ProgrammingEarly 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.
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 19
S 2004 CS325 37
user mode
kernel mode
protected
unprotected = privileged
bare hardware
S 2004 CS325 38
Multiprogramming systeme Multiprogramming systeme --memory allocationmemory allocation
operating system
user job_1
User job_2
user job_n
Jan 26
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 20
S 2004 CS325 39
CPU and I/O ActivitiesCPU and I/O Activities
Zeit t
Akt
ivitä
t
CPU
I/O
Inte
rrup
t
Inte
rrup
t
S 2004 CS325 40
I/O OverlapI/O Overlap ((Multiprogramming Multiprogramming //MultitaskingMultitasking))
Zeit t
Akt
ivitä
t
CPU
I/O
Inte
rrup
t
Inte
rrup
t
CPU
I/O
Process 1
Process 2
Process 1
Process 1
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 21
S 2004 CS325 41
Runtime Organization Runtime Organization -- Service InvocationService Invocation
• Subroutine/Coroutine– Single thread of execution
• Message Passing– Multiple threads
– Logical / virtual
– Physical / real
S 2004 CS325 42
Memory Memory ProtectionProtection
Operating system
job_1
job_n
Basisregister
Limitregister
job_2
Kernel ModeUser Mode
privilegierte Instruktionen
<
>=
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 22
S 2004 CS325 43
Protection Protection -- Kernel/User ModeKernel/User Mode
operating system
job_1
job_n
Baseregister
Limitregisterjob_2
Kernel ModeUser Mode
privilegierte Instruktionen
<
>=
PrivilegedInstructions
S 2004 CS325 44
Types of Operating SystemsTypes 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
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 23
S 2004 CS325 45
Monolithic SystemMonolithic System
User programs
Operating System
P_1 P_n
HW System
Proc-Call;SVC;
Send/Receive;
Call;Branch;Return;
Interrupt
S 2004 CS325 46
ProcessProcess--Oriented SystemOriented SystemUser
process
Operating System Kernel
u_i s_j
HW System
KernelCall Return;
Interrupt
System process
communication
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 24
S 2004 CS325 47
ObjectObject--Oriented SystemOriented SystemUser
object
Operating System Kernel
o_i o_j
HW System
KernelCall Return;
Interrupt
System object
capability
S 2004 CS325 48
Future?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 andlimits 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”
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 25
S 2004 CS325 49
Yet another quote…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 50
Not a pretty picture …Not a pretty picture …
Application program
Application program
Middleware
API
Operating System
Hardware
KI
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 26
S 2004 CS325 51
CPU und I/O activity CPU und I/O activity –– (a) instruction waits(a) instruction waits
time t
CPU
I/O
I/O instruction
I/O deviceidle idle
I/O routine
I/O routine I/O
instruction
S 2004 CS325 52
II//OO aand CPU nd CPU OvOverlapperlappiingng
inaktiv
aktiv
inaktiv
aktiv
InterruptCommand
111CPU
I/O idle
idle
READY
READY
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 27
S 2004 CS325 53
CPU und I/O activity CPU und I/O activity –– (b) parallel I/O with (b) parallel I/O with pollingpolling
time t
CPU
device I/O deviceidle idle
I/O routine
I/O routine
test
rest
art
busy
test
test
test
rest
art
test
test
S 2004 CS325 54
CPU und I/O activity CPU und I/O activity –– (c) device interrupts (c) device interrupts CPUCPU
time t
CPU
device
I/O deviceidle idle
I/O routine
I/O routine
inte
rrup
t
rest
art
busy
inte
rrup
tre
star
t
inte
rrup
t
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 28
S 2004 CS325 55
The basic structure of protection rings (Multics)
S 2004 CS325 56
XINU
Is Not Unix !
Douglas Comer: Operating System Design – the XINU Approach (LSI-11, Pentium)
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 29
S 2004 CS325 57
Design PrinciplesDesign 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 58
Layered StructureLayered Structure
Hardware
System services
Compiler ProgrammEditor
User_1 User_2 User_n
Hard-ware
System kernel
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 30
S 2004 CS325 59
Layered SystemsLayered 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) machineand 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 60
“virtualization”“virtualization”
Processing –step
Layer 3
Layer 1
Layer 2
Processing -step
Processing -step
time
Java
Java-VM
e.g. Pentium
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 31
S 2004 CS325 61
HAL and virtuHAL and virtualal mmachineachiness• 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 thesame level and in multiprogramming mode.
• The „Java VM“ supports specifically the concepts and structureof 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 62
GoalsGoals
• 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
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 32
S 2004 CS325 63
Cont.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 64
MachMach
kernelmode
usermode
HardwareHardware
Micro-kernel: Scheduler, Interprocess Communic. Basic I/O
Memory
Management
File
System
Terminal
I/O
Interface tosystem calls
and functions
User 1 User 2 . . .
Betriebssysteme ws2000/2001
Prof. H. D. Clausen 33
S 2004 CS325 65
Windows NT StrukturWindows NT Struktur
HardwareHardware
(Mikro) Kernel
Hardware Abstraction Layer
ObjectManager
ProcessManager
MemoryManager
SecurityManager
Local Proc.Calls
Executive - Systemdienste
kernelmode
usermode
I/OManager
Win32Subsyst.
security Subsyst.
Win16 VDM
OS/2applic.
POSIXSubsyst.
MSDOSVDM
OS/2Subsyst.
Win16applic.
POSIXapplic.
MSDOSapplic.
WIN32applic.
Logon proc.