CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 9: Processes and Scheduling.

Slides:



Advertisements
Similar presentations
Uniprocessor Scheduling Chapter 9 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Advertisements

Scheduling CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CS 149: Operating Systems February 3 Class Meeting
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Day 25 Uniprocessor scheduling. Algorithm: Selection function Selection function – which process among ready processes to select. w – time spent in system,
Chapter 3: CPU Scheduling
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
6/25/2015Page 1 Process Scheduling B.Ramamurthy. 6/25/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
A. Frank - P. Weisberg Operating Systems CPU Scheduling.
7/12/2015Page 1 Process Scheduling B.Ramamurthy. 7/12/2015Page 2 Introduction An important aspect of multiprogramming is scheduling. The resources that.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
Process Description and Control A process is sometimes called a task, it is a program in execution.
1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in.
Phones OFF Please Processes Parminder Singh Kang Home:
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
CS252: Systems Programming Ninghui Li Final Exam Review.
Chapter 5: CPU Scheduling (Continuation). 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length.
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.
Processor Management Introduction
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Scheduler What is the job of.
Chapter 4 Processor Management
Chapter 6 CPU SCHEDULING.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera and Chapters 7,8 of OSTEP Topic 20: Processes Scheduling.
1 Scheduling Processes. 2 Processes Each process has state, that includes its text and data, procedure call stack, etc. This state resides in memory.
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.
Operating Systems Process Management.
Scheduling Example 3 (1) Assume: FIFO Job Scheduling 100 K Main Memory Processor Sharing Process Scheduling (Cont…)
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.
1 Our focus  scheduling a single CPU among all the processes in the system  Key Criteria: Maximize CPU utilization Maximize throughput Minimize waiting.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
Process A program in execution. But, What does it mean to be “in execution”?
CE Operating Systems Lecture 7 Threads & Introduction to CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 7: CPU Scheduling Chapter 5.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 5 CPU Scheduling Slide 1 Chapter 5 CPU Scheduling.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Purpose of Operating System Part 2 Monil Adhikari.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
CPU Scheduling Operating Systems CS 550. Last Time Deadlock Detection and Recovery Methods to handle deadlock – Ignore it! – Detect and Recover – Avoidance.
Lecture 4 CPU scheduling. Basic Concepts Single Process  one process at a time Maximum CPU utilization obtained with multiprogramming CPU idle :waiting.
CPU Scheduling CS Introduction to Operating Systems.
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
CPU scheduling.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Scheduling.
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.
Processes and threads.
Chapter 5a: CPU Scheduling
Chapter 2 Scheduling.
Process management Information maintained by OS for process management
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
CPU scheduling decisions may take place when a process:
Process Scheduling Decide which process should run and for how long
Process Scheduling B.Ramamurthy 4/11/2019.
Process Scheduling B.Ramamurthy 4/7/2019.
Presentation transcript:

CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 9: Processes and Scheduling

Exam 1 on Wed Feb 19 Topics 1 – 6 C programming Program structure, process of building, gdb Unix system overview Regular expressions Unix tools Lex & Yacc (or Flex & Bison) Topic 7, part 1 Slides 1 to 19 Topic 8

Exam 1 on Wed Feb 19 Question types: Filling space True false Multiple choice Short answers

Processes A process is a program in execution A program may have multiple processes running the same program. E.g. csh running for multiple users or multiple times for the same user. Each process will be a different instance of the same program. All processes have a parent process except for the first process (init process 0). To list processes use ps - List processes of the current shell session ps –u - List processes owned by you ps –e - List all processes of the system

Example of ps command brastius 636 % ps -e PID TTY TIME CMD 0 ? 0:17 sched 1 ? 0:08 init 2 ? 0:00 pageout 3 ? 112:48 fsflush 317 ? 0:00 xdm 218 ? 0:01 cron 248 ? 0:00 sendmail 57 ? 0:00 sysevent 72 ? 0:00 picld 140 ? 0:20 in.route 153 ? 2:17 sshd 158 ? 0:43 rpcbind

