1 Process Scheduling Chapter 5. 2 Introduction u Policy and implementation u Objectives: u Fast response time u High throughput (turnaround time) u Avoidance.

Slides:



Advertisements
Similar presentations
Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
Advertisements

Chapter 9 Uniprocessor Scheduling
A. Frank - P. Weisberg Operating Systems Advanced CPU Scheduling.
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Chapter 3: CPU Scheduling
Operating System Process Scheduling (Ch 4.2, )
Operating System I Process Scheduling. Schedulers F Short-Term –“Which process gets the CPU?” –Fast, since once per 100 ms F Long-Term (batch) –“Which.
Scheduling in Batch Systems
Chapter 6: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 6: CPU Scheduling Basic.
Uniprocessor Scheduling Chapter 9. Aim of Scheduling The key to multiprogramming is scheduling Scheduling is done to meet the goals of –Response time.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 Multilevel Feedback Queue Scheduling Another way to put a preference on short-lived processes –Penalize processes that have been running longer. Preemptive.
1 Scheduling in Representative Operating Systems.
1 Uniprocessor Scheduling Chapter 9. 2 Aims of Scheduling Assign processes to be executed by the processor(s) Response time Throughput Processor efficiency.
Informationsteknologi Tuesday, October 9, 2007Computer Systems/Operating Systems - Class 141 Today’s class Scheduling.
Operating Systems Process Scheduling (Ch 4.2, )
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in.
Operating System Process Scheduling (Ch 4.2, )
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
1 Uniprocessor Scheduling Chapter 9. 2 Aim of Scheduling Main Job: Assign processes to be executed by the processor(s) and processes to be loaded in main.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU Scheduling Chapter 6 Chapter 6.
Chapter 6: CPU Scheduling
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
Chapter 9 Uniprocessor Scheduling Spring, 2011 School of Computer Science & Engineering Chung-Ang University.
Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Chapter 6 CPU SCHEDULING.
Operating System Examples - Scheduling
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
Chapter 6 Scheduling. Basic concepts Goal is maximum utilization –what does this mean? –cpu pegged at 100% ?? Most programs are I/O bound Thus some other.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
Alternating Sequence of CPU And I/O Bursts. Histogram of CPU-burst Times.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Process Scheduling 1 Chapter 5. Process Scheduling Clock interrupt handling Scheduler goal Traditional UNIX scheduling SVR4 scheduler Solaris 2.x scheduling.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
1 Uniprocessor Scheduling Chapter 9. 2 Aim of Scheduling Response time Throughput Processor efficiency.
Uniprocessor Scheduling Chapter 9. Aim of Scheduling Response time Throughput Processor efficiency.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Uniprocessor Scheduling
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 11/29/2015 Chapter 6: CPU Scheduling l Basic Concepts l Scheduling Criteria l Scheduling Algorithms l Multiple-Processor Scheduling l Real-Time Scheduling.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Uniprocessor Scheduling Chapter 9. Aim of Scheduling Assign processes to be executed by the processor or processors: –Response time –Throughput –Processor.
What is an Operating System? Various systems and their pros and cons –E.g. multi-tasking vs. Batch OS definitions –Resource allocator –Control program.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
1.  System Characteristics  Features of Real-Time Systems  Implementing Real-Time Operating Systems  Real-Time CPU Scheduling  An Example: VxWorks5.x.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
1 Uniprocessor Scheduling Chapter 3. 2 Alternating Sequence of CPU And I/O Bursts.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
1 Uniprocessor Scheduling Chapter 9. 2 Aim of Scheduling Assign processes to be executed by the processor(s) Response time Throughput Processor efficiency.
Uniprocessor Scheduling Chapter 9 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
PROCESS MANAGEMENT IN MACH
Chapter 5a: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 2: The Linux System Part 3
TDC 311 Process Scheduling.
Chapter 5: CPU Scheduling
Presentation transcript:

1 Process Scheduling Chapter 5

