a step by step picture of how processes schedulejb/cs502/project/howprocessesschedule.pdf · a step...
TRANSCRIPT
A Step By Step Picture of How Processes Schedule
(Using Test5 and TestX as examples)
Version 4.60: August 2019
A Step By Step Picture of How Processes Schedule
(Using Test5 and TestX as examples)
Here are the assumptions we’re using:1. To keep it simple, Test5 will start only ONE TestX.2. The dispatcher has a mechanism as we talked about in class –
this allows the simulator’s clock to advance.While (NothingOnReadyQ() ) {
CALL(WasteTime();}
3. The “times” listed are made up – may not be real.4. Remember CODE is static – PROCESSES are moving around.
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
3
Z502StartContextZ502Timer
TestXcode
Time = 50Test5 has created TestX and put the TestX PCB on the ready Q.Test5 Does a Sleep(1000)
TestX PCB
Hardware Interrupt Code
InterruptTestX
Test5
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
4
Z502StartContextZ502Timer
TestXcode
Time = 73Test5 puts its PCB on timer QTest5 starts the timer.
TestX PCB
Hardware Interrupt Code
InterruptTestX
Test5
Test5 PCBT = 1073
T = 1000
Delay = 1000, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
5
Z502StartContextZ502Timer
TestXcode
Time = 79Test5 finds TestX PCB on readyDoes a StartContext(Test5) after which Test5 is suspended in the hardware
Hardware Interrupt Code
InterruptTestX
Test5
Test5 PCBT = 1073
StartContext(Test5, START_CONTEXT_AND_SUSPEND)
Delay = 1000, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
6
Z502StartContextZ502Timer
TestXcode
Time = 85Process TestX in TestX code.TestX does a Sleep(500)
Hardware Interrupt Code
Interrupt
TestX
Test5
Test5 PCBT = 1073
Delay = 1000, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
7
Z502StartContextZ502Timer
TestXcode
Time = 93Process TestX in StartTimer.The new sleep is sooner than the existing one.Put new time on head of timer QReplace the current timer value with the new time.
Hardware Interrupt Code
Interrupt
TestX
Test5
TestX PCBT = 593
Delay = 500
Test5 PCBT = 1073
Delay = 500, Interrupt at 593
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
8
Z502StartContextZ502Timer
TestXcode
Time = 101Nothing on Ready QTestX executes
while() Call loop – see page 1
Hardware Interrupt Code
Interrupt
TestX
Test5
TestX PCBT = 593
Test5 PCBT = 1073
Delay = 500, Interrupt at 593
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
9
Z502StartContextZ502Timer
TestXcode
Time = 597Interrupt in Interrupt HandlerRemove TestX PCB from head of timer Q
Hardware Interrupt Code
Interrupt
TestX
Test5
Test5 PCBT = 1073
Timer Not Active
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
10
Z502StartContextZ502Timer
TestXcode
Time = 598Interrupt in Make ReadyPuts TestX PCB on Ready Q
TestX PCB
Hardware Interrupt Code
Interrupt
TestX
Test5
Test5 PCBT = 1073
Timer Not Active
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
11
Z502StartContextZ502Timer
TestXcode
Time = 600Interrupt in InterruptHandlerPuts new delay time in the timer Delay is 1073 – 600 = 473TestX PCB
Hardware Interrupt Code
Interrupt
TestX
Test5
Delay = 473
Test5 PCBT = 1073
Delay =473, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
12
Z502StartContextZ502Timer
TestXcode
Time = 601TestX sees PCB on Ready Q and removes itDoes StartContext(TestX)Hardware knows this context is already running and simply returns
Hardware Interrupt Code
Interrupt
TestX
Test5
Test5 PCBT = 1073
Delay =473, Interrupt at 1073
StartContext(TestX, START_CONTEXT_AND_SUSPEND)
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
13
Z502StartContextZ502Timer
TestXcode
Time = 603TestX returns all the way back to TestX code.
Hardware Interrupt Code
Interrupt
TestX
Test5
Test5 PCBT = 1073
Delay =473, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
14
Z502StartContextZ502Timer
TestXcode
Time = 603TestX does Sleep(463)
Hardware Interrupt Code
Interrupt
TestX
Test5
Test5 PCBT = 1073
Delay =473, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
15
Z502StartContextZ502Timer
TestXcode
Time = 612TestX puts its PCB on Timer Q (note the order)NO NEED to restart timer
Hardware Interrupt Code
Interrupt
TestX
Test5
TestX PCBT = 1075
Test5 PCBT = 1073
Delay =473, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
16
Z502StartContextZ502Timer
TestXcode
Time = 620Nothing on Ready QTestX executes the
while CALL loop
Hardware Interrupt Code
Interrupt
TestX
Test5
TestX PCBT = 1075
Test5 PCBT = 1073
Delay =473, Interrupt at 1073
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
17
Z502StartContextZ502Timer
TestXcode
Time = 1077Interrupt in InterruptHandlerRemoves first PCB on Timer Q
Hardware Interrupt Code
Interrupt
TestX
Test5
TestX PCBT = 1075
Test5 PCBT = 1073
Nothing on Timer
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
18
Z502StartContextZ502Timer
TestXcode
Time = 1079Interrupt Thread in MakeReadyPuts Test5 on Ready Q
Test5 PCB
Hardware Interrupt Code
Interrupt
TestX
Test5
TestX PCBT = 1075
Nothing on Timer
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
19
Z502StartContextZ502Timer
TestXcode
Time = 1081Interrupt in InterruptHandlerCurrent time is AFTER when next interrupt would occur, so no need to start timer. Simply take this PCB off the timer Q.
Test5 PCB
Hardware Interrupt Code
Interrupt
TestX
Test5Nothing on Timer
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
20
Z502StartContextZ502Timer
TestXcode
Time = 1083Interrupt in MakeReadyPuts TestX PCB on Ready Q in proper priority order.The Interrupt is now done.Test5 PCB
Hardware Interrupt Code
Interrupt
TestX
Test5Nothing on Timer
TestX PCB
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
21
Z502StartContextZ502Timer
TestXcode
Time = 1090TestX thread now removes the first item on the Ready Q.
TestX process calls hardware StartContext to begin running the new process.
Hardware Interrupt Code
Interrupt
TestX
Test5Nothing on Timer
TestX PCB
StartContext(Test5, START_CONTEXT_AND_SUSPEND)
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
22
Z502StartContextZ502Timer
TestXcode
Time = 1095Test5 process is now running and returns all the way back to user code.
Hardware Interrupt Code
InterruptTestX
Test5
Nothing on Timer
TestX PCB
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
23
Z502StartContextZ502Timer
TestXcode
Time = 1100Test5 does a Sleep(1000)
Hardware Interrupt Code
InterruptTestX
Test5
Nothing on Timer
TestX PCB
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
24
Z502StartContextZ502Timer
TestXcode
Time = 1110Test5 in StartTimerPuts its PCB on the Timer Q
Hardware Interrupt Code
InterruptTestX
Test5
Delay = 1000
Test5 PCBT = 2110
Delay =1000, Interrupt at 2110
TestX PCB
Yellow is CODE, Blues are Queues and Queue Elements, Red shows where a process is currently executing or suspended.
Test5code
SVC
InterruptHandlerTimerQueue
StartTimer
ReadyQueue
Dispatcher
Make_Ready_To_Run
osCreateProcess
25
Z502StartContextZ502Timer
TestXcode
You should now be able to predict the next steps and write code that performs the way described in the previous slides.
Hardware Interrupt Code
InterruptTestX
Test5
Test5 PCBT = 2110
Delay =1000, Interrupt at 2110
TestX PCB