States of a Process New ReadyRunning Waiting Terminated

States of a Process New Process is being initialized Ready The process is a candidate to run in the CPU but there is another process currently running Running The process is currently using the CPU. The number of running processes is less than or equal to the number of CPUs Waiting Process is waiting for an event Terminated Process is exiting

I/O and CPU Bound Process I/O bound processes Processes that are most of the time waiting for an event: mouse event, keyboard, Ethernet packet arrives etc. This typprocesses are in ready/running state only for a short period of time: E.g. update mouse cursor after mouse movement, show a character oe of processes are mostly in waiting state. These n the screen etc. CPU bound process: These processes need the CPU for long periods of time: Scientific/Numerical Applications, Compiler/Optimizer, Renderer, Image processing These processes are mostly in ready or running state Most applications are I/O bound

Process Table Each process will be represented with an entry in the process table. The Process Table is one of the most important data structures in the kernel. The maximum number of entries in the process table determines the maximum number of processes in the system and it is set at boot time.

Process Table Process ID (PID) MAX PID-1... Each Entry Includes: - PID: Index in process table -Command and args -Environment Vars -Current Dir -Owner (User ID) -Stdin/Stdout/Stderr -List of memory mappings used by process -PC (Program Counter) -Registers -Stack -List of Open Files -State (Wait, Ready, Running etc.)

Kernel Stacks Each process (and more generally each thread in a process) has a kernel stack When a process is executing a syscall like read, the kernel code needs to make function calls, and need a stack. This is different from the user-space stack The stack is empty when the process is running in user mode. In Linux, these kernel stacks are put in process table; other OSes handle this differently

Process Table Each process table entry contains enough information to restart (put in running state) a process that is waiting or in ready state. A process may have more than one thread. There is a stack, pc and a set of registers and state in the process table entry for each thread that the process has. (Linux)

Process Scheduling From the user’s point of view, an OS allows running multiple processes simultaneously. In reality, the OS runs one process after another to give the illusion that multiple processes run simultaneously. For single-core computers The Process Scheduler is the OS subsystem that runs one process after the other and decides what process to run next. A Context Switch is the procedure used by the OS to switch from one process to another

Process Scheduling Steps of a Context Switch Save current running process in process table Load next ready process from process table and put registers and PC in the CPU. Context Switches may happen as a result of: A process needs to go to wait state, and therefore, another process can be scheduled. A process yields (gives up) the CPU so another process can run. Timer interrupt ( Only for Preemptive Scheduling)

Types of Scheduling There are two types of scheduling: Non Preemptive Scheduling Preemptive Scheduling

Non Preemptive Scheduling In Non Preemptive Scheduling a context switch (switch from one process to another) happens only when the running process goes to a waiting state or when the process gives up the CPU voluntarily. This is a very primitive type of scheduling. It is also called cooperative scheduling. Expects all programs to “play nice”. It was used in Windows 3.1 and initial versions of MacOS. The main problem of Non Preemptive Scheduling is that a misbehaved process that loops forever may hold the CPU and prevent other processes from running.

Preemptive Scheduling In Preemptive Scheduling a context switch happens periodically (every 1/100sec or quantum time) as a result of a timer interrupt. A timer interrupt will cause a context switch, that is, the running process to go to ready state and the process that has been the longest in ready state will go to running state. Preemptive scheduling is implemented in UNIX, and Windows 95 and above.

Advantages/Disadvantages of Non Preemptive Scheduling Advantages of Non Preemptive Scheduling: More control on how the CPU is used. Simple to implement. Advantages of Preemptive scheduling: More robust, one process cannot monopolize the CPU Fairness. The OS makes sure that CPU usage is the same by all running process.

Scheduling Policies for Preemptive Scheduling Two policies: Round Robin Multilevel Feedback-Queue Scheduling Round Robin Ready processes are in a queue. Every time that a time quantum expires, a process is dequeued from the front of the queue and put in running state The previous running process is added to the end of the queue.

