cop 4600

46
COP 4600 Objective 4 & 5

Upload: bao

Post on 22-Feb-2016

38 views

Category:

Documents


0 download

DESCRIPTION

COP 4600. Objective 4 & 5. Summary of Routines. Add_cpuq() - Adds a PCB to CPU Ready Queue. Add_devq() - Adds an rb_type node to the wait queue of a device. Add_rblist() - Adds an rb_type node to the RB-list of PCB. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: COP 4600

COP 4600

Objective 4 & 5

Page 2: COP 4600

Summary of Routines

• Add_cpuq() - Adds a PCB to CPU Ready Queue.

• Add_devq() - Adds an rb_type node to the wait queue of a device.

• Add_rblist() - Adds an rb_type node to the RB-list of PCB.

• Scheduler() - Selects the Next Process from the CPU Ready Queue to give to the CPU for execution.

• Dispatcher() - Prepares scheduled PCB’s program for execution and transfers it to CPU.

Page 3: COP 4600

• Sio_Service() - Services interrupt to Start I/O (NON-BLOCKING function).Attempts to Start I/O on specified device if device not busy.

• Wio_Service() - Checks to see if a certain I/O operation that is waited upon is

done.(BLOCKING function).

• Eio_Service() - Services Interrupts from I/O Devices indicating the End of a previously assigned I/O operation. Attempts to Start I/O on the next node in Devices Queue.

Page 4: COP 4600

• Start_IO() - Simulates Device providing service to nodes waiting in its Queue.

• Find_rb() - Searches PCB’s RB-List for ‘rb’.• Delete_rb() - Deallocates ‘rb’ node if found in

PCB’s RB- List.• Purge_rb() - Purges all RB’s with Status as ‘D’ –

Done.• Load_Map() - Initializes MEMMAP h/w with

Dispatched Programs Segment Table

Page 5: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

LOGON(U001)LOGON(U003)LOGON(U002)LOGON(U004)

Script.dat

Page 6: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

LOGON(U001)LOGON(U003)LOGON(U002)LOGON(U004)

wait

QUEUE

PCB1

PCB 1

Editor.dat

Page 7: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

LOGON(U003)LOGON(U002)SIO 23LOGON(U004)

wait

QUEUE

PCB1PCB 1

Editor.dat

Page 8: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

LOGON(U002)SIO 23LOGON(U004)

wait

QUEUE

PCB1PCB 1

Editor.dat

wait

QUEUE

PCB3

PCB 3

Page 9: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

SIO 23LOGON(U004)

wait

QUEUE

PCB1PCB 1

Editor.dat

wait

QUEUE

PCB3

PCB 3

wait

QUEUE

PCB2

PCB 2

Page 10: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

LOGON(U004)SIO 32EIO

wait

QUEUE

PCB1PCB 1

Editor.dat

wait

QUEUE

PCB3

PCB 3

wait

QUEUE

PCB2

PCB 2

PCB1100

PRNT 100

Page 11: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

LOGON(U004)SIO 32EIO

wait

QUEUE

PCB1PCB 1

Editor.dat

wait

QUEUE

PCB3

PCB 3

wait

QUEUE

PCB2

PCB 2

PCB1100

PRNT 100

Page 12: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

SIO 32WIO

wait

QUEUE

PCB1PCB 1

Editor.dat

wait

QUEUE

PCB3

PCB 3

wait

QUEUE

PCB2

PCB 2

PCB1100

PRNT 100

wait

QUEUE

PCB4

PCB 4

Page 13: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

WIO

wait

QUEUE

PCB1PCB 1

Editor.dat

wait

QUEUE

PCB3

PCB 3

wait

QUEUE

PCB2

PCB 2

PCB1100

PRNT 100

wait

QUEUE

PCB4

PCB 4

PCB1300

DISK 300

Page 14: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

WIO 0EIOEIO

wait

QUEUE

PCB1PCB 1

Editor.dat

wait

QUEUE

PCB3

PCB 3

wait

QUEUE

PCB2

PCB 2

PCB1100

PRNT 100

wait

QUEUE

PCB4

PCB 4

PCB1300

DISK 300

Page 15: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

SIO 27EIOEIO

wait

QUEUE

PCB1PCB3

wait

QUEUE

PCB3

PCB 2

wait

QUEUE

PCB2

PCB 4

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

Script.dat

Page 16: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

SIO 15EIOEIO

wait

QUEUE

PCB1PCB3

wait

QUEUE

PCB3

PCB 2

wait

QUEUE

PCB2

PCB 4

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

PCB33000

DISK 3000

Printer.dat

Page 17: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

ENDEIOEIO

wait

QUEUE

PCB1PCB3

wait

QUEUE

PCB3

PCB 2

wait

QUEUE

PCB2

PCB 4

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

Printer.dat

PCB33000

DISK 3000 PRNT 100PCB 3100

Page 18: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

SIO 10EIOEIO

wait

QUEUE

PCB1

wait

QUEUE

PCB3

