CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Scheduling.

Slides:



Advertisements
Similar presentations
1 Always want to have CPU (or CPU’s) working Usually many processes in ready queue –Ready to run on CPU –Focus on a single CPU here Need strategies for.
Advertisements

CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5.
CSC 322 Operating Systems Concepts Lecture - 11: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CS 149: Operating Systems February 3 Class Meeting
Operating Systems Process Scheduling (Ch 3.2, )
Abdulrahman Idlbi COE, KFUPM Jan. 17, Past Schedulers: 1.2 & : circular queue with round-robin policy. Simple and minimal. Not focused on.
Linux Scheduler. Linux is a multitasking OS Deciding what process runs next, given a set of runnable processes, is a fundamental decision a scheduler.
Process Scheduling in Linux (Chap.7 in Understanding the Linux Kernel) J. H. Wang Oct. 1, 2009.
Operating Systems, fall 2002 SCHEDULING in Linux Lior Amar, David Breitgand (recitation)
Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
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.
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
Scheduling in Linux COMS W4118 Spring Scheduling Goals O(1) scheduling; 2.4 scheduler iterated through Run queue on each invocation Task queue.
1 Scheduling in Representative Operating Systems.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
The Linux Scheduler 2.4 vs 2.6 Michael McCabe Michael McCabe
Job scheduling Queue discipline.
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?
Operating System Process Scheduling (Ch 4.2, )
Linux Kernel 2.6 Scheduler O(1) from O(n) A B.Sc Seminar in Software Engineering Student: Maxim Raskin Lecturer: Dr. Itzhak Aviv Tel Aviv Afeka College.
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
Scheduling in Linux and Windows 2000
Linux Scheduling CS Scheduling Policy ► The scheduling algorithm of traditional Unix systems must fulfill several conflicting objectives  Fast.
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 5 – CPU Scheduling (Pgs 183 – 218). CPU Scheduling  Goal: To get as much done as possible  How: By never letting the CPU sit "idle" and not.
Outline for Today Objectives: Linux scheduler Lottery scheduling
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.
Seminar on Linux Process Management Presentation by Manoj Dhage MTech 1 st Year, SIT, IIT Kharagpur.
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.
CPU Scheduling Presentation by Colin McCarthy. Runqueues Foundation of Linux scheduler algorithm Keeps track of all runnable tasks assigned to CPU One.
Linux Scheduler © DJ Foreman 3/8/ Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
Process Scheduling in Linux (Chap. 11, Understanding the Linux Kernel) J. H. Wang Sep. 26, 2008.
What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.
Lec 3aOperating Systems1 Operating Systems Lecture 3a: Linux Schedulers William M. Mongan Material drawn in part from
Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
LINUX SCHEDULING Evolution in the 2.6 Kernel Kevin Lambert Maulik Mistry Cesar Davila Jeremy Taylor.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Processes.
ITFN 2601 Introduction to Operating Systems Lecture 4 Scheduling.
CSC 322 Operating Systems Concepts Lecture - 10: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CSC 660: Advanced Operating Systems
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Linux Process Management. Linux Implementation of Threads Threads enable concurrent programming / true parallelism Linux implementation of threads.
TANNENBAUM SECTION 2.4, 10.3 SCHEDULING OPERATING SYSTEMS.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
Operating Systems Unit 5: – Processor scheduling – Java – Linux – Windows XP Operating Systems.
Operating System Examples - Scheduling. References r er/ch10.html r bangalore.org/blug/meetings/200401/scheduler-
Scheduling.
W4118 Operating Systems Instructor: Junfeng Yang.
Process Scheduling 國立中正大學 資訊工程研究所 羅習五 老師 1. Outline OS schedulers Unix scheduling Linux scheduling Linux 2.4 scheduler Linux 2.6 scheduler – O(1) scheduler.
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.
Scheduling of Non-Real-Time Tasks in Linux (SCHED_NORMAL/SCHED_OTHER)
Chapter 2 Scheduling.
CS 3204 Operating Systems Lecture 14 Godmar Back.
Linux kernel: Processes, threads and scheduling
Scheduling.
Chapter 6: CPU Scheduling
Chapter 3: Processes.
Linux Scheduler © DJ Foreman 3/8/2009.
Linux Scheduling CSE 2431: Introduction to Operating Systems
Presentation transcript:

CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Scheduling

CSC 660: Advanced Operating SystemsSlide #2 Topics 1.Basic Concepts 2.Scheduling Policy 3.The O(1) Scheduler 4.Runqueues 5.Priority Arrays 6.Calculating Priorities and Timeslices. 7.Scheduler Interrupts. 8.Sleeping and Waking. 9.The schedule() function 10.Multiprocessor Scheduling 11.Soft Realtime Scheduling

CSC 660: Advanced Operating SystemsSlide #3 Basic Concepts Scheduler Selects a process to run and allocates CPU to it. Provides semblence of multitasking on single CPU. Scheduler is invoked when: Process blocks on an I/O operation. A hardware interrupt occurs. Process time slice expires. Kernel thread yields to scheduler.

CSC 660: Advanced Operating SystemsSlide #4 Types of Processes CPU Bound Spend most time on computations. Example: computer algebra systems. I/O Bound Spend most time on I/O. Example: word processor. Mixed Alternate CPU and I/O activity. Example: web browser.

CSC 660: Advanced Operating SystemsSlide #5 Alternating CPU and I/O Bursts

CSC 660: Advanced Operating SystemsSlide #6 Scheduling Policy Scheduler executes policy, determining 1. When threads can execute. 2. How long threads can execute. 3. Where threads can execute.

CSC 660: Advanced Operating SystemsSlide #7 Scheduling Policy Goals Efficiency –Maximize amount of work accomplished. Interactivity –Respond as quickly as possible to user. Fairness –Don’t allow any process to starve.

CSC 660: Advanced Operating SystemsSlide #8 Which goal is most important? Depends on the target audience: Desktop: interactivity But kernel shouldn’t spend all its time in context switch. Server: efficiency But should offer interactivity in order to serve multiple users.

CSC 660: Advanced Operating SystemsSlide #9 Pre-2.6 Scheduler O(n) algorithm at every process switch: 1. Scanned list of runnable processes. 2. Computed priority of each task. 3. Selected best task to run.

CSC 660: Advanced Operating SystemsSlide #10 The O(1) Scheduler Replacement for O(n) 2.4 scheduler. All algorithms run in constant time. New data structures: runqueues and priority arrays. Performs work in small pieces. Additional new features Improved SMP scalability, including NUMA. Better processor affinity. SMT scheduling.

CSC 660: Advanced Operating SystemsSlide #11 Runqueues List of runnable processes on a processor. Each runnable process is a member of precisely one runqueue. Runqueue data: Lock to prevent concurrency problems. Pointers to current and idle tasks. Priority arrays which contain actual tasks. Statistics

CSC 660: Advanced Operating SystemsSlide #12 Runqueues struct runqueue { spinlock_t lock; unsigned long nr_running; unsigned long long nr_switches; unsigned long expired_timestamp, nr_uninterruptible; unsigned long long timestamp_last_tick; task_t *curr, *idle; struct mm_struct *prev_mm; prio_array_t *active, *expired, arrays[2]; int best_expired_prio; atomic_t nr_iowait; }

CSC 660: Advanced Operating SystemsSlide #13 Priority Arrays Each runqueue contains 2 priority arrays Active array Expired array Basis for O(1) performance: Scheduler always runs highest priority task. Round robin for multiple equal priority tasks. Priority array finds highest task O(1) operation. Using two arrays allows transitions between epochs by switching active and expired pointers.

CSC 660: Advanced Operating SystemsSlide #14 Priority Arrays struct prio_array { /* # of runnable tasks in array */ unsigned int nr_active; /* bitmap: pri lvls contain tasks */ unsigned long bitmap[BITMAP_SIZE]; /* 1 list_head per priority (140) */ struct list_head queue[MAX_PRIO]; };

