Docsity

CPU scheduling - outline, chap.5: basic concepts and case studies | EECS 678, Study notes of Operating Systems

Toggle sidebar
bg1


■What is scheduling in the OS ?
■What are common scheduling criteria ?
■How to evaluate scheduling algorithms ?
■What are common scheduling algorithms ?
■How is thread scheduling different from process scheduling ?
■What are the issues in multiple-processor scheduling ?
■Operating systems case studies.


■Multiprogramming
●most processes alternate between CPU bursts and I/O bursts
●CPU free and idle during I/O burst
●schedule another process on the CPU
●maximizes CPU utilization
■CPU bound process
●spends most of its time in the CPU
●at least a few long CPU bursts
■I/O bound process
●spends most its time performing I/O
●several short CPU bursts


■Responsible for the selection of the next running process
●part of the OS dispatcher
●selects from among the processes in memory that are ready to execute
●based on a particular strategy
■When does CPU scheduling happen ?
●process switches from running to waiting state
●process switches from running to ready state
●process switches from waiting to ready state
●process terminates
■Scheduling under 1 and 4 is nonpreemptive
■All other scheduling is preemptive



■Non-preemptive scheduling
●process voluntarily releases the CPU (conditions 1 and 4)
●easy, requires no special hardware
●poor response time for interactive and real-time systems
■Preemptive scheduling
●OS can force a running process involuntarily relinquish the CPU
arrival of a higher priority process
running process exceeds its time-slot
●may require special hardware, eg., timer
●may require synchronization mechanisms to maintain data consistency
●complicates design of the kernel
●favored by most OSes
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download CPU scheduling - outline, chap.5: basic concepts and case studies | EECS 678 and more Study notes Operating Systems in PDF only on Docsity!

^  ^ ^       

^

^ ^ 

n^ What is scheduling in the OS? n^ What are common scheduling criteria? n^ How to evaluate scheduling algorithms? n^ What are common scheduling algorithms? n^ How is thread scheduling different from process scheduling? n^ What are the issues in multiple-processor scheduling? n^ Operating systems case studies.

 ^  ^ ^       

n^ Multiprogramming^ l^ most processes alternate between

CPU bursts^ and^

I/O bursts

l^ CPU free and idle during I/O burst l^ schedule^ another process on the CPU l^ maximizes CPU utilization n CPU bound process l^ spends most of its time in the CPU l^ at least a few^ long

CPU bursts

n^ I/O bound process^ l^ spends most its time performing I/O^ l^ several^ short

CPU bursts

^ ^  ^  ^ ^       

n^ Responsible for the

selection^ of the next running process

l^ part of the OS dispatcher l^ selects from among the processes in memory that are ready to execute l^ based on a particular strategy n When does CPU scheduling happen? l^ process switches from running to waiting state l^ process switches from running to ready state l^ process switches from waiting to ready state l^ process terminates n Scheduling under 1 and 4 is

nonpreemptive

n^ All other scheduling is

preemptive

^ ^ ^ ^  ^ ^       

n^ Non-preemptive scheduling^ l^ process voluntarily releases the CPU (conditions 1 and 4)^ l^ easy, requires no special hardware^ l^ poor response time for interactive and real-time systems n^ Preemptive scheduling^ l^ OS can force a running process involuntarily relinquish the CPU^ ^ arrival of a higher priority process^ ^ running process exceeds its time-slot^ l^ may require special hardware, eg., timer^ l^ may require synchronization mechanisms to maintain data consistency^ l^ complicates design of the kernel^ l^ favored by most OSes

   ^ ^       

n^ Scheduler is a part of the dispatcher module in the OS n^ Functions of the dispatcher^ l^ get the new process from the scheduler^ l^ switch out the context of the current process^ l^ give CPU control to the new process^ l^ jump to the proper location in the new program to restart that program n^ Time taken by the dispatcher to stop one process and startanother running is called the

dispatch latency

! ^  ^ ^       

