180 likes | 345 Views
Operating System Concepts and Techniques Lecture 5. Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com , or www.amazon.com. Terms.
E N D
Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com
Terms • Scheduling policydescribes the guideline for selecting the next process to use a computer resource such as CPU. • Scheduling algorithm is a finite set of clearly stated unambiguous stepwise operations that when applied to a finite set of processes waiting to use a resource, either one or more of these processes are selected or a time table for the resource usage is produced • Scheduling mechanismdetermines how to do every step of the scheduling algorithm For example, the exact steps to be taken to modify a process-queue and process state
Scheduling Criteria • Properties which influence the order in which active entities are selected to run • request Time • Processing Time • Priority • Static priority • dynamic priority • Deadline • Wait Time • Preemptability
Scheduling Objectives • Throughput • Deadline • hard real-time • soft real-time • Turnaround Time • Average turnaround time • Normalized • Response Time • Priority • Processor Utilization • System Balance • Fairness
Scheduling levels • High-Level: select requests • Medium-level: decide on process swapping • Low-level: decide on giving CPU time to ready processes • Input/output scheduling: decide on disk read/write order
First-Come-First-Served (FCFS) • FCFS: take the request which arrived earliest • Nonpreemptive • Most natural, link banks, airport check-ins, post offices, and barber shops • Irregularity in arrival requires a queue • Simple to implement • A single-linked list with two pointers; each link points from each node to the node of the previous request • Ddisadvantages: a long request can increase others wait time
Shortest Job Next (SJN) • SJN (SPN): take the request which needs the least execution time • Non-preemptive • Executes higher number of requests in one unit of time • To implement, a double-linked list with two pointers; keeps requests ordered • Disadvantages: need to know execution time, update overhead time of the list, and starvation
SRTN & HRRN • Shortest Remaining Time Next (SRTN) • Nonpreemptive • Scheduling decision right after a process is completed • Disadvantages similar to SPN • Highest Response Rattio Next (HRRN) • RR=(w+e)/e; it increases as w increases • Nonpreemptive • Scheduling decision right after a process is completed • Disadvantages similar to SPN
Two more • Fair-Share Scheduling • All users get equal shares of CPU • Prevents a user to get a big chunk of CPU time by creating many child processes or threads • Priority scheduling • Processes have priorities; A higher priority is executed before a lower priority one • Preemptive • Disadvantage: starvation of low priority request
Round Robin (RR) • The most widely used scheduling policy • A time quantum is defined and an interval timer is set to send an interrupt whenever the time quantum has passed, since the timer is set or reset • Time quantum (slice) is very small, one millisecond or less • Upon timer interrupt a process switching is done • If a process cannot use its slice, processor switches to the next process and resets timer • All (same priority) processes share CPU time
RR advantages/disadvantages • Advantages: • Quick response to interactive requests • Longer waiting time for a process that requires longer CPU time • Possibility of defining many priority levels, • Disadvantage: • Task switching overhead
Process Scheduling in Linux • Many levels of priorities (100 or more) • Three schedulers • SCHED_FIFO: Nonpreemptive, highest priority, say from 70-100, for different processes. • SCHED_RR: Preemptive, second highest priority, say from 40-69 • Same level highest priority RR processes are scheduled using round robin • Priorities are assigned so that any SCHED_FIFO process has higher priority than any SCHED_RR; any SCHED_RR has higher priority than any SCHED_OTHER
Process Scheduling in Linux… • SCHED_OTHER • Every process has a static priority • Time is divided into variable size frames called epoch • At start of every epoch, scheduler calculates every SCHED_OTHER process’ CPU share in integer number of scheduling-clock ticks; called credit, epoch length is calculated • Credit is related to static priority • Epoch length is related to how many processes are ready, what their priorities are etc.
SCHED_OTHER... • If a process cannot use its credit it is saved for the next time (see details in the book) • Goodness shows which process is executed next • For SCHED_FIFO and SCHED_RR, goodness=priority+1000 • For SCHED_OTHER, goodness=credit
Summary • It is not always the case that every service request arrives after the previous service request has been completely served. • Service requests may pile up, in which case we would like to serve requests in such an order so as to increase some metrics. • This process is called scheduling. Scheduling methodologies and algorithms for single-processor systems are considered • Many scheduling strategies are studied, FCFS, SJN, SRTN, HRRN, and RR • The Linux operating system was selected to present real-world schedulers
Find out • What an interactive process is • The block structure of an interval timer • The time slice of your computer’s processor • Whether Linux scheduler is a complete one for real-time tasks • Why epoch length is not fixed • The goals of Linux schedulers • The difference between SCHED_FIFO and SCHED_RR