Upload
echo-hyde
View
66
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Operating System Simulator Project. Purpose Basic concepts of event driven simulation Operating System Concepts Resource allocation and management context switching and interrupt handling Basic flow of control with in OS Fundamental data structures. Operating System Simulator Project. - PowerPoint PPT Presentation
Citation preview
Operating System Simulator Operating System Simulator ProjectProject
PurposePurpose Basic concepts of event driven Basic concepts of event driven
simulationsimulation Operating System ConceptsOperating System Concepts
Resource allocation and managementResource allocation and management context switching and interrupt handlingcontext switching and interrupt handling Basic flow of control with in OSBasic flow of control with in OS Fundamental data structuresFundamental data structures
Operating System Simulator Operating System Simulator ProjectProject
Program will simulate the action of both Program will simulate the action of both hardware and software componentshardware and software components
HardwareHardware CPUCPU MemoryMemory Peripheral devicesPeripheral devices Interrupt HandlerInterrupt Handler
SoftwareSoftware CPU schedulerCPU scheduler Process management functionsProcess management functions
Operating System Simulator Operating System Simulator ProjectProject
Input filesInput files System configuration FileSystem configuration File
CONFIG.DATCONFIG.DAT User logon FileUser logon File
LOGON.DATLOGON.DAT Process FileProcess File
SCRIPT.DATSCRIPT.DAT Program filesProgram files
EDITOR.DATEDITOR.DAT PRINT.DATPRINT.DAT COMPILER.DATCOMPILER.DAT LINKER.DATLINKER.DAT
Operating System Simulator Operating System Simulator ProjectProject
Simulator OverviewSimulator Overview The simulator is based on eventsThe simulator is based on events
Begins by processing events, generates Begins by processing events, generates more events during the progress and more events during the progress and processes the generated eventsprocesses the generated events
Normally starts with LOGON eventsNormally starts with LOGON events Interrupt hardwareInterrupt hardware
Changes the CPU and memory statesChanges the CPU and memory states Calls Interrupt handlerCalls Interrupt handler
Services the interruptServices the interrupt
OSSIM – Major Data StructuresOSSIM – Major Data Structures
unsigned long rateunsigned long CPU_burstunsigned char modestruct address_type pcstruct pcb_type *actvpcbstruct simtime busystruct simtime qwaitstruct simtime responsestruct simtime idleint servedint maxqint qlendouble utilizestruct pcb_list *readystruct pcb_list *tail
unsigned long rateunsigned long CPU_burstunsigned char modestruct address_type pcstruct pcb_type *actvpcbstruct simtime busystruct simtime qwaitstruct simtime responsestruct simtime idleint servedint maxqint qlendouble utilizestruct pcb_list *readystruct pcb_list *tail
cpu_type This pcb isnot in the
ready queue.It is the active
pcb!
pcb_type pcb_typepcb_type
pcb_list pcb_listpcb_list
struct pcb_type *pcbstruct pcb_list *nextstruct pcb_list *prev
struct pcb_type *pcbstruct pcb_list *nextstruct pcb_list *prev
pcb_list
Major Data StructuresMajor Data Structureschar statuschar flagschar user[5]unsigned int termnlint *scriptint pgmidstruct segment_type *segtableunsigned int segtab_lenstruct state_type cpu_savestruct simtime logontstruct simtime blockedtstruct simtime readytstruct simtime runtunsigned long sjnburstdouble sjnaveunsigned long instrleftunsigned long sliceleftstruct simtime tblockedstruct simtime treadystruct simtime trunstruct simtime tlogonint serveddouble efficncystruct rb_type *waitstruct rb_list *firstrbstruct rb_list *lastrbstruct simtime waitqstruct simtime busy
char statuschar flagschar user[5]unsigned int termnlint *scriptint pgmidstruct segment_type *segtableunsigned int segtab_lenstruct state_type cpu_savestruct simtime logontstruct simtime blockedtstruct simtime readytstruct simtime runtunsigned long sjnburstdouble sjnaveunsigned long instrleftunsigned long sliceleftstruct simtime tblockedstruct simtime treadystruct simtime trunstruct simtime tlogonint serveddouble efficncystruct rb_type *waitstruct rb_list *firstrbstruct rb_list *lastrbstruct simtime waitqstruct simtime busy
pcb_type
calloc( MAXSCRIPT, sizeof( int ))
0 1 2 … MAXSCRIPT-10 1 2 … MAXSCRIPT-1
0 1 2 … nsegs -10 1 2 … nsegs -1
calloc(nsegs, sizeof( struct segment_type ))
rb_type
rb_type rb_typerb_type
struct rb_type *rb struct rb_list *next
struct rb_type *rb struct rb_list *next
rb_list
char statusstruct pcb_type *pcbint devstruct simtime queuetunsigned long bytesstruct addr_type reqid
char statusstruct pcb_type *pcbint devstruct simtime queuetunsigned long bytesstruct addr_type reqid
rb_type
to pcb
OSSIM – Major Data Structures OSSIM – Major Data Structures
char devid[5]struct rb_type *currbunsigned long int npbunsigned long int bypsstruct simtime busystruct simtime qwaitstruct simtime responsestruct simtime idleint servedint maxqint qlendouble utilizestruct rb_list *headstruct rb_list *tailstruct simtime start
char devid[5]struct rb_type *currbunsigned long int npbunsigned long int bypsstruct simtime busystruct simtime qwaitstruct simtime responsestruct simtime idleint servedint maxqint qlendouble utilizestruct rb_list *headstruct rb_list *tailstruct simtime start
device_type
rb_type rb_type
rb_list rb_list
OSSIM -Minor Data StructuresOSSIM -Minor Data Structuresunsigned long secondsunsigned long nanosec
unsigned long secondsunsigned long nanosec
int segmentunsigned int offset
int segmentunsigned int offset
unsigned char opcodeunion operand_type operand
unsigned char opcodeunion operand_type operand
struct simtime TIME_OUTunsigned long QUANTUMstruct simtime RRSLICE
struct simtime TIME_OUTunsigned long QUANTUMstruct simtime RRSLICE
unsigned char accbitsunsigned int seglenunsigned long membase
unsigned char accbitsunsigned int seglenunsigned long membase
unsigned long segsizeunsigned long segptrstruct seg_list *next
unsigned long segsizeunsigned long segptrstruct seg_list *next
unsigned char modestruct addr_type pc
unsigned char modestruct addr_type pc
simtime
timer_type
instr_type
addr_type
segment_type
state_type
seg_list
struct addr_type addressunsigned int countunsigned long burstunsigned long bytes
struct addr_type addressunsigned int countunsigned long burstunsigned long bytes
union operand_type
event_type
struct simtime timeint event int agentstruct event_type *prevstruct event_type *next
struct simtime timeint event int agentstruct event_type *prevstruct event_type *next
waitrbfirstrb lastrb
Big Picture: Process MgmtBig Picture: Process Mgmttermtable
usr = U001status = ‘A’segtablesegtablen = 1firstrb lastrb
membase = 5
usr = U003status = ‘B’segtablesegtablen = 3
membase = 0
membase = 31
membase = 10
usr = U004status = R’segtablesegtablen = 2
firstrb lastrb
membase = 20
membase = 23
actvpcb
pc = 4
readytail
CPU
to memory
PCB PCB PCB
rb-1 rb-4 rb-5 rb-6rb-2
pcbstatus = ‘D’
dev =0 bytes =250
reqid =[0, 1]
U003rb-3
pcbstatus = ‘D’
dev =0 bytes =2000reqid =[0, 1]
U004rb-7
pcbstatus = ‘D’
dev =1 bytes =3000reqid =[1, 1]
U004rb-8
pcbstatus = ‘D’
dev =1 bytes =1500reqid =[1, 3]
U004rb-9
rb-5
To IOTo IO
Big Picture: IO MgmtBig Picture: IO Mgmtdevtable
devid[5] = ‘DISK’*currb*head*tail
devid[5] = ‘DISK’*currb*head*tail
devid[5] = ‘PRNT’*currb*head*tail
devid[5] = ‘PRNT’*currb*head*tail
dev = 0 dev = 1
pcbstatus = ‘P’
dev =0 bytes =500reqid =[0,1]
U001
rb-1pcb
status = ‘P’dev =1
bytes =600reqid =[0,3]
U001rb-2
pcbstatus = ‘P’
dev =1 bytes =250reqid =[2,1]
U003rb-6
pcbstatus = ‘A’
dev =0 bytes =5000reqid =[0,3]
U003rb-4
pcbstatus = ‘A’
dev =1 bytes =8500reqid =[1,3]
U003rb-5
Big Picture: Memory MgmtBig Picture: Memory Mgmt
SIO 500DISK 250SIO 2500DISK 5000JUMP [1, 0]
0 1 2 3 4
SIO 75DISK 2000JUMP [1, 0]SIO 1000PRNT 3000SIO 2000PRNT 1500CPU 500REQ [1, 3]END 100
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 …998999
…………..
freememsegsize = 5segptr*next
segsize = 5segptr*next
segsize = 1segptr*next
segsize = 1segptr*next
segsize = 965segptr*next
segsize = 965segptr*next
SIO 2000 DISK 500SIO 1750PRNT 600END 50
SIO 2000DISK 250CPU 500REQ [1, 3]END 700
5 6 7 8 9
1516171819
1011121314
CPU 1250REQ [0, 1]SIO 4500PRNT 8500JUMP [2, 0]
pc
From CPU
OSSIM – Objective 1OSSIM – Objective 1 LOGON.DATLOGON.DAT
<EVENT,AGENT,TIME><EVENT,AGENT,TIME> EVENTEVENT
An event in a computer system is a change of system stateAn event in a computer system is a change of system state LOGONLOGON, SIO, WIO, END, and EIO, SIO, WIO, END, and EIO Should be able to handle event names in both upper an Should be able to handle event names in both upper an
lower caseslower cases AGENTAGENT
Two typesTwo types User (Terminal) User (Terminal)
format: Uxxxformat: Uxxx DeviceDevice
Format: disk1, printerFormat: disk1, printer TIMETIME
Unsigned long decimal Unsigned long decimal
OSSIM – Objective 1OSSIM – Objective 1
Void Add_event(struct simtime *time, int event, int Void Add_event(struct simtime *time, int event, int agent )agent )
This function inserts a future event in the list This function inserts a future event in the list
new_events in the proper time sequence.new_eventsnew_events in the proper time sequence.new_events
points to the end of the list having the smallest timepoints to the end of the list having the smallest time
defined by the given function: defined by the given function:
Cmpr_time(struct simtime * , struct simtime *)Cmpr_time(struct simtime * , struct simtime *)
OSSIM – Objective 1OSSIM – Objective 1 Directions:Directions:
This function is called by Load_events(void)This function is called by Load_events(void) Use the structure event_type with the given simtime, agent, and event.Use the structure event_type with the given simtime, agent, and event.
/* The event list is a doubly-linked list of elements of EVENT_TYPE *//* The event list is a doubly-linked list of elements of EVENT_TYPE */
struct event_type {struct event_type { struct simtime time;struct simtime time;
int event;int event; int agent;int agent; struct event_type *prev,*next;struct event_type *prev,*next;
}; }; refer osdefs.h and externs.hrefer osdefs.h and externs.h
Insert it at the appropriate position in the event list (new_events). The 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 event list is ordered chronologically so make sure to maintain the correct order while inserting by using the provided function:order while inserting by using the provided function:
OSSIM – Objective 1OSSIM – Objective 1
Before:Before:
After inserting a simtime record with After inserting a simtime record with seconds = 20, nanosec = 0seconds = 20, nanosec = 0
OSSIM – Objective 1OSSIM – Objective 1
void Load_events(void) void Load_events(void)
This function is called from simulator.c (The simulator driver) This function is called from simulator.c (The simulator driver)
and it initializes the event list (new_events) from the fileand it initializes the event list (new_events) from the file
logon.dat. This file normally contains only LOGON events forlogon.dat. This file normally contains only LOGON events for
all terminals. However, for debugging purposes, logon.dat canall terminals. However, for debugging purposes, logon.dat can
contain events of any type. This function uses:contain events of any type. This function uses:
Add_event(struct simtime * , int, int) Add_event(struct simtime * , int, int)
OSSIM – Objective 1OSSIM – Objective 1
Directions:Directions: Refer to intro.doc for the logon.dat formatRefer to intro.doc for the logon.dat format
Use the given function: Use the given function: convrt_time(struct simtime * time1, long time2)convrt_time(struct simtime * time1, long time2)
The event name and agent name can be either in The event name and agent name can be either in upper or lower case or a combination. Make sure upper or lower case or a combination. Make sure you convert it to upper case.you convert it to upper case.
OSSIM – Objective 1OSSIM – Objective 1 Directions: (contd.)Directions: (contd.)
Convert the event name to eventid using the eventidtab[] defined in Convert the event name to eventid using the eventidtab[] defined in simulator.c. Example: event name = LOGON, event id = 0simulator.c. Example: event name = LOGON, event id = 0
Convert the agent name to agent. Here two cases arise:Convert the agent name to agent. Here two cases arise: If the agent name is Uxxx, agent id = xxx. (agent is a user)If the agent name is Uxxx, agent id = xxx. (agent is a user)
If the agent is a device, then: TRMSIZE + 1 <= agent <= TRMSIZE + If the agent is a device, then: TRMSIZE + 1 <= agent <= TRMSIZE + DEVSIZE where TRMSIZE is the number of terminals (users) and DEVSIZE where TRMSIZE is the number of terminals (users) and DEVSIZE is the number of devices. You will have to use the lookup DEVSIZE is the number of devices. You will have to use the lookup table devtable defined in simulator.c.table devtable defined in simulator.c.
Call Add_event(time2, enevt_id, agent_id) to build the event list.Call Add_event(time2, enevt_id, agent_id) to build the event list.
OSSIM – Objective 1OSSIM – Objective 1 void Write_event (int event, int agent, struct simtime void Write_event (int event, int agent, struct simtime
*time) *time)
This function writes an event to "simout“ with the This function writes an event to "simout“ with the format:format:
"EVENT AGENT TIME (HR:xxxxxxxx MN:xx SC:xx MS:xxx mS:xxx NS:xxx" "EVENT AGENT TIME (HR:xxxxxxxx MN:xx SC:xx MS:xxx mS:xxx NS:xxx"
You will have to convert the nanosec field to MS, You will have to convert the nanosec field to MS, mS,and NS. The seconds field will have to be mS,and NS. The seconds field will have to be converted to HR, MN, and SC.converted to HR, MN, and SC.
OSSIM – Objective 1OSSIM – Objective 1
Directions:Directions: Called from Interrupt(void)Called from Interrupt(void) Convert the event_id and agent_id to Convert the event_id and agent_id to
event name and agent name for event name and agent name for printing to the output file simout which printing to the output file simout which is already open.is already open.
OSSIM – Objective 1OSSIM – Objective 1 void Interrupt(void) void Interrupt(void)
This function is called from simulator.c (The simulator driver) This function is called from simulator.c (The simulator driver) Directions:Directions:
removes an event from new_eventsremoves an event from new_events sets CLOCK, AGENT, and EVENTsets CLOCK, AGENT, and EVENT deallocates the event elementdeallocates the event element writes the event to "simout"writes the event to "simout" Copies CPU.mode and CPU.pc into oldstateCopies CPU.mode and CPU.pc into oldstate Copies newstate into CPU.mode and CPU.pcou will have to convert Copies newstate into CPU.mode and CPU.pcou will have to convert
the nanosec field to MS, mS,and NS. The seconds field will have to the nanosec field to MS, mS,and NS. The seconds field will have to be converted to HR, MN, and SC.be converted to HR, MN, and SC.