Search
Duplicate

CPU μŠ€μΌ€μ₯΄λ§

CPU burst time 뢄포

β†’ IO bound job(CPUλ₯Ό 작고 κ³„μ‚°ν•˜λŠ” μ‹œκ°„λ³΄λ‹€ IO에 λ§Žμ€ μ‹œκ°„μ΄ ν•„μš”ν•œ job) 은 λΉˆλ„κ°€ λ§Žμ§€λ§Œ CPU λ₯Ό 짧게 μ“΄λ‹€. CPU bound job(계산 μœ„μ£Όμ˜ job) 은 λΉˆλ„κ°€ μ μ§€λ§Œ CPU λ₯Ό 길게 μ“΄λ‹€. job 의 μ’…λ₯˜κ°€ μ„žμ—¬μžˆλ‹€.
β†’ μ—¬λŸ¬ μ’…λ₯˜μ˜ job(process)이 μ„žμ—¬ μžˆκΈ°λ•Œλ¬Έμ— CPU μŠ€μΌ€μ₯΄λ§μ΄ ν•„μš”

CPU Scheduler

β€’
ready μƒνƒœμ˜ ν”„λ‘œμ„ΈμŠ€ 쀑 CPU λ₯Ό 쀄 ν”„λ‘œμ„ΈμŠ€λ₯Ό κ³ λ₯Έλ‹€.
β€’
운영 체제 μ•ˆμ—μ„œ cpu scheduling 을 ν•˜λŠ” μ½”λ“œκ°€ μžˆλ‹€.
β€’
μ–΄λ–€ ν”„λ‘œμ„ΈμŠ€μ— 쀄 것인지, 쀑간에 μ–Έμ œ 뺏을 것인지 두 가지 이슈

Dispatcher

β€’
CPU 의 μ œμ–΄κΆŒμ„ CPU Scheduler 에 μ˜ν•΄ μ„ νƒλœ ν”„λ‘œμ„ΈμŠ€μ—κ²Œ λ„˜κΈ΄λ‹€.
β€’
이 과정을 context switching

CPU μŠ€μΌ€μ₯΄λ§μ΄ ν•„μš”ν•œ 경우

β€’
Running β†’ Blocked
β—¦
IO μš”μ²­ν•˜λŠ” μ‹œμŠ€ν…œ 콜
β€’
Running β†’ Ready
β—¦
timer interrupt
β€’
Blocked β†’ Ready
β—¦
IO μ™„λ£Œ ν›„ interrupt
β€’
Terminate
β€’
preemptive(κ°•μ œλ‘œ λΉΌμ•—μŒ, μ„ μ ν˜•) vs non-preemptive(μžμ§„ λ°˜λ‚©, λΉ„μ„ μ ν˜•)

Scheduling Criteria(Performance Index)

