81
.Sc. 110: Computer Systems .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

Topic 6 : Introduction to Operating Systems L & E: Pages 1-19, 17-29 Tanenbaum: Pages 1-5, 15-16, 50-53

Embed Size (px)

Citation preview

Page 1: 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

Topic 6 : Introduction to Operating Systems

L & E: Pages 1-19, 17-29

Tanenbaum: Pages 1-5, 15-16, 50-53

Page 2: 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

Page 3: 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

Operating SystemsProvide a Virtual Machine

Hardware

Operating System Specific Interface

O/S

An OS is responsible for:

Sharing resources

Ensuring optimisation of

resources

Page 4: 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

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.

Page 5: 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

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.

Page 6: 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

This Lecture….

• Doing many things at the same (or apparently the same) time…

Page 7: 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

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.

Page 8: 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

Example Programs

• Two programs to be run.Begin

putline (“1”);putline (“2”);putline (“3”);

End.

Beginputline (“A”);putline (“B”);putline (“C”);

End.

Page 9: 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

Sequential Execution

Job One Job Two Output

Page 10: 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

Sequential Execution

Job One Job Two Output

123

Page 11: 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

Sequential Execution

Job One Job Two Output

123ABC

Page 12: 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

Concurrent Execution

Job One Job Two Output

Page 13: 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

Concurrent Execution

Job One Job Two Output

1

Page 14: 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

Concurrent Execution

Job One Job Two Output

1A

Page 15: 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

Concurrent Execution

Job One Job Two Output

1A2

Page 16: 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

Concurrent Execution

Job One Job Two Output

1A2B

Page 17: 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

Concurrent Execution

Job One Job Two Output

1A2B3

Page 18: 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

Concurrent Execution

Job One Job Two Output

1A2B3C

Page 19: 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

Parallel Execution

Job One Job Two Output

Page 20: 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

Parallel Execution

Job One Job Two Output

1 A

Page 21: 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

Parallel Execution

Job One Job Two Output

12

AB

Page 22: 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

Parallel Execution

Job One Job Two Output

123

ABC

Page 23: 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

Summary of Execution Patterns

Sequential

Concurrent

Parallel

Page 24: 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

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.

Page 25: 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

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.

Page 26: 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

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

Page 27: 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

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

Page 28: 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

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.

Page 29: 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

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

Page 30: 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

The New Dispatcher

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE = 0Acc = 0

Base = 0Limit = 0

Index = 0

67891011

Page 31: 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

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

Page 32: 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

Supporting Data Structures

BASETABLE: 000

LIMITTABLE: 000

ACCTABLE: 000

Page 33: 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

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

Page 34: 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

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

Page 35: 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

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

Page 36: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE = 1Acc = 1

Base = 0Limit = 0

Index = 1

67891011

Page 37: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE = 1Acc = 0

Base = 0Limit = 0

Index = 1

67891011

Page 38: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE = 1Acc = 0

Base = 0Limit = 0

Index = 1

67891011

Page 39: 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

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.

Page 40: 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

Supporting Data Structures

BASETABLE: 01000

LIMITTABLE: 01990

ACCTABLE: 000

Page 41: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE = 1Acc = 0

Base = 0Limit = 199

Index = 1

67891011

Page 42: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE = 1Acc = 0

Base = 0Limit =199

Index =1

67891011

Page 43: 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

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

Page 44: 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

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

Page 45: 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

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

Page 46: 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

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

Page 47: 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

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

Page 48: 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

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

Page 49: 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

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

Page 50: 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

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

Page 51: 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

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

Page 52: 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

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

Page 53: 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

Supporting Data Structures

BASETABLE: 01000

LIMITTABLE: 01990

ACCTABLE: 080

Page 54: 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

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

Page 55: 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

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

Page 56: 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

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

Page 57: 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

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

Page 58: 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

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

Page 59: 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

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

Page 60: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE =1Acc = 1

Base = 0Limit =0

Index = 1

67891011

Page 61: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE = 0Acc = 100

Base = 0Limit =0

Index = 0

67891011

Page 62: 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

Demo

DISPATCH: STILDA BASE_TABLE+JNZ RESTORE_ITJUMPSUB LOADITLDLIMIT LIMITTABLE+JUMP STARTIT

PTE =1Acc =100

Base = 0Limit = 0

Index =1

67891011

Page 63: 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

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

Page 64: 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

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

Page 65: 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

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

Page 66: 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

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

Page 67: 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

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

Page 68: 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

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

Page 69: 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

Whew ! Glad That’s Over

Page 70: 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

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.

Page 71: 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

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).

Page 72: 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

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

Page 73: 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

The Process State Model .. contd

Ready

Page 74: 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

The Process State Model .. contd

Ready

Running

Process is selected to run

Page 75: 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

Either

Page 76: 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

The Process State Model .. contd

Ready

Running

Process is selected to run

Process finishes time slice

Page 77: 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

OR

Page 78: 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

The Process State Model .. contd

Ready

Running

Process is selected to run

BlockedProcess blocks (e.g. I/O)

Page 79: 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

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)

Page 80: 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

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.

Page 81: 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

Coming next week

• Problems with concurrent processing.