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
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Slides by Magnus Almgren

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

slide-2
SLIDE 2

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)

slide-3
SLIDE 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

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

*/

};

slide-12
SLIDE 12

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 ’)

slide-13
SLIDE 13

Slides by Magnus Almgren

1 Ready Queue 2 3 4 CPU Disk Queue

slide-14
SLIDE 14

Slides by Magnus Almgren

1 Ready Queue 2 3 4 CPU Disk Queue Out of t ime

slide-15
SLIDE 15

Slides by Magnus Almgren

2 Ready Queue 3 4 1 CPU Disk Queue

slide-16
SLIDE 16

Slides by Magnus Almgren

2 Ready Queue 3 4 1 CPU Disk Queue Out of t ime

slide-17
SLIDE 17

Slides by Magnus Almgren

3 Ready Queue 4 1 2 CPU Disk Queue

slide-18
SLIDE 18

Slides by Magnus Almgren

3 Ready Queue 4 1 2 CPU Disk Queue Wait f or disk access 3

slide-19
SLIDE 19

Slides by Magnus Almgren

4 Ready Queue 1 2 CPU Disk Queue 3 4 Wait f or disk access

slide-20
SLIDE 20

Slides by Magnus Almgren

1 Ready Queue 2 CPU Disk Queue 3 4 I nt errupt : Disk access

slide-21
SLIDE 21

Slides by Magnus Almgren

2 Ready Queue CPU 3 3 Disk Queue I nt errupt : Disk access 4

slide-22
SLIDE 22

Slides by Magnus Almgren

2 Ready Queue CPU 3 4 Disk Queue I nt errupt : Disk access Process Terminat ion

slide-23
SLIDE 23

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 …

slide-24
SLIDE 24

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;

slide-25
SLIDE 25

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 */ };

slide-26
SLIDE 26

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

*/

};

slide-27
SLIDE 27

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();

slide-28
SLIDE 28

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.

slide-29
SLIDE 29

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:

slide-30
SLIDE 30

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

slide-31
SLIDE 31

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

slide-32
SLIDE 32

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
slide-33
SLIDE 33

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