01 Introduction to Operating Systems

초강송·2024년 10월 6일

운영체제

목록 보기
1/13

아주대학교 김상훈 교수님의 운영체제 강의와 강의 자료를 바탕으로 작성된 글입니다.


운영체제는 정부(government)와 유사하다. 운영체제는 정부처럼 그 자체로는 유용한 기능을 수행하지 못한다. 운영체제는 단순히 다른 프로그램이 유용한 작업을 할 수 있는 환경을 제공한다.

What operating Systems Do

사용자 관점에서 운영체제는 main은 아니면 system resource를 abstract 해 주는 굉장히 중요한 조연이다.

  • Allow to use computer hardware in an efficient and safe manner
  • Make the computer system convenient to use
  • Execute user programs and help their program solving

컴퓨터에서 돌고 있는 프로세서는 서로 리소스를 얻으려고 경쟁한다. 이런 경쟁을 관리하고 비상 상황(하드 디스크 이상, 네트워크 이상)을 대응하는 게 운영체제의 역할이다

  • Keep monitoring the systems and programs
  • Protect the system
  • Deal with exceptional situations

A View of Operating System

본질적으로 kernel은 같은 걸 쓰고 user interface만 바꿔서 쓰는(user에게 customize함) 경우가 비일비재하다. 따라서 핵심 core 파트를 분석하는 게 중요하다.
[services + operating system + hardware] 파트를 묶어 kernel이라고 표현한다.

Computer-System Architecture

옛날에는 컴퓨터의 연산 순서를 circuit에 선으로 꽂아서 정했다. 따라서 a라는 기능을 하다가 b를 하려면 이 선을 다 빼고 다시 꽂아야 하므로 굉장히 번거로웠다. 따라서 메모리에다가 실행할 instr을 써놓고 cpu가 그 instr과 data를 메모리로부터 가져와서 처리하는 아이디어를 von Neumann이 떠올렸다.

CPU(Central Processing Unit)

  • A.k.a processor
  • Most systems use a general-purpose processor
  • But may have special-purpose processor(특별한 기능을 좀 더 잘하도록 만들어진 processor, GPU/TPU)

Computer System Organization

90년대 2000년대 컴퓨터 시스템 구조이다. bus는 대용량 데이터를 전송하는 전선 같은 거다. 컴퓨터에 있는 모든 component들은 다 이 common bus에 붙어 있다. 그러나 cpu와 memory와 달리 i/o 디바이스는 버스에 직접 붙어 있지 않다. 이 디바이스를 관장하는 device controller에 연결돼 있고 이 controller가 bus에 연결돼 있다.
cpu는 버스를 이용해 메모리에 있는 데이터를 갖고 올 수 있다. 물론 굉장히 간단한 데이터는 다른 장치에게 보낼 수 있지만 일반적으로 cpu는 메모리로부터만 데이터를 가져온다.

  • One or more CPUs, device controllers are connected through a
    common bus providing access to shared memor

각 controller는 local buffer(각 controller의 memory 역할)가 하나씩 있다. cpu가 이 local buffer를 바로 읽으면 좋겠지만 컴퓨터 주변에는 주변 장치가 매우 많다. cpu를 만들 때 다른 디바이스와 통신이 가능하게끔 만드려면 가능은 하지만 굉장히 비싸고 engineering cost도 많이 든다.
그래서 과정이, 만약 내가 disk에서 어떤 내용을 읽었다고 가정하면, 그 data는 disk controller의 local buffer로 옮겨졌다가 local buffer에서 memory로 옮겨지고 그걸 cpu가 읽은 것이다.

cpu가 d.c한테 "가져다 두었냐?" 계속 물어보는 건 PIO 형태이다. "가져다 두었으면 알려줘라" 이 방식이 interrupt이다. cpu와 controller 사이에는 interrupt를 날릴 수 있는 interrupt request line이 있다. (interrupt를 날리는 건 그냥 전선에 전압을 걸면 되는데, 이건 hardware logic으로 처리한다.)

