Slides by Magnus Almgren
I nt roduct ion t o Lab 2 I nt roduct ion t o Lab 2 I nt roduct ion - - PowerPoint PPT Presentation
I nt roduct ion t o Lab 2 I nt roduct ion t o Lab 2 I nt roduct ion - - PowerPoint PPT Presentation
I nt roduct ion t o Lab 2 I nt roduct ion t o Lab 2 I nt roduct ion t o Lab 2 I nt roduct ion t o Lab 2 EDA092 EDA092 Oper at ing Syst ems Oper at ing Syst ems 2008 2008-02 02-18 18 Wolf gang J ohn Wolf gang J ohn Slides by Magnus
Slides by Magnus Almgren
Overview of OSP
- An Environment f or
Operat ing Syst em Proj ect s
- Simulat es an operat ing syst em (surprise!)
- Consist s of modules t hat execut es
dif f erent operat ing syst em f unct ions, such as
– Scheduling of CPU (lab 2.1) – Vir t ual Memor y Management (lab 2.2) – File Access (lab 2.3)
Slides by Magnus Almgren
OSP Modules: Overview
CPU DI ALOG SI MCORE I NTER DEVI NT PAGEI NT TI MEI NT DEVI CES MEMORY FI LES
Slides by Magnus Almgren
OSP Modules: Overview
CPU DI ALOG I NTER DEVI NT PAGEI NT TI MEI NT SI MCORE DEVI CES MEMORY FI LES Lab 2.1 Lab 2.2
Slides by Magnus Almgren
OSP Modules: Overview
CPU DI ALOG SI MCORE I NTER DEVI NT PAGEI NT TI MEI NT DEVI CES MEMORY FI LES
CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES
Slides by Magnus Almgren
OSP Modules: Overview
CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES
Slides by Magnus Almgren
OSP Modules: Misc
- RESOURCES –resource management
- DEVI CES
–disk access
- SOCKETS
–process communicat ion
- PROTOCOLS –prot ocols used f or t he
SOCKET module
CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES
Slides by Magnus Almgren
OSP Modules: SimCore
CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES
- SimCore – Main Par t of Syst em
– Gener at es event s
- St art and t erminat ion of processes
- Virt ual memory ref erences
- Timer int errupt s
- Read/ writ e t o ext ernal devices
- I nt errupt s f rom ext ernal devices
– Par amet er s of t he simulat ion cont r ols t he simulat ion – Collect s st at ist ics about r esour ce allocat ion
Slides by Magnus Almgren
OSP Modules: SimCore
CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES
- Har dwar e of OSP CPU
– I nt er val Timer – Clock – I nt er r upt vect or – Base r egist er f or page t ables – Disk access
- Memor y
– Vir t ual memor y wit h paging: PAGE_TBL
Slides by Magnus Almgren
- Lab 2.1: CPU Scheduling
- Three Process St at es
(+done:zombie)
- Each process has a
Process Control Block
OSP Modules: CPU
CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES
blocked ready running sleep wakeup t imer int errupt dispat ch
Slides by Magnus Almgren
struct pcb_node { /* f r om cpu.c */
int pcb_id; /*
PCB id
*/ int size; /*
process size in byt es; assigned by SI MCORE
*/ int creation_time; /*
assigned by SI MCORE
*/ int last_dispatch; /*
last t ime t he process was dispat ched
*/ int last_cpuburst; /*
lengt h of t he previous CPU burst
*/ int accumulated_cpu; /*
accumulat ed CPU t ime
*/ PAGE_TBL *page_tbl; /*
page t able associat ed wit h t he PCB
*/ STATUS status; /*
st at us of process: running, ready, wait ing, done
*/ EVENT *event; /*
event upon which process may be suspended
*/ int priority; /*
user-def ined priorit y; used f or scheduling
*/ PCB *next; /*
next PCB in what ever queue
*/ PCB *prev; /*
previous PCB in what ever queue
*/ int *hook; /*
can hook up anyt hing here
*/
};
Slides by Magnus Almgren
Lab 2.1: Round Robin Scheduling
- Round Robin = Signing pet it ions w/ out
showing who signed f irst
- Circular queue of processes ready t o
execut e
- No priorit y (regular RR)
- Each process execut es unt il it
– Ter minat es – Wait s (f or a r esour ce) – Runs out of t ime quant a (‘t imer int er r upt ’)
Slides by Magnus Almgren
1 Ready Queue 2 3 4 CPU Disk Queue
Slides by Magnus Almgren
1 Ready Queue 2 3 4 CPU Disk Queue Out of t ime
Slides by Magnus Almgren
2 Ready Queue 3 4 1 CPU Disk Queue
Slides by Magnus Almgren
2 Ready Queue 3 4 1 CPU Disk Queue Out of t ime
Slides by Magnus Almgren
3 Ready Queue 4 1 2 CPU Disk Queue
Slides by Magnus Almgren
3 Ready Queue 4 1 2 CPU Disk Queue Wait f or disk access 3
Slides by Magnus Almgren
4 Ready Queue 1 2 CPU Disk Queue 3 4 Wait f or disk access
Slides by Magnus Almgren
1 Ready Queue 2 CPU Disk Queue 3 4 I nt errupt : Disk access
Slides by Magnus Almgren
2 Ready Queue CPU 3 3 Disk Queue I nt errupt : Disk access 4
Slides by Magnus Almgren
2 Ready Queue CPU 3 4 Disk Queue I nt errupt : Disk access Process Terminat ion
Slides by Magnus Almgren
Lab 2.1 Requirement s?
Round Robin Scheduling in OSP:
I mplement a r eady queue, and move pr ocesses f r om r unning and r eady queue.
1. Key I nf ormat ion: OSP 1.6 (impossible t o do lab wit hout it !!!) 2. Main Working File: cpu.c 3. Need: Linked List f or Round Robin …
Slides by Magnus Almgren
/ *************************************************************/ / * Module CPU */ / * Ext ernal Declarat ions */ / *************************************************************/
/ * OSP const ant */
#define MAX_PAGE 16 / * max size of page t ables */
/ * OSP enumer at ion const ant s */
typedef enum { false, true / * t he boolean dat a t ype */ } BOOL; typedef enum { running,ready,waiting,done / * t ypes of st at us */ } STATUS;
Slides by Magnus Almgren
/ * ext er nal t ype def init ions */
typedef struct page_entry_node PAGE_ENTRY; typedef struct page_tbl_node PAGE_TBL; typedef struct event_node EVENT; typedef struct pcb_node PCB;
/ * ext er nal dat a st r uct ur es */
struct page_entry_node { int frame_id; / * f rame id holding t his page */ BOOL valid; / * page in main memory : valid = t rue; not : f alse */ BOOL ref; / * set t o t rue every t ime page is ref erenced AD */ int *hook; / * can hook up anyt hing here */ }; struct page_tbl_node { PCB *pcb; / * PCB of t he process in quest ion */ PAGE_ENTRY page_entry[MAX_PAGE]; int *hook; / * can hook up anyt hing here */ };
Slides by Magnus Almgren
struct pcb_node {
int pcb_id; /*
PCB id
*/ int size; /*
process size in byt es; assigned by SI MCORE
*/ int creation_time; /*
assigned by SI MCORE
*/ int last_dispatch; /*
last t ime t he process was dispat ched
*/ int last_cpuburst; /*
lengt h of t he previous CPU burst
*/ int accumulated_cpu; /*
accumulat ed CPU t ime
*/ PAGE_TBL *page_tbl; /*
page t able associat ed wit h t he PCB
*/ STATUS status; /*
st at us of process
*/ EVENT *event; /*
event upon which process may be suspended
*/ int priority; /*
user-def ined priorit y; used f or scheduling
*/ PCB *next; /*
next PCB in what ever queue
*/ PCB *prev; /*
previous PCB in what ever queue
*/ int *hook; /*
can hook up anyt hing here
*/
};
Slides by Magnus Almgren
/ * ext er nal var iables */
extern PAGE_TBL *PTBR; / * page t able base regist er */ extern int Quantum; / * global t ime quant um; cont ains t he value ent ered at t he beginning or changed at snapshot . Has no ef f ect on t imer int errupt s, unless passed t o set _t imer() */
/ * ext er nal r out ines */
extern prepage(/ * pcb */ ); extern int start_cost(/ * pcb */ ); / * PCB *pcb; */ extern set_timer(/ * t ime_quant um */ ); / * int t ime_quant um; */ extern int get_clock();
Slides by Magnus Almgren
/ *******************************************************/ / * Module CPU */ / * I nt ernal Rout ines */ / *******************************************************/ void cpu_init() { } void dispatch() { } void insert_ready(pcb) PCB *pcb; { } / * end of module */ lot s of smart code ready t o run? round robin
Her e is most ly wher e you add your code f or lab 2.1!
I mport ant : Check t he I nt ro t o OSP f or all necessary st eps.
Slides by Magnus Almgren
Building a Linked List
- Assume t hat a list of posit ions (x,y) shall be
implement ed in t he C language using linked list s. Det er mine a suit able t ype declar at ion and wr it e f unct ions t o do t he f ollowing:
– Cr eat e an empt y list – Add an element (x,y) t o a list – Sear ch f or an element (x,y) in a list and r emove it if pr esent in t he list
Previous: Next : Y: x: Previous: Next : Y: x: Previous: Next : Y: x: Previous: Next : Y: x: Head:
Slides by Magnus Almgren
I nt roduct ion t o LL
- Double-linked, circular list
- Usef ul t o have synonym f or t he last
element t oo
Previous: Next : Y: x: Previous: Next : Y: x: Previous: Next : Y: x: Previous: Next : Y: x: Head: t ail: head-> previous
Slides by Magnus Almgren
Lab 2.2 Memory Management
- OSP Modules
– MEMORY – PAGEI NT
- Caref ully read OSP 1.4.3 and 1.5 !!!
- Experiment wit h paramet ers t o
reduce t he page f ault s
CP U DI ALOG SI MCORE I NTER DEVI NT P AGEI NT TI MEI NT DEVI CES MEMORY FI LES
Slides by Magnus Almgren
Memory Management
- Algorit hms t o replace pages
– FI FO – Opt imal Algorit hm (I maginary) – LRU (Least Recent ly Used)
- Good but dif f icult t o implement
- Second-Chance Algor it hm, w/ r ef er ence bit
Slides by Magnus Almgren
2nd Chance Clock Algorit hm
1 1 1 1 1 1 next vict im
ref erence bit s pages ref erence bit s pages
Page 337 in Operat ing Syst em Concept s