1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.

Slides:



Advertisements
Similar presentations
Chapter 6: CPU Scheduling
Advertisements

1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 9: CPU Scheduling Chapter 5 (cont)
Scheduling Algorithms
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
CPU Scheduling CS 3100 CPU Scheduling1. Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various.
國立台灣大學 資訊工程學系 Chapter 5: CPU Scheduling. 資工系網媒所 NEWS 實驗室 Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling modified 02/24/2010 by H. Schulzrinne.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
1 Chapter 5: Process Scheduling Dr. İbrahim Körpeoğlu Bilkent University Department of Computer Engineering CS342 Operating.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
CS342 Operating Systemsİbrahim Körpeoğlu, Bilkent University1 Lecture 5 Process Scheduling (chapter 5) Dr. İbrahim Körpeoğlu
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling Basic.
1 Chapter 5 Process Scheduling Dr. Selim Aksoy Bilkent University Department of Computer Engineering CS342 Operating.
1 Chapter 5: Process Scheduling Dr. İbrahim Körpeoğlu Bilkent University Department of Computer Engineering CS342 Operating.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 9 Chapter 5: CPU Scheduling (cont)
Chapter 5: CPU Scheduling (Continuation). 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling.
Chapter 5: Process Scheduling. 5.2 Chapter 5: Process Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
6.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Example of SJF ProcessArrival TimeBurst Time P P P
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling Changes by M.A. Doman 2013.
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
Cosc 4740 Chapter 4 & 5 Threads & Scheduling. Motivation Threads run within application (process) Multiple tasks with the application can be implemented.
CPU Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Operating System Concept : Silberschatz, Galvin and Gagne Dave.
國立台灣大學 資訊工程學系 Chapter 5: Process Scheduling. 資工系網媒所 NEWS 實驗室 Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling Basic.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
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.
Lecture 4 CPU Scheduling Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
5.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 5: Process Scheduling Objectives To introduce CPU scheduling To describe various.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 5 CPU Scheduling Slide 1 Chapter 5 CPU Scheduling.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: Process Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
1 Uniprocessor Scheduling Chapter 3. 2 Alternating Sequence of CPU And I/O Bursts.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Basic Concepts Maximum CPU utilization obtained with multiprogramming
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling Basic.
Thread & Processor Scheduling CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Chapter 5: Process Scheduling
Chapter 6: CPU Scheduling (Cont’d)
Thread & Processor Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Lecture 6: Uniprocessor Scheduling(cont.)
Chapter 5: CPU Scheduling
Outline Scheduling algorithms Multi-processor scheduling
Shortest-Job-First (SJR) Scheduling
Topic 5 (Textbook - Chapter 6) CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Presentation transcript:

1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof. Mark Corner and Prof. Emery Berger’s OS course at Umass Amherst Assistant Professor, University of Maryland Baltimore County

2 Announcements Midterm (29 th of October in class) Project 2 is out (there are several submission dates) Readings from Silberchatz [5 th chapter] Towards the end of class today--- I will talk about project 2

Multilevel Queue Ready queue is partitioned into separate queues, eg: –foreground (interactive) –background (batch) Process permanently in a given queue Each queue has its own scheduling algorithm: –foreground – RR –background – FCFS Scheduling must be done between the queues: –Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. –Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR –20% to background in FCFS

Multilevel Queue Scheduling

Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way 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 demote a process –method used to determine which queue a process will enter when that process needs service

Example of Multilevel Feedback Queue Three queues: –Q 0 – RR with time quantum 8 milliseconds –Q 1 – RR time quantum 16 milliseconds –Q 2 – FCFS Scheduling –A new job enters queue Q 0 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 Q 1 –At Q 1 job is again served FCFS and receives 16 additional milliseconds If it still does not complete, it is preempted and moved to queue Q 2

Multilevel Feedback Queues

Thread Scheduling Distinction between user-level and kernel-level threads When threads supported, threads scheduled, not processes Many-to-one and many-to-many models, thread library schedules user-level threads to run on LWP –Known as process-contention scope (PCS) since scheduling competition is within the process –Typically done via priority set by programmer Kernel thread scheduled onto available CPU is system-contention scope (SCS) – competition among all threads in system

Pthread Scheduling API allows specifying either PCS or SCS during thread creation –PTHREAD_SCOPE_PROCESS schedules threads using PCS scheduling –PTHREAD_SCOPE_SYSTEM schedules threads using SCS scheduling Can be limited by OS – Linux and Mac OS X only allow PTHREAD_SCOPE_SYSTEM

