810 likes | 916 Views
Topic 6 : Introduction to Operating Systems. L & E: Pages 1-19, 17-29 Tanenbaum: Pages 1-5, 15-16, 50-53. Book Details Reminder:. We will use two different books for this course.
E N D
Topic 6 : Introduction to Operating Systems L & E: Pages 1-19, 17-29 Tanenbaum: Pages 1-5, 15-16, 50-53
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
Operating SystemsProvide a Virtual Machine Operating System Specific Interface O/S • An OS is responsible for: • Sharing resources • Ensuring optimisation of resources Hardware
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.
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.
This Lecture…. • Doing many things at the same (or apparently the same) time…
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.
Example Programs • Two programs to be run. Begin putline (“A”); putline (“B”); putline (“C”); End. Begin putline (“1”); putline (“2”); putline (“3”); End.
Sequential Execution Output Job One Job Two
Sequential Execution Output Job One Job Two 1 2 3
Sequential Execution Output Job One Job Two 1 2 3 A B C
Concurrent Execution Output Job One Job Two
Concurrent Execution Output Job One Job Two 1
Concurrent Execution Output Job One Job Two 1 A
Concurrent Execution Output Job One Job Two 1 A 2
Concurrent Execution Output Job One Job Two 1 A 2 B
Concurrent Execution Output Job One Job Two 1 A 2 B 3
Concurrent Execution Output Job One Job Two 1 A 2 B 3 C
Parallel Execution Output Job One Job Two
Parallel Execution Output Job One Job Two 1 A
Parallel Execution Output Job One Job Two 1 A 2 B
Parallel Execution Output Job One Job Two 1 A 2 B 3 C
Summary of Execution Patterns Sequential Concurrent Parallel
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.
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.
The Old Application Program Main Memory Address Machine Language Instruction NULL 0 #0 LDBASE 1 LOAD 6 2 MULT 6 3 6 4 STORE 5 1 JUMP 6 10
The New Application Program Main Memory Address STB 3 0 #0 LDBASE 1 JUMP @3 2 # PC Stored Here 4 3 LDA #8 4 STPC+2 B 12 JUMP 0 13
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.
0 1 2 3 4 5 PTE = 0 Base = 0 Limit = 0 Index = 0 The New Dispatcher Acc = 0 JUMP IDLE STARTIT: LDBASE BASETABLE+ JUMPSUB SAVE_IT IDLE: LDA PTE JNZ DISPATCH JUMP IDLE
PTE = 0 Base = 0 Limit = 0 Index = 0 The New Dispatcher Acc = 0 6 DISPATCH: STI LDA BASE_TABLE+ JNZ RESTORE_IT JUMPSUB LOADIT LDLIMIT LIMITTABLE+ JUMP STARTIT 7 8 9 10 11
PTE = 0 Base = 0 Limit = 0 Index = 0 The New Dispatcher Acc = 0 12 SAVE_IT: STA ACC_TABLE+ RETURN RESTORE_IT LDA ACC_TABLE+ LDLIMIT LIMIT_TABLE+ JUMP START_IT 13 14 15 16
Supporting Data Structures BASETABLE: 0 0 0 LIMITTABLE: 0 0 0 ACCTABLE: 0 0 0
0 1 2 3 4 5 PTE = 0 Base = 0 Limit = 0 Index = 0 Demo Acc = 0 JUMP IDLE STARTIT: LDBASE BASETABLE+ JUMPSUB SAVE_IT IDLE: LDA PTE JNZ DISPATCH JUMP IDLE
0 1 2 3 4 5 PTE =1 Base = 0 Limit = 0 Index = 0 Demo Acc = 1 JUMP IDLE STARTIT: LDBASE BASETABLE+ JUMPSUB SAVE_IT IDLE: LDA PTE JNZ DISPATCH JUMP IDLE
0 1 2 3 4 5 PTE = 1 Base = 0 Limit = 0 Index = 0 Demo Acc = 1 JUMP IDLE STARTIT: LDBASE BASETABLE+ JUMPSUB SAVE_IT IDLE: LDA PTE JNZ DISPATCH JUMP IDLE
PTE = 1 Base = 0 Limit = 0 Index = 1 Demo Acc = 1 6 DISPATCH: STI LDA BASE_TABLE+ JNZ RESTORE_IT JUMPSUB LOADIT LDLIMIT LIMITTABLE+ JUMP STARTIT 7 8 9 10 11
PTE = 1 Base = 0 Limit = 0 Index = 1 Demo Acc = 0 6 DISPATCH: STI LDA BASE_TABLE+ JNZ RESTORE_IT JUMPSUB LOADIT LDLIMIT LIMITTABLE+ JUMP STARTIT 7 8 9 10 11
PTE = 1 Base = 0 Limit = 0 Index = 1 Demo Acc = 0 6 DISPATCH: STI LDA BASE_TABLE+ JNZ RESTORE_IT JUMPSUB LOADIT LDLIMIT LIMITTABLE+ JUMP STARTIT 7 8 9 10 11
PTE = 1 Base = 0 Limit = 0 Index = 1 Demo Acc = 0 6 DISPATCH: STI LDA BASE_TABLE+ JNZ RESTORE_IT JUMPSUB LOADIT LDLIMIT LIMITTABLE+ JUMP STARTIT 7 8 9 10 11 Assume LOADIT finds some space in memory and fixes the base and limit registers accordingly.
Supporting Data Structures BASETABLE: 0 100 0 LIMITTABLE: 0 199 0 ACCTABLE: 0 0 0
PTE = 1 Base = 0 Limit = 199 Index = 1 Demo Acc = 0 6 DISPATCH: STI LDA BASE_TABLE+ JNZ RESTORE_IT JUMPSUB LOADIT LDLIMIT LIMITTABLE+ JUMP STARTIT 7 8 9 10 11
PTE = 1 Base = 0 Limit =199 Index =1 Demo Acc = 0 6 DISPATCH: STI LDA BASE_TABLE+ JNZ RESTORE_IT JUMPSUB LOADIT LDLIMIT LIMITTABLE+ JUMP STARTIT 7 8 9 10 11
0 1 2 3 4 5 PTE = 1 Base = 100 Limit = 199 Index = 1 Demo Acc = 0 JUMP IDLE STARTIT: LDBASE BASETABLE+ JUMPSUB SAVE_IT IDLE: LDA PTE JNZ DISPATCH JUMP IDLE
PTE =0 Base = 100 Limit = 199 Index = 1 Demo Acc = 0 Main Memory Address STB 3 100 #0 LDBASE 101 JUMP @3 102 # PC Stored Here 4 103 LDA #8 104 STPC+2 B 112 JUMP 0 113
PTE = 0 Base = 100 Limit =199 Index =1 Demo Acc = 8 Main Memory Address STB 3 100 #0 LDBASE 101 JUMP @3 102 # PC Stored Here 4 103 LDA #8 104 STPC+2 B 112 JUMP 0 113
PTE = 0 Base = 100 Limit = 199 Index = 1 Demo Acc =9 Main Memory Address STB 3 100 #0 LDBASE 101 JUMP @3 102 # PC Stored Here 4 103 LOAD #8 104 program instructions leading to it wanting to halt temporarily STPC+2 B 112 JUMP 0 113
PTE = 0 Base = 100 Limit = 199 Index = 1 Demo Acc = 8 B = 14 Main Memory Address STB 3 100 #0 LDBASE 101 JUMP @3 102 # PC Stored Here 4 103 LOAD 8 104 STPC+2 B 112 JUMP 0 113
PTE = 0 Base = 100 Limit = 199 Index = 1 Demo Acc = 8 B = 14 Main Memory Address STB 3 100 #0 LDBASE 101 JUMP @3 102 # PC Stored Here 4 103 LOAD 8 104 STPC+2 B 112 JUMP 0 113
PTE = 0 Base = 100 Limit = 199 Index = 1 Demo Acc = 8 B = 14 Main Memory Address STB 3 100 #0 LDBASE 101 JUMP @3 102 # PC Stored Here 14 103 LOAD 8 104 STPC+2 B 112 JUMP 0 113
PTE = 0 Base = 0 Limit = 199 Index = 1 Demo Acc = 8 B = 14 Main Memory Address STB 3 100 #0 LDBASE 101 JUMP @3 102 # PC Stored Here 14 103 LOAD 8 104 STPC+2 B 112 JUMP 0 113