2 Introduction u Policy and implementation u Objectives: u Fast response time u High throughput (turnaround time) u Avoidance of process starvation u Context switching is expensive u Context is a snapshot of the values of the general-purpose, memory management, and other special registers.

3 Type of Scheduling u Long-term u Performed when new process is created. u The decision to add to the pool of processes to be executed. u Medium-term u Swapping u The decision to add to the number of processes that are partially or fully in main memory

4 Types of Scheduling u Short-term u Which ready process to execute next u The decision as to which available processes will be executed by the processor. u FCFS, Round-Robin, Shortest process next, Shortest remaining time u I/O u The decision as to which process’s pending I/O request shall be handled by available I/O device

5 Scheduling and Process State Transition ExitRunning Ready Blocked Blocked, suspend Ready, suspend New Long-term scheduling Medium-term scheduling Medium-term scheduling Long-term scheduling Short-term scheduling

6 Queuing Diagram for Scheduling Processor Medium-term scheduling Medium-term scheduling Batch jobs Long-term scheduling Time-out Interactive users Ready Queue Ready, Suspend Queue Blocked, Suspend Queue Blocked Queue Event Occurs Event Wait Release Short-term scheduling

7 5.2 Clock Interrupt Handling u Clock interrupt is the 2 nd to the power-failure interrupt. u Tasks: u Returns the hardware clock u Update CPU usage statistics u Performs scheduler-related functions u Sends a SIGXCPU signal to the current process u Updates the time-of-day and other related clocks. u Handles callouts u Wakes up system processes u Handles alarms

Callouts u Records a function that the kernel must invoke at a later time. u int to_ID = timeout(void(*fn), caddr_t arg, long delta) u void untimeout(int to_ID) u Tasks: u Retransmission of network packets u Certain scheduler and memory management functions u Monitoring devices to avoid losing interrupts u Polling devices that do not support interrupts

9 Callout in BSD UNIX

Alarms u Real-time: u relates to the actual elapsed time, and notifies the process via a SIGALRM signal. u Profiling: u Measures the amount of time the process has been executing and uses the SIGPROF signal for notification. u Virtual-time: u Monitors only the time spent by the process in user mode and sends the SIGVTALRM signal.

Scheduler Goals u The scheduler must ensure that the system delivers acceptable performance to each application. u Different applications: u Interactive: ms u Batch: scientific computation u Real-time: time-critical

Traditional UNIX Scheduling u To improve response times of interactive users, while ensuring that low-priority, background jobs do not starve. u Priority-based: u User-process is preempted u Kernel is strictly non-preempted

13 Priority u Kernel:0-49, user: u proc fields: u p_pri: Current scheduling priority u p_usrpri: User mode priority u p_cpu: Measure of recent CPU usage u p_nice: User-controllable nice factor u Kernel: u Sleeping priority

14 User mode priority u Depends on two factors: u Nice: 0-39 u CPU usage u Time-sharing: equal opportunity u decay factor: for SVR3 it is 1/2, for 4.3BSD: u decay = ( 2*load_average)/(2*load_average+1) u p_cpu = p_cpu* decay u p_usrpri = PUSER + (p_cpu/4) +(2*p_nice)

15 Example : PUSER = 50 P1 P_usrpri= 110 P_cpu = 80 Nice = 20 P2 P_usrpri= 120 P_cpu = 80 Nice=25 T1 P1 P_usrpri= 115 P_cpu = 100 Nice = 20 P2 P_usrpri= 110 P_cpu = 40 Nice = 25 T2 Decay =1/2 P1 P_usrpri= 102 P_cpu = 50 Nice = 20 P2 P_usrpri= 115 P_cpu = 60 Nice = 25 T3 Decay =1/2

16 Scheduler Implementation u 32 run queues: doubly linked list of proc structures for runnable processes. u whichqs: bitmask for each queue, “1” means that there is a runnable process u swtch(): context switch by p_addr u Saving part of u area (pcb) u Loading the saved context. u VAX ffs & ffc : special instructions for context switch

