Operating System Simulator Project n Purpose Basic concepts
Operating System Simulator Project n Purpose Basic concepts of event driven simulation n Operating System Concepts n Resource allocation and management n context switching and interrupt handling n Basic flow of control with in OS n Fundamental data structures n
Operating System Simulator Project n n Program will simulate the action of both hardware and software components Hardware n n n CPU Memory Peripheral devices Interrupt Handler Software n n CPU scheduler Process management functions
Operating System Simulator Project n Input files n System configuration File n n User logon File n n LOGON. DAT Process File n n CONFIG. DAT SCRIPT. DAT Program files n n EDITOR. DAT PRINT. DAT COMPILER. DAT LINKER. DAT
Operating System Simulator Project n Simulator Overview n The simulator is based on events Begins by processing events, generates more events during the progress and processes the generated events n Normally starts with LOGON events n n Interrupt hardware Changes the CPU and memory states n Calls Interrupt handler n n Services the interrupt
OSSIM – Major Data Structures pcb_list cpu_type unsigned long unsigned char struct address_type struct pcb_type struct simtime int int double struct pcb_list rate CPU_burst mode pc *actvpcb busy qwait response idle served maxq qlen utilize *ready *tail This pcb is not in the ready queue. It is the active pcb! struct pcb_type struct pcb_list *pcb *next *prev pcb_type pcb_list
char unsigned int int struct segment_type unsigned int struct state_type struct simtime unsigned long double unsigned long struct simtime int double struct rb_type struct rb_list struct simtime status flags user[5] termnl *script pgmid *segtable segtab_len cpu_save logont blockedt readyt runt sjnburst sjnave instrleft sliceleft tblocked tready trun tlogon served efficncy *wait *firstrb *lastrb waitq busy pcb_type Major Data Structures calloc( MAXSCRIPT, sizeof( int )) 0 1 2 … MAXSCRIPT-1 calloc(nsegs, sizeof( struct segment_type )) 0 1 2 … nsegs -1 rb_type char struct pcb_type int struct simtime unsigned long struct addr_type status *pcb dev queuet bytes reqid rb_list struct rb_type struct rb_list to pcb rb_type *rb *next rb_type
OSSIM – Major Data Structures device_type char struct rb_type unsigned long int struct simtime int int double struct rb_list struct simtime devid[5] *currb npb byps busy qwait response idle served maxq qlen utilize *head *tail start rb_type rb_list
OSSIM -Minor Data Structures simtime unsigned long seconds nanosec timer_type struct simtime unsigned long struct simtime TIME_OUT QUANTUM RRSLICE instr_type unsigned char union operand_type opcode operand addr_type int unsigned int struct simtime int struct event_type time event agent *prev *next union operand_type struct addr_type unsigned int unsigned long address count burst bytes state_type segment offset segment_type unsigned char unsigned int unsigned long event_type unsigned char struct addr_type mode pc seg_list accbits seglen membase unsigned long struct seg_list segsize segptr *next
Big Picture: Process Mgmt termtable usr = U 001 status = ‘A’ segtablen = 1 firstrb lastrb rb-1 membase = 5 usr = U 003 status = ‘B’ segtablen = 3 waitrb firstrb lastrb rb-2 membase = 0 membase = 31 rb-5 rb-3 to memory To IO rb-5 pcb status = ‘D’ dev =0 bytes =250 reqid =[0, 1] To IO membase = 20 membase = 23 firstrb lastrb rb-6 U 003 actvpcb ready tail usr = U 004 status = R’ segtablen = 2 membase = 10 rb-4 CPU pc = 4 PCB PCB rb-7 pcb. U 004 status = ‘D’ dev =0 bytes =2000 reqid =[0, 1] reqid =[1, 1] bytes =3000 dev =1 status = ‘D’ pcb reqid =[1, 3] bytes =1500 dev =1 status = ‘D’ pcb rb-8 rb-9 U 004
Big Picture: IO Mgmt devtable dev = 1 dev = 0 devid[5] = ‘DISK’ *currb *head *tail U 003 rb-6 pcb status = ‘P’ dev =1 bytes =250 reqid =[2, 1] U 003 rb-4 pcb status = ‘A’ dev =0 bytes =5000 reqid =[0, 3] U 001 rb-1 pcb status = ‘P’ dev =0 bytes =500 reqid =[0, 1] devid[5] = ‘PRNT’ *currb *head *tail U 001 rb-2 pcb status = ‘P’ dev =1 bytes =600 reqid =[0, 3] U 003 rb-5 pcb status = ‘A’ dev =1 bytes =8500 reqid =[1, 3]
Big Picture: Memory Mgmt freemem segsize = 5 segptr *next 0 1 2 3 pc 4 From CPU 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 SIO DISK JUMP SIO DISK SIO PRNT END 500 2500 5000 [1, 0] 2000 500 1750 600 50 SIO DISK CPU REQ END 2000 250 500 [1, 3] 700 segsize = 1 segptr *next segsize = 965 segptr *next 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 … 998 999 SIO DISK JUMP SIO PRNT CPU REQ END 75 2000 [1, 0] 1000 3000 2000 1500 [1, 3] 100 CPU REQ SIO PRNT JUMP 1250 [0, 1] 4500 8500 [2, 0] …………. .
OSSIM – Objective 1 n LOGON. DAT n n <EVENT, AGENT, TIME> EVENT n n AGENT n n An event in a computer system is a change of system state LOGON, SIO, WIO, END, and EIO Should be able to handle event names in both upper an lower cases Two types n User (Terminal) n format: Uxxx n Device n Format: disk 1, printer TIME n Unsigned long decimal
OSSIM – Objective 1 n Void Add_event(struct simtime *time, int event, int agent ) This function inserts a future event in the list new_events in the proper time sequence. new_events points to the end of the list having the smallest time defined by the given function: Cmpr_time(struct simtime * , struct simtime *)
OSSIM – Objective 1 n Directions: n This function is called by Load_events(void) n Use the structure event_type with the given simtime, agent, and event. n /* The event list is a doubly-linked list of elements of EVENT_TYPE */ n n struct event_type { struct simtime; int event; int agent; struct event_type *prev, *next; }; refer osdefs. h and externs. h Insert it at the appropriate position in the event list ( new_events). The event list is ordered chronologically so make sure to maintain the correct order while inserting by using the provided function:
OSSIM – Objective 1 n n Before: After inserting a simtime record with seconds = 20, nanosec = 0
OSSIM – Objective 1 n void Load_events(void) This function is called from simulator. c (The simulator driver) and it initializes the event list (new_events) from the file logon. dat. This file normally contains only LOGON events for all terminals. However, for debugging purposes, logon. dat can contain events of any type. This function uses: Add_event(struct simtime * , int)
OSSIM – Objective 1 n Directions: n Refer to intro. doc for the logon. dat format n Use the given function: n n convrt_time(struct simtime * time 1, long time 2) The event name and agent name can be either in upper or lower case or a combination. Make sure you convert it to upper case.
OSSIM – Objective 1 Directions: (contd. ) n n Convert the event name to eventid using the eventidtab[] defined in simulator. c. Example: event name = LOGON, event id = 0 n Convert the agent name to agent. Here two cases arise: n n If the agent name is Uxxx, agent id = xxx. (agent is a user) n If the agent is a device, then: TRMSIZE + 1 <= agent <= TRMSIZE + DEVSIZE where TRMSIZE is the number of terminals (users) and DEVSIZE is the number of devices. You will have to use the lookup table devtable defined in simulator. c. Call Add_event(time 2, enevt_id, agent_id) to build the event list.
OSSIM – Objective 1 n void Write_event (int event, int agent, struct simtime *time) This function writes an event to "simout“ with the format: "EVENT AGENT TIME (HR: xxxx MN: xx SC: xx MS: xxx m. S: xxx NS: xxx" n You will have to convert the nanosec field to MS, m. S, and NS. The seconds field will have to be converted to HR, MN, and SC.
OSSIM – Objective 1 n Directions: n n Called from Interrupt(void) Convert the event_id and agent_id to event name and agent name for printing to the output file simout which is already open.
OSSIM – Objective 1 void Interrupt(void) n This function is called from simulator. c (The simulator driver) Directions: n n n n removes an event from new_events sets CLOCK, AGENT, and EVENT deallocates the event element writes the event to "simout" Copies CPU. mode and CPU. pc into oldstate Copies newstate into CPU. mode and CPU. pc
- Slides: 21