Multiprogramming: multiple program을 concurrent하게 작동 -> 목표: maximize CPU utilization
multiple process를 동시에 관리
Kernel-level threads -> os에 의해 scheduled
process scheduling & thread scheduling -> 종종 혼용돼서 사용
scheduling은 정확히 말하면 thread scheduling!!
process는 항상 ready 상태가 X -> data, resource를 기다리는 상황이 있을 수 있음 -> 이때, 바로 다른 process를 실행
Process execution -> CPU execution & I/O wait의 cycle
CPU burst distribution is main concern
CPU Scheduling
1. CPU Scheduler
CPU scheduler -> ready queue에 위치한 processes중 하나에 CPU core를 할당
CPU scheduling이 발생하는 순간
running -> waiting state: 실행되다가, 다른 I/O를 기다리기 위해 wait state로 -> I/O는 wait 상태 process 중 선택
running -> ready state: interrupt
waiting -> ready: 중요한 process -> 우선순위가 더 높음 -> 현재 실행되는 process를 쫓아내고 실행될 수 있음
Terminates: terminate 시에 core가 empty -> scheduling
case 1 & 4 -> new process(ready queue에 존재하는)가 반드시 하나 실행돼야 함
case 2 & 3 -> scheduling의 선택권이 발생
2. Preemptive & Nonpreemptive Scheduling
Nonpreemptive scheduling: Running process가 CPU를 release하기전(terminatingor switching to the waiting state)까지 CPU 권한 유지
case 1 & 4
규모가 작은 computing device
Preemptive scheduling: Running process가 실행 도중에 preempted될 수 있음
case 1, 2, 3, 4 어디서든 발생 가능
몇몇의 processes가 data를 공유하는 상황에서 발생할 수 있음 -> 대부분의 복잡한 OS
대부분의 modern OS(Windows, MacOS, Linux, and UNIX) -> preemtive scheduling algorithms 사용
3. Scheduling Criteria
- How optimal is a scheduling algorithm?
CPU Utilization: CPU를 가능한 한 바쁘게 유지
개념적으로는 0 ~ 100 percent (in a real system, range from 40 to 90 percent)
100에 가까울수록 positive
Throughput: 단위 시간 동안 완료된 processes의 수
CPU & Throughput은 positive할수록 좋은 지표
Turnaround Time:특정 process를 실행하는 데 걸리는 총 시간
waiting in the ready queue, executing on the CPU, doing I/O의 총합
process가 완료된 시간 - 프로세스가 도착한 시간 -> Completion Time - Arrival Time
Waiting Time: process가 ready queue에서 대기(wait)한 총 시간
waiting in the ready queue -> turnaround time의 일부
Response Time: process가 처음 실행되는 시간에서 프로세스가 도착한 시간을 뺀 시간
FirstRun Time - Arrival Time
Scheduling Algorithms
Problem -> ready queue의 어떤 processes가 CPU cores를 할당받을 것인가?
Algorithms
First-Come First-Served (FCFS) Scheduling
Shortest-Job-First (SJF) Scheduling
Round-Robin (RR) Scheduling
Priority Scheduling
Multi-level Queue Scheduling
Multi-level Feedback Queue Scheduling
1. First-Come First-Served (FCFS) Scheduling
Policy: CPU를 먼저 요청한 process 먼저 schedule -> Nonpreepmtive (먼저 cpu를 점유 -> 다른 processes 접근 X)
FIFO Queue를 이용하여 구현이 쉬움
Average waiting time이 보통 quite long
-> 상황에 따라 waiting time이 크게 벌어질 수 있다.
Convoy Effect: Short process behind Long process
하나의 CPU bound와 many I/O-bound processes
Burst: 어떤 현상이 짧은 시간 안에 집중적으로 일어나는 것
Input/output(IO): 파일을 읽고 쓰거나, 네트워크 어딘가에 있는 다른 존재와 데이터를 주고받거나, 모니터/마우스 같은 입출력 장치와 데이터를 주고 받는 것을 IO라고 한다.
CPU burst: 프로세스가 CPU에서 한 번에 연속적으로 실행되는 시간을 의미 -> 메모리에 올라간 프로세스가 자신의 차례가 되어, CPU에서 실행될 때, 자신의 instructions가 CPU에서 연속적으로 실행되는 시간
IO burst: 프로세스가 IO 작업을 요청 -> 그 결과를 기다리는 시간
-> 앞 부분은 I/O bound job -> CPU를 짧게 사용(short CPU burst) -> 뒷 부분이 CPU bound job -> CPU를 길게 점유(long CPU burst) -> CPU bound job이 CPU를 너무 길게 점유하면, I/O bound job의 대기 시간이 너무 길어짐 -> 적절한 Scheduling 필요
Nonpreemptive -> priority순서대로, but 중간에 cpu 소유권을 뺏지는 않음
Problem: Starvation - low priority는 영원히 실행되지 않을 수 있음
Solution: Aging - 시간이 흐를수록 기존 process의 priority 증가
- Priority Scheduling with Round-Robin
같은 priority를 같은 processes는 round-robin algorithm에 따라 실행
5. Multilevel Queue
Ready queue -> multiple queues로 구성
Multilevel queue scheduler를 정의하는 parameters
queue의 개수
각 queue의 Scheduling algorithm
process가 service를 필요로 할 때, process가 어떤 queue에 배정될지 결정하는 방법
Queues 간의 Scheduling
- Multilevel Queue with Priority Scheduling
각 priority 마다 별개의 queues 존재
highest-priority queue의 process 먼저 schedule
-> process type에 따라 우선순위 부여
6. Multilevel Feedback Queue
process는 다양한 queues 사이에서 이동 가능
Multilevel feedback queue scheduler를 정의하는 parameters
queue의 개수
각 queue의 Scheduling algorithm
process를 언제 upgrade할지 결정하는 방법
process를 언제 demote할지 결정하는 방법
process가 service를 필요로 할 때, process가 어떤 queue에 배정될지 결정하는 방법
Aging -> multilevel feedback queue를 사용함으로써 구현될 수 있음
- Example
Q0 - RR(time quantum 8 milliseconds)
Q1 - RR(time quantum 16 milliseconds)
Q2 - FCFS
-> new process가 Q0에 진입(RR) -> 8 milliseconds 안에 완료하지 못하면 Q1으로 이동
-> Q1에서 16 milliseconds의 추가 시간을 부여받음(RR) -> 16 milliseconds 안에 완료하지 못하면, preempted & Q2로 이동
Multiple-Processor Scheduling
Multiple CPUs
processor chip이 여러 개인 경우 -> mother board를 cpu 여러 개 설치 가능하도록 설계
Multithreaded cores
하나의 processor 안에 여러 개의 core
NUMA(Non-Uniform Memory Access) systems
processor마다 별개의 memory 존재 -> 각각의 cpu 들이 interconnect라는 내부의 연결을 통해서 서로의 memory에 접근 가능
다른 memory 접근은 더 오래 걸리므로, 데이터의 적절한 분배가 중요
Heterogeneous multiprocessing
일반적으로는 core의 성능이 모두 비슷 -> Heterogeneous에서는 core의 특성이 다 다름
ex) big little -> big core(processing power good) + little core(energy 소모 good)
좌측부터 순서대로 Multiple CPUs, Multithreaded cores, NUMA(Non-Uniform Memory Access) systems
Symmetric multiprocessing (SMP)
each processor ->self scheduling
a) 모든 threads가 공통의 common ready queue 내부에 존재
b) 각 processor는 자신의 private queue of threads를 가짐
1. Multicore Processors
Multiple processor cores를 같은 physical chip 위에 올리는 최근 트렌드 -> 더 적은 power로 더 빠른 속도
Multiple (hardware) threads per core -> memory stall의 이점을 이용 -> memory stall 대기시간 동안 또다른 thread 진행
ex) inter의 hyperthreading
- Multithreaded Multicore System
각 core가 1개보다 많은 threads 개수를 가짐
한 thread에서 memory stall 발생 -> another thread로 교체
Chip-multithreading(CMT): 각 core에 multiple hardware threads를 할당
intel의 hyperthreading
quad-core system: core 당 2개의 hardware threads -> os는 8개의 logical processors로 인식
Two levels of scheduling
operating system은 logical CPU 위에서 어떤 software thread가 작동할지 결정
각 core가 어떤 hardware thread가 physical core 위에서 작동할지 결정
Software Threads - single process 내부에서 concurrent하게 execution하는 programming contstruct - os 혹은 runtime library에 의해 관리됨 - 같은 parent process의 memory space 공유
Hardware Threads - hardware-supported multi-threading / Hyper-threading에서 언급되는 개념 - single CPU core 위에서 multiple threads가 simutaneous하게 execution하도록 함 - 각 core는 multiple hardware threads를 관리
Software Threads vs Hardware Threads - Level of Operation: - software threads: os 혹은 application level에서 존재하고, thread scheduler에 의해 관리됨 - hardware threads: cpu level에서 존재하고, single core 내에서 parallel execution 제공 - Resource Sharing - software threads: process의 같은 memory space를 공유(synchronization mechanism) - headware threads: CPU resources의 특정 부분을 공유, core 내부에서 parallel execution의 이점을 가짐 - Performance Impact - software threads: 사용 가능한 cpu cores 개수와 hardware threads의 개수에 따라 성능 향상 어느정도 제약 - hardware threads: CPU performance와 직결됨