CSC 660: Advanced Operating SystemsSlide #15 Finding Highest Priority Task 1.Find first bit set in bitmap. sched_find_first_bit() 2.Read corresponding queue[n] If one process, give CPU to that one. If multiple processes, round-robin schedule all processes in queue for that priority. idx = sched_find_first_bit(array->bitmap); queue = array->queue + idx; next = list_entry(queue->next, task_t, run_list);

CSC 660: Advanced Operating SystemsSlide #16 What if no runnable task exists? System runs the swapper task (PID 0). Each CPU has its own swapper process.

CSC 660: Advanced Operating SystemsSlide #17 Running out of Timeslice 1.Remove task from active priority array. 2.Calculate new priority and timeslice. 3.Add task to expired priority array. 4.Swap arrays when active array is empty. array = rq->active; if (unlikely(!array->nr_active)) { rq->active = rq->expired; rq->expired = array;... }

CSC 660: Advanced Operating SystemsSlide #18 Static and Dynamic Priorities Initial priority value called the nice value. Set via the nice() system call. Static priority is nice value Stored in current->static_prio. Ranges from 100 (highest) to 139 (lowest). Scheduling based on dynamic priority. Bonuses and penalties according to interactivity. Stored in current->prio. Calculated by effective_prio() function.

CSC 660: Advanced Operating SystemsSlide #19 Dynamic Priority Policy Increase priority of interactive processes. Favor I/O-bound over CPU-bound. Need heuristic for determining interactivity. Use time spent sleeping vs. runnable time. Sleep average Stored in current->sleep_avg. Incremented when task becomes runnable. Decremented for each timer tick task runs. Scaled to produce priority bonus ranging

CSC 660: Advanced Operating SystemsSlide #20 Calculating Priority /* Scale sleep_avg to range 0..MAX_BONUS */ #define CURRENT_BONUS(p) \ (NS_TO_JIFFIES((p)->sleep_avg) * MAX_BONUS / \ MAX_SLEEP_AVG) static int effective_prio(task_t *p) { int bonus, prio; bonus = CURRENT_BONUS(p) - MAX_BONUS / 2; prio = p->static_prio - bonus; return prio; }

CSC 660: Advanced Operating SystemsSlide #21 Time Slices Time slice duration critical to performance. Too short: high overhead from context switches. Too long: loss of apparent multitasking. Interactive processes and time slices Interactive processes have high priority. Pre-empt CPU bound tasks on kbd/ptr interrupts. Long time slices slow start of new tasks.

CSC 660: Advanced Operating SystemsSlide #22 Calculating Timeslice Initial Timeslice On fork(), parent + child divide remaining time evenly. Stored in current->time_slice. Recalculating Timeslices Time Slice = (140 – static priority) x 20 if static < 140 = (140 – static priority) x 5 if static >= 140 DescriptionNiceStatic PriTime Slice Highest ms Default ms Lowest ms

CSC 660: Advanced Operating SystemsSlide #23 Scheduler Interrupts Scheduler interrupt: scheduler_tick() –Invoked every 1ms by a timer interrupt. Decrements task’s time slice. If a higher priority task exists, –Higher priority task is given CPU. –Current task remains in TASK_RUNNING state. If time slice expired, –Moved to expired priority array. –If highly interactive, may be re-inserted into active priority array.

CSC 660: Advanced Operating SystemsSlide #24 Sleeping and Waking Sleeping tasks are not in runqueues. Require no CPU time until awakened. Why sleep? Waiting for I/O. Waiting for other hardware events. Waiting for a kernel semaphore.

CSC 660: Advanced Operating SystemsSlide #25 Sleeping DECLARE_WAITQUEUE(wait, current); /* q is a wait queue, wait is a q entry */ add_wait_queue(q, &wait); while (!condition) { set_current_state(TASK_INTERRUPTIBLE); if (signal_pending(current)) /* Handle signal */ schedule() } set_current_state(TASK_RUNNING); remove_wait_queue(q, &wait);

CSC 660: Advanced Operating SystemsSlide #26 Waking wake_up() wakes up tasks on event Exclusive: only wakes up one task on waitqueue Non-exclusive: wakes all tasks on waitqueue TASK_INTERRUPTIBLE TASK_RUNNING Signal add_wait_queue wake_up

