Summary of Lecture 19 - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Summary of Lecture 19

Description:

... queue, if not create RelD event ... UCPU,wd -- CPU idling while there are ... create new event at time TG, that is event A-load (event A in fact can be ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 29
Provided by: kevin566
Category:

less

Transcript and Presenter's Notes

Title: Summary of Lecture 19


1
Summary of Lecture 19
  • 1. Simple simulator, code analysis
  • 2. Event procedures
  • 3. Statistics
  • 4. Definition of the Project
  • Diagram of the Project Task Flow
  • Events in the Project Simulation
  • Discussion of the project

2
Simple Simulator Declarations
  • / Define simulation
    /
  • define MPL 4
  • define N 12
  • define TCPU 0.4
  • define TQ 0.4
  • define TIR 0.04
  • define TDS 0.06
  • define TTH 8
  • define TT 10000
  • define MEMQ 0
  • define CPUQ 1
  • define DISKQ 2
  • define REQM 0
  • define REQCPU 1
  • define RELCPU 2
  • define REQDISK 3
  • define RELDISK 4
  • define CPU 0
  • define DISK 1

define EMPTY -1 define LOW 0 define HIGH 1
define p2(x) (1Lltlt((x)-1)) includeltmath.hgt
includeltstdio.hgt struct Task float
tcpu,tq,tir,start taskN / Job list
/ struct Events / Event list /
int head, tail float timeN int taskN,
eventN elist struct Queue / Queues
0 memory, 1 - CPU, 2 Disk / int head,
tail, q, n, taskN float ws, tch, ts,
tentryN queue3 struct Device /
Devices 0 - CPU, 1 - Disk/ int busy
float tch, tser server2 int inmem0,
finished_tasks0 float sum_response_time0.0 voi
d ReqM(int, float), ReqCPU(int, float),
RelCPU(int, float), ReqD(int, float),
RelD(int, float) float exprnd(float) void
qplace(int, float, int), create_event(int, int,
float, int), init(), stats() int qremove(int,
float)
3
Simple System Simulator
  • include "header.h"
  • main()
  • float global_time0.0
  • int process, event
  • init()
  • while (global_timeltTT) /
    Main simulation loop /
  • processelist.taskelist.head /
    Select new event /
  • global_time elist.timeelist.head
  • event elist.eventelist.head
  • elist.head(elist.head1)N
  • switch(event)
    / Execute event /
  • case REQM ReqM(process, global_time)
    break
  • case REQCPU ReqCPU(process, global_time)
    break
  • case RELCPU RelCPU(process, global_time)
    break
  • case REQDISK ReqD(process, global_time)
    break
  • case RELDISK RelD(process, global_time)
  • stats()

4
Procedure ReqM
  • void ReqM(int process, float time)
  • / Create a ReqCPU event or place a task in
    memory queue /
  • if (inmemltMPL)
  • inmem
  • / Create a new task
    /
  • taskprocess.tcpuexprnd(TCPU)
  • taskprocess.tq TQ
  • taskprocess.tir exprnd(TIR)
  • create_event(process, REQCPU, time, LOW)
  • else qplace(process, time, MEMQ)

5
Procedure ReqCPU
  • void ReqCPU(int process, float time)
  • float release_time
  • / Place in CPU queue if server is busy
    /
  • if (serverCPU.busy1) qplace(process,time,CPU
    Q)
  • else
  • serverCPU.busy1
  • serverCPU.tchtime
  • / Find the time of leaving CPU
    /
  • if (taskprocess.tcpulttaskprocess.tq)
    release_timetaskprocess.tcpu
  • else release_timetaskprocess.tq
  • if (release_timegttaskprocess.tir)
    release_timetaskprocess.tir
  • / Update the process times and create RelCPU
    event /
  • taskprocess.tcpu-release_time
  • taskprocess.tir-release_time
  • taskprocess.tq-release_time
  • create_event(process, RELCPU,
    timerelease_time, LOW)

6
Procedure RelCPU
  • void RelCPU(int process, float time)
  • int queue_head
  • / Update CPU statistics
    /
  • serverCPU.busy0 serverCPU.tser(time-se
    rverCPU.tch)
  • queue_headqremove(CPUQ, time) /
    remove head of CPU queue /
  • if (queue_head!EMPTY) create_event(queue_head,
    REQCPU, time, HIGH)
  • / Depending on reason for leaving CPU, select
    the next event /
  • if (taskprocess.tcpu0) /
    task termination /
  • create_event(process, REQM, timeexprnd(TTH),
    LOW)
  • inmem-- queue_headqremove(MEMQ, time)
  • if (queue_head!EMPTY) create_event(queue_head
    , REQM, time, HIGH)
  • else if (taskprocess.tq0) /
    time slice interrupt /
  • taskprocess.tqTQ create_event(process,
    REQCPU, time, LOW)
  • else / disk
    access interrupt /
  • taskprocess.tirexprnd(TIR)
    create_event(process, REQDISK, time, LOW)

7
Procedures ReqD, RelD
  • void ReqD(int process, float time)
  • / If Disk busy go to Disk queue, if not
    create RelD event /
  • if (serverDISK.busy) qplace(process,time,DISKQ
    )
  • else
  • serverDISK.busy1
  • serverDISK.tchtime
  • create_event(process, RELDISK,
    timeexprnd(TDS), LOW)
  • void RelD(int process, float time)
  • int disk_queue_head
  • / Update statistics for Disk and create
    ReqCPU event /
  • serverDISK.busy0
  • serverDISK.tser(time-serverDISK.tch)
  • disk_queue_headqremove(DISKQ, time)
  • if (disk_queue_head!EMPTY) create_event(disk_qu
    eue_head, REQDISK,time,HIGH)
  • create_event(process, REQCPU, time, LOW)

8
Removing Process from a Queue
  • int qremove(int current_queue, float time)
  • int process
  • / If queue not empty, remove the head of the
    queue /
  • if (queuecurrent_queue.qgt0)
  • processqueuecurrent_queue.taskqueuecurren
    t_queue.head
  • / Update statistics for the queue
    /
  • queuecurrent_queue.wstime-queuecurrent_qu
    eue.tentryqueuecurrent_queue.head
  • queuecurrent_queue.ts
  • (time-queuecurrent_queue.tch)queuecurren
    t_queue.q
  • queuecurrent_queue.q--
  • queuecurrent_queue.tchtime
  • / Remove the head from the queue and return
    it /
  • queuecurrent_queue.head(queuecurrent_queue
    .head1)N
  • return(process)
  • else return(EMPTY)

9
Placing Process in a Queue
  • void qplace(int process, float time, int
    current_queue)
  • / Update statistics for the queue
    /
  • queuecurrent_queue.ts
  • (time-queuecurrent_queue.tch)queuecurrent_
    queue.q
  • queuecurrent_queue.q
  • queuecurrent_queue.n
  • queuecurrent_queue.tchtime
  • / Place the process at the tail of queue and
    move the tail /
  • queuecurrent_queue.taskqueuecurrent_queue.t
    ailprocess
  • queuecurrent_queue.tentryqueuecurrent_queue
    .tailtime
  • queuecurrent_queue.tail(queuecurrent_queue.
    tail1)N

10
Create a New Event
  • void create_event(int process, int event, float
    time, int priority)
  • int i, notdone1, placeelist.tail
  • / Move all more futuristic tasks by one
    position /
  • for(i(elist.tailN-1)N notdone i(iN-1)N)
  • if (elist.timeilttime (priorityLOW
    elist.timeitime) notdone0
  • else
  • elist.timeplaceelist.timei
  • elist.taskplaceelist.taski
  • elist.eventplaceelist.eventi
  • placei
  • if (ielist.head) notdone0
  • / Place the argument event in the newly
    created space /
  • elist.timeplacetime
  • elist.taskplaceprocess
  • elist.eventplaceevent
  • elist.tail(elist.tail1)N

11
Statistics
  • float exprnd (float y) / random function
    /
  • static unsigned long w 0L, g, m, x
  • if ( w 0L ) w sizeof ( long ) 8 g
    p2(w-1) m p2(w/2) 3 x p2(w/4) 1
  • x (xm) g
  • return -ylog((double)x/g)
  • void stats()
  • if (serverCPU.busy1) serverCPU.tser(TT-s
    erverCPU.tch)
  • if (serverDISK.busy1) serverDISK.tser(TT
    -serverDISK.tch)
  • printf("utilizations are CPU 5.2f Disk
    5.2f\n", 100.0server0.tser/TT,100.0server1.
    tser/TT)
  • printf("mean waiting time in qe 5.2f qCPU
    5.2f qDisk 5.2f\n", queue0.ws?queue0.ws/(qu
    eue0.n-queue0.q)0.0,
  • queue1.ws?queue1.ws/(queue1.n-queue1.q)0
    .0,
  • queue2.ws?queue2.ws/(queue2.n-queue2
    .q)0.0)
  • printf("mean queue length in qe 5.2f qCPU
    5.2f qDisk 5.2f\n",
  • queue0.ts/queue0.tch,queue1.ts/queue1.tc
    h, queue2.ts/queue2.tch)

12
Results
  • N1, MPL1 utilizations are CPU 4.40 Disk
    6.57
  • mean waiting time in qe 0.00 qCPU 0.00
    qDisk 0.00
  • mean queue length in qe 0.00 qCPU 0.00 qDisk
    0.00
  • N12, MPL1 utilizations are CPU 37.73 Disk
    56.84
  • mean waiting time in qe 3.97 qCPU 0.00
    qDisk 0.00
  • mean queue length in qe 3.42 qCPU 0.00 qDisk
    0.00
  • N12, MPL4 utilizations are CPU 46.66 Disk
    70.36
  • mean waiting time in qe 1.22 qCPU 0.05
    qDisk 0.11
  • mean queue length in qe 0.29 qCPU 0.30 qDisk
    0.81
  • number of visits in qe 2376 qCPU 57674
    qDisk 75230
  • average response time 2.12 tasked finished
    11781

13
Simulation Project Simulator due Lecture 21,
Project due Lecture 23
  • There are two kinds of processes in the computer
    system.
  • Interactive processes created at n terminals,
    repeatedly making rounds between the terminal and
    the memory system.
  • A parallel process executing constantly in the
    memory system (i.e., its processing time is so
    large that it will not leave the memory system
    during the simulation).
  • The service time distributions for interactive
    processes are
  • Terminal (thinking) time tt 4 sec,
    exponential distribution.
  • CPU tCPU 120 ms, exponential
    distribution.
  • PAGE Inter paging interval exponential with
    the fault probability function f(m)2-p, where
    pm/11717 and m denotes memory allocated to a
    task measured in Mbytes and f(m) denotes
    probability that an instruction will cause a page
    fault.
  • Inter IO interval tIiO 8 ms, exponential
    distribution.

14
Simulation Project, continued
  • Each interactive process creates a single task
    when leaving a terminal. A parallel process
    creates four tasks. The service time
    distributions for the parallel tasks are
  • Intersynchronization interval (time between
    subsequent barrier synchronization points) tbs
    0.12 sec, exponential distribution. After
    reaching a synchronization point a parallel task
    is suspended until all three other parallel tasks
    created by the parallel process reach this point.
    Unsuspended parallel tasks enter the CPU queue.
  • PAGE Inter paging interval defined as for
    interactive tasks.
  • Inter IO interval time tPIO 30 ms,
    exponential distribution.
  • The system is a quad (four CPU's) with a shared
    memory of 8 Gbytes organized into pages of
    4kbytes each. The operating system occupies 512
    Mbytes (128k pages). An instruction cycle is 10-9
    sec. There is also a cache from which 92 of all
    memory references are loaded in one instruction
    cycle. Cache miss cost is 51 machine cycles (that
    is the time in which the needed data will be
    loaded from main memory to cache and CPU).

15
Simulation Project, Selection
  • There a disk used for paging and IO operations,
    with the service time tdiskser 4 ms, constant.
  • Each task (interactive or parallel) is assigned
    an equal amount of memory during execution
    defined by the formula (Mem-OS)/MPL.
  • Context switching time ts 0.2ms.
  • A task is dispatched from the CPU queue when one
    of the processors becomes free.
  • Except for the exceptions mentioned below, all
    queues are organized as First-In-First-Out. An
    interactive task leaving CPU on a time slice,
    releases also its memory frames and leaves the
    system (a parallel task in this situation just
    returns to the ready queue).
  • The time slice for all tasks tq is 120 ms.
  • Select one of the following two policies for
    scheduling tasks
  • 1. Parallel tasks of a parallel process
    execute only if there is a processor that would
    become idle because there are no interactive
    tasks in the ready queue.
  • 2. All tasks execute on all CPUs in FIFO
    order from the ready queue.

16
Simulation Project, Evaluation
  • Simulating 1,000,000 sec. of execution time,
    evaluate
  • UCPU,ps -- Problem state utilization
  • UCPU,wd -- CPU idling while there are
    processes in disk queue
  • UCPU,wi -- CPU idling while internal queues
    are empty (but some process(es) may be serviced
    by disk(s)) (eligible queue is external and does
    not have to be empty)
  • te -- average waiting time in eligible queue.
  • Show a graph of the above values as a function of
    n and MPL,
  • n - number of terminals active, consider n
    30, 60, 90.
  • MPL - multiprogramming level, consider MPL
    15, 20, 30.
  • Based on the simulation, to serve 90 users with
    less than 0.5s average response time select the
    proper integer MPL and the minimum cost additions
    to the system from the following list.

17
Project Improvement List
  • a -- add a CPU at 300,
  • b --add cache, each addition cuts the current
    cache miss rate by half and costs 100 per
    addition, how many ? (e.g, two additions cut the
    miss rate to 2, three to 1)
  • c -- increase memory, and by how much? (cost
    100 per 1GBytes), or
  • d -- increase the number of disks at 100 per
    disk.
  • Explain your choice. Show by simulation that the
    extended system achieves a 0.5s response time.
  • Discuss the obtained plots.
  • Bonus 5pts. Assume that you split interactive
    tasks into two categories (i) urgent, that are
    tasks with CPU burst less than 0.05s, and (ii)
    non-urgent, those with the CPU burst time equal
    to or greater than 0.05s. Select the time slice
    tqopt to optimize the response time of the urgent
    and only urgent tasks. Provide the value of this
    response time and the total response time for all
    interactive tasks for the following values of
    time slice tqopt/2, tqopt, 2tqopt, for the
    computer system with 0.5s response time.
  • Students may joint into two-student teams to
    implement the basic simulation, but each partner
    should simulate individually different scheduling
    policy.

18
System Diagram for Project
Time Slice Expiration
CPU1
CPU2
DISK
qdisk
BS
qCPU
Barrier Synchronization Suspension
CPU4
CPU3
CPUs
Memory System Boundary
M1
monitors
Eligible queue
Mk
Time Slice Expiration
Mn
19
State Diagram for Project
Eligible Queue
qe
E
DISK
Fp
A-create
DH
Monitor
qCPU
CPU
qDisk
BH
D
B
Fi
A-load
C
BS
Barrier Synchronization
Events and Tasks States
20
Project Hints
  • How to compute average inter-page-fault time ?
  • Note that 1/f(m) is the number of instructions
    that on average are executed between two page
    faults, so to get the inter-page-fault rate the
    value 1/f(m) must be calibrated to the time units
    (using the time which the machine spends
    executing an instruction).
  • How to compute average waiting time for barrier
    synchronization?
  • (only for analytical analysis of the system)
  • The maximum execution time for 4 jobs with Ta
    average processing time has as distribution
  • P(xmaxltX) P(x1ltX)P(x2ltX)P(x3ltX)P(x4ltX)
    (1-e-X/Ta)4
  • and the average value
  • Tb integrate(xP from x0 to infinity)
    25Ta/12
  • so the average waiting time is Tbw Tb -
    Ta TaTa/12

21
Task Status Table
  • TASK STATUS TABLE (Interactive/Parallel Tasks)
  • Task type (interactive or parallel)
  • Current node (position in the system, server or
    queue)
  • Current queue position (if in queue)
  • Arrival time in queue (if in queue)
  • Departure time from Think node/ Synchronization
    barrier
  • tCPU - time to the end of task/to the next
    synchronization barrier
  • tslice - time to the end of time slice
  • tpage - time to the next page fault
  • tIO - time to the next IO interrupt

22
Project Initialization Step
  • Initialize
  • Task table, clock, and all variables,
  • All tasks in think state/suspension at barrier
  • for k-th interactive task set the time for
    leaving think state to ktt/n,
  • Simulation time (set it to 1,010,000 sec, but
    collect statistics after the initial 10,000 sec)

23
Project Iteration
  • II. Iterate
  • 1. Select the task in the future event queue
    with the lowest event time
  • (simply keep the future event list sorted in
    increasing order of the event time)
  • 2. Advance clock to the next event time. Stop
    the simulation if it exceeds simulation time.
  • 3. Execute transition routine corresponding to
    the selected event.
  • a. change state associated variables in task
    table.
  • b. compute next event time
  • c. update statistics (omit first 10,000 sec of
    statistics)

24
Projects Event A
  • A-create generate thinking time tthink, total
    CPU time tCPU , time slice tslice, time to the
    next page fault tPAGE and time to the next IO
    interrupt tIO. If you use more than one disk,
    assign one of them randomly to the created task
    (see event D).
  • Create task A-load for this task with time TG
    tthink
  • A-load if MPLgtqCPUqDiskCPUDISKBS,
  • then create event B for this task with global
    clock TG
  • otherwise put this task into qe at that time
  • Hint it is more efficient to keep count of
    processes in the system than to compute number of
    such processes in Event A. Count changes only in
    Event A (potentially), event C for interactive
    processes and for event F.


25
Project Event B
  • B. Request CPU if CPU not free
  • put calling task into qCPU, otherwise
  • a) Select mmin(tCPU , tslice , tPAGE , tIO).
  • b) Set tCPU -m, tslice -m, tPAGE -m, tIO -m.
  • c) Create the next event for the calling
    task with
  • time TG ts m where TG is the
    current value of
  • the global clock and the event is defined
    by
  • the first zero counter among (tPAGE , tIO
    , tCPU , tslice).
  • It is either C, D, or F. Note that we
    add context
  • switching time at the end of CPU
    service.
  • Comment order of zero counter selection is
    rather arbitrary, different ones make sense
    assume tPAGE, tIO, tcpu, tslice order.