Pthread Scheduling API #include #define NUM THREADS 5 int main(int argc, char *argv[]) { int i; pthread_t tid[NUM THREADS]; pthread_attr_t attr; /* get the default attributes */ pthread_attr_init(&attr); /* set the scheduling algorithm to PROCESS or SYSTEM */ pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); /* set the scheduling policy - FIFO, RT, or OTHER */ pthread_attr_setschedpolicy(&attr, SCHED_OTHER); /* create the threads */ for (i = 0; i < NUM THREADS; i++) pthread create(&tid[i],&attr,runner,NULL);

Pthread Scheduling API /* 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) { printf("I am a thread\n"); pthread exit(0); }

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available Asymmetric multiprocessing – only one processor accesses the system data structures, alleviating the need for data sharing Symmetric multiprocessing (SMP) – each processor is self-scheduling, all processes in common ready queue, or each has its own private queue of ready processes –Currently, most common Processor affinity – process has affinity for processor on which it is currently running –soft affinity –hard affinity

Multicore Processors (Scheduling is an open problem) Recent trend to place multiple processor cores on same physical chip Faster and consumes less power Multiple threads per core also growing –Takes advantage of memory stall to make progress on another thread while memory retrieve happens

Multithreaded Multicore System (Heuristic)

Linux Kernel Scheduler (CFS – completely Fair) CFS a very simple scheduler Intuition behind the scheduler “ideal, precise multitasking CPU” – one that could run multiple processes simultaneously, giving each equal processing power.

CFS scheduling CFS measures how much runtime each task has had and try and ensure that everyone gets their fair share of time. This value is held in the vruntime variable for each task, and is recorded at the nanosecond level. A lower vruntime indicates that the task has had less time to compute, and therefore has more need of the processor. Furthermore, instead of a queue, CFS uses a Red-Black tree to store, sort, and schedule tasks.

Red Black Trees A red-black tree is a binary search tree, which means that for each node, the left subtree only contains keys less than the node's key, and the right subtree contains keys greater than or equal to it. A red-black tree has further restrictions which guarantee that the longest root-leaf path is at most twice as long as the shortest root-leaf path. This bound on the height makes RB Trees more efficient than normal BSTs. Operations are in O(log n) time.

Red Black Trees A red-black tree is a binary search tree, which means that for each node, the left subtree only contains keys less than the node's key, and the right subtree contains keys greater than or equal to it. A red-black tree has further restrictions which guarantee that the longest root-leaf path is at most twice as long as the shortest root-leaf path. This bound on the height makes RB Trees more efficient than normal BSTs. Operations are in O(log n) time.

CFS Tree The key for each node is the vruntime of the corresponding task. To pick the next task to run, simply take the leftmost node.

20 Kernel Dive to understand entry points for the scheduler

A Bit about Project 2 (Goal) Well behaved process Malicious process close mmap getpid open mmap getpid open System call sequence = Well behaved case = Malicious case = Distance between these two = 4

22 Flow of control during a system call invocation system call invocation entry_32.S Saves registers on stack Save return address of user process (thread_info) syscall_table.S table of function pointers system call execution Kernel space User space your application library (libc) int 0x80 restore registers return value stored in the stack location corresponding to %eax iret Return value Error = -1 Errorcode = errorno

23 Simplified view of sysenter/sysexit in Linux > 2.5 _ _kernel_vsyscall entry_32.S Saves user mode stack Save return address of user process (thread_info) syscall_table.S table of function pointers system call execution Kernel space User space your application library (libc) sysenter restore registers return value stored in the stack location corresponding to %eax sysexit Return value Error = -1 Errorcode = errorno

Key goal: how to trap the system calls in the kernel To make your life easier: you need to disable one of the two system call invocation --- choose which ever you want hint in the text on how to disable sysenter/sysexit

25 Flow of control during a system call invocation system call invocation entry_32.S Saves registers on stack Save return address of user process (thread_info) syscall_table.S table of function pointers system call execution Kernel space User space your application library (libc) int 0x80 restore registers return value stored in the stack location corresponding to %eax iret Return value Error = -1 Errorcode = errorno Trap the system call invocation here

What does trapping a sys call mean Interrupt Descriptor Table int 0x80Entry point in the entry_32.S ENTRY(system_call) Your function (logging) Save the registers Restore the registers Make a call to ENTRY

What are the things you have to think about? (1)Finding where the IDT is? (2)Finding which entry in the IDT to hook? (3)How to replace the entry with your function (4)Proper saving/restoring of register