CPU Scheduling - hochan222/Everything-in-JavaScript GitHub Wiki

๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ”๋กœ๊ฐ€๊ธฐ

CPU and I/O Bursts in Program Execution

  • ์—ฌ๋Ÿฌ ์ข…๋ฅ˜์˜ job(=process)๊ฐ€ ์„ž์—ฌ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— CPU ์Šค์ผ€์ค„๋ง์ด ํ•„์š”ํ•˜๋‹ค
    • interactive job์—๊ฒŒ ์ ์ ˆํ•œ response ์ œ๊ณต ์š”๋ง
    • CPU์™€ I/O ์žฅ์น˜ ๋“ฑ ์‹œ์Šคํ…œ ์ž์›์„ ๊ณจ๊ณ ๋ฃจ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉ

ํ”„๋กœ์„ธ์Šค์˜ ํŠน์„ฑ ๋ถ„๋ฅ˜

  • ํ”„๋กœ์„ธ์Šค๋Š” ๊ทธ ํŠน์„ฑ์— ๋”ฐ๋ผ ๋‹ค์Œ ๋‘๊ฐ€์ง€๋กœ ๋‚˜๋ˆ”
    • I/O bound process
      • CPU๋ฅผ ์žก๊ณ  ๊ณ„์‚ฐํ•˜๋Š” ์‹œ๊ฐ„๋ณด๋‹ค I/O์— ๋งŽ์€ ์‹œ๊ฐ„์ด ํ•„์š”ํ•œ job
      • (many short CPU bursts)
    • CPU-bound process
      • ๊ณ„์‚ฐ ์œ„์ฃผ์˜ job
      • (few very long CPU bursts)

CPU Scheduler & Dispatcher

  • 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

1, 4์—์„œ์˜ ์Šค์ผ€์ค„๋ง์€ nonpreemptive(=๊ฐ•์ œ๋กœ ๋บด์•—์ง€ ์•Š๊ณ  ์ž์ง„ ๋ฐ˜๋‚ฉ)
๋‹ค๋ฅธ๊ฑด ๊ฐ•์ œ๋กœ ๋บ์Œ preemptive

Scheduling Criteria

  • CPU utilization (์ด์šฉ๋ฃŒ)
    • keep the CPU as busy as possible
  • Throughput (์ฒ˜๋ฆฌ๋Ÿ‰)
    • of processes that complete their execution per time unit
  • Turnaround 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 (์‘๋‹ต ์‹œ๊ฐ„) (์ตœ์ดˆ CPU์–ป๊ธฐ๊นŒ์ง€ ์‹œ๊ฐ„)
    • amount of time it takes from when a request was submitted until the first response is produced, not output

