C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Topic 6 : Introduction to Operating Systems
L & E: Pages 1-19, 17-29
Tanenbaum: Pages 1-5, 15-16, 50-53
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Book Details Reminder:
• We will use two different books for this course.• “Fundamentals of Operating Systems”,
A. M. Lister and R. D. Eager, Fifth Edition, Macmillan Computer Science Series, ISBN. 0-333-59848-2, £13.99.
• “Operating Systems Design and Implementation”, A. S. Tanenbaum, Prentice-Hall International, ISBN. 0-13-630195-9, about £29.99.
• www.comp.lancs.ac.uk/computing/staff/kc/keiths_teaching.html
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Operating SystemsProvide a Virtual Machine
Hardware
Operating System Specific Interface
O/S
An OS is responsible for:
Sharing resources
Ensuring optimisation of
resources
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Wrote a minimal dispatcher.
• Basic idea is to load the program from disk and start it executing.
• When its finished start executing another one.
• During its period of execution the program is called a process.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Approach for Simple Dispatcher
• Sit in a loop waiting for a program to be ready to run.
• Load the specified program from disk into memory.
• Use base and limit registers to make sure program addresses work.
• When the program has finished go back to the loop and wait for another to be ready.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
This Lecture….
• Doing many things at the same (or apparently the same) time…
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Some Simple Definitions
• Sequential = doing things one at a time.
• Concurrent = doing things (apparently) at the same time.
• Parallel = doing things really at the same time.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Example Programs
• Two programs to be run.Begin
putline (“1”);putline (“2”);putline (“3”);
End.
Beginputline (“A”);putline (“B”);putline (“C”);
End.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Sequential Execution
Job One Job Two Output
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Sequential Execution
Job One Job Two Output
123
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Sequential Execution
Job One Job Two Output
123ABC
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Concurrent Execution
Job One Job Two Output
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Concurrent Execution
Job One Job Two Output
1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Concurrent Execution
Job One Job Two Output
1A
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Concurrent Execution
Job One Job Two Output
1A2
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Concurrent Execution
Job One Job Two Output
1A2B
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Concurrent Execution
Job One Job Two Output
1A2B3
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Concurrent Execution
Job One Job Two Output
1A2B3C
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Parallel Execution
Job One Job Two Output
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Parallel Execution
Job One Job Two Output
1 A
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Parallel Execution
Job One Job Two Output
12
AB
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Parallel Execution
Job One Job Two Output
123
ABC
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Summary of Execution Patterns
Sequential
Concurrent
Parallel
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Extending Our Dispatcher to Deal With Concurrency• Load programs into different parts of
memory.• Make each program save its data and where
it is when it wants to temporarily stop running (c.f. interrupts).
• Modify the dispatcher so it can jump to these saved points.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Why Multiple Programs?
• Support multiple tasks by users.
• Allow tasks to proceed in background.
• Allow programs to be structured as
independent tasks.
• Support multiple users.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The Old Application Program
Main Memory Address Machine Language Instruction
2
345
6
LOAD 6
MULT 6STORE 6
JUMP
0
1
NULL
LDBASE #0
1
10
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The New Application Program
Main Memory Address
4 LDA #8
0
1
STB
LDBASE #0
3
2
3
JUMP
4 # PC Stored Here
@3
12 STPC+2 B
13 JUMP 0
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The New Dispatcher
• Sit in a loop waiting for a program to be ready to run.
• If it’s a new program load the specified program from disk into memory and jump to the start.
• If it’s an old program ... restore the registers and jump back via stored PC.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The New Dispatcher
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
0
12
345
PTE = 0Acc = 0
Base = 0Limit = 0
Index = 0
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The New Dispatcher
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 0Acc = 0
Base = 0Limit = 0
Index = 0
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The New Dispatcher
SAVE_IT: STA ACC_TABLE+RETURN
RESTORE_IT LDA ACC_TABLE+LDLIMIT LIMIT_TABLE+JUMP START_IT
1213
141516
PTE = 0Acc = 0
Base = 0Limit = 0
Index = 0
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Supporting Data Structures
BASETABLE: 000
LIMITTABLE: 000
ACCTABLE: 000
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
0
12
345
PTE = 0Acc = 0
Base = 0Limit = 0
Index = 0
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE =1Acc = 1
Base = 0Limit = 0
Index = 0
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE = 1Acc = 1
Base = 0Limit = 0
Index = 0
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 1Acc = 1
Base = 0Limit = 0
Index = 1
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 1Acc = 0
Base = 0Limit = 0
Index = 1
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 1Acc = 0
Base = 0Limit = 0
Index = 1
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 1Acc = 0
Base = 0Limit = 0
Index = 1
67891011
Assume LOADIT finds some space in memory and fixes thebase and limit registers accordingly.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Supporting Data Structures
BASETABLE: 01000
LIMITTABLE: 01990
ACCTABLE: 000
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 1Acc = 0
Base = 0Limit = 199
Index = 1
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 1Acc = 0
Base = 0Limit =199
Index =1
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE = 1Acc = 0
Base = 100Limit = 199
Index = 1
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LDA #8
100
101
STB
LDBASE #0
3
102
103
JUMP
4 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE =0Acc = 0
Base = 100Limit = 199
Index = 1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LDA #8
100
101
STB
LDBASE #0
3
102
103
JUMP
4 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE = 0Acc = 8
Base = 100Limit =199
Index =1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LOAD #8
100
101
STB
LDBASE #0
3
102
103
JUMP
4 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE = 0Acc =9
Base = 100Limit = 199
Index = 1
program instructions leading to it wanting to halt temporarily
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LOAD 8
100
101
STB
LDBASE #0
3
102
103
JUMP
4 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE = 0Acc = 8
Base = 100Limit = 199
Index = 1
B = 14
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LOAD 8
100
101
STB
LDBASE #0
3
102
103
JUMP
4 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE = 0Acc = 8
Base = 100Limit = 199
Index = 1
B = 14
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LOAD 8
100
101
STB
LDBASE #0
3
102
103
JUMP
14 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE = 0Acc = 8
Base = 100Limit = 199
Index = 1
B = 14
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LOAD 8
100
101
STB
LDBASE #0
3
102
103
JUMP
14 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE = 0 Acc = 8
Base = 0Limit = 199
Index = 1
B = 14
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
0
12
345
PTE = 0Acc = 8
Base = 0Limit = 199
Index = 1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
SAVE_IT: STA ACC_TABLE+RETURN
RESTORE_IT LDA ACC_TABLE+LDLIMIT LIMIT_TABLE+JUMP START_IT
1213
141516
PTE = 0Acc = 8
Base = 0Limit = 199
Index = 1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Supporting Data Structures
BASETABLE: 01000
LIMITTABLE: 01990
ACCTABLE: 080
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
SAVE_IT: STA ACC_TABLE+RETURN
RESTORE_IT LDA ACC_TABLE+LDLIMIT LIMIT_TABLE+JUMP START_IT
PTE =0Acc = 8
Base = 0Limit = 199
Index = 1
1213
141516
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE =0Acc = 0
Base = 0Limit = 199
Index = 1
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE = 0Acc = 0
Base = 0Limit = 0
Index = 1
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE = 0Acc = 0
Base = 0Limit = 0
Index = 1
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE = 1Acc = 1
Base = 0Limit = 0
Index = 1
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
PTE =1Acc = 1
Base = 0Limit = 0
Index = 1
0
12
345
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE =1Acc = 1
Base = 0Limit =0
Index = 1
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE = 0Acc = 100
Base = 0Limit =0
Index = 0
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT
PTE =1Acc =100
Base = 0Limit = 0
Index =1
67891011
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
SAVE_IT: STA ACC_TABLE+RETURN
RESTORE_IT LDA ACC_TABLE+LDLIMIT LIMIT_TABLE+JUMP START_IT
1213
141516
PTE =1Acc =8
Base = 0Limit = 0
Index =1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
SAVE_IT: STA ACC_TABLE+RETURN
RESTORE_IT LDA ACC_TABLE+LDLIMIT LIMIT_TABLE+JUMP START_IT
PTE =1Acc =8
Base = 0Limit = 199
Index =1
1213
141516
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
SAVE_IT: STA ACC_TABLE+RETURN
RESTORE_IT LDA ACC_TABLE+LDLIMIT LIMIT_TABLE+JUMP START_IT
1213
141516
PTE =1Acc =8
Base = 0Limit = 199
Index =1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
JUMP IDLE STARTIT: LDBASE BASETABLE+
JUMPSUB SAVE_IT
IDLE: LDA PTEJNZ DISPATCHJUMP IDLE
0
12
345
PTE =1Acc =8
Base = 100Limit = 199
Index =1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LOAD #8
100
101
STB
LDBASE #0
3
102
103
JUMP
14 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
PTE =0Acc =8
Base = 100Limit = 199
Index =1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Demo
Main Memory Address
104 LOAD 8
100
101
STB
LDBASE #0
3
102
103
JUMP
14 # PC Stored Here
@3
112 STPC+2 B
113 JUMP 0
114
PTE =0Acc =8
Base = 100Limit = 199
Index =1
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Whew ! Glad That’s Over
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Process Context
• We save two pieces of information: accumulator and PC
• In practice processes have much more context that needs to be saved.
• Term process context is used to describe all of the state a process must save to be able to resume execution from the same point.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Which Process to Run
• Question: Why stop a process and change to another during its execution ?
• Answer: Lots of reasons .....• Want to give other processes a chance to run
(concurrent execution).• The process can’t continue until another process has
finished its task.• The process is waiting for something to happen (e.g.
I/O).• An exceptional event has occurred (i.e. an interrupt).
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The Process State Model
• The decision on which process to run therefore has to be based on knowing whether the process can be run.
• During their lifetime processes typically cycle through 3 states• Ready• Running• Blocked
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The Process State Model .. contd
Ready
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The Process State Model .. contd
Ready
Running
Process is selected to run
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Either
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The Process State Model .. contd
Ready
Running
Process is selected to run
Process finishes time slice
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
OR
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The Process State Model .. contd
Ready
Running
Process is selected to run
BlockedProcess blocks (e.g. I/O)
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
The Process State Model .. contd
Ready
Running
Process is selected to run
BlockedProcess blocks (e.g. I/O)
Blocking operation finishes (e.g. I/O)
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Summary
• Described different execution patterns: sequential, concurrent and parallel.
• Developed a simple dispatcher which can handle concurrent processes.
• Started to look at why you might want to change between concurrent processes - the process state model.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Coming next week
• Problems with concurrent processing.