Download presentation
Presentation is loading. Please wait.
1
Slides by Magnus Almgren Introduction to Lab 2 EDA092 – Operating Systems 2008-02-18 Wolfgang John
2
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)
3
Slides by Magnus Almgren OSP Modules: Overview CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES
4
Slides by Magnus Almgren OSP Modules: Overview CPU DIALOG INTER DEVINT PAGEINT TIMEINT SIMCORE DEVICES MEMORY FILES Lab 2.1 Lab 2.2
5
Slides by Magnus Almgren OSP Modules: Overview CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES
6
Slides by Magnus Almgren OSP Modules: Overview CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES
7
Slides by Magnus Almgren OSP Modules: Misc RESOURCES–resource management DEVICES–disk access SOCKETS–process communication PROTOCOLS–protocols used for the SOCKET module CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES
8
Slides by Magnus Almgren OSP Modules: SimCore CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT 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
9
Slides by Magnus Almgren OSP Modules: SimCore CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT 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
10
Slides by Magnus Almgren Lab 2.1: CPU Scheduling Three Process States (+done:zombie) Each process has a Process Control Block OSP Modules: CPU CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES blockedready running sleep wakeup timer interrupt dispatch
11
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 */ };
12
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’)
13
Slides by Magnus Almgren 1 Ready Queue 234 CPU Disk Queue
14
Slides by Magnus Almgren 1 Ready Queue 234 CPU Disk Queue Out of time
15
Slides by Magnus Almgren 2 Ready Queue 341 CPU Disk Queue
16
Slides by Magnus Almgren 2 Ready Queue 341 CPU Disk Queue Out of time
17
Slides by Magnus Almgren 3 Ready Queue 412 CPU Disk Queue
18
Slides by Magnus Almgren 3 Ready Queue 412 CPU Disk Queue Wait for disk access 3
19
Slides by Magnus Almgren 4 Ready Queue 12 CPU Disk Queue 3 4 Wait for disk access
20
Slides by Magnus Almgren 1 Ready Queue 2 CPU Disk Queue 3 4 Interrupt: Disk access
21
Slides by Magnus Almgren 2 Ready Queue CPU 3 3 Disk Queue Interrupt: Disk access 4 1
22
Slides by Magnus Almgren 2 Ready Queue CPU 3 4 Disk Queue Interrupt: Disk access 1 Process Termination
23
Slides by Magnus Almgren Lab 2.1 Requirements? 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.c 3.Need: Linked List for Round Robin …
24
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;
25
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*/ };
26
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 */ };
27
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();
28
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 add your code for lab 2.1! Important: Check the Intro to OSP for all necessary steps.
29
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:
30
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
31
Slides by Magnus Almgren Lab 2.2 Memory Management OSP Modules –MEMORY –PAGEINT Carefully read OSP 1.4.3 and 1.5 !!! Experiment with parameters to reduce the page faults CPU DIALOGSIMCORE INTER DEVINT PAGEINT TIMEINT DEVICES MEMORY FILES
32
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
33
Slides by Magnus Almgren 2 nd Chance Clock Algorithm 0 0 1 1 1 1 0 0 0 1 1 0 0 0 next victim reference bits pages reference bits pages Page 337 in Operating System Concepts
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.