slides by magnus almgren introduction to lab 2 eda092 – operating systems 2008-02-18 wolfgang john

33
Slides by Magnus Almgren Introduction to Introduction to Lab 2 Lab 2 EDA092 – Operating Systems EDA092 – Operating Systems 2008-02-18 2008-02-18 Wolfgang John Wolfgang John

Post on 22-Dec-2015

220 views

Category:

Documents


2 download

TRANSCRIPT

Slides by Magnus Almgren

Introduction to Lab 2Introduction to Lab 2Introduction to Lab 2Introduction to Lab 2

EDA092 – Operating SystemsEDA092 – Operating Systems2008-02-182008-02-18

Wolfgang JohnWolfgang John

Slides by Magnus Almgren

Overview of OSP• An Environment for

Operating System Projects• Simulates an operating system

(surprise!)• Consists of modules that executes

different operating system functions, such as– Scheduling of CPU (lab 2.1)– Virtual Memory Management (lab 2.2)– File Access (lab 2.3)

Slides by Magnus Almgren

OSP Modules: OverviewCPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

Slides by Magnus Almgren

OSP Modules: OverviewCPU

DIALOG

INTERDEVINTPAGEINTTIMEINT

SIMCORE

DEVICES

MEMORY

FILES

Lab 2.1Lab 2.2

Slides by Magnus Almgren

OSP Modules: OverviewCPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

CPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

Slides by Magnus Almgren

OSP Modules: Overview

CPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

CPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

Slides by Magnus Almgren

OSP Modules: Misc• RESOURCES –resource management• DEVICES –disk access• SOCKETS –process

communication• PROTOCOLS –protocols used for the

SOCKET moduleCPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

Slides by Magnus Almgren

OSP Modules: SimCore

CPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

• SimCore – Main Part of System– Generates events

• Start and termination of processes• Virtual memory references• Timer interrupts• Read/write to external devices• Interrupts from external devices

– Parameters of the simulation controls the simulation– Collects statistics about resource allocation

Slides by Magnus Almgren

OSP Modules: SimCore

CPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

• Hardware of OSP CPU– Interval Timer– Clock– Interrupt vector– Base register for page tables– Disk access

• Memory– Virtual memory with paging: PAGE_TBL

Slides by Magnus Almgren

• Lab 2.1: CPU Scheduling• Three Process States

(+done:zombie)

• Each process has aProcess Control Block

OSP Modules: CPU

CPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

blocked ready

running

sleep

wakeup

timerinterrupt

dispatch

Slides by Magnus Almgren

struct pcb_node { /* from cpu.c */

int pcb_id; /* PCB id */

int size; /* process size in bytes; assigned by SIMCORE */

int creation_time; /* assigned by SIMCORE */

int last_dispatch; /* last time the process was dispatched */

int last_cpuburst; /* length of the previous CPU burst */

int accumulated_cpu; /* accumulated CPU time */

PAGE_TBL *page_tbl; /* page table associated with the PCB */

STATUS status; /* status of process: running, ready, waiting, done */

EVENT *event; /* event upon which process may be suspended */

int priority; /* user-defined priority; used for scheduling */

PCB *next; /* next PCB in whatever queue */

PCB *prev; /* previous PCB in whatever queue */

int *hook; /* can hook up anything here */

};

Slides by Magnus Almgren

Lab 2.1: Round Robin Scheduling

• Round Robin = Signing petitions w/out showing who signed first

• Circular queue of processes ready to execute

• No priority (regular RR)• Each process executes until it

– Terminates– Waits (for a resource)– Runs out of time quanta (‘timer interrupt’)

Slides by Magnus Almgren

1Ready Queue 2 3 4

CPU

Disk Queue

Slides by Magnus Almgren

1Ready Queue 2 3 4

CPU

Disk Queue

Out of time

Slides by Magnus Almgren

2Ready Queue 3 4 1

CPU

Disk Queue

Slides by Magnus Almgren

2Ready Queue 3 4 1

CPU

Disk Queue

Out of time

Slides by Magnus Almgren

3Ready Queue 4 1 2

CPU

Disk Queue

Slides by Magnus Almgren

3Ready Queue 4 1 2

CPU

Disk Queue

Wait for disk access

3

Slides by Magnus Almgren

4Ready Queue 1 2

CPU

Disk Queue 3 4

Wait for disk access

Slides by Magnus Almgren

1Ready Queue 2

CPU

Disk Queue 3 4

Interrupt: Disk access

Slides by Magnus Almgren

2Ready Queue

CPU

3

3Disk Queue

Interrupt: Disk access

4

1

Slides by Magnus Almgren

2Ready Queue

