i nt roduct ion t o lab 2 i nt roduct ion t o lab 2 i nt
play

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


  1. 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 Almgren

  2. 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

  3. OSP Modules: Overview CPU MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT PAGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  4. OSP Modules: Overview Lab 2.2 Lab 2.1 CPU MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT PAGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  5. OSP Modules: Overview CPU MEMORY CP U MEMORY SI MCORE DI ALOG SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT FI LES I NTER DEVI NT PAGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  6. OSP Modules: Overview CP U MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT CP U MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  7. 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 MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  8. OSP Modules: SimCore • 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 CP U MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  9. OSP Modules: SimCore • 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 CP U MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  10. OSP Modules: CPU • Lab 2.1: CPU Scheduling • Three Process St at es wakeup (+done:zombie) blocked ready t imer sleep dispat ch int errupt • Each process has a running Process Control Block CP U MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

  11. struct pcb_node { /* f r om cpu.c */ PCB id int pcb_id; /* */ process size in byt es; assigned by SI MCORE int size; /* */ assigned by SI MCORE int creation_time; /* */ last t ime t he process was dispat ched int last_dispatch; /* */ lengt h of t he previous CPU burst int last_cpuburst; /* */ accumulat ed CPU t ime int accumulated_cpu; /* */ page t able associat ed wit h t he PCB PAGE_TBL *page_tbl; /* */ st at us of process: running, ready, wait ing, done STATUS status; /* */ event upon which process may be suspended EVENT *event; /* */ user-def ined priorit y; used f or scheduling int priority; /* */ next PCB in what ever queue PCB *next; /* */ previous PCB in what ever queue PCB *prev; /* */ can hook up anyt hing here int *hook; /* */ }; Slides by Magnus Almgren

  12. 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

  13. CPU Ready Queue 1 2 3 4 Disk Queue Slides by Magnus Almgren

  14. CPU Out of t ime Ready Queue 1 2 3 4 Disk Queue Slides by Magnus Almgren

  15. CPU Ready Queue 2 3 4 1 Disk Queue Slides by Magnus Almgren

  16. CPU Out of t ime Ready Queue 2 3 4 1 Disk Queue Slides by Magnus Almgren

  17. CPU Ready Queue 3 4 1 2 Disk Queue Slides by Magnus Almgren

  18. CPU Wait f or disk access Ready Queue 3 4 1 2 Disk Queue 3 Slides by Magnus Almgren

  19. CPU Wait f or disk access Ready Queue 4 1 2 Disk Queue 4 3 Slides by Magnus Almgren

  20. CPU I nt errupt : Disk access Ready Queue 1 2 Disk Queue 4 3 Slides by Magnus Almgren

  21. CPU I nt errupt : Disk access Ready Queue 2 3 Disk Queue 4 3 Slides by Magnus Almgren

  22. CPU I nt errupt : Disk access Process Terminat ion Ready Queue 2 3 Disk Queue 4 Slides by Magnus Almgren

  23. 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

  24. / *************************************************************/ / * Module CPU */ / * Ext ernal Declarat ions */ / *************************************************************/ / * OSP const ant */ / * max size of page t ables */ #define MAX_PAGE 16 / * OSP enumer at ion const ant s */ typedef enum { / * t he boolean dat a t ype */ false, true } BOOL; typedef enum { / * t ypes of st at us */ running,ready,waiting,done } STATUS; Slides by Magnus Almgren

  25. / * 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 */ / * page in main memory : valid = t rue; not : f alse */ BOOL valid; / * set t o t rue every t ime page is ref erenced AD */ BOOL ref; / * can hook up anyt hing here */ int *hook; }; struct page_tbl_node { / * PCB of t he process in quest ion */ PCB *pcb; PAGE_ENTRY page_entry[MAX_PAGE]; / * can hook up anyt hing here */ int *hook; }; Slides by Magnus Almgren

  26. struct pcb_node { PCB id int pcb_id; /* */ process size in byt es; assigned by SI MCORE int size; /* */ assigned by SI MCORE int creation_time; /* */ last t ime t he process was dispat ched int last_dispatch; /* */ lengt h of t he previous CPU burst int last_cpuburst; /* */ accumulat ed CPU t ime int accumulated_cpu; /* */ page t able associat ed wit h t he PCB PAGE_TBL *page_tbl; /* */ st at us of process STATUS status; /* */ event upon which process may be suspended EVENT *event; /* */ user-def ined priorit y; used f or scheduling int priority; /* */ next PCB in what ever queue PCB *next; /* */ previous PCB in what ever queue PCB *prev; /* */ can hook up anyt hing here int *hook; /* */ }; Slides by Magnus Almgren

  27. / * ext er nal var iables */ / * page t able base regist er */ extern PAGE_TBL *PTBR; / * global t ime quant um; cont ains t he value extern int Quantum; 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

  28. / *******************************************************/ / * Module CPU */ / * I nt ernal Rout ines */ / *******************************************************/ void cpu_init() { lot s of smart code } Her e is most ly wher e you add your code f or lab 2.1! void dispatch() { ready t o run? I mport ant : Check t he I nt ro t o OSP f or all necessary st eps. } void insert_ready(pcb) PCB *pcb; { round robin } / * end of module */ Slides by Magnus Almgren

  29. 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 Head: Previous: Previous: Previous: Previous: Next : Next : Next : Next : x: x: x: x: Y: Y: Y: Y: Slides by Magnus Almgren

  30. 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: Previous: Previous: Previous: Next : Next : Next : Next : Head: x: x: x: x: Y: Y: Y: Y: t ail: head-> previous Slides by Magnus Almgren

  31. 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 MEMORY SI MCORE DI ALOG FI LES I NTER DEVI NT P AGEI NT DEVI CES TI MEI NT Slides by Magnus Almgren

Recommend


More recommend