OS_14_2_I/O Devices and Operations

saewoohan·2023년 7월 28일
0

OS

목록 보기
17/19
post-thumbnail

OS_14_2_I/O Devices and Operations

1. I/O Interfaces and Operations

1) I/O Bus and Connection

  • I/O bus에 device들이 붙는다.
    • ISA, PCI, EISA, SCSI, …

2) I/O Registers

  • I/O interface는 4가지의 register로 구성되어 있다.
    • Status register: host에 의해서 state를 읽는다.
      • 현재 명령이 완료되었는지
      • data-in register에서 읽을 수 있는 byte가 있는지
      • device error가 있는지
    • Control register: host에 의해서 씌여지는 명령
      • 명령을 시작하고 device의 모드 변경
    • Data-in register: input read by the host
    • Data-out register: output written by the host

a) Two Types of I/O Register Access

  • Memory-Mapped IO (MMIO)
    • MMIO는 메모리와 I/O device의 동일한 주소 공간을 사용한다.
    • Memory and I/O 접근은 같은 instruction을 사용한다.
      • Data Bus, Address Bus, Control Bus are shared
  • Port-Mapped IO (PMIO or isolated I/O)
    • MMIO는 메모리와 I/O deviece에 대해서 동일한 주소공간을 사용한다.
    • Memory and I/O 접근은 다른 명령어를 사용해서 이루어진다.
      • Data Bus and Address Bus are shared, but Control Bus not shared

b) Memory-Mapped I/O

  • I/O device를 수용하기 위해서, CPU가 사용하는 주소 영역 중 일부는 I/O를 위해서 예약되어 있어서 일반적인 물리 메모리로 사용할 수 없다.
    • 이런 reservation은 영구적 또는 일시적이다.
  • CPU가 주소에 접근 할 때, 해당 주소가 물리 RAM의 일부를 가리킬 수도 있고, 대신 I/O device의 메모리를 가리킬 수도 있다.
    • 각 I/O device는 CPU address bus를 모니터링 하고, 해당 디바이스에 할당된 주소에 대한 CPU 접근에 응답하여 data bus를 원하는 디바이스의 하드웨어 레지스터에 연결한다.

c) Port-Mapped I/O

  • Port-mapped IO 구조는 2가지 address space를 제공한다.
    • Memory address space and I/O (or porty) address space
    • I/O address space는 process의 같은 address pin을 사용한다. 마치 memory address space인 것 처럼.

d) Instructions for Port-Mapped I/O

  • Port-mapped input/output은 특별한 명령어를 사용한다.
  • Register I/O instructions
    • e.g., in and out (80386)
    • I/O port와 general registers 사이에서 data를 옮긴다.
    • Data는 may be a byte, word, or doubleword
  • Block I/O instructions
    • e.g., ins and outs (80386)
    • data의 block을 I/O port와 memory space 사이에서 옮긴다.

3) Basic I/O Operations

  • CPU는 I/O module status를 확인한다.
  • I/O module는 status를 return 한다.
  • 준비 되었다면, CPU는 data transfer를 요쳥한다.
  • I/O module은 디바이스로부터 데이터를 가져오거나 I/O module에서 CPU로 데이터를 전송한다.

2. Device Drivers

1) I/O Device Drivers

  • Character and block device drivers
    • kernel은 일반적인 routine을 구현한다.
      • open, close, read, write, ioctl (I/O control → 4개로 표현할 수 없는 명령어를 위해서 spare)
    • User program들은 device file을 통해서 device driver에 접근 할 수 있다.
  • Network device drivers
    • Kernel은 gerneral routine을 구현한다.
      • open, close, read, write, ioctl
    • User program은 socket APIs를 통해서 device driver에 접근 할 수 있다.

2) Device File

  • Device file은 일반적인 파일처럼 파일 시스템에 나타나는 device driver의 interface이다.
  • device file은 device driver를 통해서 노출되는 내용에 따라 달라진다.
    • character device file /dev/input/mice은 마우스의 움직임을 문자 스트림으로 노출한다.
    • block device file /dev/sda, 하드 디스크의 주소 지정 가능한 영역을 노출한다.
    • 일부 device file은 입력도 받을 수 있으며, user-space application이 해당 장치 파일에 쓰는 것을 통해 장치와 통신할 수 있도록 한다.
  • Attributes
    • Type: block or character
    • Major number: specifies device driver
    • Minor number: argument to device driver

3) Structure of Character Device Drivers

4) Structure of Block Device Drivers

5) Two Types of I/O Data Transfer

  • Polling (Programmed I/O)
    • 시스템이 데이터를 읽거나 쓸 수 있는지의 여부를 반복적으로 확인한다.
    • Usually used for character devices
  • Interrupts (Interrupt-Driven I/O)
    • system이 데이터를 읽거나 쓸 수 있을 때까지 프로세스를 sleep로 유지하고, 기다리는 interrupt를 받을 때 프로세스를 깨운다.
    • Usually used for character and block devices

a) Interrupt Handling

  • Register “interrput handling routine”
    • 커널이 인터럽트가 발생할 때 등록한 핸들러를 호출하는 것이다.
  • Linux interrupt handling (two-level processing)
    • Interrupt handler (top half)
      • 높은 우선순위 함수 (PIC에 응답하는 등의 작업 수행)
      • Run with interrupt disabled
      • interrupt가 발생할 때 깨운다.
      • bottom half를 활성화한다.
    • Bottom half
      • 낮은 우선순위 함수 (장치로 부터 데이터를 전송하는 등의 작업 수행)
      • Run with interrupt enabled
      • 실행이 연기 될 수도 있다.

6) Read/Write Processing

  • Device driver는 장치의 특성이나 기반이 되는 OS의 정책에 따라 polling이나 interrupt를 선택할 수 있다.
  • Device drivers can block or not
    • Blocking (Synchronize)
      • data를 읽고 쓸 수 없는 경우 ready까지 wait
    • Non-blocking (Asynchronize)
      • 만약 data를 읽고 쓸 수 없는 경우 즉시 반환

Read

Write

7) DMA (Direct Memory Access)

  • 인터럽트 기반과 프로그래밍 I/O는 active CPU intervention을 필요로한다.
    • Transfer rate is limited
    • CPU가 점유
  • DMA (Direct Memory Access)
    • DMA controller가 필요하다.
    • CPU를 우회하여 데이터를 I/O장치와 메모리 간에 직접 전송

8) DMA Controllers

  • DMA를 수행하기 위해서 I/O device는 DMA controller에 연결 되어야 한다.
    • 하나의 controller에는 여러 device가 연결 될 수 있다.
    • Controller 자체는 메모리 매핑 된 I/O device로 간주된다.
      • Processor는 시작 메모리 주소, 전송 크기 등을 초기화한다.
    • DAM controller는 bus 경쟁과 전송 세부사항들을 처리한다.
      • 이는 bus가 경쟁과 multiple master를 처리할 수 있기 때문이다.

9) Cycle Stealing

  • DMA controller가 memory bus를 점유 할 때,
    • CPU는 일시적으로 main memory에 접근 할 수 없다.
  • cycle stealing은 CPU 계산 속도를 늦출 수 있지만, 데이터 전송 작업을 DMA에게 offload함으로 써, 전체 system 성능이 개선된다.
    • CPU는 메모리에 접근하지 않고, cache에 접근 할 수 있다.

0개의 댓글