CPU

3

4Disk Queue

Interrupt: Disk access

1

Process Termination

Slides by Magnus Almgren

Lab 2.1Requirements?

Round Robin Scheduling in OSP:Implement a ready queue, and move processes from running and ready queue.

1. Key Information: OSP 1.6(impossible to do lab without it!!!)

2. Main Working File: cpu.c3. Need: Linked List for Round Robin …

Slides by Magnus Almgren

/*************************************************************//* Module CPU *//* External Declarations

*//*************************************************************/

/* OSP constant */#define MAX_PAGE 16 /* max size of page tables */

/* OSP enumeration constants */typedef enum { false, true /* the boolean data type

*/} BOOL;

typedef enum { running,ready,waiting,done /* types of status */} STATUS;

Slides by Magnus Almgren

/* external type definitions */typedef struct page_entry_node PAGE_ENTRY;typedef struct page_tbl_node PAGE_TBL;typedef struct event_node EVENT;typedef struct pcb_node PCB;

/* external data structures */struct page_entry_node { int frame_id; /* frame id holding this page */ BOOL valid; /* page in main memory : valid = true; not : false */ BOOL ref; /* set to true every time page is referenced AD

*/ int *hook; /* can hook up anything here */};struct page_tbl_node { PCB *pcb; /* PCB of the process in question */ PAGE_ENTRY page_entry[MAX_PAGE]; int *hook; /* can hook up anything here */};

Slides by Magnus Almgren

struct pcb_node {

int pcb_id; /* PCB id */

int size; /* process size in bytes; assigned by SIMCORE */

int creation_time; /* assigned by SIMCORE */

int last_dispatch; /* last time the process was dispatched */

int last_cpuburst; /* length of the previous CPU burst */

int accumulated_cpu; /* accumulated CPU time */

PAGE_TBL *page_tbl; /* page table associated with the PCB */

STATUS status; /* status of process */

EVENT *event; /* event upon which process may be suspended */

int priority; /* user-defined priority; used for scheduling */

PCB *next; /* next PCB in whatever queue */

PCB *prev; /* previous PCB in whatever queue */

int *hook; /* can hook up anything here */

};

Slides by Magnus Almgren

/* external variables */extern PAGE_TBL *PTBR; /* page table base register */

extern int Quantum; /* global time quantum; contains the value entered at the beginning or changed at snapshot. Has no effect on timer interrupts, unless passed to set_timer() */

/* external routines */extern prepage(/* pcb */);extern int start_cost(/* pcb */); /* PCB *pcb; */ extern set_timer(/* time_quantum */); /* int time_quantum; */extern int get_clock();

Slides by Magnus Almgren

/*******************************************************//* Module CPU *//* Internal Routines *//*******************************************************/

void cpu_init() {

}

void dispatch() {

}

void insert_ready(pcb) PCB *pcb;{

}

/* end of module */

lots of smart code

ready to run?

round robin

Here is mostly where you addyour code for lab 2.1!

Important: Check the Intro to OSP for all necessary steps.

Slides by Magnus Almgren

Building a Linked List• Assume that a list of positions (x,y) shall be

implemented in the C language using linked lists. Determine a suitable type declaration and write functions to do the following:– Create an empty list– Add an element (x,y) to a list– Search for an element (x,y) in a list and remove it if

present in the list

Previous:

Next:

Y:

x:

Previous:

Next:

Y:

x:

Previous:

Next:

Y:

x:

Previous:

Next:

Y:

x:

Head:

Slides by Magnus Almgren

Introduction to LL• Double-linked, circular list• Useful to have synonym for the last

element too

Previous:

Next:

Y:

x:

Previous:

Next:

Y:

x:

Previous:

Next:

Y:

x:

Previous:

Next:

Y:

x: Head:

tail: head->previous

Slides by Magnus Almgren

Lab 2.2Memory Management

• OSP Modules– MEMORY– PAGEINT

• Carefully read OSP 1.4.3 and 1.5 !!!

• Experiment with parameters to reduce the page faults

CPU

DIALOGSIMCORE

INTERDEVINTPAGEINTTIMEINT

DEVICES

MEMORY

FILES

Slides by Magnus Almgren

Memory Management• Algorithms to replace pages

– FIFO– Optimal Algorithm (Imaginary)– LRU (Least Recently Used)

• Good but difficult to implement• Second-Chance Algorithm, w/ reference

bit

Slides by Magnus Almgren

2nd Chance Clock Algorithm

0

0

1

1

1

1

0

0

0

1

1

0

0

0

nextvictim

referencebits

pages referencebits

pages

Page 3

37

in O

pera

ting S

yst

em

Conce

pts