n^ Job queue: consists of all processes^ l^ all jobs (processes), once submitted, are in the job queue^ l^ scheduled by the long-term scheduler n^ Ready queue: consists of processes in memory^ l^ processes ready and waiting for execution^ l^ scheduled by the short-term or CPU scheduler n^ Device queue: processes waiting for a device^ l^ multiple processes can be blocked for the same device^ l^ I/O completion moves process back to ready queue

!"#$^ ^  ^ ^       

^  ^ ^       

^ 

n^ CPU utilization

:^ percentage of time that the CPU is busy

n^ Throughput

:^ number of processes that complete theirexecution per time unit

n^ Turnaround time

:^ amount of time to execute a particular

process (submission time to completion time) n Waiting time :^ amount of time a process has been waiting in theready queue n Response time

:^ amount of time it takes from when a request

was submitted until the first response is produced n Scheduling goals^ l^ maximize CPU utilization and throughput^ l^ minimize turnaround time, waiting time and response time^ l^ be fair to all processes and all users

&', ^  ^ ^       

n^ Suppose we have processes A, B, and C, submitted at time 0. n^ We want to know the response time, waiting time, andturnaround time of process C

^ ^ ^ ^ ^ 

^ ^ ^ ^

^ 

&%' ^ ("#$^ ^  ^ ^       

n^ Queueing models^ l^ analytically model the queue behavior (under some assumptions)^ l^ involves a lot of complicated math^ l^ can only handle a limited number of distributions and algorithms^ l^ may not be very accurate because of unrealistic assumptions n^ Simulations^ l^ get a workload information from a system^ l^ simulate the scheduling algorithm^ l^ compute the performance metrics^ l^ time and space intensive^ l^ is practically the best evaluation method

-^ ^  ^ ^       