Round Robin Round Robin (cont.) (T=10ms) ProcessBurst Time p124ms p23ms p33ms 310 P3P1P2 Average completion time = ( )/3=19.6ms 3 P1 10 P1 4

Quantum Length Analysis What is the impact of quantum length? Assume T=10ms. ProcessBurst Time p120ms p21ms p31ms 110 P3P1P2 Average completion time = ( )/3=15ms 1 P1 10

Quantum Length Analysis What if we choose a smaller quantum length?Assume T=1ms. ProcessBurst Time p120ms p21ms p31ms 11 P3P1P2 Average completion time = (2+3+22)/3=9ms 1 P1 T=1ms P

Quantum Length Analysis The shorter the quantum, the shorter the average completion time. Based on this we could make the quantum time very small to achieve faster response time. What is the catch? We are not considering that context switch takes time. We have to consider the context switch overhead.

Context Switch Overhead The context switch overhead is the time it takes to do a context switch as a portion of the quantum time. Xoverhd% = 100*X/T where Xoverhd% = Context Switch Overhead X = Context Switch Time T = Quantum Time. Assume X=.1ms. For T=10ms Ovhd=100*.1/10=1% For T=2ms Ovhd=100*.1/2=5% For T=.2ms Ovhd=100*.1/.2=50%

Context Switch Overhead Conclusions: The smaller the quantum, the faster the response time (small average completion time) but the larger the context switch overhead. The larger the quantum the smaller the context switch overhead but the larger the response (large average completion time). The standard quantum time is 1/100sec = 10ms that is a compromise between response time and context switch overhead. This may change in the future with faster processors.

CPU Burst Distribution Processes are in waiting state most of the time except for the times they need the CPU, that is usually for short periods of time. These shorts periods of time the processes need the CPU are called CPU bursts. % Distribution of CPU Bursts 10ms 90% 10% CPU burst (ms)

CPU Burst Distribution 90% of CPU bursts are smaller than 10ms. By choosing 10ms to be the quantum length, we make sure that 90% of the CPU burst run until completion without being preempted. This reduces the context switch overhead and reduces the completion time and makes the response time faster.

How to Choose the Size of a Quantum Make the quantum small enough to make the response time smaller (faster). Make the quantum large enough to have an acceptable context switch overhead. Make the quantum large enough so most CPU bursts are able to finish without being preempted.

Scheduling Policies for Preemptive Scheduling Multilevel Feedback-Queue Scheduling Instead of a having a single queue of ready processes, there are multiple queues of different priorities. The scheduler will schedule the ready processes with the highest priority first. Within processes of the same priority round robin is used.

Multilevel Feedback-Queue Scheduling Problem: If you have processes of higher priority, low priority processes will never run. Solution: Use Process Aging: The longer a process stays in a queue, the priority is artificially increased. The process will be scheduled at some point. After that, the priority is reset to the initial priority. Also, the scheduler benefits interactive processes by increasing their priority if they finish before the quantum expires. It also decreases priority if the quantum expires before the burst finishes. The smaller the CPU burst estimate, the higher the priority. The larger the CPU burst estimate the lower priority.

Multilevel Feedback-Queue Scheduling P1P6P7 P2P5P8 Priority 10 9 P3P4P98 P10P11P127 Small CPU Burst. Increase priority Large CPU Burst. Decrease priority

Review Questions What are the 5 states of processes? What causes the transitions between the states? What are i/o-bound and cpu-bound processes? What is a context switch? What may cause a context switch? What are non-preemptive scheduling and preemptive scheduling? What are the pros & cons of each? Which one is used in modern OS?

Review Questions How does the round robin scheduling work? How to compute response time and overhead for a given quantum length. How response time and overhead are affected by quantum length? What are factors for choosing quantum length? Response time, overhead, CPU burst distribution What is Multilevel Feedback-Queue Scheduling? Key idea: use multiple priority queues, reward processes with smaller CPU burst