System Structure & Program Execution

Reference: ์ดํ™”์—ฌ๋Œ€ ์šด์˜์ฒด์ œ ๊ฐ•์˜ - ๋ฐ˜ํšจ๊ฒฝ ๊ต์ˆ˜๋‹˜

์ปดํ“จํ„ฐ ์‹œ์Šคํ…œ ๊ตฌ์กฐ

Mode bit

  • Mode bit์ด๋ž€?

    • ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์˜ ์ž˜๋ชป๋œ ์ˆ˜ํ–‰์œผ๋กœ ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋žจ ๋ฐ ์šด์˜์ฒด์ œ์— ํ”ผํ•ด๊ฐ€ ๊ฐ€์ง€ ์•Š๋„๋ก ํ•˜๊ธฐ ์œ„ํ•œ ๋ณดํ˜ธ ์žฅ์น˜

  • Mode bit์ด ํ•„์š”ํ•œ ์ด์œ 

    • CPU๊ฐ€ ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์— ๋„˜์–ด๊ฐ€๋ฉด ์šด์˜์ฒด์ œ๋Š” ์ œ์–ดํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ

    • CPU์—์„œ ๊ธฐ๊ณ„์–ด๋ฅผ ์‹คํ–‰ํ•  ๋•Œ ์šด์˜์ฒด์ œ๊ฐ€ ์‹คํ–‰ํ•˜๋Š”์ง€ or ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰ํ•˜๋Š”์ง€ ๊ตฌ๋ถ„ํ•˜๋Š” ์กด์žฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค

  • Mode bit์˜ ์ข…๋ฅ˜

    Mode bit์„ ํ†ตํ•ด ํ•˜๋“œ์›จ์–ด์ ์œผ๋กœ ๋‘ ๊ฐ€์ง€ ๋ชจ๋“œ์˜ operation์„ ์ง€์›ํ•œ๋‹ค

    • 1 ์‚ฌ์šฉ์ž ๋ชจ๋“œ

      • ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ ์ˆ˜ํ–‰

      • ์œ„ํ—˜ํ•œ ๊ธฐ๊ณ„์–ด (ํŠน๊ถŒ ๋ช…๋ น)๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ฒŒ ์ œํ•œํ•œ๋‹ค

    • 0 ๋ชจ๋‹ˆํ„ฐ ๋ชจ๋“œ (= Kernel mode, System mode)

      • OS ์ฝ”๋“œ ์ˆ˜ํ–‰

      • ๋ณด์•ˆ์„ ํ•ด์น  ์ˆ˜ ์žˆ๋Š” ์ค‘์š”ํ•œ ๋ช…๋ น์–ด (ํŠน๊ถŒ ๋ช…๋ น)๋Š” ๋ชจ๋‹ˆํ„ฐ ๋ชจ๋“œ์—์„œ๋งŒ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅํ•˜๋‹ค

  • Mode bit ์ „ํ™˜ ๋ฐฉ์‹

    1. Interrupt๋‚˜ exception ๋ฐœ์ƒ ์‹œ ํ•˜๋“œ์›จ์–ด๊ฐ€ mode bit์„ 0์œผ๋กœ ๋ฐ”๊พผ๋‹ค

      • Interrupt๋Š” CPU Interrupt๋ฅผ ๋œปํ•จ

        • from Disk controller, I/O controller, etc.

      • exception์€ ๊ถŒํ•œ์ด ์—†๋Š” ์ž‘์—…์„ ์‹คํ–‰ํ•˜๋ ค๊ณ  ํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” exception์„ ๋œปํ•จ

    2. ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์—๊ฒŒ CPU๋ฅผ ๋„˜๊ธฐ๊ธฐ ์ „์— mode bit์„ 1๋กœ ์„ธํŒ…ํ•œ๋‹ค

Registers

  • Register๋ž€?

    • ์—ฐ์‚ฐ์˜ output์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„๋กœ, CPU์— ๋ถ™์–ด์žˆ๋‹ค

  • Register์˜ ์ข…๋ฅ˜

    • PC (Program Counter) Register

      • ๋‹ค์Œ๋ฒˆ์— ์‹คํ–‰ํ•  ๊ธฐ๊ณ„์–ด์˜ memory ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค

          == ์ฃผ์†Œ๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ๋‹ค
      • CPU๋Š” PC register๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ๋Š” memory ์ฃผ์†Œ์˜ ๊ธฐ๊ณ„์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค

          โ†’ ์‹คํ–‰์ด ๋๋‚˜๋ฉด ๊ทธ ๋‹ค์Œ ์œ„์น˜์˜ ๊ธฐ๊ณ„์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค
      • CPU Interrupt๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด PC Register๊ฐ€ ๋ฐ”๋ผ๋ณด๊ณ  ์žˆ๋Š” memory๋Š” OS๊ฐ€ ๋œ๋‹ค