지금까지의 핵심 내용을 정리하면 아래와 같다.
1. cpu는 mem로부터만 데이터를 읽을 수 있다.
2. cpu는 controller에게 간단한 request를 날릴 수 있다.
3. controller는 interrupt request line으로 cpu에게 interrupt를 날릴 수 있다.

Common Functions of Interrupts

어떤 interrupt를 받았을 때 어떤 action을 취해야 하는지 소프트웨어적으로 instr이 기술된 부분이 interrupt service routine( = interrupt handler routine = interrupt handler)이다. 이 instr 역시 mem에 구현돼 있다.

어떤 interrupt handler를 불러야 할지는 software가 아니라 hardward 파트로 만들어져 있다. 특정 핀에 전압이 걸리면 하드웨어가 자신이 아는 Interrupt Descriptor Table(IDT)(mem에 있음, 내가 실행해야 하는 코드의 주소가 쓰여 있음) 를 보고, 해당하는 위치에 있는 주소로 가서, 그 주소에 있는 instr을 가져와 처리한다. 이 IDT는 cpu마다 다르고 특정 핀에 대한 핸들러의 위치는 os가 컴퓨터가 부팅될 때 써준다.

지금까지의 핵심 내용을 정리하면 아래와 같다.

  1. cpu는 메모리에만 있는 데이터만 읽을 수 있고 주변 장치들과는 간단한 데이터만 주고받든지 interrupt line통해서 연결돼 있다.
  2. 주변 장치들은 cpu의 어텐션이 필요하면 interrupt request line에 전압을 건다. 전압을 걸면 cpu가 전압이 걸린 pin의 번호를 보고 idt에서 그 pin에 해당하는 interrupt service routine 주소로 가서 instr를 실행한다.

Common Functions of Interrupts

Interrupt가 터지면 컴퓨터 CPU의 register들은 지정된 모종의 위치에 dump시키고 IDT를 확인한 다음 interrupt를 handling한다. handling을 마친 다음에는 저장해 뒀던 register 값을 이용하여 CPU를 복원시킨다.

  • Systems preserve the current state of the CPU
    • To come back after handling the interrupt
    • Save registers and the address of the interrupted instruction
    • Done by HW or/and operating systems
  • Return to the last state by restroing the registers

Advanced Concepts in Interrupts

  • Programmable Interrupt Controller (PIC)
    • 앞에서는 cpu랑 device controller 사이에 interrupt request line이 1:1로 모두 연결돼 있다고 설명했지만 요즘 건 좀 다르다. 요즘에는 interrupt를 대리해서 처리해 주는 PIC가 있고 이 PIC에 pin들이 잔뜩 붙어져 있다.
    • A Programmable Interrupt Controller (PIC) is a hardware component used in computers to manage interrupts generated by other hardware components. It consists of input interrupt request lines and an output line to a secondary PIC. When an interrupt occurs on any of these lines, it is sensed by the processor. The PIC can be programmed to enable or disable specific interrupt lines. (https://www.sciencedirect.com/topics/computer-science/programmable-interrupt-controller)
  • Interrupt Ack

    • cpu가 interrupt handling을 끝냈다는 걸 명시적으로 알리는 것
    • 예시) 친구가 카톡을 보내면 내가 읽고 답장
  • Interrupt Sharing

    • 하나의 interrupt를 여러 device가 share
    • 예시) 단톡방
    • 13번으로 interrupt를 날리면 slave pic가 IRQ2로 Master PIC에게 전달하고, MASTER가 CPU에게 최종적으로 interrupt를 날린다. CPU는 자신에게 interrupt가 도착했다는 사실은 알 수 있지만, 그 interrupt를 어떤 device가 보냈는지는 알 수 없다.
  • Interrupt Masking

    • Interrupt를 계속 날려도 current context processing을 계속 유지
    • 예시) 방해 금지 모드
  • Nested Interrupt Handling

    • interrupt를 핸들링 하는 도중에 도착한 다른 인터럽트를 핸들링
    • 예시) A랑 카톡 나누다가 도착한 B의 카톡에 답장

0개의 댓글