Introduction to CPU Schedulingosdc.hanyang.ac.kr/.../1_Introduction_to_CPU_Scheduling.pdf ·...
Transcript of Introduction to CPU Schedulingosdc.hanyang.ac.kr/.../1_Introduction_to_CPU_Scheduling.pdf ·...
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Introduction to CPU Scheduling
Hanyang University
Hyunmin Yoon
2
2
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Process 1 3 Page
Scheduling 2 11 Page
Q & A 3 25 Page
3
3
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
This document is based-on linux 3.17.4 version (released at 2014.11.21)
1st revision by Minsoo Ryu, 2014.06. 2nd revision by Hyunmin Yoon, 2014.12.
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Process
5
5
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Process and Thread
Process Internal programmed activities, such as memory management Program ≠ Process
• Program is a passive entity ex) A file containing a list of instructions stored on disk
• Process is an active entity ex) Program counter, a set of associated resources
Program becomes a process when an executable file is loaded into memory
Thread
A thread is an instruction stream of execution Some modern operating systems support multi-thread for
one process • However, a thread is just a special kind of process in Linux
6
6
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Process and Thread in Linux
User’s View
Kernel’s View
Process Thread Thread Process
State
Process State Thread Thread
Process
Process
7
7
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Process States
Three key states running: Instructions are being executed. waiting: The process is waiting for some event to occur
(I/O completion, signal reception). ready: The process is waiting to be assigned to a process.
(Wiley, Operating System Concepts 8th Edition)
8
8
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
State Transitions
(Wiley, Operating System Concepts 8th Edition)
9
9
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Linux Process States
(Robert Love, Linux Kernel Development 3rd Edition)
10
10
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Linux Process State Flags
Flags Description
TASK_RUNNING The process is runnable; it is either currently running or on a runqueue waiting to run.
TASK_INTERRUPTIBLE
The process is sleeping, waiting for some condition to exist. When this condition exists, the kernel sets the process’s state to TASK_RUNNING. The process also awakes prematurely and becomes runnable if it receives a signal.
TASK_UNINTERRUPTIBLE
This state is identical to TASK_INTERRUPTIBLE except that it does not wake up and become runnable if it receives a signal.
11
11
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Linux Process Descriptor
It is an element of the task list It has type struct task_struct
struct task_struct is defined in <linux/shched.h>
It contains all the information that the kernel has and needs about a process
(Robert Love, Linux Kernel Development 3rd Edition)
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Scheduling
13
13
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Scheduling Criteria
Performance objectives Maximize CPU utilization or throughput Minimize completion time, waiting time, or response time
Real-time constraints Satisfy deadlines
Proportional share constraints Provide CPU cycles proportional to weights
14
14
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Classification of Scheduling Policies
Scheduling mechanisms Priority-based scheduling Proportional share scheduling
Target processors Uniprocessor scheduling Multiprocessor scheduling
15
15
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Priority-Based 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) Preemptive Nonpreemptive
Task A (priority 1)
Task B (priority 2) Task C (priority 3) Task D (priority 4) time
16
16
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Priority-Based Scheduling Policies
Non-real-time policies FCFS (First-Come, First-Served) SJF (Shortest-Job-First) SRTF (Shortest-Remaining-Time-First)
Real-time policies
RM (Rate Monotonic) EDF (Earliest Deadline First)
17
17
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
FCFS (First-Come, First-Served)
Process Execution Time P1 24 P2 3 P3 3
Suppose that 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: (0 + 24 + 27)/3 = 17
P1 P2 P3
24 27 30 0
18
18
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Proportional Share Scheduling
Basic concept A weight value is associated with each process The CPU is allocated to the process in proportion to its
weight
Two contexts Fair queueing (in the context of communication networks)
• Packet scheduling Proportional share (in the context of operating systems)
• Process scheduling
time
Task A (weight 25.0%)
Task B (weight 12.5%) Task C (weight 50.0%) Task D (weight 12.5%)
19
19
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Proportional Share Scheduling Algorithms
Network scheduling PGPS (= WFQ), Demers et al., 1989 Virtual Clock, Lixia Zhang, 1990 SCFQ, Golestani, 1994 SFQ, Goyal et al., 1996 WF2Q, Bennett et al., 1996
CPU scheduling
Lottery and Stride, Waldspurger, 1995 Hierarchical SFQ, Goyal et al., 1996 BVT, Duda et al., 1999 VTRR, Nieh et al., 2001
20
20
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Uniprocessor vs. Multiprocessor Scheduling
Uniprocessor scheduling It is to decide when and which job will run
Multiprocessor scheduling It is to decide not only when but also where a job will run Almost the same goals as those of uniprocessor
scheduling But it raises new issues
• How to assign applications to multiple processors? • How to balance workload among processors? • How to define and exploit affinity? • How to manage processor heterogeneity?
21
21
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Multiprocessor Scheduling Policies
The same mechanisms as uniprocessor policies Priority-based scheduling: FCFS, SJF, SRTF, RM, EDF Proportional share scheduling: PGPS, SFQ, WF2Q, Lottery
and Stride, BVT, VTRR
Two approaches Global scheduling
• The system has a single global process queue • Processes are dispatched to any available processors
Partitioned scheduling • Each processor has a separate process queue • Each queue is scheduled by an independent scheduler • Process migration may be allowed or not
22
22
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Global vs. Partitioned Scheduling
Global Scheduling Partitioned Scheduling
23
23
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Global vs. Partitioned Scheduling
Global scheduling It is generally believed that global scheduling can achieve
better performance However, it can be inefficient due to the contention at the
single queue and increased cache misses
Partitioned scheduling Performance can vary depending on the initial distribution
of processes, i.e., a bin-packing problem Different scheduling policies can be employed across
processors We can use the rich and extensive results from the
uniprocessor scheduling theory
24
24
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Global WFQ
Consider the following tasks Process A : weight = 1 Process B : weight = 2 Process C : weight = 2 Process D : weight = 4
CPU #1
CPU #2
25
25
Real-Time Computing and Communications Lab. Hanyang University
어코드 사업단 “리눅스 CFS와 로드밸런서” 교육 January, 2015
Partitioned WFQ with Load Balancing
Consider the following tasks Process A : weight = 1 Process B : weight = 2 Process C : weight = 2 Process D : weight = 4
CPU #1 (A, D)
CPU #2 (B, C)
migrate migrate migrate