Timer

  • Timer๋ž€?

    • CPU ์‚ฌ์šฉ๊ถŒ์„ ๋บ์–ด์˜ค๋Š” ์ž‘์—…์€ OS๊ฐ€ ํ•  ์ˆ˜ ์—†์Œ

      โ†’ CPU์˜ `๋…์ `์„ ๋ง‰๊ธฐ ์œ„ํ•œ `hardware`๊ฐ€ ํ•„์š”ํ•˜๊ณ , ๊ทธ๊ฒŒ ๋ฐ”๋กœ Timer๋‹ค
  • Timer์˜ ์—ญํ• 

    • ์ •ํ•ด์ง„ ์‹œ๊ฐ„์ด ํ๋ฅธ ๋’ค OS์—๊ฒŒ ์ œ์–ด๊ถŒ์ด ๋„˜์–ด๊ฐ€๋„๋ก Interrupt๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค

      • ์ผ์ • ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด Interrupt ๋ฅผ ๋ฐœ์ƒ์‹œ์ผœ์„œ CPU์˜ ์‚ฌ์šฉ๊ถŒ์„ ๋บ์–ด์˜ค๋Š” ์—ญํ• ์„ ํ•œ๋‹ค

  • Timer ๋™์ž‘ ๋ฐฉ์‹

    • Timer๋Š” ๋งค clock tick ๋งˆ๋‹ค 1์”ฉ ๊ฐ์†Œํ•œ๋‹ค

    • Timer ๊ฐ’์ด 0์ด ๋˜๋ฉด Timer Interrupt๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค

    • CPU๋ฅผ ํŠน์ • ํ”„๋กœ๊ทธ๋žจ์ด ๋…์ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•œ๋‹ค

Interrupt

  • Interrupt ๋™์ž‘ ๋ฐฉ์‹

    • Interrupt ๋‹นํ•œ ์‹œ์ ์˜ register์™€ Program Counter๋ฅผ ์ €์žฅํ•œ ํ›„ CPU์˜ ์ œ์–ด๋ฅผ Interrupt ์ฒ˜๋ฆฌ ๋ฃจํ‹ด์— ๋„˜๊ธด๋‹ค

  • Interrupt ์˜ ์˜๋ฏธ

    • Interrupt (Hardware Interrupt)

      • Hardware๊ฐ€ ๋ฐœ์ƒ์‹œํ‚จ Interrupt

      • ex) I/O Controller๊ฐ€ ์ผ์œผํ‚จ Interrupt

    • Trap (Software Interrupt)

      • Exception

        • Program์ด ์˜ค๋ฅ˜๋ฅผ ๋ฒ”ํ•œ ๊ฒฝ์šฐ

        • Program์ด ํŠน๊ถŒ ๋ช…๋ น์„ ์ˆ˜ํ–‰ํ•˜๋ ค๊ณ  ํ•˜๋ฉด ๋ฐœ์ƒ

      • System Call

        • Program์ด Kernel ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒฝ์šฐ

  • Interrupt ๊ด€๋ จ ์šฉ์–ด

    • Interrupt Vector

      • ํ•ด๋‹น Interrupt ์ฒ˜๋ฆฌ ๋ฃจํ‹ด ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ

    • Interrupt ์ฒ˜๋ฆฌ ๋ฃจํ‹ด

      (= Interrupt Service Routine, Interrupt Handler)
      • ํ•ด๋‹น Interrupt๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” Kernel ํ•จ์ˆ˜