17

18 Run Queue Manipulation u roundrobin(): for the processes with the same priority. u schedcpu(): recomputes the priority once per second u Removes the process from the run queue; u recomputes the priority u Puts it back

19 When to switch context u The current process blocks on a resource or exits. u The priority recomputation procedure results in the priority of another process becoming greater than that of the current one( flag runrun set). u The current process, or an interrupt handler, wake up a higher-priority process

20 Analysis u Not scale well u No way to let a specific process to occupy the CPU u No guarantee to real-time applications u Little control of priorities u Kernel is non-preemptive, high-priority runnable processes may have to wait for the kernel to relinquish the CPU

The SVR4 Scheduler u Support a diverse range of applications including those requiring real-time response u Separate the scheduling policy from the mechanisms that implement it u Provide applications with greater control over their priority and scheduling. u Define a scheduling framework with a well-defined interface to the kernel u Allow new scheduling policies to be added in a modular manner, including dynamic loading of scheduler implementations. u Limit the dispatch latency for time-critical applications.

22 The class-independent Layer u Responsible for context switching, run queue management, & preemption.

23 Preemption points u Places of code where the kernel data is in a steady state and is about to begin a long computation. u In the pathname parsing routine lookuppn() u In the open system call, before file creation u In the memory subsystem, before freeing the pages of a process. u Call PREEMPT() check kprunrun

24 Interface to the Scheduling Classes u 3 fields of proc u p_cid: class ID, an index into the global class table u p_clfuncs: pointer to the classfuncs vector for the class u p_clproc: pointer to a class-dependent private data structure u #define CL_SLEEP(procp, clprocp, …) (*(procp)-p->clfuncs->cl_sleep)(clprocp, …)

25 Interface cnt’d u Entry u CL_TICK: the clock interrupt handler u CL_FORK, CL_FORKRET: fork u CL_ENTERCLASS, CL_EXITCLASS: enter, exit u CL_SLEEP: sleep() u CL_WAKEUP: wakeprocs() u Priorities: u 0-59: time-sharing class u 60-99: system priority u : real-time class

26

27 The Time Sharing Class u The default class for a process. u Round-robin scheduling: u Event-driven scheduling u tsproc: u ts_timeleft: time remaining in the quantum u ts_cpupri : system part of the priority u ts_upri: user part of the priority(nice value) u ts_umpri: user mode priority (ts_cpupri+ ts_upri) u ts_dispwait: seconds since start the quantum u Dispatcher parameter table

28 Dispatcher parameter table New ts_cpupri to set when the quantum expires. New ts_cpupri to set when returning to user mode after sleeping Number of seconds to wait for quantum expiry before using ts_lwait. Use instead of ts_tqexp if process took longer than ts_maxwait to use up its quantum.

29 The Real-Time Class u : higher than any time-sharing process. u The real-time process must wait until the current process is about to return to user mode or until it reaches a kernel preemption point. u Real-time processes require bounded dispatch latency and bounded response time. u The response time = the time for interrupt handler + dispatch latency.

30

31 The priocntl System Call u Basic operations: u Changing the priority class of the process u Setting ts_upri for time-sharing processes u Resetting priority and quantum for real-time processes u Obtaining the current value of several scheduling parameters u priocntlset: perform the same operations on a set of processes - a system/ a process group/ session/ a scheduling class/ a particular user/ having the same parent.

32 Adding a scheduling class u Provide an implementation of each class- dependent scheduling function u Initialize a classfuncs vector to point to these functions u Provide an initialization function to perform setup tasks such as allocating internal data structures u Add an entry for this class in the class table u Rebuild the kernel

33 Analysis u Provides flexible approach that allows the addition of scheduling classes to a system. u Event-driven scheduling favors I/O-bound & interactive jobs over CPU-bounded ones. u No good way for a time-sharing class process to switch to a different one. priocntl is only used by the superuser. u It is difficult to tune the system properly for a mixed set of applications. u Solaris2.x improved SVR4