CSC 660: Advanced Operating SystemsSlide #27 Multiprocessor Architectures Classic Memory shared by all CPUs. Hyperthreading Single CPU executing multiple on-chip threads. NUMA CPUs + RAM grouped in local nodes. Reduces contention for accessing RAM. Fast to access local RAM. Slower to access remote RAM.

CSC 660: Advanced Operating SystemsSlide #28 Multiprocessor Scheduling Each CPU has own runqueue. Scheduler selects tasks from local runqueue. CPU cache more likely to still be hot. Periodic checks to balance load across CPUs. Called by rebalance_tick(). Loops over all scheduling domains. Calls load_balance() if balance interval expired.

CSC 660: Advanced Operating SystemsSlide #29 load_balance() 1.Acquires this_rq->lock spin lock. 2.Finds busiest CPU with > 1 process. 3.If no busiest or current CPU is busiest, terminates. 4.Obtains spin lock on busiest CPU. 5.Pull tasks from busiest CPU to local runqueue. 6.Releases locks.

CSC 660: Advanced Operating SystemsSlide #30 move_tasks() Searches for runnable tasks in expired runqueue. Then scans active runqueue. Call pull_task() to move task if all true: Task not currently being executed. Local CPU is in cpus_allowed bitmask. At least one of the following is true: Local CPU is idle. Multiple attempts to move processes have failed. Process is not cache hot.

CSC 660: Advanced Operating SystemsSlide #31 Realtime Scheduling Hard Real-time Guaranteed response within defined period. Used for embedded systems: car engines. Ex: RealTime Application Interface (RTAI) Soft Real-time Best effort to meet scheduling constraints. Used for multimedia applications. Currently provided by Linux. Improved by Realtime Preemption Patch.

CSC 660: Advanced Operating SystemsSlide #32 Soft Realtime Scheduling Scheduling Priorities RT have higher priorities than any non-RT tasks. RT priorities are static, ranging 1-99, not dynamic. If RT tasks are runnable, no other tasks can run. Scheduling Policies SCHED_NORMAL (non-realtime) SCHED_FIFO SCHED_RR

CSC 660: Advanced Operating SystemsSlide #33 Realtime Policies SCHED_FIFO First-in First-out real-time Scheduling Process uses CPU until: It blocks or yields the CPU voluntarily. A higher priority real-time process pre-empts it. SCHED_RR Round Robin real-time scheduling. Process runs for time slice, then waits for other equal priority real-time processes in runqueue.

CSC 660: Advanced Operating SystemsSlide #34 Realtime Process Replacement Realtime processes replaced only when: Pre-empted by a high-priority RT process. Process performs a blocking operation. Process is stopped or killed by a signal. Process invokes sched_yield() system call. SCHED_RR process has exhausted its time slice.

CSC 660: Advanced Operating SystemsSlide #35 Realtime System Calls Scheduler Policy sched_setscheduler() sched_getscheduler() Priority sched_getparam() sched_setparam()

CSC 660: Advanced Operating SystemsSlide #36 Yielding the Processor sched_yield() system call Moves regular task to expired priority array. RT tasks moved to end of priority list. Kernel tasks can yield the CPU too. Call yield() function.

CSC 660: Advanced Operating SystemsSlide #37 References 1.Josh Aas, “Understanding the Linux Scheduler,” Daniel P. Bovet and Marco Cesati, Understanding the Linux Kernel, 3 rd edition, O’Reilly, Corbet, “Realtime preemption and read-copy-update,” Linux Weekly News, March 29, Robert Love, Linux Kernel Development, 2 nd edition, Prentice-Hall, Claudia Rodriguez et al, The Linux Kernel Primer, Prentice-Hall, RTAI, Peter Salzman et. al., Linux Kernel Module Programming Guide, version 2.6.1, Avi Silberchatz et. al., Operating System Concepts, 7 th edition, Andrew S. Tanenbaum, Modern Operating Systems, 3 rd edition, Prentice-Hall, 2005.