System Call

  • System Call์ด๋ž€?

    • ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์ด OS์˜ ์„œ๋น„์Šค๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•ด Kernel ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ

    • CPU๊ฐ€ I/O ๋ฅผ ์š”์ฒญํ•˜๋Š” ๊ธฐ๊ณ„์–ด๋Š” ํŠน๊ถŒ ๋ช…๋ น์ด๋‹ค

      • ์ฆ‰, ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰ํ•  ์ˆ˜ ์—†๋‹ค

          (mode bit์ด 1์ธ ์‚ฌ์šฉ์ž ๋ชจ๋“œ์ผ ๋•Œ๋Š” ํŠน๊ถŒ ๋ช…๋ น์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ)
      • ๊ทธ๋ž˜์„œ OS์— ํ•ด๋‹ฌ๋ผ๊ณ  ์š”์ฒญ์„ ํ•ด์•ผํ•œ๋‹ค

          โ†’ ๊ทธ๊ฒŒ ๋ฐ”๋กœ System Call ์ด๋‹ค
    • ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์ด ์Šค์Šค๋กœ Interrupt๋ฅผ ๊ฑฐ๋Š” ๊ฒƒ์„ System Call ์ด๋ผ๊ณ  ํ•œ๋‹ค

      • CPU๋ฅผ OS์— ๋„˜๊ธฐ๊ธฐ ์œ„ํ•ด์„œ ์ง์ ‘ Program Counter๋ฅผ ๋„˜๊ธธ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— Interrupt๋ฅผ ๊ฑด๋‹ค

Device Controller

  • I/O Device Controller

    • ํ•ด๋‹น I/O ์žฅ์น˜ ์œ ํ˜•์„ ๊ด€๋ฆฌํ•˜๋Š” ์ผ์ข…์˜ ์ž‘์€ CPU

    • ์ œ์–ด ์ •๋ณด๋ฅผ ์œ„ํ•ด control register , status register ๋ฅผ ๊ฐ€์ง

      • control register

        • processor๋‚˜ ๋‹ค๋ฅธ hardware ์žฅ์น˜์˜ ๋™์ž‘์„ ์ œ์–ดํ•˜๊ณ  ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” register

      • status register

        • processor์˜ ํ˜„์žฌ ์ƒํƒœ์™€ flag ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” register

        • ์ฃผ๋กœ processor์˜ ์‹คํ–‰ ์ƒํƒœ, ์—ฐ์‚ฐ ๊ฒฐ๊ณผ, Interrupt ์ƒํƒœ์™€ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ณ  ์ œ์–ดํ•œ๋‹ค

        • Flag ์ข…๋ฅ˜

          1. Zero Flag (ZF)

            1. ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๊ฐ€ 0์ธ ๊ฒฝ์šฐ์— ์„ค์ •๋œ๋‹ค

            2. ์ฃผ๋กœ ๋น„๊ต ์—ฐ์‚ฐ๊ณผ ๊ด€๋ จ๋˜์–ด ์‚ฌ์šฉ๋œ๋‹ค

          2. Sign Flag (SF)

            1. ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๊ฐ€ ์Œ์ˆ˜์ธ ๊ฒฝ์šฐ์— ์„ค์ •๋œ๋‹ค

          3. Overflow Flag (OF)

            1. ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๊ฐ€ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ์— ์„ค์ •๋œ๋‹ค

            2. ์ •์ˆ˜ ์—ฐ์‚ฐ์—์„œ ์‚ฌ์šฉ๋œ๋‹ค

          4. Carry Flag (CF)

            1. ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๊ฐ€ ์บ๋ฆฌ(์ž๋ฆฌ ์˜ฌ๋ฆผ)๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ์— ์„ค์ •๋œ๋‹ค

            2. ์‚ฐ์ˆ  ์—ฐ์‚ฐ์—์„œ ์‚ฌ์šฉ๋œ๋‹ค

          5. Parity Flag (PF)

            1. ์—ฐ์‚ฐ ๊ฒฐ๊ณผ์˜ ํ•˜์œ„ ๋น„ํŠธ๋“ค ์ค‘ 1์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ง์ˆ˜์ผ ๊ฒฝ์šฐ์— ์„ค์ •๋œ๋‹ค

    • local buffer๋ฅผ ๊ฐ€์ง (์ผ์ข…์˜ data register)

  • I/O ๋Š” ์‹ค์ œ device ์™€ local buffer ์‚ฌ์ด์—์„œ ์ผ์–ด๋‚จ

  • Device Controller๋Š” I/O ๊ฐ€ ๋๋‚ฌ์„ ๊ฒฝ์šฐ Interrupt ๋กœ CPU์—๊ฒŒ ๊ทธ ์‚ฌ์‹ค์„ ์•Œ๋ฆผ

  • ์šฉ์–ด ์ •๋ฆฌ

    • Device Driver (์žฅ์น˜ ๊ตฌ๋™๊ธฐ)

      • OS ์ฝ”๋“œ ์ค‘ ๊ฐ ์žฅ์น˜๋ณ„ ์ฒ˜๋ฆฌ ๋ฃจํ‹ด โ†’ software

      • CPU๊ฐ€ device controller์—๊ฒŒ ๋ถ€ํƒ์„ ํ•˜๋Š” ๊ธฐ๊ณ„์–ด

      • ์ปดํ“จํ„ฐ ๋‚ด๋ถ€์—์„œ CPU๊ฐ€ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฝ”๋“œ

    • Device Controller (์žฅ์น˜ ์ œ์–ด๊ธฐ)

      • ๊ฐ ์žฅ์น˜๋ฅผ ์ œ์–ดํ•˜๋Š” ์ผ์ข…์˜ ์ž‘์€ CPU โ†’ hardware