Scheduling algorithm

  • FCFS (First-Come First-Served)
    • nonpreemptive
    • Convoy effect
  • SJF (Shortest-Job-First)
    • ์ฃผ์–ด์ง„ ํ”„๋กœ์„ธ์Šค๋“ค์— ๋Œ€ํ•ด minimum average waiting time ๋ณด์žฅ
    • Nonpreemptive
      • ์ผ๋‹จ CPU๋ฅผ ์žก์œผ๋ฉด ์ด๋ฒˆ CPU burst๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ CPU๋ฅผ ์„ ์ ๋‹นํ•˜์ง€ ์•Š์Œ
    • Preemptive
      • ํ˜„์žฌ ์ˆ˜ํ–‰์ค‘์ธ ํ”„๋กœ์„ธ์Šค์˜ ๋‚จ์€ burst time๋ณด๋‹ค ๋” ์งง์€ CPU burst time์„ ๊ฐ€์ง€๋Š” ์ƒˆ๋กœ์šด ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋„์ฐฉํ•˜๋ฉด CPU๋ฅผ ๋นผ์•—๊น€
      • ์ด ๋ฐฉ๋ฒ•์„ Shortest-Remaining-Time-First(SRTF)์ด๋ผ๊ณ ๋„ ๋ถ€๋ฅธ๋‹ค.
    • ๋ฌธ์ œ
      • long process starvation (์‹œ๊ฐ„ ๊ธด๊ฑฐ๋Š” ์•„์— ๋ชป ์“ธ์ˆ˜ ์žˆ์Œ)
      • CPU burst time์„ ๋ฏธ๋ฆฌ ์•Œ ์ˆ˜ ์—†์Œ
      • ๊ณผ๊ฑฐ์˜ CPU burst time์„ ์ด์šฉํ•ด์„œ ์ถ”์ •
  • Priority Scheduling
    • Preemptive
    • Nonpreemptive
    • ๋ฌธ์ œ
      • starvation ํŠน์ • ํ”„๋กœ์„ธ์Šค ์ฐจ๋ณ„
    • => aging ์˜ค๋ž˜ ๊ธฐ๋‹ฌ๋ฆฌ๊ฒŒ๋˜๋ฉด ์šฐ์„ ์ˆœ์œ„๋ฅผ ๋†’์—ฌ์ฃผ์ž.
  • Round Robin (RR)
    • ๊ฐ ํ”„๋กœ์„ธ์Šค๋Š” ๋™์ผํ•œ ํฌ๊ธฐ์™€ ํ• ๋‹น ์‹œ๊ฐ„์„ ๊ฐ€์ง.
    • ํ• ๋‹น ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด ํ”„๋กœ์„ธ์Šค๋Š” ์„ ์ ๋‹นํ•˜๊ณ  ready queue์˜ ์ œ์ผ ๋’ค์— ๊ฐ€์„œ ๋‹ค์‹œ ์ค„์„ ์„ ๋‹ค
    • n๊ฐœ์˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ ready queue์— ์žˆ๊ณ  ํ• ๋‹น ์‹œ๊ฐ„์ด q time unit์ธ ๊ฒฝ์šฐ ๊ฐ ํ”„๋กœ์„ธ์Šค๋Š” ์ตœ๋Œ€ q time unit ๋‹จ์œ„๋กœ CPU ์‹œ๊ฐ„์˜ 1/n์„ ์–ป๋Š”๋‹ค.
    • Perfomance
    • q large => FCFS
    • q small => context switch ์˜ค๋ฒ„ํ—ค๋“œ
  • Multilevel Queue
    • forground (interactive, RR)
    • background (batch - no human interaction, FCFS)
  • Multilevel Feedback Queue
    • ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋‹ค๋ฅธ ํ๋กœ ์ด๋™ ๊ฐ€๋Šฅ
    • ์—์ด์ง•์„ ์ด์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Multiple -Processor Scheduling
    • CPU๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ์ธ ๊ฒฝ์šฐ ์Šค์ผ€์ค„๋ง์€ ๋”์šฑ ๋ณต์žกํ•ด์ง
    • Homogeneous processor์ธ ๊ฒฝ์šฐ
      • Queue์— ํ•œ์ค„๋กœ ์„ธ์›Œ์„œ ๊ฐ ํ”„๋กœ์„ธ์„œ๊ฐ€ ์•Œ์•„์„œ ๊บผ๋‚ด๊ฐ€๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • Load sharing
      • ์ผ๋ถ€ ํ”„๋กœ์„ธ์„œ์— job์ด ๋ชฐ๋ฆฌ์ง€ ์•Š๋„๋ก ๋ถ€ํ•˜๋ฅผ ์ ์ ˆํžˆ ๊ณต์œ ํ•˜๋Š” ๋ฉ”์ปค๋‹ˆ์ฆ˜
      • ๋ณ„๊ฐœ์˜ ํ๋ฅผ ๋‘๋Š” ๋ฐฉ๋ฒ• vs ๊ณต๋™ ํ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
    • symmetric Multiprocessing (SMP)
      • ๊ฐ ํ”„๋กœ์„ธ์„œ๊ฐ€ ๊ฐ์ž ์•Œ์•„์„œ ์Šค์ผ€์ค„๋ง ๊ฒฐ์ •
    • Asymmetric multiprocessing
      • ํ•˜๋‚˜์˜ ํ”„๋กœ์„ธ์„œ๊ฐ€ ์‹œ์Šคํ…œ ๋ฐ์ดํ„ฐ์˜ ์ ‘๊ทผ๊ณผ ๊ณต์œ ๋ฅผ ์ฑ…์ž„์ง€๊ณ  ๋‚˜๋จธ์ง€ ํ”„๋กœ์„ธ์„œ๋Š” ๊ฑฐ๊ธฐ์— ๋”ฐ๋ฆ„
  • Real-Time Scheduling
    • Hard real-time Scheduling
      • ๋ฐ˜๋“œ์‹œ ์ •ํ•ด์ง„ ์‹œ๊ฐ„์•ˆ์— ๋๋‚ด๋„๋ก ์Šค์ผ€์ค„๋ง ๋ผ์•ผํ•จ
    • Soft real-time Scheduling
      • ์ผ๋ฐ˜ ํ”„๋กœ์„ธ์Šค์— ๋น„ํ•ด ๋†’์€ priority๋ฅผ ๊ฐ–๊ฒŒํ•จ
  • Thread Scheduling
    • Local Scheduling
      • User level thread์˜ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž ์ˆ˜์ค€์˜ thread library์— ์˜ํ•ด ์–ด๋–ค thread๋ฅผ ์Šค์ผ€์ค„ํ• ์ง€ ๊ฒฐ์ •
      • ์šด์˜์ฒด์ œ๋Š” thread์˜ ์กด์žฌ๋ฅผ ๋ชจ๋ฆ„
    • Global Scheduling
      • Kernel level thread์˜ ๊ฒฝ์šฐ ์ผ๋ฐ˜ ํ”„๋กœ์„ธ์Šค์™€ ๋งˆ์ฐฌ ๊ฐ€์ง€๋กœ ์ปค๋„์˜ ๋‹จ๊ธฐ ์Šค์ผ€์ค„๋Ÿฌ๊ฐ€ ์–ด๋–ค thread๋ฅผ ์Šค์ผ€์ค„ํ• ์ง€ ๊ฒฐ์ •

Algorithm Evaluation

  • Queueing models
  • Implementation(๊ตฌํ˜„) & Measurement(์„ฑ๋Šฅ ์ธก์ •)
    • ์‹ค์ œ ์‹œ์Šคํ…œ์— ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ตฌํ˜„ํ•˜์—ฌ ์‹ค์ œ ์ž‘์—…์— ๋Œ€ํ•ด์„œ ์„ฑ๋Šฅ์„ ์ธก์ • ๋น„๊ต
  • Simulation(๋ชจ์˜ ์‹คํ—˜)
    • ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋ชจ์˜ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์ž‘์„ฑํ›„ trace๋ฅผ ์ž…๋ ฅ์œผ๋กœ ํ•˜์—ฌ ๊ฒฐ๊ณผ ๋น„๊ต