β€’
CPU utilization(이용λ₯ )
β—¦
keep the CPU as busy as possible
β€’
Throughput(μ²˜λ¦¬λŸ‰)
β—¦
complete processes’ execution per time unit
β€’
Turn-around time(μ†Œμš” μ‹œκ°„)
β—¦
amount of time to execute a particular process
β€’
Waiting time(λŒ€κΈ° μ‹œκ°„)
β—¦
amount of time a process has been waiting in the ready queue
β€’
Response time(응닡 μ‹œκ°„)
β—¦
ν•˜λ‚˜μ˜ μš”μ²­μ΄ submit 되고 응닡이 produce 될 λ•ŒκΉŒμ§€ κ±Έλ¦° μ‹œκ°„, not output
β—¦
μ‚¬μš©μž 응닡과 κ΄€λ ¨ν•˜μ—¬ μ€‘μš”ν•˜κΈ°λ•Œλ¬Έμ— 쑴재
β†’ λŒ€κΈ° μ‹œκ°„μ€ queue μ—μ„œ 총 κΈ°λ‹€λ¦° μ‹œκ°„, 응닡 μ‹œκ°„μ€ 처음 queue 에 λ“€μ–΄μ™€μ„œ 처음 CPU λ₯Ό μ–»κΈ°κΉŒμ§€ κΈ°λ‹€λ¦° μ‹œκ°„, μ†Œμš” μ‹œκ°„μ€ CPU에 λ“€μ–΄μ™€μ„œ λ‚˜κ°ˆ λ•ŒκΉŒμ§€ 총 κ±Έλ¦° μ‹œκ°„
β€’
μœ„ λ‘κ°œλŠ” μ‹œμŠ€ν…œ 상, μ•„λž˜ μ„Έκ°œλŠ” ν”„λ‘œμ„ΈμŠ€ 상
β€’
β†’ 쀑ꡭ집 μ£Όλ°©μž₯, μ†λ‹˜ μ˜ˆμ‹œ
β€’
FCFS(First Come First Served)
β—¦
average waiting time = (0 + 24 + 27) / 3 = 17
β—¦
ν”„λ‘œμ„ΈμŠ€ 도착 μˆœμ„œμ— 따라 variation(λΆ„μ‚°) 이 크닀.
β—¦
은행, ν™”μž₯μ‹€ μ˜ˆμ‹œ
β—¦
λΉ„μ„ μ ν˜•
β—¦
λΉ„νš¨μœ¨μ , 곡평함
β—¦
convoy effect: short process behind long process
β€’
SJF(Shortest Job First)
β—¦
CPU μ‚¬μš© μ‹œκ°„μ΄ κ°€μž₯ 짧은 ν”„λ‘œμ„ΈμŠ€λ₯Ό λ¨Όμ € μŠ€μΌ€μ₯΄
β—¦
전체 queue κ°€ μ€„μ–΄λ“œλŠ” 효과
β—¦
minimum average waiting time 보μž₯
β—¦
two schemes
β–ͺ
λΉ„μ„ μ ν˜•
β€’
일단 CPU λ₯Ό 작으면 CPU burst κ°€ μ™„λ£Œλ  λ•ŒκΉŒμ§€ CPU λ₯Ό 놓지 μ•ŠμŒ
β–ͺ
μ„ μ ν˜•
β€’
ν˜„μž¬ μˆ˜ν–‰μ€‘μΈ ν”„λ‘œμ„ΈμŠ€μ˜ 남은 burst time 보닀 더 짧은 CPU burst time 을 κ°€μ§€λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ λ„μ°©ν•˜λ©΄ CPU λ₯Ό λΉΌμ•—κΉ€
β€’
이 방법을 SRTF(Shortest Remaining Time First)
β–ͺ
λΉ„μ„ μ ν˜•μ€ CPU μ‚¬μš©μ΄ μ™„λ£Œ 됐을 λ•Œ μŠ€μΌ€μ₯΄λ§, μ„ μ ν˜•μ€ 도착, μ™„λ£Œ λ‘˜ λ‹€ μŠ€μΌ€μ₯΄λ§
β—¦
문제 1: starvation(κΈ°μ•„ ν˜„μƒ) λ°œμƒ κ°€λŠ₯
β—¦
문제 2: CPU burst time 을 μ˜ˆμΈ‘ν•  수 μ—†λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ μžˆλ‹€.
β–ͺ
κ³Όκ±° μ‚¬μš© ν”μ μœΌλ‘œ 예츑(exponential averaging)
β–ͺ
보톡 interactive IO λŠ” 짧고, κ³„μ‚°ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€λŠ” κΈΈλ‹€.
β€’
Priority Scheduling
β—¦
μ •μˆ˜λ‘œ μš°μ„ μˆœμœ„κ°€ 주어짐
β—¦
μž‘μ€ μˆ˜κ°€ μš°μ„ μˆœμœ„κ°€ 높은 것
β—¦
문제: starvation
β—¦
ν•΄κ²°μ±…: aging 방식, 였래되면 μš°μ„ μˆœμœ„λ₯Ό 높인닀.
β€’
Round Robin
β—¦
ν˜„λŒ€μ μΈ CPU μŠ€μΌ€μ₯΄λ§μ€ RR 을 기반
β—¦
각 ν”„λ‘œμ„ΈμŠ€λŠ” 동일 크기의 CPU ν• λ‹Ή μ‹œκ°„(time quantum)을 가진닀. 일반적으둜 10-100 ms
β—¦
μž₯점: 응닡 μ‹œκ°„(response time)이 λΉ λ₯΄λ‹€.
β—¦
ν• λ‹Ή μ‹œκ°„μ΄ λλ‚˜λ©΄ μΈν„°λŸ½νŠΈκ°€ λ°œμƒν•΄μ„œ CPUλ₯Ό λΉΌμ•—κΈ°κ³  아직 μ²˜λ¦¬κ°€ λ˜μ§€ μ•Šμ•˜λ‹€λ©΄ 큐의 제일 뒀에 κ°€μ„œ λŒ€κΈ°
β—¦
ν• λ‹Ή μ‹œκ°„μ΄ κΈΈλ©΄ FCFS, ν• λ‹Ή μ‹œκ°„μ΄ 짧으면 context switch κ°€ λΉˆλ²ˆν•˜κ²Œ λ°œμƒν•˜μ—¬ μ˜€λ²„ν—€λ“œκ°€ 컀짐
β—¦
n 개의 ν”„λ‘œμ„ΈμŠ€κ°€ CPU 큐에 μžˆλŠ” 경우
β–ͺ
μ΅œλŒ€ (n-1) * ν• λ‹Ήμ‹œκ°„
β–ͺ
λŒ€κΈ°μ‹œκ°„μ΄ ν”„λ‘œμ„ΈμŠ€μ˜ CPU μ‚¬μš© μ‹œκ°„μ— λΉ„λ‘€
β—¦
μ˜ˆμ‹œ

Multi-level Queue

