Download presentation
Presentation is loading. Please wait.
1
Chapter 6: CPU Scheduling
Rev. by Kyungeun Park, 2017
2
Chapter 6: CPU Scheduling
Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Real-Time CPU Scheduling Operating Systems Examples Algorithm Evaluation
3
Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various CPU-scheduling algorithms To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system To examine the scheduling algorithm of several operating systems
4
Basic Concepts Maximum CPU utilization obtained with multiprogramming
CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait CPU burst : the amount of time a process uses CPU. Long burst : process is CPU-bound Short burst : process is I/O-bound CPU burst followed by I/O burst CPU burst distribution will be the key factor to enhance CPU utilization.
5
CPU-bound vs. I/O-bound
(a) CPU-bound (compute-bound) processes (b) I/O-bound processes
6
Histogram of CPU-burst durations
Tend to be I/O-bound program Tend to be CPU-bound program Generally, a large number of short CPU bursts and a small number of long CPU bursts
7
When to schedule? Typical two occasions of scheduling:
When a process exits. When a process blocks on I/O, or a semaphore Most recent process becomes unready: Another must be chosen to run next Three other occasions of scheduling: When a new process is created. When an I/O interrupts occurs (I/O Completion Blocked and waiting process now be ready to run). When a clock interrupt occurs (Time slice expiration Consider two scheduling policy). Depends on how the scheduling algorithms deal with clock interrupts: Preemptive scheduling scheme Non-preemptive scheduling scheme
8
CPU Scheduler (short-term scheduler)
Short-term scheduler selects a process from the processes in ready queue, and allocates the CPU to that process Queue may be ordered in various ways: FIFO Queue, Priority Queue, Tree, etc. CPU scheduling decisions needed when a process: Switches from running to waiting state (I/O request or invocation of wait()) : no choice Switches from running to ready state (interrupt request) : choice* Switches from waiting to ready (completion of I/O) : choice* Terminates : no choice Non-preemptive scheduling scheme : scheduling only under 1 and 4 Preemptive scheduling scheme : all other cases (2 and 3) Ex) By allowing an interrupt, the OS may need to accept interrupts at almost all times. Careful consideration is needed: access to shared data preemption while in kernel mode interrupts occurring during crucial OS activities
9
Process States (from Chapter 3)
2 4 1 3 1, 4 : nonpreemptive scheduling 2, 3 : preemptive scheduling Many processes are in ready or waiting states in multiprogrammed operating systems. Dispatch : allocation of the CPU control
10
Handling Preemption in Designing OS
Preemptive Scheduling scheme causes the following: Race conditions when data are shared among several processes: inconsistent data view Affect the design of the OS kernel: A process preempted in the middle of changes (processing a system call) on important kernel data (I/O queues) causes inconsistent data view to a kernel trying to read or modify the same data. By waiting either for a system call to complete or for an I/O block operations to complete before context switch OS needs to accept interrupts at almost all times: By disabling interrupts at entry and re-enabling them at exit Those sections of code might be short and occur rarely. * 여기서 View는 ‘상황, 경우, 상태’ 의 뜻으로 쓰인다고 보면 됨
11
Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency – time it takes for the dispatcher to stop one process and start another running Dispatcher CPU Process Ready Running
12
Context Switch (from Chapter 3)
Interrupt or System Call Dispatcher latency Gap Interrupt or System Call Executing Gap
13
Scheduling Criteria Different CPU-scheduling algorithms prioritizes different factors. Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process (generally limited by the speed of the output device) Waiting time – amount of time a process has been waiting in the ready queue Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) in an interactive system
14
Scheduling Algorithm Optimization Criteria
Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time In most cases, the best policy is to optimize the average measure. For interactive systems, it is more important to minimize the variance in the response time than to minimize the average response time.
15
Scheduling Algorithms
First-come, First-Served Scheduling (FCFS) Shortest-Job-First Scheduling (SJF) Priority Scheduling Round-Robin Scheduling (RR) Multilevel Queue Scheduling (MQ)
16
First-Come, First-Served (FCFS) Scheduling
Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: Waiting time for P1 = 0; P2 = 24; P3 = 27 Average waiting time: ( )/3 = 17 The FCFS policy is easily implemented with a FIFO queue. Simple to write and understand The FCFS scheduling algorithm is non-preemptive. Release CPU only for terminating or requesting I/O Cause trouble for time-sharing systems P1 P2 P3 24 27 30
17
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order: P2 , P3 , P1 The Gantt chart for the schedule is: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: ( )/3 = 3 Much better than previous case !! Convoy effect - short process behind long process Consider one CPU-bound and many I/O-bound processes All the I/O-bound processes wait for the one big process (CPU-bound process) to get off the CPU. Results in lower CPU and device utilization P1 P3 P2 6 3 30
18
Shortest-Job-First (SJF) Scheduling
Associates each process with the length of its next CPU burst Use these lengths to schedule the process with the shortest time SJF is optimal – gives minimum average waiting time for a given set of processes The difficulty is to know the length of the next CPU request Could ask the user
19
Example of SJF Process l Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7
SJF scheduling chart Average waiting time = ( ) / 4 = 7 P4 P3 P1 3 16 9 P2 24
20
Determining Length of Next CPU Burst
Can only estimate the length – should be similar to the previous one Then pick process with shortest predicted next CPU burst Estimation can be done by using the length of previous CPU bursts, using exponential averaging tn : contains the most recent information n : contains the past history (substitute n with tn-1 …) α : controls the relative weight of recent and past history in the prediction process. Commonly, set to ½ Preemptive SJF version is sometimes called shortest-remaining-time-first scheduling.
21
Prediction of the Length of the Next CPU Burst
α set to ½ 8=½*6 + ½*10 *Refer to Figure 6.3 in the textbook 6=½*4 + ½*8
22
Examples of Exponential Averaging
=0 n+1 = n = n-1 = n-2 … = 0 Recent history does not count (no effect): current conditions are assumed to be transient. =1 n+1 = tn Only the actual last CPU burst counts: history is assumed to be old and irrelevant. If we expand the formula, we get: n+1 = tn + (1 - ) tn-1 + (1 - ) 2 tn-2 + … + (1 - )j tn -j + … + (1 - )n t0 + (1 - )n +1 0 Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor. Recent history is more influential to estimate the next CPU burst.
23
Example of Shortest-remaining-time-first
Now we add the concepts of varying arrival times and preemption to the analysis ProcessA arri Arrival TimeT Burst Time P1 0 8 P2 1 4 P3 2 9 P4 3 5 Preemptive SJF Gantt Chart Average waiting time = [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6.5 msec P1 P2 1 17 10 P3 26 5 P4
24
Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority) SJF is priority scheduling where priority is the inverse of predicted next CPU burst time The larger the CPU burst, the lower the priority Problem Starvation – low priority processes may never execute Solution Aging – as time progresses increase the priority of the process
25
Example of Priority Scheduling
* Now we assume that multiple processes arrive simultaneously. ProcessA arri Burst TimeT Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority Scheduling Gantt Chart Average waiting time = [(6)+(0)+(16)+(18)+(1)]/5 = 41/5 = 8.2 msec P2 P3 P5 1 18 16 P4 19 6 P1
26
Round Robin (RR) Especially for time-sharing systems
Each process gets a small unit of CPU time (time quantum q), usually milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)*q time units until its next time quantum. Timer interrupts every quantum to schedule next process
27
Example of RR with Time Quantum = 4
Process Burst Time P1 24 P2 3 P3 3 The Gantt chart is: P1 P2 P3 4 7 10 14 18 22 26 30
28
Time Quantum and Context Switch Time
Performance: highly depending on the size of the time quantum q large degenerates to an FCFS policy q small processor sharing, resulting in a large number of context switches q to be large with respect to context switch time, otherwise overhead is too high Typically, higher average turnaround than SJF, but better response In practice, q usually 10 msec to 100 msec, context switch < 10 msec
29
Turnaround Time Varies With The Time Quantum
Turnaround time depends on the size of the time quantum. But, avg. turnaround time: not necessarily improve as the time-quantum size increases In general, the average turnaround time can be improved if most processes finish their next CPU burst in a single time quantum. A rule of thumb: the time quantum, q, should be longer than 80 percent of the next CPU bursts.
30
Multilevel Queue As a solution for processes which can be easily classified into different groups. ex.) different response-time requirements : foreground (interactive) processes : priority over background processes background (batch) processes Ready queue is partitioned into separate queues. Multilevel Queue Scheduling (Process permanently in a given queue.) Processes do not move from one queue to the other. Low scheduling overhead, but it is inflexible. Each queue has its own scheduling algorithm: foreground – RR background – FCFS Each queue has absolute priority over lower-priority queues preemption… Scheduling must be done between the queues: Problem: Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. Solutions: Time slice scheduling – each queue gets a certain portion of the CPU time, which it can schedule among its processes; i.e., 80% to foreground for RR scheduling, 20% to background on the FCFS basis
31
Multilevel Queue Scheduling
Multilevel queue scheduling algorithm partitions the ready queue into several separate queues.
32
Multilevel Feedback Queue
A process can move between the various queues; aging can be implemented this way How to get the feedback? Idea: separate processes according to the characteristics of their CPU bursts Process using too much CPU time : move to a lower-priority queue I/O-bound and interactive processes : left in the higher-priority queues Aging: process that waits too long in a lower-priority queue may be moved to a higher-priority queue. Starvation prevention Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to downgrade a process method used to determine which queue a process will enter when that process needs service
33
Example of Multilevel Feedback Queue
Q0 : FCFS with 8 msec Three queues: Q0 – RR with time quantum 8 milliseconds Q1 – RR with time quantum 16 milliseconds Q2 – FCFS Scheduling A new job enters queue Q0 which is served FCFS When it gains CPU, job receives 8 milliseconds If it does not finish in 8 milliseconds, job is moved to queue Q1 At Q1 job is again served FCFS and receives 16 additional milliseconds If it still does not complete, it is preempted and moved to queue Q2 Q1 : FCFS with 16 msec Q2 : FCFS
34
Thread Scheduling In chapter 4, distinction between user-level and kernel-level threads When kernel-level threads supported, threads (not processes) are scheduled by the OS. Many-to-one and many-to-many models, thread library schedules user-level threads to run on available LWP. Scheduling user threads by the thread library does not mean that the threads are actually running on a CPU. A scheme known as process-contention scope (PCS), since scheduling competition takes place among threads belonging to the same process Typically done via priority set by programmer Actual running on a CPU Kernel uses system-contention scope (SCS) Competition takes place among all threads in the system Systems using the one-to-one model (Windows, Linux, and Solaris) schedule threads using only SCS. Note: One distinction between user-level and kernel-level threads lies in how they are scheduled (as above:).
35
Thread Scheduling (cont)
Process Scope (Unbound Threads) Threads are created as unbound threads The mapping is managed by the threads library. System Scope (Bound Threads) Threads are created as bound threads. A bound thread is permanently attached to an LWP. Each LWP is a kernel resource in a kernel pool, and is allocated and de-allocated to a thread on a per thread basis.
36
Pthread Scheduling API allows specifying either PCS or SCS scheduling during thread creation PTHREAD_SCOPE_PROCESS schedules threads using PCS scheduling; create an unbound thread PTHREAD_SCOPE_SYSTEM schedules threads using SCS scheduling; create a bound thread On systems implementing the many-to-many model: PTHREAD_SCOPE_PROCESS scheduling policy: the thread library schedules user-level threads onto available LWPs The number of LWPs is maintained by the thread library, using scheduler activations, upcall from the kernel to the thread library. PTHREAD_SCOPE_SYSTEM scheduling policy will create and bind an LWP for each user-level thread on many-to-many systems, effectively mapping threads using the one-to-one policy. Contention scope might be limited by the OS: Linux and Mac OS X only allow PTHREAD_SCOPE_SYSTEM
37
Pthread Scheduling API
#include <pthread.h> #include <stdio.h> #define NUMB_THREADS 5 int main(int argc, char *argv[]) { int i, scope; pthread_t tid[NUMB_THREADS]; pthread_attr_t attr; /* get the default attributes */ pthread_attr_init(&attr); /* first inquire on the current scope */ if (pthread_attr_getscope(&attr, &scope) != 0) fprintf(stderr, "Unable to get scheduling scope\n"); else { if (scope == PTHREAD_SCOPE _PROCESS) printf("PTHREAD_SCOPE_PROCESS"); else if (scope == PTHREAD_SCOPE_SYSTEM) printf("PTHREAD_SCOPE_SYSTEM"); else fprintf(stderr, "Illegal scope value.\n"); }
38
Pthread Scheduling API
/* set the scheduling algorithm to PCS or SCS */ pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); /* create the threads */ for (i = 0; i < NUMB_THREADS; i++) pthread_create(&tid[i],&attr,runner,NULL); /* now join on each thread */ for (i = 0; i < NUM THREADS; i++) pthread_join(tid[i], NULL); } /* Each thread will begin control in this function */ void *runner(void *param) { /* do some work ... */ pthread exit(0);
39
Multiple-Processor Scheduling
If multiple CPUs are available, Load sharing becomes possible; however, CPU scheduling more complex Even with homogeneous processors, limitations on scheduling in case of a specific processor with an I/O device attached to its private bus Asymmetric multiprocessing – only one processor (the master server processor) has all scheduling decisions, I/O processing, and other system activities. Exclusive use of the system data structures: Simple, reducing the need for data sharing. Symmetric multiprocessing (SMP) – each processor is self-scheduling, all processes in a common ready queue, or each has its own private queue of ready processes The scheduler of each processor examines and selects a process: currently, most common Ensure that multiple CPUs do not choose the same process and that processes are not lost from the ready queue.
40
Processor Affinity Consider what happens to cache memory on SMP systems A process starts data transfer to the cache of a processor Cache hit and cache miss with the process the cache is stabilized What if the process is scheduled on the different processor: Migration! The cache will be invalidated, and then new cache must be repopulated for the second processor: Repopulation! Expensive! Most SMP systems try to avoid migration of processes from one processor to another and keep a process running on the same processor Processor affinity – process has affinity for processor on which it is currently running due to migration cost regarding cache memory handling soft affinity : not guaranteeing that a process will keep the same processor hard affinity : by providing system calls that allow a process to specify that it is not to migrate to other processors Ex) Linux implements soft affinity; Also, provides the sched_setaffinity() system call for supporting hard affinity. Variations within processor sets, limiting which processes can run on which CPUs. (Solaris)
41
NUMA and CPU Scheduling
Note that main-memory architecture of a system can also consider processor affinity. Co-work between CPU scheduler and memory-placement algorithm is required.
42
Multiple-Processor Scheduling – Load Balancing
Need to keep the workload balanced across all processors in an SMP system. Load balancing attempts to keep workload evenly distributed Push migration – a specific task periodically checks the load on each processor, and if it finds an imbalance, pushes task from overloaded CPU to idle or less-busy processors Pull migration – occurs when an idle processor pulls a waiting tasks from a busy processor Both are often implemented in parallel on load-balancing systems.
43
Multicore Processors Recent trend to place multiple processor cores on the same physical chip an multicore processor Each core has a register set to maintain its architectural state. SMP systems with multicore processors are faster and consumes less power Multicore processors complicate scheduling issues: As significant amount of time waiting for the data to become available from memory : Memory Stall (delay) Due to a cache miss (accessing data that is not in cache memory) Multithreaded processor cores in which two (ore more) hardware threads (logical cores) are assigned to each core. Operating system recognizes how many hardware threads in a core and schedules software threads to each of them allow better utilization of the processor Takes advantage of memory stall to make progress on another thread while memory retrieval happens : Interleaving multithreads on a core
44
Multithreaded Multicore System
Processor core Dual-threaded processor core By Interleaving : Multithreaded multicore system
45
Virtualization and Scheduling
Virtualization software (Virtual Machine) schedules multiple guests onto CPU(s) Each guest doing its own scheduling Not knowing it doesn’t own the CPUs Can result in poor response time Incorrect time-of-day clocks in guests
46
Real-Time CPU Scheduling
Can present obvious challenges Soft real-time systems – no guarantee as to when critical real-time process will be scheduled Hard real-time systems – task must be serviced by its deadline Event latency – the amount of time from when an event occurs to when it is serviced Two kinds of latencies affecting performance of real-time systems: Interrupt latency – time from arrival of interrupt to start of routine (ISR) that services interrupt - Also interrupt disabling period: must be very short Dispatch latency – time for schedule to take current process off CPU (stop one process) and switch to another (start another)
47
Dispatch Latency Conflict phase of dispatch latency has two components: Preemption of any process running in kernel mode Release of resources occupied by low-priority processes and needed by a high-priority process stop one process & start another
48
Priority-Based (Real-time) Scheduling
For real-time scheduling, scheduler must support a priority-based scheduling algorithm with preemption But only guarantees soft real-time For hard real-time must also provide ability to meet deadlines Processes have new characteristics: The processes are considered periodic. A periodic process requires CPU at constant intervals (periods) The process has a fixed processing time t, a deadline d, and period p 0 ≤ t ≤ d ≤ p the rate of a periodic task is 1/p the execution of a periodic process over time
49
Rate Monotonic (Real-time) Scheduling
Rate-monotonic scheduling algorithm schedules periodic tasks using a static priority policy with preemption. Each periodic task is assigned a priority inversely based on its period Shorter periods higher priority Longer periods lower priority Assign a higher priority to tasks that require the CPU more often. Example: P1 (=50) is assigned a higher priority than P2 (=100) Processing time: t1 (=20) for P1 and t2 (=35) for P2 Rate-monotonic Scheduling : new period
50
Missing Deadlines with Rate Monotonic Scheduling
Rate-monotonic scheduling algorithm is optimal among any other algorithms that assign static priorities, where priorities are fixed. Following processes cannot be scheduled using the rate-monotonic algorithm. Optimal, but has limitation! Missing deadline: due to static priority assignment Process P1: p1=50, t1=25 Process P2: p2=80, t2=35
51
Earliest Deadline First (Real-time) Scheduling (EDF)
Priorities are dynamically assigned according to deadlines: the earlier the deadline, the higher the priority the later the deadline, the lower the priority Unlike the Rate-Monotonic scheduling: Processes: no need to be periodic, nor a constant amount of CPU time per burst But, a process needs to announce its deadline to the scheduler when runnable dynamic priority assignment according to deadlines
52
Proportional Share Scheduling
T shares are allocated among all processes in the system An application receives N shares where N < T This ensures each application will receive N / T of the total processor time Admission controller denies new process(es) into the system when sufficient shares are not available
53
POSIX Real-Time Scheduling
The POSIX.1b standard POSIX API provides functions for managing real-time threads Defines two scheduling classes for real-time threads: SCHED_FIFO - threads are scheduled using a FCFS strategy with a FIFO queue. There is no time-slicing for threads of equal priority SCHED_RR - similar to SCHED_FIFO except time-slicing occurs for threads of equal priority Defines two functions for getting and setting scheduling policy: pthread_attr_getsched_policy(pthread_attr_t *attr, int *policy) pthread_attr_setsched_policy(pthread_attr_t *attr, int policy)
54
POSIX Real-Time Scheduling API
#include <pthread.h> #include <stdio.h> #define NUMB_THREADS 5 int main(int argc, char *argv[]) { int i, policy; pthread_t tid[NUM THREADS]; pthread_attr_t attr; /* get the default attributes */ pthread_attr_init(&attr); /* get the current scheduling policy */ if (pthread_attr_getsched_policy(&attr, &policy) != 0) fprintf(stderr, "Unable to get policy.\n"); else { if (policy == SCHED_OTHER) printf("SCHED_OTHER\n"); else if (policy == SCHED_RR) printf("SCHED_RR\n"); else if (policy == SCHED_FIFO) printf("SCHED_FIFO\n"); }
55
POSIX Real-Time Scheduling API (Cont.)
/* set the scheduling policy - FIFO, RR, or OTHER */ if (pthread_attr_setsched_policy(&attr, SCHED_FIFO) != 0) fprintf(stderr, "Unable to set policy.\n"); /* create the threads */ for (i = 0; i < NUMB_THREADS; i++) pthread_create(&tid[i],&attr,runner,NULL); /* now join on each thread */ for (i = 0; i < NUMB_THREADS; i++) pthread_join(tid[i], NULL); } /* Each thread will begin control in this function */ void *runner(void *param) { /* do some work ... */ pthrea_ exit(0);
56
Algorithm Evaluation How to select CPU-scheduling algorithm for an OS?
Determine criteria, then evaluate algorithms Deterministic modeling Type of analytic evaluation Takes a particular predetermined workload and defines the performance of each algorithm for that workload Consider 5 processes arriving at time 0
57
Deterministic Evaluation
For each algorithm, calculate minimum average waiting time Simple and fast, but requires exact numbers for input, applies only to those inputs FCFS is 28ms: Non-preemptive SJF is 13ms: RR is 23ms:
58
Queueing Models There is no static set of processes(or times) to use for deterministic modeling. However, in most cases, the distribution of CPU and I/O burst is available. Also we can describe the distribution of times when processes arrive in the system (the arrival-time distribution). Possible to compute the average throughput, utilization, waiting time, etc. for most algorithms. Queueing-network analysis Computer system described as network of servers, each with a queue of waiting processes. CPU: a server with its queue I/O system: its device queues Knowing arrival rates and service rates we can compute utilization, average queue length, average wait time, etc.
59
Little’s Formula Little’s Formula n = λ x W n = average queue length
W = average waiting time in queue λ = average arrival rate into queue We expect that during the time W that a process waits, λ x W new processes will arrive in the queue. In steady state, processes leaving queue must be equal to processes that arrive. Useful because the equation is valid for any scheduling algorithm and arrival distribution For example, if on average 7 processes arrive per second, and normally 14 processes in queue, then average wait time per process = 2 seconds Queueing analysis can be useful in comparing scheduling algorithms, but it has limitations. : assumptions causing inaccurate estimation Approximations of real system
60
Simulations Queueing models limited
Simulations as a more accurate evaluation method of scheduling algorithms Programmed model of computer system Clock as a variable increases as time flows. The simulator modifies the system state to reflect the activities of the devices, the processes, and the scheduler. As the simulation executes, statistics indicating algorithm performance are gathered. Data to drive simulation generated via Random number generator according to probability distributions Trace tapes by monitoring the real system and recording the sequence of actual events.
61
Evaluation of CPU Schedulers by Simulation
62
Implementation Even a simulation is of limited accuracy
Just implement new scheduler and test in real systems High cost, high risk Environments vary Most flexible schedulers can be modified per-site or per-system Or APIs to modify the priority of a process or thread But again environments vary
63
Operating System Examples
Linux scheduling Windows scheduling Solaris scheduling
64
Linux Scheduling in Version 2.6.23 +
Prior to kernel version 2.5, ran variation of standard UNIX scheduling algorithm Not adequate to support SMP with a large number of processes in a system Since Ver , Completely Fair Scheduler (CFS) Based on Scheduling classes Each has specific priority: different scheduling algorithms per class Scheduler picks highest priority task in highest scheduling class Two scheduling classes included, others can be added a default scheduling class using the CFS scheduling algorithm a real-time scheduling class Rather than quantum based on fixed time allotments, based on proportion of CPU time from the value of targeted latency Quantum calculated based on nice value from -20 to +19 Lower value is higher priority Calculates target latency – interval of time during which task should run at least once Target latency can increase if the number of active tasks increases Rather than directly assigning priorities, CFS scheduler maintains per task virtual run time in variable vruntime Associated with a decay factor based on priority of task – lower priority is higher decay rate Normal priority tasks (nice values of 0) are assigned virtual run time = actual run time To decide next task to run, scheduler picks task with lowest virtual run time
65
CFS Performance Only tasks runnable are added to the balanced binary search tree whose key is based on the value of vruntime.
66
Linux Scheduling (Cont.)
Real-time scheduling according to POSIX standard: runs at a higher priority than non-real-time tasks SCHED_FIFO SCHED_RR Linux uses two separate priority ranges: real-time tasks: real-time tasks have static priorities (0-99) normal tasks: ( ) Two ranges map into a global priority scheme: the lower the values, the higher relative priorities Normal tasks: based on their nice values Nice value of -20 maps to global priority 100 Nice value of +19 maps to priority 139
67
Windows Scheduling Windows uses priority-based preemptive scheduling
Highest-priority thread runs next Dispatcher is scheduler Thread runs until (1) blocks, (2) uses time slice, (3) preempted by higher-priority thread Real-time threads can preempt non-real-time 32-level priority scheme Variable class is 1-15, real-time class is 16-31 Priority 0 is memory-management thread Queue for each priority If no ready thread is found, runs a special thread called idle thread
68
Windows Priority Classes
Win32 API identifies several priority classes to which a process can belong REALTIME_PRIORITY_CLASS, HIGH_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, IDLE_PRIORITY_CLASS All are variable except REALTIME A thread within a given priority class has a relative priority TIME_CRITICAL HIGHEST ABOVE_NORMAL NORMAL BELOW_NORMAL LOWEST IDLE
69
Windows Threads Priorities
Priority classes Relative priority Base priority
70
Windows Priority Classes (cont.)
Priority class and relative priority combine to give numeric priority Base priority is NORMAL within the class For the variable-priority class threads, If quantum expires, then interrupted: priority lowered, but never below base priority If released from wait: priority boosted depending on what was waited for Interactive threads: get higher priority than disk operation thread Foreground window in the normal-priority class: given 3x priority boost
71
Solaris Priority-based thread scheduling where each thread belongs to one of six scheduling classes: Time sharing (default) : TS Interactive : IA Real time : RT System : SYS Fair Share : FSS Fixed priority : FP Given thread can be in one class at a time Each class has its own scheduling algorithm The default scheduling class for a process is time sharing. Time sharing with varying priorities and time slices of different lengths using multi-level feedback queue The higher the priority, the smaller the time slice: inverse relationship between priorities and time slices.
72
Solaris Dispatch Table for time-sharing and interactive threads
Lowered new priority after expiration Boosted new priority after sleep to provide good response time for interactive processes Lowest priority with highest time quantum Highest priority with lowest time quantum
73
Solaris Scheduling Threads in the real-time class are given the highest priority and will run before a process in any other class. Threads in the fixed-priority have the same priority range as those in the time-sharing class; however, their priorities are not dynamically adjusted. The fair-share scheduling class uses CPU shares instead of priorities to make scheduling decisions. The scheduler selects the thread with the highest global priority to run after converting the class-specific priorities into global priorities. 10 threads for servicing interrupts
74
Solaris Scheduling (Cont.)
Scheduler converts class-specific priorities into a per-thread global priority Thread with highest priority runs next Runs until (1) blocks, (2) uses time slice, (3) preempted by higher-priority thread Multiple threads at same priority: selected via RR scheme
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.