강의 정리/운영체제 강의 정리

Operating Systems - Review of Computer Hardware

htaekjung 2024. 11. 4. 15:34

KMOOC 운영체제의 기초

I.Computer Systems Architecture

Components inside Computer

Stored Program concept - 하드웨어가 data & data 조작하는 코드를 메모리에 저장하는 방식

  • 폰 노이만 구조
    • 필수요소
      • Processing unit : ALU, registers, control unit, PC(Program Counter), CPU
        • data path, memory, I/O에게 명령을 내리는 구성요소
      • Memory : storage area of data and instructions
      • I/O : User interface devices, Storage devices, Network adapters
        • I/O Controller : CPU대신 I/O 디바이스 통제해서 I/O operation 수행 -> CPU로 interrupt 보내주는 것
  • 데이터 단위
    • 1 bit
    • 1 byte = 8 bits
    • 1 word : 하드웨어가 주고받는 데이터의 유닛, CPU 안에서의 연산이 word를 단위로 나타냄

 

System Interconnect

  • System bus
    • CPU : Bus를 주체적으로 사용

System bus

  • Control Bus
    • 시스템의 각 구성 요소가 수행할 작업을 제어하고 동기화하는 신호를 전달하는 버스
    • 주로 CPU가 메모리나 장치와의 통신에서 read/write 같은 명령을 내리기 위해 사용됨
  • Address Bus
    • 메모리나 장치의 위치(주소)를 지정하는 신호를 전달하는 버스
    • CPU가 데이터나 명령을 read/write 할 때 대상이 되는 메모리나 장치의 주소를 전달
  • Data Bus
    • 실제 데이터가 전송되는 통로
    • CPU와 메모리, 또는 다른 장치 간에 데이터를 주고받을 때 사용됨
  • Bus arbiter
    • 여러개의 component 중 하나를 선정해 Bus 허용(bus grant signal)
    • CPU가 bus request signal을 bus arbiter에게 주면 bus arbiter이 bus grant signal을 component에게 줌
  • Bus master
    • 주체적으로 bus transaction(read/write) control 할 수 있는 component
    • ex1. CPU
      • Memory와 CPU 레지스터 간 데이터를 옮김
    • ex2. DMA(Direct Memory Access)
      • CPU의 도움 없이 메인 메모리와 I/O buffer 간 데이터를 옮김
      • CPU를 경유하지 않고 I/O controller가 메인 메모리에 직접 접근해서 ㄷ데이터 모아 block으로 만든 다름 통째로 출력하는 연산
    • Bus slave
      • Bus transaction(read/write)를 initiation 했을 때, response할 수 있는 entity component
      • ex1. Memory controller
      • ex2. Device Controller(I/O Device)
        • Data register : I/O register
          • input register : input device가 생성한 데이터를 CPU에 전달하기 위해 데이터 임시 저장하는 곳
          • output register : CPU가 출력하기를 원하는 데이터 저장하는 곳
        • Control register : control register, status register
          • 지금 연산이 input/output operation인지 표현하는 명령어 command

I/O operations

I/O operations are initiated by CPU

  • Output operation
    • Status register을 통해 output register이 가능한지 확인
      • 만일 비어있으면 데이터를 output register로 옮기고 output command를 I/O register의 control register로 옮김
      • 비어있지 않으면, output register이 가능해질 때까지 반복 
    • Success -> CPU로 거꾸로 interrupt 걸게 됨
    • Interrupt-driven I/O : 장치가 준비되었을 때 CPU에 interrupt 신호를 보내 데이터를 전송하거나 처리 요청
    • Polling I/O : CPU가 주기적으로 장치 상태 확인(poll)하여 데이터 전송이 가능한지 여부 검사
      • 비효율적
  • I/O addressing (I/O register address 구별 방법) 의 2가지 방법
    • Memory-mapped I/O
      • 사용되지 않은 주소 매핑
      • 레지스터들을 메모리 주소 공간의 일부로 할당하여 관리
      • 추가적인 명령어 필요 없음, 프로그래밍 용이
    • Port-mapped I/O
      • 별도의 주소공간 사용, 메모리 주소 & 입출력 공간 분리
      • 메모리 관리 효율적

 

II.Interrupt Mechanism (중요!!)

CPU 외곽에 있는 circuit - I/O Controller가 CPU의 관심을 얻어오고자 할 때 CPU에 전달하는 시그널

  • Operating System scheduler & dispather 구현하는데 있어서 굉장히 중요한 하드웨어 support임

Types of interrupts

  • Hardware interrupt
    • 택배 초인종 울릴 때 하는 일 멈추고 택배 받으러 가는 것 ( 하는 일 멈추고 interrupt 수행)
    • Asynchronous
    • CPU 외곽에 있는 external interrupt source 필요 
    • 1. 하드웨어 interrupt signal 도착해서 interrupt request number 얻음
    • 2. Interrupt vector table 뒤져서 interrupt 서비스 루트는 점프해서 수행한 다음 리턴
  • Software interrupt
    • 책 읽다가100페이지 읽으면 물 마시고 오는 것(100페이지까지 읽은 순간 software interrupt 수행)
    • Synchronous 
    • 1. 내부적으로 sofrware interrupt instruction 수행 
    • 2. CPU가 시그널을 받지 않지만 interrupt 걸린 것처럼 생각
    • 3. Software instructions의 operand로 IRQ number를 받음 
    • 4. Vector table 뒤져서 서비스 루틴 점프하게 됨

Interrupt Operation

  • Interrupt 발생
  • Interrupt request number 획득
  • Interrupt request number를 인덱스로 있는 배열을 뒤지면 interrupt handling하는 루틴 시작 주소 얻음 
    • Interrupt handling : IRQ(Interrupt Request) number를 통해 ISR의 주소 얻는 것
  • 현재 프로그램의 실행 멈춤
  • interrupted instruction의 주소 저장 -> PC에 저장
  • Jump to interrupt address

 

III.Hardware Protection

Dual Mode Operation 

  • 무한히 안전한 Kernel mode
    • privilege instruction (kernel mode에서만 수행되는 명령어) 수행
  • 권한에 일부 제약이 있는 User mode

Transition between Modes

  • 전제 : OS가 신뢰 가능하며, 인터럽트가 OS 내에 구현되어야 함 
    • Interrupt / Trap : User mode -> Kernel mode
    • Return from ISR  : Kernel mode -> User mode
  • PSR(Processor Status Register) : 현재 모드를 알려주는 역할
    • 0 : Kernel mode
    • 1 : User mode
  • System call
    • user code가 필요로 하는 operating system service를 받기 위해서 software interrupt 걸어주는 것

 

I/O protection

  • I/O controller에 있는 레지스터들의 access 통제 -> 유저 코드는 I/O 장치 사용 불가
  • 모든 I/O 명령어들은 privileged instructions임

 

Memory protection

  • Base registers, Bound registers로 해결
    • 이전 포스트에 설명

 

CPU protection

  • CPU가 독점되는 걸 방지