OS1Notes
OS1Notes
Course Notes
Aims ii
Course Outline
• Part I: Context: Computer Organisation
– Machine Levels
– Operation of a Simple Computer.
– Input/Output.
Outline iii
Recommended Reading
• Tannenbaum A S
Structured Computer Organization (3rd Ed)
Prentice-Hall 1990.
• Patterson D and Hennessy J
Computer Organization & Design (2rd Ed)
Morgan Kaufmann 1998.
• Bacon J [ and Harris T ]
Concurrent Systems or Operating Systems
Addison Wesley 1997, Addison Wesley 2003
• Silberschatz A, Peterson J and Galvin P
Operating Systems Concepts (5th Ed.)
Addison Wesley 1998.
• Leffler S J
The Design and Implementation of the 4.3BSD
UNIX Operating System.
Addison Wesley 1989
• Solomon D and Russinovich M
Windows Internals (4th Ed)
Microsoft Press 2000, Microsoft Press 2005
Books iv
A Quick Refresher on Background
Processor Bus
Address Data Control
Register File
(including PC)
Memory
Control Execution e.g. 1 GByte
Unit Unit 2^30 x 8 =
8,589,934,592bits
Reset
Hard Disk
Framebuffer
Super I/O
Sound Card
Mouse Keyboard Serial
Address
Data
Control
Bus
Execution Unit
+
Register File
PC
Decode IB
A
#Ra
A
#Rb Execution
PC
#Rd
A Unit
K
Fn
Carry Out
• Signed subtraction:
01010 10 10110 -10
+ 11001 -7 + 10110 -10
------------- --------------
1 00011 3 1 01100 12
------------- --------------
1 0
Big Endian
DE AD BE EF
00 01 02 03 04 05 06 07 08
EF BE AD DE
Little Endian
20 62 75 50 Ox351A.25E4 75 50 00 09
65 6D 69 54 Ox351A.25E8 69 54 20 62
xx xx 00 21 Ox351A.25EC xx 21 65 6D
• 0x49207769736820697420776173203a2d28
Execution Unit
+
Register File
BU PC
ALU Decode IB
MAU
Baud
r/w read/write Rate
/cs chip select Generator
sector
cylinder
arm
platter
rotation
Framebuffer
from CPU Dot
VRAM/ Clock
SDRAM/ hsync
SGRAM vsync to Monitor
Red
RAMDAC Green
Blue
Graphics
PCI/ Processor
AGP
Other Devices
Caches
Processor
512MByte
DIMM
512MByte
DIMM
Bridge
Framebuffer
ISA Bus (8Mhz)
PCI Bus (33/66Mhz)
Bridge
SCSI
Controller
Sound
Card
0x0020: ...
0x184c: add r0, r0, #8 0x0024: <do stuff>
...... ...
0x1850: sub r1, r5, r6
0x0038: rti
0x1854: ldr r0, [r0]
0x1858: and r1, r1, r0
Processor
8259A PIC
IR0
INT IR1
IR2
Intel INTA IR3
Clone IR4
IR5
D[0:7] IR6
IR7
App N
App 1
App 2
Operating System
Hardware
Time
App. App.
App. App.
Scheduler
interrupt or fault
reset Kernel User
Mode Mode
0xFFFF
Job 4
0xD800
Job 3 limit register
0x9800 0x4800
Job 2
0x5000 0x5000
Job 1 base register
0x3000
Operating
System
0x0000
base base+limit
Memory
yes yes
CPU
no no
Unpriv
Priv Kernel System Calls
Scheduler
Server Server
Unpriv
Priv Server Device Device
Driver Driver
Kernel Scheduler
S/W
H/W
• Alternative structure:
– push some OS services into servers.
– servers may be privileged (i.e. operate in kernel
mode).
• Increases both modularity and extensibility.
• Still access kernel via system calls, but need new
way to access servers:
⇒ interprocess communication (IPC) schemes.
Ready Running
timeout
or yield
event event-wait
Blocked
Program Counter
Other Information
(e.g. list of open files, name of
executable, identity of owner, CPU
time used so far, devices owned)
Refs to previous and next PCBs
executing
idle
Save State into PCB A
idle
Restore State from PCB B
executing
timeout or yield
Wait Queue(s)
event event-wait
create create
(batch) (interactive)
Frequency
2 4 6 8 10 12 14 16
Memory
no
+
CPU logical physical
address yes address
address fault
OS A
B
C
1700K 1700K
P2
P4 P4 P4
1000K 1000K 1000K
900K
P1 P1 P1 P5
400K 400K 400K
OS OS OS OS OS
0 0 0
P4 P5 P6
P3 P3 P3 P3 P3 P3
P2
P4 P4 P4 P4
P1 P1 P1 P5 P5
OS OS OS OS OS OS
P4 P4
1500K 900K 900K 1500K
300K
1200K 1200K 1200K
P3 P4 1000K P3
1000K
800K
900K
400K P4
P3
600K 600K 600K 600K
500K P2 500K P2 500K P2 500K P2
P1 P1 P1 P1
300K 300K 300K 300K
0
OS 0
OS 0
OS 0
OS
Memory
p
CPU 1 f f o
physical
address
Page n-1
Memory
CPU
TLB
p1 f1
p2 f2
p o p3 f3
p4 f4 f o
logical address
physical address
Page Table
1 f
L1 Page Table
0
L2 Page Table
n L2 Address 0
n Leaf PTE
N
20 bits
PTA IGN P Z A C W U R V
S O C D T S W D
1024
entries
PFA IGN G Z D A C W U R V
L O Y C D T S W D
1024
entries
Frame Number K R W X V
40
35
CLOCK
30
25 LRU
20
OPT
15
10
0
5 6 7 8 9 10 11 12 13 14 15
thrashing
CPU utilisation
Degree of Multiprogramming
B B
Shared
[DANGEROUS] [SAFE]
Sharing segments:
• wasteful (and dangerous) to store common
information on shared segment in each process
segment table
• assign each segment a unique System Segment
Number (SSN)
• process segment table simply maps from a Process
Segment Number (PSN) to SSN
Memory
logical physical
address address
CPU MMU
translation
fault (to OS)
data (r/w)
read (W/O)
write (W/O)
command
Storage Service
I/O subsystem
Disk Handler
Name SFID
hello.java 12353
Makefile 23812
README 9742
Location on Disk
Size in bytes
Time of creation
Access permissions
A D E F I J
mail java
B C G H
sent
A D E F I J
mail java
B C G H
sent
Name D SFID
Ann Y 1034 Name D SFID
Bob Y 179 mail Y 2165 Name D SFID
A N 5797 sent Y 434
B N 2459
Yao Y 7182 C N 25
current
file position
User
System Call Interface
Kernel
Memory Process
File System
Management Management
Hardware
unix.ps index.html
direct
direct blocks (x12) blocks
(512)
data
single indirect
double indirect to block with 512
single indirect entries
triple indirect data
to block with 512
double indirect entries
Super-Block
Boot-Block
N 32
17 78
Inode 78
system-wide
open file table
= 0640 = 0755
Stack Segment
Address Space
grows downward as per Process
functions are called
Free
Space
grows upwards as more
memory allocated
Data Segment
Text Segment
parent
process parent process (potentially) continues
fork wait
child zombie
process process
program executes
execve exit
child
fork process execve
no fg? program
executes
yes
zombie exit
wait process
• Prompt is ‘#’.
• Use man to find out about commands.
• User friendly?
Buffer
Cache
Cooked
Character I/O
Hardware
• Recall:
– everything accessed via the file system.
– two broad categories: block and char.
• Low-level stuff gory and machdep ⇒ ignore.
• Character I/O low rate but complex ⇒ most
functionality in the “cooked” interface.
• Block I/O simpler but performance matters ⇒
emphasis on the buffer cache.
CP Uj (i − 1)
Pj (i) = Basej + + 2 × nicej
4
2 × loadj
CP Uj (i) = CP Uj (i − 1) + nicej
(2 × loadj ) + 1
ru
syscall
z exit rk preempt p
sleep schedule
same
state
sl wakeup
rb
fork() c
Win32
Subsytem
User Mode
Native NT Interface (Sytem Calls)
Kernel Mode
EXECUTIVE
I/O VM Object Process
Manager Manager Manager Manager
Hardware
Kernel
• Foundation for the executive and the subsystems
• Execution is never preempted.
• Four main responsibilities:
1. CPU scheduling
2. interrupt and exception handling
3. low-level processor synchronisation
4. recovery after a power failure
• Kernel is objected-oriented; all objects either
dispatcher objects and control objects
Process
1
Object Name Process
Object Directory 2 Process
Security Descriptor 3
Quota Charges
Object Open Handle Count
Header Open Handles List
Type Object
Temporary/Permanent
Type Object Pointer Type Name
Reference Count Common Info.
Methods:
Open
Object Object-Specfic Data Close
(perhaps including Delete
Body a kernel object) Parse
Security
Query Name
exams.tex
winnt\ temp\
File
System
Driver
I/O Intermediate
Manager Driver
Device
Driver
HAL
Time (2 Bytes)
Date (2 Bytes)
Free First Cluster (2 Bytes)
EOF
File Size (4 Bytes)
n-1 Free
15
16 user file/directory
17 user file/directory
Partition A1
Partition B1
Partition A2
Partition A3 Partition B2