PCB 4

wait

QUEUE

PCB2

PCB 2

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

Editor.dat

PCB33000

DISK 3000 PRNT 100PCB 3100

Page 19: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

WIOEIOEIO

wait

QUEUE

PCB1

wait

QUEUE

PCB3

PCB 4

wait

QUEUE

PCB2

PCB 2

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

Editor.dat

PCB33000

DISK 3000 PRNT 100PCB 3100

PCB21000

DISK 1000

Page 20: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

SIO 18EIOEIO

wait

QUEUE

PCB1

wait

QUEUE

PCB3

PCB 4

wait

QUEUE

PCB2

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

printer.dat

PCB33000

DISK 3000 PRNT 100PCB 3100

PCB21000

DISK 1000

Page 21: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

WIOEIOEIO

wait

QUEUE

PCB1

wait

QUEUE

PCB3

PCB 4

wait

QUEUE

PCB2

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

printer.dat

PCB33000

DISK 3000 PRNT 100PCB 3100

PCB21000

DISK 1000

DISK 1000

PCB41000

Page 22: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

EIOEIO

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

printer.dat

PCB33000

DISK 3000 PRNT 100PCB 3100

PCB21000

DISK 1000 DISK 1000

PCB41000

Page 23: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

EIO(PRNT PCB1)EIO(DISK PCB1)

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB1100

PRNT 100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

PCB33000

DISK 3000 PRNT 100PCB 3100

PCB21000

DISK 1000 DISK 1000

PCB41000

Page 24: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

EIO(DISK PCB1)EIO(PRNT PCB3)

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB3100

wait

QUEUE

PCB4PCB1300

DISK 300

DISK 300

PCB33000

DISK 3000 PRNT 100

PCB21000

DISK 1000 DISK 1000

Page 25: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

EIO(PRNT PCB3)EIO(DISK PCB3)

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB3100

wait

QUEUE

PCB4PCB 33000

PCB21000

DISK 3000 PRNT 100

DISK 1000 DISK 1000

PCB 1

Page 26: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

SIO 15EIO(PRNT PCB3)EIO(DISK PCB3)

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB3100

wait

QUEUE

PCB4PCB 33000

PCB21000

DISK 3000 PRNT 100

DISK 1000 DISK 1000

PCB 1

Page 27: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

ENDEIO(PRNT PCB3)EIO(DISK PCB3)

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB3100

PRNT 150

wait

QUEUE

PCB4PCB 33000

PCB21000

DISK 3000 PRNT 100

DISK 1000 DISK 1000

PCB 1

PCB 1150

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

ENDEIO(PRNT PCB3)EIO(DISK PCB3)

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB3100

wait

QUEUE

PCB4PCB 33000

PCB21000

DISK 3000 PRNT 100

DISK 1000 DISK 1000

PCB 1

PCB 1150

Page 28: COP 4600

CPU

PRNT

DISK

actvpcb

QUEUE

currb

QUEUE

currb

QUEUE

EIO(PRNT PCB3)EIO(DISK PCB3)

wait

QUEUE

PCB1

wait

QUEUE

PCB3

wait

QUEUE

PCB2

PCB3100

PRNT 150

wait

QUEUE

PCB4PCB 33000

PCB21000

DISK 3000 PRNT 100

DISK 1000 DISK 1000

PCB 1150

Page 29: COP 4600

Interrupt() Interrupt_Handler() Schedular() Dispatcher()

Logon() Sio_Service() Wio_Service() Eio_Service() End_Service()(Obj 3)

(Obj 3)Additional Statements used

-Initialize ‘rb’-Add_devq()-Add_rblist()-StartIO()

-Find_rb()-If(‘P’ or ‘A’)BLOCK-elseDelete_rb()

-Mark RBStatus as ‘D’-StartIO()-Cases forpcb->status

-Purge_rb()-Next_pgm()

Page 30: COP 4600

Interrupt() Interrupt_Handler() Schedular() Dispatcher()

-LoadMap()-XPGM()

Page 31: COP 4600

Add_cpuq(struct pcb_type *pcb) Create a pcb_list* node and set pcb to the pcb_type pointer in

the node If the wait queue in CPU is empty, add

the node to head of the wait queue. Update the tail in CPU

Otherwise, add the node to the end of the wait queue in the CPU. Update the tail.

Page 32: COP 4600

• Add_devq(int dev, struct rb_type *rb) Create a rb_list* node and set rb to the rb_type pointer in the

node Record the time when the rb is queued If the device is empty, add the node to

head of the wait queue in device. Update the tail in device

Otherwise, add the node to the end of the wait queue in the device. Update the tail.

Page 33: COP 4600

• Add_rblist(struct pcb_type *pcb, struct rb_type *rb) Create a rb_list* node and set rb to the rb_type pointer in the

node If the rb_list queue is empty in pcb, add

the node to head of the rb_list queue in pcb. Update the tail in pcb

Otherwise, add the node to the end of the rb_list queue in the pcb. Update the tail.