Solaris 2.x Enhancements u Multithreaded, symmetric- multiprocessing OS u Preemptive Kernel u Fully preemptive u Implement interrupts by special kernel threads u Interrupt threads always run at the highest priority in the system.

35 Multiprocessor Support u Processors can communicate by cross- processor interrupt u Per-processor data structure u Cpu_thread: currently running thread u Cpu_dispthread: last selected to run u Cpu_idle: idle thread u Cpu_runrun: preemption flag used for time- sharing threads u Cpu_kprunrun: preemption flag set by real-time threads u Cpu_chosen_level: priority of thread that is going to preempt the current thread

36 Multiprocessor scheduling T6 becomes runnable - preempts T3

37

38 Hidden Scheduling u The kernel schedules the work without considering the priority of the thread for which it is doing the work. u E.G. STREAMS services. u Moving STREAMS processing into kernel threads. u Callouts handled by a special callout thread (has max system priority)

39 Priority Inversion u A situation where a lower-priority thread holds a resource needed by a higher priority process, thereby blocking that higher-priority process.

40 Solution u Solved by priority inheritance or priority lending.

41 Priority inheritance must be transitive.

42 Implementation of Priority inheritance u An extra state to implement priority inheritance u A global priority & inherited priority for each thread u pi_willto(): traverses the synchronization chain and passes on the inherited priority of the calling thread. u pi_waive(): surrenders its inherited priority.

43

44

45 Limitations of Priority Inheritance u Can be implemented only when it is known which thread is going to free the resource, i.e. when the resource is held by a single, known thread. u For mutexes the owner is always known, so pr. Inh. can be used, u For semaphores, and conditions variables the owner is usually indeterminate, so pr. inh. is not used, u When a reader/writer lock is used for writing there is a single, known owner; It may be held however by multiple readers, so then there is no single owner.

46 Limitations of Priority Inheritance u Solaris defines an owner-of record, which is the first thread that obtained the read clock. If a higher priority writer blocks on this object, the owner-of record thread will inherit its priority. If there are other readers – they cannot inherit the writer’s priority, so the solution is limited. u While reducing the time a high-priority process must block, in the worst case however this time is still much greater than what is acceptable for many real-time applications. u Alternative solutions – ceiling protocol – it requires however a priori knowledge of all processes in the system and their resource requirements – possible in embedded applications.

47 Turnstiles u Restrict the sleep queue to threads blocked on a particular resource – limiting the time taken to process the queue u Threads are queued in order of their priority; u To unlock turnstile: signal – for single highest priority thread, broadcast – for all blocked threads.

48

49 Solaris scheduling evaluation u Suitable for multithreaded and many real-time applications for uni- and multiprocessors; u Still missing other desirable real-time features such as gang scheduling and deadline-driven scheduling

50 Linux Scheduling u Scheduling classes u SCHED_FIFO: First-in-first-out real-time threads u SCHED_RR: Round-robin real-time threads u SCHED_OTHER: Other, non-real-time threads u Within each class multiple priorities may be used

51

52 Non-Real-Time Scheduling u Linux 2.6 uses a new scheduler - the O(1) scheduler u Time to select the appropriate process and assign it to a processor is constant regardless of the load on the system or number of processors u Separate queue for each priority. u Higher priority assigned lower number

53 Non-Real-Time Scheduling u Two queue structure – for active queues and for expired queues u All scheduling is done from the active queue structure; u when it becomes empty a switch is made with the expired queue structure and the scheduling continues

54

55 Calculating priorities u For non-real time priority is changed dynamically as a function of the task’s static priority and its execution behavior. u For real-time tasks priority is fixed u SCHED_FIFO tasks do not have assigned time-slices u SCHED_RR tasks have assigned time slices but they are never moved to the expired queue structure