CPU๊ฐ€ OS์— ๋„˜์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ

Interrupt๊ฐ€ ๊ฑธ๋ฆฌ๋ฉด ๋„˜์–ด๊ฐ„๋‹ค

  1. Hardware ์žฅ์น˜๋“ค์ด Interrupt๋ฅผ ๊ฑฐ๋Š” ๊ฒฝ์šฐ

    โ†’ ์ง„์ •ํ•œ ์˜๋ฏธ์˜ Interrupt

    • Timer

      • CPU์˜ ๋…์ ์„ ๋ง‰๊ธฐ์œ„ํ•œ hardware

  2. Program์ด ์ง์ ‘ Interrupt line์„ ์„ค์ •ํ•˜๋Š” ๊ฒฝ์šฐ

    • System call

      • CPU๊ฐ€ I/O ๋ฅผ ์š”์ฒญํ•˜๋Š” ๊ธฐ๊ณ„์–ด๋Š” ํŠน๊ถŒ ๋ช…๋ น ์ด๋ผ ์‚ฌ์šฉ์ž Program์ด ์‹คํ–‰ํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ์กด์žฌํ•œ๋‹ค

Sync I/O vs Async I/O

๋‘ ๊ฒฝ์šฐ ๋ชจ๋‘ I/O ์™„๋ฃŒ๋Š” Interrupt๋ฅผ ํ†ตํ•ด ์•Œ๋ ค์ค€๋‹ค

  • ๋™๊ธฐ์‹ ์ž…์ถœ๋ ฅ (Synchronous I/O)

    • I/O ์š”์ฒญ ํ›„ ์ž…์ถœ๋ ฅ ์ž‘์—…์ด ์™„๋ฃŒ๋œ ํ›„์—์•ผ ์ œ์–ด๊ฐ€ ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์— ๋„˜์–ด๊ฐ

    • ๊ตฌํ˜„ ๋ฐฉ๋ฒ• 1. I/O๊ฐ€ ๋๋‚  ๋•Œ๊ฐ€์ง€ CPU๋ฅผ ๋‚ญ๋น„์‹œํ‚ด - ๋งค ์‹œ์  ํ•˜๋‚˜์˜ I/O๋งŒ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ์Œ 2. I/O๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ํ•ด๋‹น ํ”„๋กœ๊ทธ๋žจ์—๊ฒŒ์„œ CPU๋ฅผ ๋นผ์•—๊ณ , I/O ์ฒ˜๋ฆฌ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ค„์— ๊ทธ ํ”„๋กœ๊ทธ๋žจ์„ ์ค„ ์„ธ์›€ - ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋žจ์—๊ฒŒ CPU๋ฅผ ์คŒ

  • ๋น„๋™๊ธฐ์‹ ์ž…์ถœ๋ ฅ (Asynchronous I/O)

    • I/O ๊ฐ€ ์‹œ์ž‘๋œ ํ›„ ์ž…์ถœ๋ ฅ ์ž‘์—…์ด ๋๋‚˜๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ์ œ์–ด๊ฐ€ ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์— ์ฆ‰์‹œ ๋„˜์–ด๊ฐ

DMA (Direct Memory Access)

  • ๋น ๋ฅธ I/O ์žฅ์น˜๋ฅผ memory์— ๊ฐ€๊นŒ์šด ์†๋„๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ

    โ†’ memory์— ์ง์ ‘ ์ ‘๊ทผํ•˜๊ธฐ์œ„ํ•œ ์žฅ์น˜

  • CPU์˜ ์ค‘์žฌ ์—†์ด device controller๊ฐ€ device์˜ buffer storage์˜ ๋‚ด์šฉ์„ block ๋‹จ์œ„๋กœ ์ง์ ‘ ์ „์†ก

  • Byte ๋‹จ์œ„๊ฐ€ ์•„๋‹ˆ๋ผ block ๋‹จ์œ„๋กœ interrupt๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค

Last updated