β€’
Ready queue λ₯Ό μ—¬λŸ¬ 개둜 λΆ„ν• 
β—¦
foreground(interactive)
β—¦
background(batch)
β€’
각 νλŠ” 독립적인 μŠ€μΌ€μ₯΄λ§ μ•Œκ³ λ¦¬μ¦˜
β—¦
foreground - RR
β—¦
background - FCFS
β€’
큐에 λŒ€ν•œ μŠ€μΌ€μ₯΄λ§
β—¦
Fixed priority scheduling
β–ͺ
starvation
β—¦
time slice
β–ͺ
각 큐에 CPU time 을 μ μ ˆν•œ λΉ„μœ¨λ‘œ ν• λ‹Ή

Multi-level Feedback Queue

β€’
ν”„λ‘œμ„ΈμŠ€κ°€ λ‹€λ₯Έ 큐둜 이동 κ°€λŠ₯
β€’
aging 방식
β€’
CPU μ‚¬μš© μ‹œκ°„μ΄ 짧은 ν”„λ‘œμ„ΈμŠ€μ—κ²Œ μš°μ„ μˆœμœ„λ₯Ό λ†’κ²Œ μΉ¨
β€’
μ‚¬μš© μ‹œκ°„ 예츑 λΆˆν•„μš”

Multi-Processor Scheduling

β€’
CPU κ°€ μ—¬λŸ¬ 개인 경우 λ³΅μž‘ν•΄μ§
β€’
homogeneous processor
β—¦
queue λ₯Ό ν•œμ€„λ‘œ μ„Έμš°κΈ°
β—¦
νŠΉμ • ν”„λ‘œμ„Έμ„œμ—μ„œ μˆ˜ν–‰λ˜μ–΄μ•Ό ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ μžˆλŠ” 경우(λ―Έμš©μ‹€ μ „λ‹΄ λ””μžμ΄λ„ˆ μ˜ˆμ‹œ)
β€’
load sharing
β—¦
λΆ€ν•˜ 쑰절
β—¦
λ³„κ°œμ˜ 큐 vs 곡동 큐
β€’
symmetric multiprocessing
β—¦
각 ν”„λ‘œμ„Έμ„œκ°€ 각자 μ•Œμ•„μ„œ μŠ€μΌ€μ₯΄λ§
β€’
asymmetric multiprocessing
β—¦
ν•˜λ‚˜μ˜ ν”„λ‘œμ„Έμ„œκ°€ μ‹œμŠ€ν…œ 데이터 μ ‘κ·Ό, 곡유 μ±…μž„
β—¦
λ‚˜λ¨Έμ§€ ν”„λ‘œμ„Έμ„œλŠ” 거기에 따름

Real-Time Scheduling

β€’
deadline 이 μžˆλŠ” job
β€’
정해진 μ‹œκ°„μ•ˆμ— 일이 μˆ˜ν–‰λ˜μ–΄μ•Ό ν•˜λŠ” job
β€’
hard real time system
β—¦
정해진 μ‹œκ°„ μ•ˆμ— λ°˜λ“œμ‹œ λλ‚΄λŠ” μŠ€μΌ€μ₯΄λ§
β€’
soft real time computing
β—¦
일반 ν”„λ‘œμ„ΈμŠ€λ³΄λ‹€ 높은 priority

Thread Scheduling

β€’
local scheduling
β—¦
user level thread 의 경우 μ‚¬μš©μž ν”„λ‘œμ„ΈμŠ€κ°€ 직접 thread λ₯Ό κ΄€λ¦¬ν•˜κ³  운영 μ²΄μ œλŠ” μ“°λ ˆλ“œμ˜ 쑴재λ₯Ό λͺ¨λ¦„
β—¦
μ‚¬μš©μž ν”„λ‘œμ„ΈμŠ€κ°€ μ“°λ ˆλ“œμ˜ μŠ€μΌ€μ₯΄μ„ 결정함
β€’
global scheduling
β—¦
kernel level thread 의 경우 운영 μ²΄μ œκ°€ μ“°λ ˆλ“œμ˜ 쑴재λ₯Ό μ•Œκ³  μžˆλ‹€.
β—¦
운영 μ²΄μ œκ°€ ν”„λ‘œμ„ΈμŠ€ μŠ€μΌ€μ₯΄λ§ ν•˜λ“―μ΄ μ“°λ ˆλ“œμ˜ μŠ€μΌ€μ₯΄ κ²°μ •

Algorithm Evaluation

β€’
queueing model
β—¦
μ΄λ‘ μ μž„
β—¦
ν™•λ₯  λΆ„ν¬λ‘œ μ£Όμ–΄μ§€λŠ” arrival rate 와 service rate 등을 톡해 각쒅 performance index 값을 계산
β€’
implementation & measurement
β—¦
μ‹€μ œ μ‹œμŠ€ν…œμ— μ•Œκ³ λ¦¬μ¦˜μ„ κ΅¬ν˜„ν•˜μ—¬ μ‹€μ œ μž‘μ—…μ— λŒ€ν•΄ μ„±λŠ₯ μΈ‘μ • 및 비ꡐ
β€’
simulation
β—¦
λͺ¨μ˜ ν”„λ‘œκ·Έλž¨μœΌλ‘œ μž‘μ„± ν›„ 더미 데이터λ₯Ό λ„£μ–΄ κ²°κ³Ό μΈ‘μ •