26
Project Events C,D,F
  • C,D,F, Release CPU release CPU and release head
    of qCPU (if any), then depending on the reason,
    branch into
  • C. Termination when total CPU becomes 0, i.e.,
    tCPU 0,
  • If the task is parallel, then go to
    synchronization
  • generate CPU time till next synchronization
    barrier tCPU, next io interrupt time, next time
    slice time and next page interrupt time (like in
    event A)
  • If all four parallel tasks reached BS, create for
    all of them event B with time TG, otherwise stay
    at BS
  • else (task is interactive), execute completion
  • create event A for this task, then
  • release head of qe (if any).

27
Project Events D, E
  • D. Request Disk Service
  • (i.e., tPAGE 0 or tIO 0).
  • Regenerate corresponding time to next interrupt
  • (i.e., tPAGE or tIO ).
  • Remember to assign (randomly) one disk to all
    tasks requests at the time of task creation, in
    event A.
  • If the server busy, place the task in the server
    queue.
  • Otherwise create event E for the task at time TG
    disk_processing_time.
  • E. Leaving Disk Server
  • Simply create event B for the task at time TG
    and release head of the server queue (if any
    exists).

28
Project Events F (Fi and Fp)
  • F. Time Slice Expiration tslice 0 -- reset it,
    and
  • For interactive tasks (Fi)
  • release the head of qe (if any)
  • create new event at time TG, that is event
    A-load (event A in fact can be treated as two
    events,
  • A-create and A-load).
  • For parallel tasks (Fp)
  • Create a new event at time TG, that is event B
    (low)
Write a Comment
User Comments (0)
About PowerShow.com