(^ ^  ^ ^       

n^ First Come, First Served (FCFS) n^ Shortest Job First (SJF) n^ Priority Based n^ Round Robin (RR) n^ Multilevel Queue Scheduling n^ Multilevel Feedback Queue Scheduling

^  ^ ^       

^

n^ Assigns the CPU based on the order of the requests. n^ Implemented using a FIFO queue. n^ No preemption n^ Advantages^ l^ straightforward, simple to write and understand n^ Disadvantages^ l^ average waiting time may be too long^ ^ huge variation based on when processes arrive^ l^ cannot balance CPU-bound and I/O-bound processes^ ^ convoy effect,

short process behind long process l^ cannot be used for time-sharing systems

..^ ^ ',^ ^  ^ ^       

Suppose that the processes arrive in the order: n

P ,^ P ,^ P^1 2

Waiting time for n

P = 0;^ P = 24;^1

P = 27^3

n^ Average waiting time: (0 + 24 + 27)/3 = 17

P^1

PP^2 324 27

^0

^ ^

^ 

^

^ 

^

^ 

^

^ 

..^ ^ "#$^ ^  ^ ^       

Suppose that the processes arrive in the order

P ,^ P ,^ P^2 3

n^ The Gantt chart for the schedule is: n^ Waiting time for

P=^^6 ; P = 0^1 2 ;^

P=^^3^3

n^ Average waiting time:

n^ Much better than previous case^ l^ but large variation

P^1

PP^3263

01."^ ^  ^ ^       

0.$^ 

n^ Order each process based on the length of its

next^ CPU burst

n^ Allocate CPU to the process from the front of the list^ l^ shortest next CPU burst n^ Advantages^ l^ SJF is optimal^ ^ achieves minimum average waiting time for a given set of processes n^ Disadvantages^ l^ difficult to know the length of the next CPU request^ ^ can ask the user, who may not know any better!^ ^ model-based prediction^ l^ can lead to process

starvation

^ 0. ^  ^ ^       

n^ New^ shorter

process can preempt

longer^ current running

process^  n Shortest Remaining Time First scheduling chart: n Average waiting time = 6.

^ 

^ 

^

^ 

^

^ 

^

^ +

^

^ ,

^ ^

^

^



^ ^ ^

^

^



4^  ^  ^ ^       

n^ A priority number associated with each process n^ CPU allocated to the process with the highest priority^ l^ equal priority processes scheduled in FCFS order n^ Internally determined priorities^ l^ time limit, memory requirements, etc^ l^ SJF uses next CPU burst for its priority (how?) n^ Externally specified priorities^ l^ process importance, user-level, etc n^ Can be preemptive or non-preemptive n^ Text uses low numbers for high priorities

4^ "#$^ ^  ^ ^       

n^ Advantages^ l^ priorities can be made as general as needed n^ Disadvantage^ l^ low priority process may never execute (indefinite blocking or starvation) n^ Aging^ l^ technique to prevent starvation^ l^ increase priority of processes with time

551^ "55$^ ^  ^ ^       

n^ Round robin algorithm^ l^ arrange jobs in FCFS order^ l^ allocate CPU to the first job in the queue

for one time-slice

l^ preempt job, add it to the end of the queue l^ allocate CPU to the next job and continue... n One time slice is called a

time quantum

n^ Is by definition preemptive^ l^ can be considered as FCFS with preemption n^ Advantages^ l^ simple, avoids starvation n^ Disadvantages^ l^ may involve a large context switch overhead^ l^ higher average waiting time than SJF^ l^ an I/O bound process on a heavily loaded system will run more slow

^  ^ ^       

',%5567!89 n The Gantt scheduling chart is:^ PP^1 n Average waiting time = 5.

PPP 2 3 1 1

PPP 1 1 1

^

^ 

^

^

^

551^^ ^  ^ ^       

n^ Performance^ l^ depends on the length of the time quantum^ l^ large time quantum

FCFS like behavior l^ small time quantum

large context switch overhead

n^ Generally,^ l^ time quanta range from 10 – 100 milliseconds^ l^ context switch time is less than 10 microseconds n^ RR has larger waiting time, but provides better response time forinteractive systems n^ Turnaround time depends on the size of the time quantum

^  ^ ^       

&! ^  ^ ^       

n^ Ready queue is partitioned into separate queues:foreground (interactive)background (batch) n^ Each queue has its own scheduling algorithm^ l^ foreground – RR^ l^ background – FCFS n^ Scheduling must be done between the queues^ l^ Fixed priority scheduling; (i.e., serve all from foreground then frombackground). Possibility of starvation.^ l^ Time slice – each queue gets a certain amount of CPU time which it canschedule amongst its processes; i.e., 80% to foreground in RR^ l^ 20% to background in FCFS

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

     ^  

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

      ^ ^  

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

        ^ ^  

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

^  ^ ^       

',%&.1*! n^ Priority 0 (time slice = 1): n^ Priority 1 (time slice = 2): n^ Priority 2 (time slice = 4):

24^ ', ^  ^ ^       

n^ Short jobs: 10 tickets each n^ Long jobs: 1 ticket each^ :;1<:;1

=%^ %;

=%^ %;

-^

+.^

-^

.^

-^

,.^

-^

.^

-^

,.^

7^ ^ ^  ^ ^       

n^ On systems supporting threads^ l^ kernel^ threads are the real scheduling entities^ l^ user^ threads need to be mapped to kernel threads for execution^ l^ scheduling attributes may be set at thread creation n^ Contention-scope^ l^ PTHREAD_SCOPE_PROCESS^ ^ group user threads to contend for common kernel thread(s)^ l^ PTHREAD_SCOPE_SYSTEM^ ^ directly assign to kernel thread, contends with other kernel threads n^ inheritsched^ l^ PTHREAD_INHERIT_SCHED^ ^ inherit scheduling policy and priority from parent thread^ l^ PTHREAD_EXPLICIT_SCHED^ ^ explicitly specify scheduling policy and priority of the new thread

7^ "#$^ ^  ^ ^       

n^ schedpolicy^ l^ SCHED_OTHER^ ^ regular non-real-time scheduling^ l^ SCHED_RR^ ^ real-time round-robin scheduling^ l^ SCHED_FIFO^ ^ real-time FCFS scheduling n^ schedparam^ l^ set/get the priority of the thread n^ All parameters only relevant^ l^ if thread library supports non-one-to-one user level threads^ l^ for real-time scheduling

^ ',^ ^  ^ ^       



^             

    !"#$%%%&%'$(     ')!$+%#" $%&%'$(     ,-./." !' "')$!  ^  , %#)$+"')$!01233     4566 01245(')!$+%33 7 4566 8  

 9/ :9 ;1 8

