CPU Scheduler
- Ready 상태의 프로세스 중에서 이번에 CPU를 줄 프로세스를 고른다.
Dispatcher
- CPU의 제어권을 CPU Scheduler에 의해 선택된 프로세스에게 넘긴다.
- 이 과정을 context switch(문맥 교환)라고 한다.
CPU 스케줄링이 필요한 경우는 프로세스에게 다음과 같은 상태 변화가 있는 경우이다.
1. Running -> Blocked (예: I/O 요청하는 시스템 콜)
2. Running -> Ready (예: 할당시간 만료로 timer interrupt)
3. Blocked -> Ready (예: I/O 완료후 인터럽트)
4. Terminate
CPU스케줄링은 현재 ready queue에 들어와있는 CPU를 얻고자 하는 프로세스 중에서 어떤 프로세스에게 CPU를 줄거냐는 메커님즘을 말한다.
CPU Scheduler
Dispatcher
CPU 스케줄링이 필요한 경우는 프로세스에게 다음과 같은 상태 변화가 있는 경우이다.
1. Running -> Blocked(I/O 요청하는 시스템 콜)
2. Running -> Ready(할당시간 만료로 time interrupt)
3. Blocked -> Ready(I/O완료후 인터럽트)
4. Terminate
비선점형 nonpreemptive(강제로 빼앗지 않음)
선점형 preemptive(강제로 빼앗을 수 있는 경우)
Performance Index ( = Performance Measure, 성능 척도)
1. CPU utilization(이용률)
2. Thoughtput(처리량)
3. Turnaround time(소요시간, 반환시간)
4. Waiting time(대기 시간)
5. Response time(응답 시간)
CPU Scheduling Algorithm
먼저온 순서대로 처리함.
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting tiem : (0 + 24 + 27)/3 = 17
convoy effect : 큐에서 오래 기다리는 현상
Nonpreemptive:
- 일단 CPU를 잡으면 이번 CPU burst가 완료될 때 까지 CPU를 선점(Preemption) 당하지 않음
Preemptive
- 현재 수행중인 프로세스의 남은 burst time 보다 더 짧은 CPU burst time을 가지는 새로운 프로세스가 도착하면 CPU를 뺴앗김
- 이 방법을 Shortest-Remaining-Time-First(SRTF)이라고 부른다.
A priority number(integer) is associated with each process
highest priority를 가진 프로세스에게 CPU할당 (Smallest integer - highest priority)
preemptive
nonpreemptive
SJF는 일종의 priority scheduling이다.
*priority = predicted next CPU burst time
Problem
Starvation(기이 현상) : low priority process may never execute
CPU사용시간을 미리 알 수 없다.
Solution
*Aging: as time progress increase the priority of the process
(노화 : 아무리 우선 순위가 낮은 프로세스라도 오래 기다렸으면 우선 순위를 조금씩 높여주자.)
각 프로세스는 동일한 크기의 할당 시간(time quantum)을 가짐
*일반적으로(10-100 milliseconds)
할당 시간이 지나면 프로세스는 선점(preempted)당하고 ready queue의 제일 뒤에 가서 다시 줄을 선다.
n 개의 프로세스가 ready queue에 있고 할당 시간이 q time unit인 경우 각 프로세스는 최대 q time unit 단위로 CPU 시간의 1/n을 얻는다.
=> 어떤 프로세스도 (n-1)q time unit 이상 기다리지 않는다.
Performance
q large => FIFO
q small => context switch 오버헤드가 커진다.
일반적으로 SJF보다 average turnaround time이 길지만 response time은 더 짧다.
Ready queue를 여러 개로 분할
foreground(interactive)
background(batch-no human interaction)
각 큐는 독립적인 스케줄링 알고리즘을 가짐
foreground-RR
background-FCFS
큐에 대한 스케줄링이 필요
Fixed priority scheduling
- serve all from foreground then from background
- Possibility of starvation
Time slice
- 각 큐에 CPU time을 적절한 비율로 할당
- Eg., 80% to foreground in RR, 20% to background in FCFS