Title: Process Fundamentals, Queueing Theory,
1Process Fundamentals, Queueing Theory,
Simulation
2Process States
- A process state describes its current status
- running
- waiting
- for I/O to complete
- for an available CPU
- for system call to complete
- ... ???
- completed
- ... ???
3Process State Transitions
4Process State Transitions ...
5Process State Transitions ...
6Process State Transitions ...
7Process States O/S Design
- Any change in am O/S state means an O/S change
- code modification
- performance changes
- extra hardware needed now?
- ...
- Can either just build the new O/S (costly) ...
- ... or simulate the new system (cheaper), giving
- performance measures
- prediction of hardware needs
- ...
- ... or ...
8Queuing Theory
- ... OR , perform queuing analysis
- formal, mathematical analysis of states and
queues - under assumptions, gives accurate results
- no need for any coding whatsoever!
- but, one needs to understand the math involved
9Queuing Theory ...
- Consider the following simple queuing system
- given that
- the system is stable (the queue is finite)
- ?in is job arrival rate (new jobs per sec.)
- ?out is job completion rate (jobs finished per
sec.) - Can we relate ?in to ?out ?
CPU
?in ?out (Surprise!!)
10Queuing Theory ...
- Other quantities of interest
- Ts average service time (time in CPU)
- Tw average wait time (time spent in CPU queue)
- w average number waiting jobs (CPU queue
length) - ? average server utilization (CPU utilization)
- r average number of jobs in system
- Tr average response time
- Some simple observations/formulas
- TrTsTw
- ??inTs
- r?inTr (Littles formula/law)
11Queuing Theory ...
- since TrTs/(1-?) and r?inTr ,
- r?inTs/(1-?)
- (?inTs)/(1-?)
- ?/(1-?) ?
- Can you show that w?2/(1-?) ?
- How about Tw?Ts/(1-?) ?
12O/S Example
?ts
?in
?out
Ts
- What does adding a time slice do?
- Suppose
- ?in 1 job / 60 sec
- Ts 20 sec/job
- Prob(?ts) Prob(?out)
0.5
13O/S Example ...
?ts
?in
?out
Ts
?in ?ts
- ?out ?in
- ?out 0.5 (?in ?ts)
- ?ts 0.5 (?in ?ts)
- 0.5 ?ts 0.5 ?in
- ?ts ?in
14O/S Example ...
?ts
?in
?out
Ts
?in ?ts
- But, theres a catch
- derived equations assume only 1 pass through
CPU - this model has several
- how long is typical pass through CPU?
- Assume it is 10 seconds here (well discuss
later) - now, have 2 passes through CPU with Ts10
- and Tr 2 (10/(1-?)) 210/(1-1/3)30 (secs.)
15O/S Example ...
?ts
?in
?out
Ts
?in ?ts
- Another catch dont know probabilities in
advance - Do know time time slice length, though!!
- ex. Ts30s , time slice5s, ?in1job/100seconds
- over n secs, exitsn/30, time slicesn/5 (at
most) - P(exit) exits/(exits time slices)
- P(time slice) time slices(exits time
slices) - time in CPU P(event)(event length)
16O/S Example ...
?ts
?in
?out
Ts
?in ?ts
- P(exit)limn?8(n/30)/( (n/30)(n/5) ) 1/7
- P(time slice)limn?8(n/5)/( (n/30)(n/5) ) 6/7
- again Ts30s , time slice5s, ?in1job/100seconds
- ?ts6/7(?in?ts), so ?ts6?in
- ?(?in?ts)Ts7?inTs7(1/100)(30/7)3/10
- Tr6 passes (Ts/(1-?)) 65/(1-3/10)300/7
17Another Option
- As systems get larger and more complex ...
- ... Queuing Analysis becomes more difficult
- ... sometimes too difficult.
- Instead, perform a discrete event simulation
- simulates large amounts of system time (years)
- ... taking only seconds of real time
- ... calculates important statistics along the
way - Tr, ? (for all devices in system), ...
18Discrete Event Simulation
- The core of Discrete Event Simulation is the
event - In O/S, an event is an action that needs O/S
intervention - new job arriving
- time slice expiring
- job requires I/O
- job completes
- I/O completes
- ...
19Discrete Event Simulation ...
- Basic Idea
- start with a single seed event (process
arrival) - add the event to a sorted event queue
- set curr_time0
- while(queue not empty curr_timeltmax_time)
- remove first event ev from queue
- set curr_timeev.time
- update internal statistics
- generate next event(s) based on this event
- add the new events to the queue
20Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- seed event 1st process enters
Statistics curr_time 0 jobs_done 0
CPU_time 0
21Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process event (0,0, New)
- adds (0,75, Exit) and ...
Statistics curr_time 0 jobs_done 0
CPU_time 0
22Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process event (0,0, New)
- adds (0,75, Exit) and ...
- (1, 100, New)
Statistics curr_time 0 jobs_done 0
CPU_time 0
23Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process event (0,75, Exit)
- updates stats
Statistics curr_time 75 jobs_done 1
CPU_time 75
24Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process event (1,100, New)
- adds (1, 175, Exit) and
- (2,200, New)
Statistics curr_time 100 jobs_done 1
CPU_time 75
25Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process event (1,175, Exit)
- updates stats
Statistics curr_time 175 jobs_done 2
CPU_time 150
26Discrete Event Simulation ...
- When done, will have
- total time in CPU
- total time so far
- number of jobs completed
- could also track other stats along the way
- but there are problems
- real jobs dont have constant CPU (or arrival)
times - vary values using exponential random distribution
- CPU queue not used in prior example
27Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- seed event 1st process enters
CPU Queue
CPU Status
idle
Statistics curr_time 0 jobs_done 0
CPU_time 0
28Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process event (0, 0, New)
- generate CPU time 89 ns
- generate next new 08686 ns
CPU Queue
0
CPU Status
idle
Statistics curr_time 0 jobs_done 0
CPU_time 0
29Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- check CPU - is it busy?
- yes, so pull a job from queue
- schedule CPU exit event
CPU Queue
CPU Status
busy
Statistics curr_time 0 jobs_done 0
CPU_time 0
30Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process next event (1, 86, New)
- CPU busy, so add to queue
- generate next new 86112198
CPU Queue
1
CPU Status
busy
Statistics curr_time 86 jobs_done 0
CPU_time 86
31Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process next event (0, 89, Exit)
- Update Statistics
- Schedule queued job (t8951)
CPU Queue
CPU Status
busy
Statistics curr_time 89 jobs_done 1
CPU_time 89
32Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process next event (1, 140, Exit)
- Update Statistics
- No jobs in queue ...
CPU Queue
CPU Status
idle
Statistics curr_time 140 jobs_done 2
CPU_time 140
33Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process next event (2, 198, New)
- queue empty, run on CPU (exit event)
- generate next new event
CPU Queue
CPU Status
busy
Statistics curr_time 198 jobs_done 2
CPU_time 140
34Discrete Event Simulation ...
- Example - two state model
- jobs arrive every 100 ns
- takes 75 ns to serve them
- process next event (2, 276, Exit)
- update statistics
- queue empty ...
CPU Queue
CPU Status
busy
Statistics curr_time 276 jobs_done 3
CPU_time 218