22
ICS 145B -- L. B ic 1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

Embed Size (px)

Citation preview

Page 1: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 1

Project: Processes and Resource Management

Textbook: pages 482-491

ICS 145B

L. Bic

Page 2: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 2

Assignment

• Design/implement a simplified process and resource manager

• basic operations (if working alone)– Process: create/destroy– Resource: request/release– Time-out interrupt

• additional tasks for teams– I/O processing– 5.1. page 490 of textbook

Page 3: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 3

• Problem: we do not have the actual processes or hardware

• Solution: your terminal (or test files) represent– currently running process, and

– the hardware causing interrupts

Overall Organization

Page 4: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 4

• write presentation/test shell– reads command from terminal or test file– invokes kernel function– displays reply (on terminal or in output file)

• which process is running• any errors

Overall Organization

your terminal/test files

repeat get f, par invoke f(par) get reply display reply

Process andResource Manager

Page 5: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 5

Presentation/test shell • Example*Process Init is running. . .shell> cr A 1*Process A is runningshell> cr B 2*Process B is runningshell> cr C 1*Process B is runningshell> req R1*Process B is blocked; Process A is running. . .

Page 6: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 6

Process states and operations• Process states: ready, running, blocked• Possible Operations:

– Create: (none) ready– Destroy: running/ready/blocked (none)– Request: running blocked– Release: blocked ready– Time_out: running ready– Request_IO: running blocked– IO_Completion: blocked ready – Scheduler: ready running/running ready

Page 7: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 7

Operations• Request, Request_IO: performed by current process• Create, Destroy: performed by parent process• Release: performed by some other process• Time_out, IO_completion: performed by hardware• Scheduler: invoked at end of each operation

Page 8: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 8

Process Control Block (PCB)• PID• CPU state — not used• Memory — not used• Open_Files — not used• Other_resources• Status: Type & List• Creation_tree: Parent/Children• Priority: 0, 1, 2 (Init, User, System)

Page 9: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 9

Create a processCreate(initialization parameters){

create PCB data structureinitialize PCB using parameterslink PCB to creation treeinsert(RL, PCB)Scheduler() }

• Init process is created at start-up & can create first system or user process

• Any new or released process is inserted at the end of the queue (RL)

Page 10: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 10

Destroy a processDestroy (pid) {

get pointer p to PCB using pidKill_Tree(p)Scheduler() }

Kill_Tree(p) {for all child processes q Kill_Tree(q)free memory and other resourcesdelete PCB and update all pointers }

• Process can be destroyed by any of its ancestors or by itself (exit)

Page 11: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 11

Representation of Resources

• There is a fixed set of resources• Resource Control Block (RCB)

– RID– Status: free or allocated (or counter, if multiple

resource units are implemented)– Waiting_List: list of blocked processes

Page 12: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 12

Request resourceRequest(rid) { r = Get_RCB(rid); if (r->Status == 'free') { r->Status = 'allocated‘; insert(self->Other_Resources, r); } else { self->Status.Type = 'blocked'; self->Status.List = r; remove(RL, self); insert(r->Waiting_List, self); Scheduler(); }

• all requests are satisfied in strict FIFO order

Page 13: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 13

Release resourceRelease(rid) { r = Get_RCB(rid); remove(self->Other_Resources, r); if (r->Waiting_List == NIL} { r->Status = 'free'; } else { remove(r->Waiting_List, q); q->Status.Type = 'ready'; q->Status.List = RL; insert(RL, q); Scheduler(); }}

Page 14: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 14

Scheduling

• 3-level priority scheduler

• Use preemptive round-robin scheduling within level

• Time sharing is simulated by function call

• Init process serves a dual purpose: – Dummy process: lowest priority/never blocked– Root of process creation tree

Page 15: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 15

Scheduler• Called at the end of every kernel call(1) Scheduler() {(2) find highest priority process p(3) if (self->priority < p->priority ||(4) self->Status.Type != 'running' ||(5) self == NIL) (5) preempt(p, self) }

Condition (3): called from create or releaseCondition (4): called from request or time-outCondition (5): called from destroyPreemption: • Change status of p to running (status of self already changed

to ready/blocked)• Context switch—output name of running process

Page 16: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 16

Time-out Interrupts

• Simulate time-sharing

Time_out() { find running process q; remove(RL, q); q->Status.Type = 'ready'; insert(RL, q) find highest priority ready process p; ///delete line

p->Status.Type = 'running'; ///delete line

Scheduler();}

Page 17: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 17

I/O Processing

• Represent all I/O devices collectively as a resource named IO

• RCB– Name: IO– Waiting_List

• Assume I/O requests finish in the order of submission

Page 18: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 18

Request I/O

Request_IO() {

self->Status.Type = 'blocked';

self->Status.List = IO;

remove(RL, self);

insert(IO->Waiting_List, self);

Scheduler();

}

Page 19: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 19

I/O Completion

• Simulates HW interrupt

IO_completion() {

remove(IO->Waiting_List, p);

p->Status.Type = 'ready';

p->Status.List = RL;

insert(RL, p);

Scheduler();

}

Page 20: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 20

Presentation/Test Shell• Mandatory Commands

o inito quito cr <name> <priority> o de <name>o req <resource name> or req <resource name> <# of units> o rel <resource name> or rel <resource name> <# of units> o to o rio o ioc

Page 21: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 21

Presentation/Test Shell

• Optional Commands (Examples):– list all processes and their status– list all resources and their status– provide information about a given process – provide information about a given resource

Page 22: ICS 145B -- L. Bic1 Project: Processes and Resource Management Textbook: pages 482-491 ICS 145B L. Bic

ICS 145B -- L. Bic 22

Summary of tasks• Design/implement the process and resource manager

– data structures and functions

• Design/implement a driver program (shell)– command language and interpreter

• Instantiate the manager to include at start-up:– A Ready List with 3 priorities– A single process, Init– 4 resources labeled: R1, R2, R3, R4 (multiple units for teams)– An IO resource (teams only)

• Submit your program for testing, submit documentation for grading