๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš— Major Study (Bachelor)/๐ŸŸง Operating System

[OS / ์šด์˜์ฒด์ œ] CPU-I/O Burst Cycle, CPU Scheduler, Preemptive Scheduling, Scheduling Criteria, Shortest Job First Scheduling

by UKHYUN22 2022. 4. 14.
728x90

 

CPU-I/O Burst Cycle

read from file์„ ํ•˜๋ฉด IO๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‹คํ–‰์„ ํ•˜๋‹ค๋ณด๋ฉด ์–ด๋–จ ๋•Œ๋Š” IO๋ฅผ ์“ฐ๊ณ  ์–ด๋–จ ๋•Œ๋Š” CPU๋ฅผ ์“ด๋‹ค. IO๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ตฌ๊ฐ„์„ IO Burst๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ๊ต๋Œ€๋กœ ๋ฐฐ์น˜๊ฐ€ ๋˜๊ฒŒ ๋œ๋‹ค. Process๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋ฉด Ready Queue๋กœ ๋“ค์–ด๊ฐ„๋‹ค. ๊ฐ•์ œ ์ข…๋ฃŒ๋ฅผ ์‹œํ‚ค๋ฉด ๋งˆ์ง€๋ง‰์ด IO์ผ์ˆ˜๋„ ์žˆ์ง€๋งŒ ์ •์ƒ์ ์ธ ๊ฒฝ์šฐ ์ฒ˜์Œ๊ณผ ๋งˆ์ง€๋ง‰์€ CPU์ด๋‹ค

 

 

Historgram of CPU burst Duration

CPU burst์˜ ๋Œ€๋ถ€๋ถ„์€ ์งง๋‹ค. ์ „์ฒด์ ์œผ๋กœ ๋ณด๋ฉด ์งง์€ ๊ฒƒ์ด ๋งŽ์ง€๋งŒ ๊ฐ€๋”์‹ ๊ธด burst๊ฐ€ ๋‚˜์˜จ๋‹ค. ์งง์€ ๊ฒฝ์šฐ๋Š” IO Bound์—์„œ ์˜จ ๊ฑฐ๊ณ  ๊ธด ๋ถ€๋ถ„์€ CPU Bound์—์„œ ์˜จ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค. 



CPU Scheduler

short term scheduler๋กœ ๋ถˆ๋ฆฐ๋‹ค. dispatch๋Š” CPU๋กœ ์˜ฌ๋ฆฌ๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค. Context Switching์„ Dispatcher๊ฐ€ ํ•œ๋‹ค. Ready queue๋Š” PCB์˜ Linked List๋กœ ๊ตฌํ˜„ํ•œ๋‹ค๊ณ  ํ–ˆ์—ˆ๋‹ค. 

 

Preemptive Scheduling

MultiProgramming๊ณผ Multitasking์€ Scheduling์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๋‹ค๋ฅธ ๊ฒƒ์ด ์ฃผ๋œ ์ฐจ์ด์ ์ด๋‹ค. nonpreemptivev scheduling์˜ ๊ฒฝ์šฐ๋Š” Multiprogramming์— ํ•ด๋‹นํ•œ๋‹ค. ์ง€๊ธˆ ๋Œ๊ณ  ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋Š์„ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด Preemptive scheduling์ด๋‹ค.

 

 

When Scheduling Occurs?

running -> switching

running -> ready

waiting -> ready

process terminated

4๊ฐ€์ง€์˜ ๊ฒฝ์šฐ Scheduling์ด ๊ด€์—ฌ๋ฅผ ํ•œ๋‹ค. 1๋ฒˆ๊ณผ 4๋ฒˆ์€ ํ•„์ˆ˜์ด๋‹ค. ์•ˆํ•˜๋ฉด CPU๊ฐ€ ๋†€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. 

2๋ฒˆ๊ณผ 3๋ฒˆ์˜ ๊ฒฝ์šฐ ํ•„์ˆ˜๋Š” ์•„๋‹ˆ๋‹ค. ๊น€๋ฒ”์ˆ˜๊ฐ€ ์˜ค๋“  ๋ง๋“  ๋…ธ๋ž˜๋ฅผ ๋ถ€๋ฅด๋Š” ๊ฒฝ์šฐ. 

Preemtive์™€ NonPreemtive๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ธฐ์ค€. 

 

 

Preemptive Scheduling

race condition์€ bug์˜ ์ผ์ข…์ด๊ณ  ๋ง‰์•„์•ผ ํ•œ๋‹ค. 

 

 

Preemptive of OS kernel

preemptive scheduling์€ usermode์—์„œ preemtive kernel mode๋Š” kernelmode์—์„œ ๋˜๋Š๋ƒ ์•ˆ๋˜๋Š๋ƒ๋ฅผ ๋‹ค๋ฃฌ๋‹ค.(**********). ์ผ๋‹จ System call์— ๋“ค์–ด์˜ค๋ฉด ๋๋‚˜๊ธฐ ์ „๊นŒ์ง€ Switching๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์ด Windows nonpreemptive kernel์ด๋‹ค. 

non์˜ ์žฅ์ 

: performance๊ฐ€ ์ข‹๋‹ค. 

preemp์˜ ์žฅ์ 

: real time application์— ์ข‹๋‹ค. ์ผ์ • ์‹œ๊ฐ„ ๋‚ด์— ๋ฌด์กฐ๊ฑด ๋๋‚˜์•ผ ํ•˜๋Š” ๊ฒƒ. Multiprogramming์ด performance๊ฐ€ ๋” ์ข‹์ง€๋งŒ Multitasking์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ์™€ ๋™์ผ

 

 