^  ^ ^       

&^

n^ Multiprocessor Scheduling^ l^ asymmetric multiprocessing^ ^ only one processor accesses the system data structures^ ^ simple^ l^ symmetric multiprocessing (SMP)^ ^ each processor is self-scheduling^ ^ need to maintain scheduler data structures synchronization n^ Processor affinity^ l^ process has affinity for processor on which it is currently running^ ^ reduce memory and cache overhead^ ^ memory affinity important for NUMA architectures^ l^ soft and hard processor affinity^ ^ how strictly OS maintains affinity policy

^ &(^^ ^  ^ ^       

^ 

^  ^ ^       

&^

n^ Load balancing^ l^ keep workload evenly distributed across all CPUs^ l^ important if each processor has its own queue of ready processes^ l^ push^ and^

pull^ migration  push or pull tasks towards idle processors

n^ Multicore^ processors^ l^ multiple processor cores on same physical chip^ ^ uniform memory access, faster intercore communication^ l^ may be simultaneously multithreaded (SMT, or

hyperthreaded) ^ instructions from multiple threads simultaneously live in differentpipeline stages ^ OS given a view of one processor per

hardware thread ^ may reduce memory stalls ^ may increase resource contention

^  ^ ^ ^  ^ ^       

n^ Priority-based scheduling n^ Six classes^ l^ real time, system, fair share, fixed priority, time shar, and interactive(in order of priority)^ l^ different priorities and scheduling algorithms in different classes n^ The default class is time sharing^ l^ uses multilevel feedback queue with variable time slices^ l^ inverse relationship between priorities and time slices^ l^ good response time for interactive processes and good throughput forCPU-bound processes^ l^ see the dispatch table

^  2, ^  ^ ^       

n^ New Linux scheduling^ l^ constant order

O (1) scheduling time

l^ support for SMP systems l^ provide fairness and support for interactive tasks n Priority-based, preemptive, global round-robin scheduling l^ two priority ranges: time-sharing and real-time l^ Real-time^ range from 0 to 99 and

nice^ value from 100 to 140 l^ numerically lower values have higher priorities l^ higher priority tasks are give longer time slice l^ see mapping figure

7^ ^  ^ ^       

^  2,^ ^  ^ ^       

n^ More about Linux scheduling^ l^ maintains two arrays:

active^ and^ expired l^ tasks linked in arrays according to their priorities l^ active tasks on expiration of their time quanta move to the expired array l^ real-time tasks have

static^ priorities l^ normal tasks have

dynamic^ priorities

^  2,^ ^  ^ ^       

n^ Even more about Linux scheduling^ l^ After the time slice of a process is used up, the process must wait until allready processes to use up their time slice (or be blocked)^ ^ round-robin approach^ ^ no starvation problem^ l^ for a user process, its priority may + or – 5 depending whether the processis I/O- bound or CPU-bound^ ^ I/O bound process is given higher priority

^   ^  ^ ^       

n^ Basic idea for schedule user processes is the same for allsystems^ l^ lower priority for CPU bound process^ l^ increase priority for I/O bound process n^ The scheduling in Solaris / Linux is more concerned about^ fairness^ l^ more popular as the OSes for servers n^ The scheduling in Window XP is more concerned about userperceived performance^ l^ more popular as the OS for personal computers