Hanbat National Univ. Computer Eng. Dept. Y.J.Kim © 2009 Operating System Concepts – 8th Edition,
Chapter 5: CPU Scheduling
2/50 Operating System Concepts – 7th Edition
Chapter 5: Process Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Thread Scheduling
Multiple-Processor Scheduling
Operating Systems Examples
Algorithm Evaluation
3/50 Operating System Concepts – 7th Edition
Objectives
멀티프로그래밍 OS의 기본이 되는 process scheduling의 개념
각종 process-scheduling algorithm
이상적인 알고리즘은?
process-scheduling algorithm을 선전하기 위한 평가 방법
4/50 Operating System Concepts – 7th Edition
Basic Concepts
• 프로세스 스케줄링
• 장기 job scheduling , 단기 CPU scheduling, 중기 swapping
• CPU-I/O 버스트 주기(burst cycle)
» cycle : CPU 실행(CPU burst) I/O 대기(I/O burst)
» CPU burst 유형
• I/O bound program : 많은 짧은 CPU burst 가짐
• CPU bound program : 적은 아주 긴 CPU burst 가짐
• CPU 스케줄러
» 단기 스케줄러(short-term scheduler) : ready queue에서 선택
FIFO(First-In First-Out)큐
우선순위 큐, 트리 , 연결리스트
• Burst
• CPU Burst : Time it takes for the CPU to execute an operation
• I/O Burst : Time it takes for the CPU to wait for I/O task
• Goal of processor scheduling :
Maximum CPU utilization obtained with multiprogramming
5/50 Operating System Concepts – 7th Edition
CPU burst vs. IO burst
(a) A CPU-bound process
(b) An I/O-bound process
5
6/50 Operating System Concepts – 7th Edition
Alternating Sequence of CPU And I/O Bursts
7/50 Operating System Concepts – 7th Edition
Histogram of CPU-burst Times
8/50 Operating System Concepts – 7th Edition
CPU스케줄링(CPU Scheduling)
CPU scheduling란 대기중인 프로세스들ㄷ중에서 하나를 선택하고 CPU를 할당하는 절차
선점/비선점 스케줄링(Preemptive/Non-Preemptive Scheduling)
선점(preemptive) 스케줄링
특수하드웨어(timer)필요 , 공유 데이터에 대한 프로세스 동기화 필요
Windows95~, MacxOS8(Power PC)~
비선점(non preemptive) 또는 협조적(cooperative) 스케줄링
MS-Windows, 특수 하드웨어(timer) 없음 , 종료 또는 I/O까지 계속 CPU점유
~Windows 3.x, ~MacOS8 이전 버전
Kernel의 선점 처리
case 1(초기 Unix) : system call 완료 또는 I/O 완료할 때 까지 기다렸다가 문맥교환
실시간 컴퓨팅, 멀티프로세싱에 나쁨
case 2(대부분의 Unix) : interrupt 중 다른 interrupt enable(우선순위에 따라) 선점 처리
critical section(공유 데이터 수정하는 코드 부분)에 있는 동안 interrupt disable 해야 함
CPU scheduling decision time
1. running waiting : non preemptive
2. running ready (interrupt) : preemptive
3. waiting ready (I/O 완료) : preemptive
4. halt : non preemptive
9/50 Operating System Concepts – 7th Edition
CPU스케줄링(CPU Scheduling)
분배기(Dispatcher) : 단기 스케줄러가 선택한 프로세스에서 CPU의 제어을
넘기고 다음의 작업을 담당한다.
문맥 교환
사용자 모드로 전환
프로그램의 적절한 위치로 점프하여 프로그램 재시작
• dispatch latency(분배기가 한프로세스를 종료시키고 다음 프로세스를 실행
시킬 때까지의 시간)가 짧아야 함
Scheduling Criteria
• 이용률(CPU utilization) : 40% ~ 90%
• 처리율(throughput) : 처리된 프로세스 개수/시갂 단위
• 반환시갂(turnaround time) : 프로세스가 system in system out 걸린 시갂
• 대기시갂(waiting time) : ready queue에서 기다린 시갂
• 응답시갂(response time) : 대화형 시스템에서 첫 응답까지의 시갂
10/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
척도 : 평균 대기 시간(average waiting time)
단일 프로세서 알고리즘
1. 선입 선처리(First-Come, First-Served) 스케줄링
2. 최소 작업 우선(Shortest-Job-First) 스케줄링
3. 우선순위(Priority) 스케줄링
4. 순환 할당(Round-Robin) 스케줄링
5. 다단계 큐(Multilevel Queue) 스케줄링
6. 다단계 귀환 큐(Multilevel Feedback Queue) 스케줄링
스레드 스케줄링(Thread scheduling)
다중 프로세서 스케줄링(Multiple-Processor Scheduling)
실시간 스케줄링
EDF (Earliest Deadline First)
Rate Monotonic
Rate Monotonic vs. EDF
실례 :
Solaris 2 Scheduling,
Windows XP Scheduling,
Linux Scheduling
11/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
1. 선입 선처리(First-Come, First-Served) 스케줄링
들어온 순서대로 처리, e.g. supermarket, bank tellers, McDonalds, etc
FIFO queue : First-in tail, First-out head
호위 효과(convoy effect) : 큰 job 하나가 끝나기를 모두 기다림 (CPU-
bound process가 끝나기를 I/O bounded process들이 기다림)
non-preemptive임(time-sharing에서는 곤란)
Jobs are treated equally: no starvation
12/50 Operating System Concepts – 7th Edition
예)First-Come, First-Served (FCFS) Scheduling
예 1 FCFS:
Process Burst Time
P1 24
P2 3
P3 3
프로세스들이 P1 , P2 , P3 순으로 도착한다면
스케줄을 위한 트 차트(Gantt Chart):
대기시간(Waiting time) for P1 = 0; P2 = 24; P3 = 27
평균대기시간(Average waiting time): (0 + 24 + 27)/3 = 17
P1 P2 P3
24 27 30 0
13/50 Operating System Concepts – 7th Edition
FCFS Scheduling (Cont)
예2)
프로세스 도착 순서가 P2 , P3 , P1 이면
스케줄을 위한 간트 차트(Gantt chart)는:
대기시간(waiting time) for P1 = 6; P2 = 0; P3 = 3
평균대기시간(average waiting time): (6 + 0 + 3)/3 = 3
Much better than previous case!
호위효과(Convoy effect): short process behind long process
P1 P3 P2
6 3 30 0
14/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
2. 최소 작업 우선(Shortest-Job-First) 스케줄링
Shortest Next CPU Burst Scheduling
다음 CPU burst 시간이 가장 짧은 프로세스를 먼저 실행 시킨다.
두 가지 스케줄링 기법
non-preemptive SJF
preemptive SJF = Shortest Remaining Time First Scheduling
최적(Optimal)
단점 : 기아 상태(starvation)
long-term scheduling에 좋음 프로세스 시간의 사용자 예측 치 이용
short-term scheduling에는 덜 좋음 차기 CPU burst 시간 파악이 어려워서
차기 CPU 버스트 시간 예측 모델
HRN(Highest-Response-ratio Next) 스케줄링
1971 Brinch Hansen
SJF의 단점 보완
dynamic priority = (time waiting + service time) / (service time)
오래 기다린 프로세스는 time waiting이 증가하므로 priority 커지고
short process일수록 priority 커짐
non-preemptive 였음
15/50 Operating System Concepts – 7th Edition
비선점형 SJF(Example of Non-Preemptive SJF)
예 NP-SJF
SJF (non-preemptive)
Average waiting time = (0 + 6 + 3 + 7)/4 = 4 P1 0=0-0 P2:8-2.0=6 P3:7-4.0=3 P4:12-5.0=7 0: P1(7) =>P1(7) p1(7) ~ 7:P2(4),P3(1),P4(4) => P3(1) p3(1) ~ 8: P2(4),P4(4) =>P2(4) p2(4) ~ 12:P4(4)=>P4(4) p4(4) ~ 16 15
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
16/50 Operating System Concepts – 7th Edition
선점형 SJF(Example of Preemptive SJF)
예 P SJF
SJF (preemptive) (= SRTF)
Average waiting time = (9 + 1 + 0 +2)/4 = 3 P1:0-0 + 11-2=9 P2:2-2.0 + 5-4=1 P3=4-4.0=0 P4:7-5=2 0 : P1(7) =P1(7) P1(7) ~ 2.0 p2(4) : P1(5) , p2(4) => p2(4) P2(4) ~ 4.0 p3(1) : p1(5), p2(2), p3(1) => p3(1) P3(1) ~ 5.0 p4(4) : p1(5),P2(2), p4(4) =>P2(2) P2(2) ~ 7.0 : p1(5),P4(4) =>P4(4) p4(4) ~ 11.0 : P1(5) =>P1(5) p1(5) ~ 16.0 :
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
17/50 Operating System Concepts – 7th Edition
(예) SJF 스케줄링
연습문제 non-preemptive / preemptive SJF
프로세스들이 P1 , P2 , P3 순으로 도착한다면
스케줄을 위한 간트 차트(Gantt Chart) ?
대기시간(Waiting time) for P1 = ; P2 = ; P3 =
평균대기시간(Average waiting time): ( + + )/3 =
Process Burst Time
P1 24
P2 3
P3 2
0
18/50 Operating System Concepts – 7th Edition
Determining Length of Next CPU Burst
다음의 CPU burst 시간을 예측
이전 CPU 버스트 시간들의 지수적 편균(exponential averaging)으로 예측
가능
.1 1 nnn t :Define 4.
10 , 3.
burst CPUnext for the valuepredicted 2.
burst CPU oflength actual 1.
1
n
th
n nt
19/50 Operating System Concepts – 7th Edition
Prediction of the Length of the Next CPU Burst
66*5.06*5.01
68*5.04*5.01
810*5.06*5.01
6 ,5.0,10
223
112
001
00
t
t
t
t
20/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
3. 우선 순위(priority) 스케줄링
높은 우선 순위의 프로세스를 먼저
ready queue : priority queue
FCFS : equal priority(non-priority)
SJF : priority : Preemptive ,nonpreemptive
proirity 에 영향을 미치는 OS 내부요인
시간제한(time limit), 메모리 요구량,오픈화일수,(average I/O
burst)/(average CPU burst) 비율등
proirity 에 영향을 미치는 OS 외부요인
프로세스의 중요도, 컴퓨터사용료 형태와 금액,
작업부서,정치적요인등
무한정지(blocking) 또는 기아상태(starvation)
Aging : 재기시간이 길어지면 우선순위를 높여준다.
P184 예제
21/50 Operating System Concepts – 7th Edition
Priority Scheduling
Abstractly modeled as multiple “priority queues”
Put ready job on Queue associated with its priority
22/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
4. 순환할당(Round Robin,RR) 스케줄링
FCFS +preemptive scheduling
circular ready queue (FIFO)
time quantum : 프로세스가 cpu를 사용하느시간 보통 10-100 milliseconds.
Performance
quantum -> : FIFO
quantum -> 0 : processor sharing
If small, then context switches are frequent incurring high overhead
(CPU utilization drops)
If large, then response time drops
A rule of thumb: 80% of the CPU bursts should be shorter than the time
quantum
23/50 Operating System Concepts – 7th Edition
Example of RR with Time Quantum = 4
Process Burst Time
P1 24
P2 3
P3 3
The Gantt chart is:
평균대기시간(average waiting time): (?+?+?) / 3 = ?
평균반환시간(average turnaround) : (30+7+10) / 3 = 15.6
일반적으로 SJF보다 평균반환시간(average turnaround)은 길지만 응답시간(response time)은 짧다. queue : p1(24),p2(3),p3(3) 0 : p1(24) : p2(3),p3(3) timer 4:p2(3) : p3(3),p1(20) release 7 : p3(3) : p1(20), release 10:p1(20) : timer 14:p1(16): timer 18:p1(12): timer 22:p1(8): timer 26:p1(4): timer 30: * lease :non-preempted, timer : preempted
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
24/50 Operating System Concepts – 7th Edition
(예) RR with Time Quantum = 20
예) RR
Process Burst Time
P1 53
P2 17
P3 68
P4 24
The Gantt chart is:
평균대기시간(average waiting time) = ( ? + ? + ? + ? )/4 = ?
평균반환시간( average turnaround) = ( ? + ? + ? + ? )/4 = ?
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
25/50 Operating System Concepts – 7th Edition
Time Quantum and Context Switch Time
26/50 Operating System Concepts – 7th Edition
Turnaround Time Varies With The Time Quantum
At Q2=5 , turnaround time=?+?+?+?=12.7
27/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
5. 다단계 큐(Multilevel Queue) 스케줄링
각 프로세스는 우선 순위가 다른 여러 개의 큐 중 하나에 영원히 할당
(그림 5.6)
각 queue는 자싞의 고유한 scheduling algorithm 가짐
foreground (interactive) queue : RR알고리즘
background (batch) queue : FCFS알고리즘
queue들 사이의 scheduling : 고정 우선 순위 선점 스케줄링(fixed priority
preemptive scheduling)
큐 사이의 CPU time slice 할당 예
80% for RR
20% for FCFS
스케줄링 부담 적으나 융통성이 적음
28/50 Operating System Concepts – 7th Edition
Multilevel Queue Scheduling(Fig.5.6)
29/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
6. 다단계 피드백 큐(Multilevel Feedback Queue) 스케줄링
프로세스가 여러 큐 사이를 이동 (그림 5.7)
짧은 프로세스(I/O bound, interactive processes)가 우선
긴 프로세스는 자꾸 낮은 큐로 이동
aging(오래 기다리면 우선순위 높여 기아 상태 예방)
preemptive 임(큐 사이)
the most sophisticated, the most complex
가장 일반적 => 해당 시스템에 맞게 설정해야(configure)
큐의 개수
각 큐의 스케줄링 알고리즘
높은 우선 순위로 올려 주는 시기
낮은 우선 순위로 내려 주는 시기
어느 큐에 들어갈 것인가
30/50 Operating System Concepts – 7th Edition
Scheduling Algorithm
Three queues:
Q0 – time quantum 8 milliseconds
Q1 – time quantum 16 milliseconds
Q2 – FCFS
Scheduling
FCFS queue Q0 에 새로 들어온 작업이 8 milliseconds 동안 CPU를 받고도 작업이
끝나지 않으면 선점되어 queue Q1으로 이동
Q1의 작업은 FCFS로 16 additional milliseconds을 받고 그래도 끝나지 않으면
선점되어 queue Q2로 이동
31/50 Operating System Concepts – 7th Edition
Thread Scheduling 2 스레드 지원 수준
User level: process local scheduling
threads library가 사용 가능한 LWP에 thread를 할당 (실제로 CPU 차지했다는 뜻 아님)
Kernel level: system global scheduling
kernel이 다음 실행할 kernel thread를 결정 (CPU 차지)
pthread scheduling
프로세스-경쟁-범위(process-contention scope; PCS): pthread library가 사용 가능한 LWP에
user-level thread 할당, CPU 차지하기 위한 투쟁이 한 프로세스 내에서 일어남
PTHREAD_SCOPE_PROCESS
many-to-many mapping
시스템-경쟁-범위(system-contention scope; SCS): kernel이 CPU 차지할 kernel thread 결정,
CPU 차지 위한 투쟁이 전체 시스템에서 일어남 (Linux, Mac OS는 시스템-경쟁-범위만 지원)
PTHREAD_SCOPE_SYSTEM
one-to-one mapping
pthread IPC
pthread_attr_setscope(pthread_attr-t *attr, int scope)
pthread_attr_getscope(pthread_attr-t *attr, int *scope)
스레드 매핑 모델별 적용
many-to-many 또는 many-to-one: PCS & SCS
one-to-one: SCS맊 사용 (Linux, Windows XP, Solaris 9)
32/50 Operating System Concepts – 7th Edition
Pthread Scheduling API for POSIX
#include <pthread.h>
#include <stdio.h>
#define NUM THREADS 5
int main(int argc, char *argv[])
{
int I, scope;
pthread_t tid[NUM THREADS];
pthread_attr_t attr;
/* get the default attributes */
pthread_attr_init(&attr); /* first inquire on the current scope */ if (pthread_attr_getscope(&attr, &scope) != 0) printf(stderr, “Unable to get scheduling scope\n”); else { if (scope == PTHREAD_SCOPE_PROCESS) pritnf(“PTHREAD_SCOPE_PROCESS”); else if (scope == PTHREAD_SCOPE_SYSTEM) pritnf(“PTHREAD_SCOPE_SYSTEM”); else printf(stderr,”Illegal scope value.\n”); }
/* set the scheduling algorithm to PCS(PROCESS) or (SCS)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);
/* 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)
{
/* do some work */
printf("I am a thread\n");
pthread exit(0);
}
33/50 Operating System Concepts – 7th Edition
다중프로세서 스케줄링(Multiple-Processor Scheduling)
동종 다중 프로세서(homogeneous multiprocessor)
프로세서는 큐에 있는 어떤 프로세스(any processes)든 실행: 부하 공유(load sharing)
별도 준비 큐(separate ready queue): unfair SMP 경우 load balancing 필요할까?
공동 준비 큐(common ready queue): fair SMP 경우 load balancing 필요할까?
AMP(Asymmetric Multiprocessing): 비대칭적 스케줄링 (asymmetric scheduling)
한 프로세서(master)가 다른 프로세서(slaves) 스케줄링
– master server : all system activity, client processors: user code only
master만 kernel system data structure에 접근 가능
– 공유 자료구조 접근 동기화 필요 없어 처리가 간단
SMP(Symmetric Multiprocessing): 대칭적 스케줄링 (symmetric scheduling)
각 프로세서가 스스로 스케줄링(self-scheduling)
공유 자료구조 접근에 대한 세심한 처리 필요
대부분의 현대 OS가 지원: Windows XP, Windows 2000, Solaris, Linux, Max OS X
처리기 친근성(processor affinity): 한 프로세서에서 작업하면 cash hit-ratio 높아져 효율적
약한 친화성(soft affinity): 친근 노력하나 프로세스 이주(process migration) 발생 가능
강한 친화성(hard affinity): 절대 친근 보장, 이주 불허도 가능 (예, Linux에서 시스템
호출로 요청)
부하 균형(load balancing): 별도 준비 큐 경우 일 부담의 균등 분배
push migration: 과부하 프로세서가 자신의 프로세스를 노는 프로세서로 이주시킴
pull migration: 노는 프로세서가 바쁜 프로세서에서 대기 중인 프로세스를 끌어옴
– Linux scheduler는 push & pull 모두 지원
이종 다중 프로세서(heterogeneous multiprocessor) = 분산 시스템
컴파일된 프로세스들의 기계어가 실행하고자 하는 프로세서의 기계어와 동일한 경우만
실행 가능
34/50 Operating System Concepts – 7th Edition
다중프로세서 스케줄링(Multiple-Processor Scheduling)
Symmetric multithreading(SMT)
Hyperthreading technology in Intel company
OS offers logical processor to each thread
35/50 Operating System Concepts – 7th Edition
다중프로세서 스케줄링(Multiple-Processor Scheduling)
SMP(Symmetric Multiprocessing) Architecture
36/50 Operating System Concepts – 7th Edition
다중프로세서 스케줄링(Multiple-Processor Scheduling)
NUMA (Non-Uniform Memory Access and CPU Scheduling
같은 보드에 있는 CPU의 메모리 접근시갂이 더 적은 경우 강한 친화성(affinity)
37/50 Operating System Concepts – 7th Edition
다중프로세서 스케줄링(Multiple-Processor Scheduling)
멀티코어 프로세서 (Multicore Processors)
최근 추세는 하나의 칩에 다수의 프로세서를 위치시킴
빠르고 파워 소모 적음
각 코어가 독자적으로 다중 스레드 처리하는 추세
멀티스레디드 프로세서 코어(multithreaded processor cores)
메모리의 데이터가 사용 가능할 때까지 상당한 메모리 지연(memory stall) 시간이 있음을
발견, 하나의 코어에 2개 이상의 하드웨어 스레드를 할당하여 메모리 지연시간을 최대한
활용
Intel Itanium: dual-threaded dual-core system = 4 logical processors,
urgency(0~7) hardware thread scheduling
UltraSPARC T1 CPU: 8 cores * 4 hardware threads per core = 32 logical processors,
simple RR hardware thread scheduling
Memory stall (fig.5.10) Multithread multicore system(Fig. 5.11)
38/50 Operating System Concepts – 7th Edition
다중프로세서 스케줄링(Multiple-Processor Scheduling)
A Dual-Core Design
39/50 Operating System Concepts – 7th Edition
운영체제사례(Operating System Examples)
사례
Solaris scheduling ,Windows XP scheduling, Linux scheduling
Solaris 2 scheduling 우선순위 기반 스레드 스케줄링(priority-based process scheduling)
6 classes (OSC version 8)
(TS)시분할(time sharing): default class
– multi-level feedback queue scheduling
– 우선순위가 높을수록, time slice(20ms) 작고, 우선순위가 낮을수록 time slice(200ms) 큼
– CPU-bound processes 우선순위 낮아짐
– sleep에서 복귀한 스레드는 높은 우선순위
(IA)대화형(interactive)
– multi-level feedback queue scheduling
– windowing application에 높은 우선순위
(RT) 실시간(real time): 최상위 우선순위
(SYS)시스템(system): 우선순위 결정된 후 불변
(FSS)공평 공유(fair share): CPU 공유량을 기준으로 스케줄
(FP) 고정우선순위(fixed priority): 시분할 스레드와 같은 우선순위이나 고정
Scheduler가 class-specific priorities를 global priorities로 변환
우선순위 같을 때는 round-robin
수행 중인 thread가 멈추는 경우
blocks
time slice 완료
더 높은 우선순위의 thread가 선점(preempt)
40/50 Operating System Concepts – 7th Edition
Solaris 2 Scheduling
41/50 Operating System Concepts – 7th Edition
Solaris 2 Scheduling
(ms)
Low high
= 대화형과 시분할 스레드를 위한 Solaris 디스패치 테이블 (Solaris Dispatch Table for time-sharing and interactive threads)
※ Solaris & Windows XP: 높은 우선순위 프로세스에 짧은 time quantum 할당
42/50 Operating System Concepts – 7th Edition
• 32-level priority scheme • 0: memory management • 1~15: variable class • 16~31: real-time class
• 각 우선순위마다 하나의 큐 가짐 (a queue for each scheduling priority) • idle thread: ready thread 없을 때 dispatcher가 실행 • 보통 NORMAL_PRIORITY_CLASS, base priority=normal • 1 time quantum 받은 후 우선순위 낮아짐 • 대화형 스레드(interactive threads )에 좋은 응답시갂 (response times) 제공
» priority boost(인상): keybord I/O boost > disk I/O boost » 스크린에서 활성화된 전위 프로세스(foreground process)에게 활성화되지 않은 후위
프로세스(background process)보다 3배 많은 time quantum 부여
Windows XP Scheduling
priority class→
relative priority↓
base priority=normal
불변 가변 가변 가변 가변 가변
Windows XP Priorities
43/50 Operating System Concepts – 7th Edition
Windows Thread Scheduling Example(c#)
Thread.Proity Property Example
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
System.Threading.ThreadPriority public enum ThreadPriority {Lowest,BelowNormal,Normal,AboveNoraml,Higest}
Thread T = new Thread(new ThreadStart(p.method));
T.Priority = ThreaPriority.BelowNormal;
T.Start();
예제 시나리오
쓰레드 생성
– T1 :Normal Priority,
– T2 : Below Normal Priority
두 프로세스가 동시에 정수를 세게하고 10초 후에 정지시키고
센 수를 점검하여 T1의 수가 더 큰지를 점검한다.
즉 Thread Scheduling에 의하여 우선순위가 높은 Thread가 더 많이 CPU를
사용을 배정하여 더 셀수 있었는지를 검증
44/50 Operating System Concepts – 7th Edition
Windows Thread Scheduling Example(c#)
static void Main() { PriorityTest p = new PriorityTest(); Thread T1=new ThreadStart(p.ThreadMethod); Thread T2=new ThreadStart(p.ThreadMethod);
T1.Name=“ThreaOne”; //T1 : Normal Prioty T2.Name=“ThreadTwo; T2.Prioty = ThreaPrioty.BelowNormal; T1.Start(); T2.Start(); Thread.Sleep(10000); p.LoopSwitch.false;
class P { bool loopSwitch; public P() { loopSwitch = true; } public bool LoopSwitch { set{ loopSwitch = value; } } public void ThreadMethod() { long threadCount = 0; while(loopSwitch) { threadCount++; } Console.WriteLine( "{0} with {1,11} priority has a count = {2,13}", Thread.CurrentThread.Name, Thread.CurrentThread.Priority.ToString(), threadCount.ToString("N0"));
} } 실행 결과
45/50 Operating System Concepts – 7th Edition
Linux Scheduling (Linux kernel 2.5)
Linux kernel version 2.5 이후
SMP 지원 향상: processor affinity, load balancing
공평 몫 스케줄링 (fair-share scheduling) 지원
interactive task 지원
Linux scheduler: preemptive, priority-based algorithm
2 priority ranges: 낮은 값이 높은 우선순위
real-time tasks: 0~99
other tasks (nice): 100~140
긴 sleep time (interactive): nice value -5
짧은 sleep time (CPU-bound): nice value +5
높은 우선순위 프로세스에 긴 time-quantum 할당 (Solaris, Windows XP 등 대부분
OS와 다름)
각 프로세서는 자신의 runqueue (active array, expired array) 유지
active: time quantum 남은 프로세스
expired: time quantum 소진한 프로세스
한번 time quantum 받은 프로세스는 expired queue로 이동
active array의 모든 프로세스들이 time quantum 소진하면, 두 array 교환
46/50 Operating System Concepts – 7th Edition
Linux Scheduling (Linux kernel 2.5)
Priorities and Time-slice length
Constant order O(1) scheduling time
Two priority ranges: time-sharing and real-time
Real-time range from 0 to 99 and nice value from 100 to 140
47/50 Operating System Concepts – 7th Edition
Linux Scheduling (Linux kernel 2.5)
우선순위에 따라 인덱스 된 태스크 리스트 (List of Tasks Indexed According to Priorities)
48/50 Operating System Concepts – 7th Edition
알고리즘 평가(Algorithm Evaluation)
결정성 모형화(Deterministic Modeling)
작업부하(workload)에 따른 성능 비교 : 5.7.1절 예제(p205-206) 꼭 보세요!!!
반환시간
대기시간 등
CPU 버스트 시간 등 많은 정확한 정보 요구
큐잉 모형(Queueing Models)
CPU-I/O 버스트 뿐 아니라 프로세스 도착시간의 분포도 평가에 고려해야
도착율과 서비스율 알면 이용율, 평균 큐 길이, 평균대기시간 알 수 있음
Little의 공식 : n = x W (평균 큐 길이) = (도착 율) x (평균대기 시간) (예) 초당 평균 7개 프로세스가 도착하고, 큐에 평균 14개 프로세스가 있다면, 평균대기시간은 2초
모든 경우에 적용가능하나 근사치일 뿐
모의 실험(Simulations)
소프트웨어 자료구조로 clock variable, system state variables등 표현하고 통계
사건 분포는 수학적(균일, 지수, 포아송), 또는 경험적으로 정의
사건 생성 순서 정보 제공 위해 trace tapes 이용
정확하나 비용이 많이 듬
구현(Implementation)
가장 정확하나 비용 많고 사용자 적응이 문제
가장 융통성 있는 스케줄링 알고리즘(flexible scheduling algorithm)
tunable scheduling
• 시스템 관리자가 응용 영역에 따라 스케줄러 변수들을 변경할 수 있음
» 몇몇 Unix 버전에서 세밀한 tuning 가능
• Yield() 나 setPriority() API 이용하여 응용의 동작 예측 가능하게 함
49/50 Operating System Concepts – 7th Edition
알고리즘 평가(Algorithm Evaluation)
Evaluation of CPU schedulers by Simulation
50/50 Operating System Concepts – 7th Edition
알고리즘 평가(Algorithm Evaluation)
Deterministic modeling 예(p205)
Process : p1 p2 p3 p4 p5
Burst time(ms) : 10 29 3 7 12
FCFS scheduling algorithm
Averaging waiting time : (10+39+42+49)/5 = 28 ms
SJF scheduling algorithm(p 205)
Averaging waiting time : (10 + 32+0+3+20)/5=13 ms
51/50 Operating System Concepts – 7th Edition
알고리즘 평가(Algorithm Evaluation)
Deterministic modeling 예(p206)
Process : p1 p2 p3 p4 p5
Burst time(ms) : 10 29 3 7 12
RR at time quantum = 10ms
Averaging waiting time : (0+32+20+23+40)/5 = 23 ms
p1 : 0
p2 : 10+20+2 =32
p3 : 20
p4 : 23
p5 : 30+10=40
Hanbat National Univ. Computer Eng. Dept. Y.J.Kim © 2009 Operating System Concepts – 8th Edition,
End of Chapter 5