os lacture

Post on 11-Jun-2015

436 Views

Category:

Travel

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Operating Systems

Lecture 18

Syed Mansoor Sarwar

April 13, 2023 © Copyright Virtual University of Pakistan

Agenda for Today

Review of previous lectureUNIX System V scheduling Algorithm evaluationProcess synchronizationRecap of lecture

April 13, 2023 © Copyright Virtual University of Pakistan

Review of Lecture 17

Multi-level queues schedulingMulti-level feedback queues

schedulingUNIX System V scheduling

algorithm

April 13, 2023 © Copyright Virtual University of Pakistan

Every second, the priority number of all those processes that are in the main memory and ready to run is updated by using the following formula:

Priority# = (Recent CPU Usage)/2 + Thr. Pri.+ nice

Threshold priority and nice values are always positive to prevent a user from migrating out of its assigned group

UNIX System V Scheduling Algorithm

April 13, 2023 © Copyright Virtual University of Pakistan

Time

0

1

2

3

4

5

Priority

60

75

67

63

76

68

CPU Count

01…6030

3015

78…6733

16

PA

Priority

60

60

75

67

63

76

CPU Count

0

01…6030

3015

78…6733

PB

Priority

60

60

60

75

67

63

CPU Count

0

0

01…6030

3015

7

PC

UNIX System V Example

April 13, 2023 © Copyright Virtual University of Pakistan

Round Robin Scheduling and Process Priorities

A

Hig

her

Prio

rity

60

A

A

A

B

B

B A B B A runs first

1

4

2 3

5 6

April 13, 2023 © Copyright Virtual University of Pakistan

Algorithm Evaluation Analytic Evaluation

The algorithm and some system workload are used to produce a formula or number which gives the performance of the algorithm for that workload.

Deterministic modeling Queuing models

Implementation

April 13, 2023 © Copyright Virtual University of Pakistan

Deterministic Modeling Predetermined workload and

performance of each algorithm for that workload. Use of Gantt charts.

Simple and fast Exact numbers for comparison Requires exact input Performance figures may not be

true in general

April 13, 2023 © Copyright Virtual University of Pakistan

Process Arrival Time Burst Time

P1 0.0 7

P2 2.0 4

P3 4.0 1

P4 5.0 4

Gantt chart

Average waiting time = (9 + 1 + 0 +2)/4 = 3

P3P2

42 110

P4

5 7

P2 P1

16

P1

Deterministic Modeling

April 13, 2023 © Copyright Virtual University of Pakistan

Queuing Modeling Computer system viewed as a

network of queues and servers: ready queue, I/O queue, event queues, CPUs, I/O device controllers, etc.

Input: Arrival and service rates Output: CPU utilization, average

queue length, average waiting time, …

April 13, 2023 © Copyright Virtual University of Pakistan

Queuing Modeling

Little’s Formula:n = λ* W

wheren = average queue lengthλ = average arrival rateW = average waiting time in a

queue

April 13, 2023 © Copyright Virtual University of Pakistan

Queuing ModelingLet the average job arrival rate be 0.5

Algorithm Average Wait TimeW=tw

Average Queue Length(n)

FCFS 4.6 2.3

SJF 3.6 1.8

SRTF 3.2 1.6

RR (q=1) 7.0 3.5

RR (q=4) 6.0 3.0

April 13, 2023 © Copyright Virtual University of Pakistan

Queuing Modeling Complicated mathematics Distributions (Poisson, uniform,

exponential, etc) for the arrival and departure rates can be difficult to work with

Assumptions may not be accurate Approximation of the real system

April 13, 2023 © Copyright Virtual University of Pakistan

SimulationProgramming model for the

computer systemWorkload generated by

assuming some distribution and a random number generator, or by collecting data from the actual system.

April 13, 2023 © Copyright Virtual University of Pakistan

SimulationCharacteristics

Expensive: hours of programming and execution time

May be erroneous because of the assumptions about distributions

April 13, 2023 © Copyright Virtual University of Pakistan

Simulation

April 13, 2023 © Copyright Virtual University of Pakistan

Implementation

BestMost expensive

Good option due to Open Source kernels such as Linux

April 13, 2023 © Copyright Virtual University of Pakistan

Process Synchronization

Concurrent access to shared data may result in data inconsistency.

Maintaining data consistency requires mechanisms to ensure that cooperating processes access shared data sequentially.

April 13, 2023 © Copyright Virtual University of Pakistan

Bounded-Buffer Problem

Shared data#define BUFFER_SIZE 10typedef struct {

. . .} item;

item buffer[BUFFER_SIZE];int in = 0, out = 0;int counter = 0;

April 13, 2023 © Copyright Virtual University of Pakistan

Producer processitem nextProduced;…while (1) { while (counter == BUFFER_SIZE) ; buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++;}

Bounded-Buffer Problem

April 13, 2023 © Copyright Virtual University of Pakistan

item nextConsumed;while (1) { while (counter == 0) ; nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--;}

Bounded-Buffer ProblemConsumer process

April 13, 2023 © Copyright Virtual University of Pakistan

“counter++” in assembly language

MOV R1, counter

INC R1 MOV counter, R1

“counter--” in assembly languageMOV R2, counter

DEC R2 MOV counter, R2

Bounded-Buffer Problem

April 13, 2023 © Copyright Virtual University of Pakistan

If both the producer and consumer attempt to update the buffer concurrently, the machine language statements may get interleaved.

Interleaving depends upon how the producer and consumer processes are scheduled.

Bounded-Buffer Problem

April 13, 2023 © Copyright Virtual University of Pakistan

Assume counter is initially 5. One interleaving of statements is:

producer: MOV R1, counter (R1 = 5) INC R1 (R1 = 6)consumer: MOV R2, counter (R2 = 5) DEC R2 (R2 = 4)producer: MOV counter, R1 (counter = 6)consumer: MOV counter, R2 (counter = 4)

The value of count may be either 4 or 6, where the correct result should be 5.

Bounded-Buffer Problem

April 13, 2023 © Copyright Virtual University of Pakistan

Race Condition: The situation where several processes access and manipulate shared data concurrently, the final value of the data depends on which process finishes last.

Process Synchronization

April 13, 2023 © Copyright Virtual University of Pakistan

Critical Section: A piece of code in a cooperating process in which the process may updates shared data (variable, file, database, etc.).

Critical Section Problem: Serialize executions of critical sections in cooperating processes

Process Synchronization

April 13, 2023 © Copyright Virtual University of Pakistan

Software based solutions Hardware based solutions Operating system based

solution

Solution of the Critical Problem

April 13, 2023 © Copyright Virtual University of Pakistan

do {

critical section

reminder section

} while (1);

entry section

exit section

Structure of Solution

April 13, 2023 © Copyright Virtual University of Pakistan

Recap of Lecture

UNIX System V scheduling Algorithm evaluationProcess synchronizationRecap of lecture

Operating Systems

Lecture 18

Syed Mansoor Sarwar

top related