Scheduling Criteria

CPU utilization - CPU๊ฐ€ ๋†€๋ฉด ์•ˆ๋€๋‹ค. ์ตœ๋Œ€ํ•œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์Šค์ผ€์ค„๋Ÿฌ๊ฐ€ ์ข‹์€ ๊ฒƒ์ด๋ผ๋Š” ๊ฒƒ.

Throughput - ๋‹จ์œ„ ์‹œ๊ฐ„์ด ๋๋‚  ๋•Œ ์™„์„ฑ๋˜๋Š” ํ”„๋กœ์„ธ์Šค์˜ ๊ฐœ์ˆ˜.

Turnaroundtime - 

Waiting time - ready queue์—์„œ๋Š” ๊ธฐ๋‹ค๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ์ ์„ ์ˆ˜๋ก ์ข‹๋‹ค. ready queue์—์„œ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์‹œ๊ฐ„์„ ์–˜๊ธฐํ•œ๋‹ค.

Response time - 

 

 

Scheduling Algorithm

 

 

First-Come First Served Scheduling

non-preemptive ํ•œ scheduling์„ ์˜๋ฏธํ•œ๋‹ค. P1์„ ๋จผ์ € ์‹คํ–‰์‹œํ‚จ๋‹ค. ์ค‘๊ฐ„์— ๋Š์„ ์ˆ˜ ์—†๋‹ค. 

 

 

Shortest Job first Scheduling

๊ฐ€์žฅ ์งง์€ ๊ฒƒ์„ ๋จผ์ € ์‹คํ–‰์‹œํ‚ค๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค. ๊ทธ๋ž˜์„œ optimalํ•˜๋‹ค๊ณ  ํ‘œํ˜„์„ ํ•œ๋‹ค. ์ด๋ณด๋‹ค ์งง๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์—†๋‹ค. ๊ณผ๊ฑฐ์— ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ–ˆ๋Š”์ง€์˜ history๋ฅผ ๊ฐ€์ง€๊ณ  ์˜ˆ์ธกํ•  ์ˆ˜ ์—†๋‹ค. 

 

 

Shortest Job First Scheduling

ํ˜„์žฌ๊นŒ์ง€์˜ ์˜ˆ์ธก์น˜์™€ ์ธก์ •์น˜๋ฅผ ๊ฐ€์ง€๊ณ  ๋‹ค์Œ ์‹œ๊ฐ„์—์„œ์˜ ์˜ˆ์ธก์ง€๋ฅผ ๊ณ„์‚ฐํ•˜๊ฒ ๋‹ค๋ผ๋Š” ๊ฒƒ์ด๋‹ค. 

 

 

์ฒ˜์Œ ์˜ˆ์ธก์น˜๊ฐ€ 10์— ํ•ด๋‹นํ•œ๋‹ค. ํ˜„์žฌ์˜ ๊ฐ’์€ 6์— ํ•ด๋‹นํ•œ๋‹ค. ๊ทธ๊ฒƒ๋“ค์„ ํ‰๊ท ๋‚ด๋ฉด ๋‹ค์Œ ๋ฒˆ ์˜ˆ์ธก์น˜๊ฐ€ 8์ด ๋˜๋Š” ๊ฒƒ์ด๋‹ค. ๊ฒ€์€์ƒ‰์€ ์‹ค์ธก์ด๊ณ  ํŒŒ๋ž€์ƒ‰์€ ์˜ˆ์ธก์ด๋‹ค. ํŒŒ๋ž€์ƒ‰์„ ๊ฐ€์ง€๊ณ  Shortest ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

Shortest Job First Scheduling

๋ฐ”๋€” ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์—ฌ๋Ÿฌ๊ฐ€์ง€์˜ ๊ฒฝ์šฐ๊ฐ€ ์กด์žฌํ•œ๋‹ค. 7ms ์ดํ›„์— ๋๋‚˜๋Š”๋ฐ ๋“ค์–ด์˜ค๋Š” ์‹œ์ ์ด ๊ทธ ์•ˆ์— ์žˆ๋‹ค๋ฉด P2๊ฐ€ ๋“ค์–ด์˜ค๋Š” ์ˆœ๊ฐ„์— ์Šค์ผ€์ค„๋ง์„ ํ• ์ง€ ๋ง์ง€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. P1์˜ ๊ฒฝ์šฐ Burst Time์€ 5๋กœ ์ˆ˜์ •ํ•ด์•ผ ํ•œ๋‹ค. P2์˜ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’๋‹ค, ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— P2๊ฐ€ 2ms์—์„œ ๋Œ๊ธฐ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. P2๊ฐ€ ๋๋‚  ๋•Œ ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋“ค์–ด์™”์„ ๋•Œ๋ฅผ ๋‹ค์‹œ ์ƒ๊ฐํ•ด๋ด์•ผ ํ•œ๋‹ค. 4ms์— ๋„์ฐฉํ•œ ๊ฒƒ์ด๋ฉด 2ms ์ดํ›„๋กœ๋ถ€ํ„ฐ 2ms ์ด๋”ฐ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. 2์ดˆ ํ›„์— P3๊ฐ€ ๋“ค์–ด์™”๊ณ . 7์ด 5, 4๊ฐ€ 2, 1์ด 0์œผ๋กœ ๋ณ€ํ•ด์•ผ ํ•œ๋‹ค. ๋‹ค์‹œ ์ƒ๊ฐํ•ด๋ณผ ๊ฒƒ.,....