What does an operating system do?
- ํ๋์จ์ด์ ์ถ์ํ๋ ๋ ์ด์ด๋ฅผ ์ ๊ณต.
- ์ฉ H/W๋ฅผ ์ ๊ฒฝ์ฐ์ง ์๊ณ ํ๋ก๊ทธ๋๋ฐํ ์ ์์
- ์ํํธ์จ์ด์ ์ธ ๋ฆฌ์์ค๋ฅผ ๊ด๋ฆฌํด์ค.
- ์ฌ๋ฌ ํ๋ก๊ทธ๋จ์ด ๋์์ ์คํ๋ ์ ์๋๋ก
( = CPU, ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋๋์ด ์ธ์ ์๋๋ก OS์์ ๊ด๋ฆฌํด์ค๋ค)
- ์ฌ๋ฌ ํ๋ก๊ทธ๋จ์ด ๋์์ ์คํ๋ ์ ์๋๋ก
CPU PipeLining
- A susperscalar CPU : ๋์์ ์ฌ๋ฌ instruction์ ์ํํ ์ ์๋ ๊ตฌ์กฐ
- Kernel mode : CPU์์ ์ ๊ณตํ๋ ๋ชจ๋ instruction ์ํ ๊ฐ๋ฅ. ๋ชจ๋ H/W feature (Device)์ access ๊ฐ๋ฅ.
- User mode : ๋ชจ๋ instruction์ด ์๋ ์ ํ๋ ๋ช ๋ น์ด๋ง ์ฌ์ฉ ๊ฐ๋ฅ. Device access์๋ ์ ํ.
I/O Devices
I/O Access ๋ฐฉ์์๋ busy waiting, interrupt, DMA ๋ฑ์ด ์๋ค.
๊ทธ ์ค์์ interrupt ๋ฐฉ์์ ๋ํด์.
์ธ๋ถ์์ ์ ํธ๊ฐ CPU๋ก ๋ค์ด์ค๋ฉด (..์ค๋ต) ์ํํ๋ ๋ช ๋ น์ด๋ฅผ ์ค๋จํ๊ณ Kernal mode๋ก ์ ํํ๋ค. ํน์ ์ฃผ์์ง๋ก ๋ฐ์ด์ inst ์คํ.
- OS์์ Device controller๋ก ๋ช ๋ น.
- Device๊ฐ ์์ ์ ์๋ฃํ๋ฉด, Interrupt controller(IC)์๊ฒ ์ข ๋ฃ ์๊ทธ๋์ ์ ์ก (interrupt ์์ผ์ฃผ์ธ์ฉ).
- IC์์ CPU์๊ฒ Device๊ฐ ์์ ์๋ฃํ์์ ์๋ฆผ (๋ฌผ๋ฆฌ์ ์ ํธ)
- IC๋ฅผ ํตํด์ ์ฌ๋ฌ๊ฐ์ Disk controller๊ฐ ์ฐ๊ฒฐ๋์ด ์์ ์ ์๋ค. ์ด๋ ์ฐ์ ์์์ ์ํด์ ์ฒ๋ฆฌ๋จ.
- step3์์ interrupt signal์ ์ ์กํจ๊ณผ ๋์์, interrupt๋ฅผ ๋ฐ์์ํจ device์ ๋ฒํธ๋ฅผ ๊ฐ์ด ๋ณด๋.
- ์คํ์ค์ธ ๋ช ๋ น์ด๋ค์ด ์์ฌ์๋ ๋ฉ๋ชจ๋ฆฌ์ ๋ชจ์ต
- ๋ช ๋ น์ด ์คํ ์ค์ interrupt๊ฐ ๋ฐ์๋๋ฉด Kernel ๋ชจ๋๋ก ์ ํ๋๋ค. Interrupt vector๋ฅผ ํตํด์ Dispatch Handler๊ฐ ์๋ ์ฃผ์์ง๋ก ์ ํ.
- User ๋ชจ๋์์๋ ์ํ ๋ถ๊ฐ๋ฅํ ๋ช ๋ น์ด๊ฐ ์๊ธฐ ๋๋ฌธ์ OS๋ Kernel ๋ชจ๋์์๋ง ์ํ๋๋ค.
- memory์์ interrupt๋ฅผ ์ํํ๋ ์ฝ๋ (interrupt handler Routine)์ ํจ์นญํด์ ์ํํ๋ค.
- ์ด๋ ์๊น 4๋ฒ ์๊ทธ๋๋ก ๋๊ฒจ์คฌ๋ ๋ฒํธ๋ฅผ ๊ฐ์ง๊ณ ํน์ ์ฃผ์์ง๋ฅผ ์ฐพ์ ๋ถ๋ฌ์จ๋ค ( = interrupt vector)
- ๊ทธ ๋, ๊ธฐ์กด์ ์ฌ์ฉ๋๋ PC์ PSW? ๋ ์ง์คํฐ ์ ๋ณด๋ค์ ๋ฐ๋ก ์ ์ฅํจ. Handler์ ์์ ์ด ์๋ฃ๋๋ฉด ๋ค์ ๋์๊ฐ์ ์ฌ๊ฐํ ์ ์๋๋ก.
- returnํด์ next instruction์ด ์งํ๋๋ค.
- Fault : 0์ผ๋ก ๋๋๊ธฐ ๋ฑ, instruction์ด ์ํ ๋ถ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ผ๋ - ์ํํ๋ ๋ช ๋ น์ด๋ฅผ ์ค๋จํ๊ณ , Kernel ๋ชจ๋๋ก ์ ํํ๋ค. ํน์ ์ฃผ์์ง (PC์ ์๋ ๊ฐ)์ผ๋ก ๋ฐ์ด์ inst ์ํ
Protection
Protected Instructions : ์ปค๋ ๋ชจ๋์์๋ง ์ฌ์ฉ ๊ฐ๋ฅํ Instruction
- I/O Device์ ์ง์ ์ ์ผ๋ก ์ ๊ทผํ๋ ๋ช ๋ น์ด
- ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ๋ช ๋ น์ด
- Protected Processor Register(ex.PSW)์ ์ค์ ๋๋ Mode Bit์ ์ค์ ํ๋ ๋ช ๋ น์ด
- halt ๋ช ๋ น์ด (CPU๋ฅผ ๋ฉ์ถ๊ฒ ํ๋ ๊ฒ : ์ด๋ฐ๊ฑธ ์ ์ ๋ชจ๋์์ ์ธ ์ ์์ผ๋ฉด ์ํ)
Crossing Protection Boundaries
์ ์ ๋ชจ๋์์ ์ปค๋๋ชจ๋๋ก ์ ํํ๋ ๊ณผ์ (?)
Interrupt (H/W Interruption)
- Device Controller๊ฐ Interrupt Signal์ ๋ฐ์์ํค๋ฉด OS๊ฐ ์ปค๋๋ชจ๋๋ก ์ ํ (ํ๋์จ์ด์์ ๋์ด์ค๋๊ฑฐ)
Trap (S/W Interruption)
- ์ ์ ํ๋ก๊ทธ๋จ์ด Protected Instruction์ ์คํ์ํค๊ธฐ ์ํด System Call์ ์ด์ฉํ๋ค.
- Kernel Handler ventor์ ์ ์ฅ๋ ์ฃผ์๋ก ์ด๋์ํด (์ปค๋๋ชจ๋๋ก ์ ํ)
- System Call์ด ์คํ๋๋ ์๊ฐ, caller์ ์ํ (๋ ์ง์คํฐ, mode bit ๋ฑ)์ ๋ฐฑ์ ๋จ (fault๋ interrupt ์ํ๋๋๊ฒ๊ณผ ๋น์ท)
- ์์คํ ์ฝ ํจ์์ ํ๋ผ๋ฏธํฐ๋ก ๊ฐ๋ค์ ๋๊ธธ ์ ์์. OS๋ ๊ทธ๋ฐ ๊ฐ๋ค์ ์ฒดํฌ
- ์์ ์ด ๋๋๋ฉด ๋ค์ user mode๋ก ๋๊ธด๋ค. (iret๊ณผ ๊ฐ์ ๋ช ๋ น์ด๋ฅผ ํตํด)
System Calls
OS์ ๊ธฐ๋ฅ์ ๋ถ๋ฌ๋ด๋ ์ธํฐํ์ด์ค์ด๋ค. ํจ์์ฒ๋ผ ์ฌ์ฉ.
- PSW (Program State Word) : ์ด ๋นํธ๊ฐ ๋ช์ด๋ฉด ์ปค๋๋ชจ๋, ๋ช์ด๋ฉด ์ ์ ๋ชจ๋..
A Kernel Crossing Illustrated
ex
int read(int fd, char *buf, int size) {
// fd : File Descriptor (ํฌ์ธํฐ ๊ฐ์๊ฑฐ์)
// buf : ์ฃผ์๊ฐ
// size : readํ ๋ฐ์ดํฐ์ ํฌ๊ธฐ
move fd, buf, size to Rโ, Rโ, Rโ
// ์ธ์๋ก ๋ฐ์๊ฑธ ๋ ์ง์คํฐ์ ์ ์ฅํด๋๋ค
move READ to Rโ
// (#define READ 3 ๊ฐ์๊ฑฐ์) ํน์ ์์๊ฐ์ ์ ์ฅ
int $0x80
// Trap ๋ช
๋ น์ด๋ฅผ ์ํ
move result to R_result
// ์ปค๋๋ชจ๋์์ ์์
๊ฒฐ๊ณผ(result)๋ฅผ ๋ ์ง์คํฐ์ ์ ์ฅํ ํ, read() ์ข
๋ฃ
// result : ์ฝ์ด๋ค์ธ ๋ฐ์ดํฐ์ Byte ์
}
OS Structure
os๋ฅผ ์ด๋ป๊ฒ ๊ตฌ์ฑํ๋๊ฒ ์ข์๊ฐ..
Monolithic Kernel
- OS๊ฐ ํ ๋ฉ์ด๋ฆฌ์ธ๊ฒ
- ๋ชจ๋ ๊ฒ ๋ค ์ปค๋๋ชจ๋
- ์ต์์์์ ํน์ System Call์ ํธ์ถํ๋ฉด, ํด๋น System์ ํ์ํ ๋ค๋ฅธ Function์ ํธ์ถํด ๋๊ฐ๋ค/
- ๋ชจ๋๊ฐ Call ํ๋ ์๊ฐ์ด ์งง์, ์ฑ๋ฅ์ด ์ข์
- ๋์ ํ๋ก๊ทธ๋จ์ ํฌ๊ธฐ๊ฐ ํฐ ๋งํผ, ์ ์ง๋ณด์๊ฐ ์์ข๋ค
- ์ผ๋ถ์ ๋ฌธ์ ๊ฐ ์๊ธฐ๋ฉด ์ ์ฒด๊ฐ ์ ง๋ค์ด ๋๋ ๊ฐ๋ฅ์ฑ
MicroKernel
- ๋ง์ดํฌ๋กํ ์ ๋ค๋ง ์ปค๋์์ ๋๋ฆฌ์ : ์ปค๋๋ชจ๋์ฉ ๊ธฐ๋ฅ์ ์ต์ํํ๋ค. ๋๋จธ์ง๋ user-level process
- ์์คํ ๋ชจ๋์ด ์๋ก ๋ ๋ฆฝ๋์ด ์์ด์ ์ ๋ขฐ์ฑ์ด ์์(?)
- ๋ฌธ์ ๊ฐ ์๊ธฐ๋ฉด ๊ฑฐ๊ธฐ๋ง ๊ณ ์น๊ณ ์ด์ฉ๊ณ ํ ์ ์์. ์ ์ง๋ณด์์ฑ์ด ๋์์ง๋ค
- ํ์ง๋ง user-kernel crossing์ ํด์ผํด์ ์ฑ๋ฅ์ ๋น๊ต์ ์์ข์.