Page 34: COP 4600

Struct pcb_type* scheduler() If the ready queue in CPU is empty,

return Update the number of processes served

by the CPU FCFS:

Grab the first node in the list Record when the process became ACTIVE Calculate time process was READY and

increment CPU qwait time

Page 35: COP 4600

Dispatcher() Prepares the scheduled program for

execution and then transfers control to it LoadMap ( CPU.avtvpcb->segtable,

CPU.actvpcb->segtab_len)

XPGM(&CPU.actvpcb->cpu_save);

Page 36: COP 4600

rb_type* Alloc_rb() Allocates an I/O request block (rb) Sets rb->status to “Pending” Sets rb->pcb to Termtable[AGENT –1] The device instruction must be found in

memory using only the current pcb with the pcb's saved program counter incremented passed the point needed.

We subtract 1 from the offset when calculating the device instruction since we increment offset by 2 in Cpu()

When calculating the request ID for the rb, one is subtracted from the offset since 2 was added to PC in Cpu()

EG: SIO 35,PRNT 200, WIO 24

Page 37: COP 4600

Alloc_rb ( ) (contd..) Set rb->bytes Set rb-> reqid to logical address of Device

instruction rb-> reqid.segment = rb->pcb->cpu_save.pc.segment ; rb-> reqid.offset = rb->pcb->cpu_save.pc.offset – 1;

Page 38: COP 4600

Sio_service() (Non Blocking function) Allocate & initialize new rb Add_devq(); Add_rblist(); Attempt to initiate an operation on the

requested device – StartIO(); Set CPU_SW = 1 and SCHED_SW = 0;

Page 39: COP 4600

Wio_Service(void) (Blocking Function) Retrieve pcb from Term_table Locate REQ instruction to retrieve address

field. Call Find_rb() to to get status of IO operation

waited upon. If status is ‘P’ or ‘A’, BLOCK pcb. Set CPU_SW = SCHED_SW = 1 Calculate ACTIVE time for process and Busy

time for CPU Record the time the process what blocked and

return. Else process can continue running.

Call Delete_rb() to deallocate the IORB. Set CPU_SW = 1 , SCHED_SW = 0;

Page 40: COP 4600

Eio_Service(void) Self explanatory See the objective 4

Page 41: COP 4600

Start_IO(int dev)

[ Attempts to start an operation on a device (dev) ]

If Device is busy : devtable[dev].currb != NULL - return .

If Device Queue is empty - return. Remove the next rb from the device queue and store it

in ‘currb’ Update Total Wait time for the device while in Queue Calculate the time (eiotime) at which the operation will

terminate depending on Device Speed Update Device’s Busy Time Create future time event for IO operation Add_event(&eiotime, EIO , dev+TRMSIZE + 1) Update number of IO requests served for the device.

Page 42: COP 4600

• Find_rb()[ Searches RB list of PCB to locate an RB ]

• Delete_rb()

[ Deletes and deallocates an ‘rb’ from the PCB RB list]

• Purge_rb()

[Purges all RB’s with COMPLETE Status ]• LoadMap()

[ Initialises the MEMMAP hardware to dispatched programs segment table ]

Page 43: COP 4600

Objective 5 Calc_stats(void)[ The Function computes all the simulation statistics and

stores them in the appropriate variables and data structures for display. This function is called by Wrapup() ]

for i = 0 to TRMSIZE // I.e for each PCB { Total Processing time - TOTLOGON Total Job blocked time - TOTBLKED Total Job Wait time - TOTWAIT Total Job Execution Time – TOTRUN Efficiency for each process – temp = total blocked time + total Run time termtable[i]->effciency = 100.0 * Divd_time( &temp,

&termtable[i]->tlogon ); }

Page 44: COP 4600

for i= 0 to DEVSIZE{[ Calculate Response time for all devices ]• temp = Busy time + Qwait time• Ave_time(,&temp ,&devtable[i].num_served ,

&devtable[i].response);[ Calculate idle time ]• devtable[i].idle.seconds = CLOCK.seconds• devtable[i].idle.nanosec = CLOCK.nanosecDiff_time( &devtable[i].busy, &devtable[i].idle )[ Utilization ]Devtable[i].utilize = 100.0 * Divd_time(&devtable[i].busy,&CLOCK)}

Page 45: COP 4600

• Average user execution time using TOTRUN and TRMSIZE• Average user logon time using TOTLOGON and TRMSIZE• Average Blocked Time using TOTBLKED and TRMSIZE• Average User wait Time using TOTWAIT and TRMSIZE

Page 46: COP 4600

• Response Time for CPU temp = busy + qwait Ave_time(,&temp,CPU.served,&CPU.response)• Idle time for CPU CPU.idle.seconds = CLOCK.seconds CPU.idle.seconds = CLOCK.seconds Diff_time(&CPU.busy, &CPU.idle)

• Total Utilization for CPU CPU.utilize = 100.0 * Divd_time (&CPU.busy, &CLOCK)