teacher's notes - lec chapter 4 - process scheduling

Upload: francisemmanuelgonzaga

Post on 05-Jul-2018

242 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    1/12

    J.E.D.I.

     1 Process Scheduling

     1.1 ObjectivesThis chapter introduces the different ways processes in the ready queue. We will focus on thedifferent scheduling schemes available, as well as discuss the scheduling algorithm actually

    being used by the olaris system.

    1.2 Chapter OutlineThis chapter is divided into the following sections!

    ● cheduling introduction

    ● "irst#come#first#serve scheduling

    ● hortest Job first scheduling

    ● $riority scheduling

    ● %ound#robin scheduling

    ● &ulti#queue scheduling

    ● olaris process scheduling

     1.3 Introduction's operating systems allow for multiple processes sharing a single processor, the operating

    system must establish a consistent scheme that chooses the ne(t process to run on the )$* inthe event that the currently running process voluntarily or involuntarily relinquishes control ofthe )$*.

    'n analogy for this concept +and we will be using this throughout this chapter is the idea ofthe )$* being a swing in a playground, with processes as children all lining up to use theswing, which only one child at a time can use. 'll the children must ta-e turns using the swingin a way that effectively minimies swing idle time and would allow all the children to ride on

    the swing.

    We will now introduce some scheduling concepts.

     1.3.1 CPU burst – I/O burst cycle's was discussed in an earlier chapter, a process undergoes a )$* burst / I01 burst cycle. ')$* burst is when the process is running instructions. 'n I01 burst is when the process iswaiting for some I01 to finish. When the process is waiting for I01, it sits idle on the )$*,waiting for the I01 instruction to finish. To allow for more efficient use of the )$*, the processis removed from the )$*, entering the waiting state. This allows the other process to run their)$* burst. When the process is finished with its I01 burst, it comes bac- to the ready queue inorder to have a turn at the )$* to run its ne(t )$* burst.

    1perating ystems 2

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    2/12

    J.E.D.I.

    CPU – I/O Burst cycle

    'gain, with our playground analogy, eventually a child on the swing will tire and would have torest for a while. To ma-e sure that the swing is always used, a different child ta-es the place inthe swing. 'fter a while, the child would be finished with his rest and would go bac- to the lineon the swing.

    1.3.2 CPU bound, I/O bound processes

    ' )$* bound process is a process that spends most of its e(ecution in a )$* burst. This wouldoccur for those process that are primarily computational in nature rather than interactive. 'napplication that computes the result of complicated mathematical functions is )$* bound.$hoto editing applications as well as applications that render computer graphics are also )$*bound.

    I01 bound processes on the other hand are processes that mostly wait for user input or ta-e

    1perating ystems 3

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    3/12

    J.E.D.I.

    time to produce user output. &ost interactive applications such as word processors andspreadsheets are usually I01 bound.

    This distinction is used by the long#term scheduler to optimie )$* performance. We will

    discuss the long#term scheduler later on.

    1.3.3 Schedulers

    $rimarily, when we tal- about process scheduling, we consider what is called the short#term

    scheduler. The purpose of the short#term scheduler is to choose which process is to run ne(ton the )$*.

    There are four possible times when the process selection is made.

    ● "irst, a process4s )$* burst period ends and begins to wait for I01. 's discussed earlier,

    this process is removed from the )$* to allow the )$* burst of other processes to run.

    ● ' second scenario is when a process starts. 1ften, processes are created by other

    processes. When you double clic- an application icon, the mouse control process

    spawns the application process. When invo-ing an application from the command line,the command line process starts your application process. ' decision must be made onwhich process to run, the parent process or the child process.

    ● Decisions are also made when a process ends.

    ● ' fourth scenario occurs in certain types of scheduling algorithms where the 1 itself

    revo-es a process4 turn on the )$* in what is termed as preemption. We will discussthis in detail in a later section.

    "or all of these scenarios, the scheduler always tries to ma(imie )$* use as well as give allthe processes a chance to run. The focus of the rest of this chapter is on what scheduling

    algorithms are used by the short term scheduler.

    It is worth mentioning that some operating systems come with a long#term scheduler. Thelong#term scheduler is responsible for fine#tuning the mi( of processes in the ready queue. 'swas discussed earlier, processes are either )$* bound or I01 bound. If the processes in the

    ready queue are mostly )$* bound, then most of the time a lot of the processes would bewaiting for their turn on the )$*. If most of the processes are I01 bound on the other hand,

    then the )$* would be mostly idle as most of the processes would be waiting for I01 to finishinstead of running on the )$*. The long#term scheduler tries to prevent these e(tremes from

    happening. ometimes, the long#term scheduler may temporarily swap out certain processesfrom memory +effectively ma-ing these processes halt in order to maintain an optimal mi( of)$* and I01 bound processes.

    1.3.4 Preemption

    ome scheduling routines may suddenly forcibly evict a currently running process from the

    )$*, even if that process is still not finished with its )$* burst. If this happens, we say thatthe scheduling algorithm has a preempted the process.

    $reemption may occur when a process with a higher priority enters the ready queue. This willbe discussed in greater detail later on.

    1.3. Conte!t s"itch time

    The conte(t switch time is the time spent when a process is removed from the )$* in order foranother process to ta-e its place. During the conte(t switch time, the 1 writes the $rocess

    )ontrol 5loc- information of the e(iting process. 'fter this is done, the 1 loads from theincoming process4 $rocess )ontrol 5loc- the values of the )$* registers, sets memory

    1perating ystems 6

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    4/12

    J.E.D.I.

    locations, goes to the latest e(ecuting instruction of the incoming process in order to pic- upwhere the process left off.

    While this is being done, the )$* is left totally idle. In essence , the )$* does not do any wor-

    while processes are being switched. This is why doing too much process switching actually

    decreases )$* utiliation, and has a derogatory effect in some scheduling algorithms.

    1.3.# Schedulin$ criteri%

    's this chapter discusses different scheduling algorithms, we will introduce some metrics thatwould characterie a scheduling algorithm4s performance.

    ● )$* utiliation / a good scheduling algorithm tries to ma(imie the amount of time the

    )$* is doing wor-.

    ● Turn#around time / this describes how long it ta-es for a process to finish running. This

    may not be 7ust dependent on how long the process ta-es to run. 't some point theprocess may be waiting for I01 or idle as it waits in line in the ready queue for its turn

    to run on the )$*.● Throughput / this describes how many processes get finished in a given time. We would

    li-e to have as many processes finished as possible. 8owever, if the scheduler onlychooses processes that ta-e only a short time to run, we would be ma(imiingthroughput at the e(pense of turn#around time.

    ● Waiting#time / this is how long the process is -ept idle in the ready queue

    ● %esponse time / this describes how long does it ta-es after a user has provided input

    before the process can respond. This is more of a sub7ective measure. &ost users are

    comfortable with long program loading times but would li-e a very responsive programonce it is loaded. Typing on the -eyboard should have a nearly instantaneous response+the character should appear on the screen immediately while copying a file is

    e(pected to ta-e some time.

    ● "airness / the 1 must give a chance for all the processes to run on the )$*. )ertain

    scheduling algorithms have the tendency of pic-ing processes over others, and someprocess may end up not running at all. This behavior is called starvation.

     1.3.& 'epresentin$ process e!ecution

    There are many ways to represent process e(ecution. 1ne of the common ways to show whichprocesses are running on the )$* is via a 9antt chart. "or e(ample, the following 9antt chartshows $rocess $2 starting at time : and ending 7ust before time 2;. $rocess 3 runs for 2:seconds, ending at 7ust before time 3; and so on.

    'nother way is through a process e(ecution table. 8ere is an e(ample process e(ecution table!

    cheduling! "irst#come first#served with conte(t switch time of 2 second.

    1perating ystems

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    5/12

    J.E.D.I.

    $rocesses! $2 with )$* burst

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    6/12

    J.E.D.I.

    we will discuss in a later section.

    "or our e(amples, we will consider )$* burst times in the scale of a few seconds. In reality,these burst times are in the millisecond range. We will use seconds in order to easily visualie

    the e(amples.

    1.4.1 *irst+come irst+ser-ed 

    $erhaps the simplest scheduling algorithm, the first#come first#served algorithm simply queues

    the processes in the order that they arrive. When the process on the )$* is finished with its)$* burst, the ne(t process in line will be chosen. ' newly arriving process is 7ust simply

    added to the end of the queue.

    "or e(ample, we have < processes $2 to $< with burst times ;, 6, 2:2 > 2:3 > 2:6 0 ; ? B2.3 seconds

    If however, we made $2 run last, then the 9antt chart would loo- li-e this!

    The average waiting time would then be! +: > 2 > 3 > 6 >

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    7/12

    J.E.D.I.

    "ollowing our analogy, the first#come#first#serve scheme would be the basic strategy forchildren wanting to play the swing, the first children who come in line to ride the swing get toride it first.

    1.4.2 Shortest ob *irst The shortest 7ob first algorithm ma-es sure that the process with the shortest )$* burst ise(ecuted first. "or e(ample, if processes with )$* burst times of 2:, ;, 6, 3, < are in the readyqueue, then the process with burst time of 3 would be chosen to run on the )$*.

    hortest Job "irst has been mathematically proven to give the shortest possible waiting timefor any group of processes already in the queue. 8owever, if additional processes arrive, then

    the solution is no longer optimal.

    )onsider our previous e(ample! $2, $3, $6, $

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    8/12

    J.E.D.I.

    Time )$* %eady =ueue )omment

    : $2 +; $3 + $2, $3 arrives. $2 chosen to run

    2 $2 +

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    9/12

    J.E.D.I.

    3 $6 +p?2,t?2 $3 +p?;,t?

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    10/12

    J.E.D.I.

     1.4.& ultiple ueues

    1perating ystems actually use a combination of scheduling algorithms, placing processes onmultiple queues, each with its own scheduling scheme, with a priority scheme used to selectbetween queues.

    "ollowing our playground analogy, the children could all line up by grade level, one line for9rade 2 students, one line for 9rade 3 and so on. ' grade level may have their own schemeper line! ")" for 9rade 2, %ound %obin for 9rade 3, etc. 1nce each grade level has decidedwho goes to the head of the line, the teacher chooses from which line the ne(t student to playon the swing comes from.

    ' simple scheme, found in some *CIG systems, is the use of two queues! a foreground orinteractive queue and a bac-ground or batch queue. When processes start, they would beassigned a queue automatically via some characteristic of the process. *sers can even runcommands in order to assign processes either to the foreground or bac-ground queue. Theforeground queue may use a round robin scheme, while the bac-ground queue uses a ")"scheme in choosing the process that comes at the head of the line. The -ernel then choosesbetween each queue, giving higher priority to the foreground queue.

    The olaris scheduling scheme has A such queues or scheduling classes! the Timeshare,Interactive, "air#share scheduler, "i(ed $riority, ystem and %eal#time scheduling classes.

    Timeshare is the default scheduling class for processes. $rocess priorities in this queue are

    ad7usted in order to optimie resource usage. It aims to divide )$* usage fairly among users.If there are three users logged on, then the processes from a single user gets chosen 206 ofthe time. 1f course processes of that user would have to share in that 206 of )$* time,whether the user has 2 process or many.

    The Interactive scheduling class applies to the processes involved with the actively selectedapplication in the 9*I. 's the currently running 9*I application is most probably interacting

    with the user, then processes in this queue would have slightly higher priority on the )$* andwith other system resources.

    Timeshare and Interactive queues use a round#robin scheduling scheme with an adaptive time#quantum. It also ad7usts the priority of I01 bound processes, increasing their priority so that

    they could finish with their short )$* burst faster, leaving the )$* bound processes more timeto run on the )$* while the I01 bound processes wait for slower I01. The interactive schedulersimply places an additional 2: priority to processes that are associated with the active windowin the 9*I, providing a better response time to users.

    "i(ed $riority scheduling class are for processes that the user does not want to change priority

    as the other queues would dynamically change process priority.

    1perating ystems 2:

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    11/12

    J.E.D.I.

    The "air#share scheduler improves on the Timeshare queue as it gives )$* time based on theconcept of )$* shares. *sing olaris commands, an application can be given a certain numberof )$* shares. The amount of )$* time that processes belonging to that application is basedon what percentage of total )$* shares that application has.

    "or e(ample, if an application has 2: shares and the total number of allocated )$* shares is2::, then that application gets 2:H of )$* time. 'ny application with ero )$* shares will notbe granted )$* time until all applications with shares are finished.

    The "air#share scheduler, however, does not wor- well with the Timeshared, "i(ed priority orInteractive scheduling queues. The "air#share scheduler is a special scheduling algorithm which

    is recommended to be assigned to a processor all by itself as combining this schedulingalgorithm with other queues on the same processor may result in une(pected behavior.

    $rocesses in olaris can have priority numbers from : to 2AF, with 2AF being the highestpriority. If a process has priority :#;F, it is assigned to one of the queues discussed above.

    ernel processes, with priority A:#FF are placed in the ystem scheduling class. ernelprocesses cannot preempt other -ernel processes, even if they have a higher priority.

    The final queue is the real#time queue. $rocesses with priorities 2::#2AF fall into this queue.$rocesses in the real#time queue have fi(ed#priority, with a fi(ed time quantum. 5ecause they

    have the highest priority, they can preempt -ernel threads. %eal#time threads need to havethis high a priority level because they operate with a very fi(ed time constraint and their tas-

    may fail if they do not meet the deadline.

    1.4.( ultile-el *eedb%c ueue Schedulin$

    The multi#level feedbac- queue scheduling scheme has multiple queues, but these queues are

    interconnected, processes leaving one queue enters the ne(t one.

    "or e(ample, consider the following multi#level queue. The first queue where processes enterhas a time quantum of

  • 8/15/2019 Teacher's Notes - Lec Chapter 4 - Process Scheduling

    12/12