Download presentation
Presentation is loading. Please wait.
Published byMadeline Tamsyn Nash Modified over 9 years ago
1
4330/6310 FIRST ASSIGNMENT Spring 2015 Jehan-François Pâris jfparis@uh.edu
2
The model We have One quad-core CPU One disk One input device Three queues CPU queue "ready queue" Disk queue Device queue RQRQ DQDQ Disk CC CC IQIQ Input
3
AN EXAMPLE
4
P0 begins at t = 0 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 RQRQ DQDQ Disk CC CC IQIQ Input NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40
5
P0 gets core until t = 0 + 200 = 200 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 RQRQ DQDQ Disk CC CC IQIQ Input NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40
6
What's next? RQRQ DQDQ Disk CC CC IQIQ Input NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40
7
P1 arrives at t = 100 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
8
P1 gets core until t = 100 + 30 = 130 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
9
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
10
P1 waits for input until t = 130 +800 = 930 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
11
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
12
P0 waits for input device NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
13
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
14
P1 gets core until t = 930 + 40 = 970 P0 waits for input until t = 930 + 900 = 1830 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
15
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
16
P1 terminates at t = 970 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
17
Your program will display (I) Process 1 terminates at t = 970 Core 0 is IDLE Core 1 is IDLE Core 2 is IDLE Core 3 is IDLE Disk is IDLE Average number of busy cores: Ready queue contains: -- Disk queue contains: --
18
Your program will display (II) Process IDStart timeCPU timeStatus 00200WAITING 110070TERMINATED
19
How to compute CPU utilization Keep track of total time for all CPU requests: 200 + 30 + 40 = 270 ms Divide by elapsed time: 270/970 = 0.278 (rounded) Since there are four cores, the maximum CPU utilization is 4.0
20
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
21
P0 gets core until t = 1830 +10 = 1840 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
22
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
23
P0 gets disk until t = 1840 + 10 = 1850 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
24
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
25
P0 gets CPU until t = 1850 + 30 =1880 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
26
What's next? NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
27
P0 terminates at t = 1880 NEW 0 START 0 CPU 200 INPUT 900 CPU 10 I/O 10 CPU 30 NEW 1 START 100 CPU 30 INPUT 800 CPU 40 RQRQ DQDQ Disk CC CC IQIQ Input
28
Your program will display (I) Process 0 terminates at t = 1880 Core 0 is IDLE Core 1 is IDLE Core 2 is IDLE Core 3 is IDLE Disk is IDLE Average number of busy cores: 0.174 Ready queue contains: -- Disk queue contains: --
29
Your program will display (II) Process IDStart timeCPU timeStatus 00240TERMINATED
30
How to compute CPU utilization Keep track of total time for all CPU requests: 200 + 10 + 30 + 30 + 40 = 310 ms Divide by elapsed time: 310/1880 = 0.165 (rounded) Since there are four cores, the maximum CPU utilization is 4.0
31
HANDLING ZERO-DELAY DISK ACCESSES
32
Zero-delay disk accesses Represent disk requests that can be satisfied without actually accessing the disk: Data can be read from the I/O buffer Data are written to the I/O buffer A process performing a zero-delay I/O request will: Skip the disk Start without further delay its next processing step
33
An example (I) … CPU 5 I/O 0 CPU 20 … RQRQ DQDQ Disk CC CC IQIQ Input Assume next step for red process is I/O 0
34
An example (II) … CPU 5 I/O 0 CPU 20 … RQRQ DQDQ Disk CC CC IQIQ Input Red process will immediately request a core (and get one because one or more cores were idle)
35
ENGINEERING THE SIMULATION
36
Simulating time Absolutely nothing happens to our model between two successive "events" Events are Arrival of a new process Start of a computing step Completion of a computing step We associate an event routine with each event
37
Arrival event routine Process first request of process It will always be a CPU request
38
CPU request routine current time is clock request time is crt if a core is free : mark core busy until clock + crt add crt to corebusytimes else : enter process in ready queue
39
CPU request completion routine if ready queue is empty : mark core idle else: pick first process P' in ready queue crt' is request time for P' mark core busy until clock + crt' add crt' to corebusytimes proceed with next request for completing process
40
Disk request routine current time is clock request time is drt if drt == 0: proceed with next process request if disk is free : mark disk busy until clock + drt add drt to diskbusytimes else : enter process request in disk queue
41
Disk request completion routine if disk queue is empty : mark disk idle else : pick first process request P' in disk queue drt' is request time for P' mark disk busy until clock + drt' add drt' to diskbusytimes proceed with next request for completing process
42
Input request routine current time is clock request time is irt if input device is free : mark input device busy until clock + irt else : enter process request in device queue
43
Input request completion routine if input queue is empty : mark input device idle else : pick first process request P' in input queue irt' is request time for P' mark disk busy until clock + irt' proceed with next request for completing process
44
The simulation scheduler 1.Find next event by looking at: CPU request completion times Disk request completion time time Input request completion time Arrival time of next process 2.Set current time to event time 3.Process event routine 4.Repeat until all processes are done
45
Organizing our program (I) Most steps of simulation involve scheduling future completion events Associate with each completion event an event notice Time of event Device Process sequence number
46
Organizing our program (II) Do the same with process starts Time of event Process start Process sequence number
47
Organizing our program (III) Process all event notices in chronological order Release disk 247 Release core 250 New process 245 New process 270 New process 310 First notice to be processed
48
Organizing our program (IV) Keep the event list sorted (priority queue) Release disk 247 Release core 250 New process 245 New process 270 New process 310 First notice to be processed is head of the list
49
Organizing our program (V) Overall organization of main program schedule first event # will be a process start while event list is not empty : process next event in list print simulation results
50
Organizing our event list Priority queue Two kinds of entries Computational steps completion times: Created and inserted "on the fly" Process arrivals: Created during input phase Already sorted
51
An implementation My main data structures would be: Data table Process table Device table
52
The data table Stores the input data Line indices are used in process table OperationParameter NEW 5 CPU 10 INPUT 0 CPU 20 NEW 20 CPU 50 … …
53
The process table (I) Start Time First Line Last Line Current Line 503 varies 204…… …………
54
The process table (I) Start Time First Line Last Line Current Line 503 varies 204…… …………
55
The process table (II) One line per process Line index is process sequence number! First column has start time of process First line, last line and current line respectively identify first line, last line and current line of the process in the input table Last column is for processes waiting for end of an INPUT step
56
The device table (I) ProcessCompletion time P015 -- -- First column is not needed: use row index to specify device
57
The device table (II) One line per device (core, disk and Input) Contains A busy/free flag A process sequence number if device is busy A completion time Zero (or a very large value) if device is free
58
Finding the next event (I) If you use a priority list for your events, you should start by "seeding" your priority list with the arrival times of all processes After that, you add successive events to the list each time you can allocate a resource to a process. Your simulation will end once the list is empty (and you cannot add anything to it).
59
Finding the next event (II) If you do not use a priority list for your events, you can find the next event to process by searching the lowest value in The process start times in the process table Completion times of INPUT steps The completion times in the device table
60
A full list implementation INT… 0 INT… 5 RUN 10 RUN 20 … … … Very elegant but harder to debug
61
Reading your input You must use I/O redirection assign1 < input_file Advantages Very flexible Programmer writes her code as if it was read from standard input No need to mess with fopen(), argc and argcv
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.