본문 바로가기

운영체제/Device driver

운영체제 - Device driver

운영체제 - Device driver

Device driver의 정의
- A computer program that enables OS to interact with a hardware device

<그림 1: Device driver>

Device driver는 I/O driver와 통신이 가능하도록 하게 하는 소프트웨어이다.

I/O device가 character device, block device 혹은 network device이냐에 따라 각기 다른 device driver에 의해 처리된다.
block device driver는 character device driver와 기능이 흡사하지만 buffer cache공간을 지녔다는 차이가 있다.(*File : named collection of data)

 

파일 시스템의 역할은?
1. 디스크에 있는 data를 읽거나 쓸 수 있는 기능을 제공
2. File이나 Device와 같은 시스템 자원들에게 name space를 제공

UNIX 계열에서는 file은 byte sequence이며,
File = Real data + Meta data로 이루어진다. real data는 실제 유효한 data의 byte sequence이고 meta data는 file의 특성을 표현하는 부가적인 data이다.
meta data의 예시로는 major number와 minor number가 있다.

<그림 2: 파일의 Major, Minor number>

major number : 해당 파일이 어떤 device driver type에 의해 처리되어야 하는 지 표시
minor number : 해당 파일을 처리하는 device driver type의 instance(ex. <그림 2>와 같이 동일한 하드디스크 타입이지만, 서로 다른 Minor number를 지닌 /dev/had, /dev/had2를 확인할 수 있다)

<그림 3: character device table>

 

<그림 4: block device table>

운영체제가 파일을 접근하면 그 file이 character device, block device에 따라 각기 다른 device table을 참조한다.
device table에서는 file이 가진 major number를 확인하고 최종적으로 그에 걸맞는 device driver를 찾는다.(하드디스크가 100개여도 1개의 device driver만 있으면 된다.)

block device 파일의 접근은 character device와는 다르게 Buffer cache를 지녔다는 것이 가장 큰 차이점이다.

<그림 5: two-level interrupt handling>


Q. 운영체제가 ISR(Interrupt Service Routine)을 수행하는 동안 다른 interrupt가 발생하면 어떻게 될까?
- 이러한 경우에는 concurrency 문제가 발생하므로 운영체제에서는 ISR이 수행되는 동안에는 Interrupt를 disable하여 다른 ISR이 호출되는 것을 막는다. 리눅스 계열에서는 interrupt를 아래와 같이 두 단계로 나누어 처리하여 interrupt handler(첫번째 단계)에서는 가장 중요한 작업을 "interrupt disable" 상태에서 최대한 빠르게 처리하고 시간이 오래 걸리는 작업은 Bottom Half(두번째 단계)에서 처리함으로써 interrupt disable time을 최소화 시킨다.

Linux interrupt handler
1. Interrupt Handler
- High priority function (such as acknowledging to PIC)
- Run with interrupt disabled
- Invoked every time interrupt occurred
- Marks a bottom half as active

2. Bottom Half
- Low priority function (such as transferring data from device)
- Run with interrupt enabled
- Execution may be deferred

Polling vs. interrupt driven
1. Polling
– checks device if data can be read or written
– Usually for character device
- flag와 loop를 사용하여 flag값이 변경되는 지를 확인하는 방식

2. Interrupt Driven
– sleep process until data can be read or written
– Usually for character and block device

Blocking vs. Non-blocking
Blocking
– If data cannot be read or written: wait until ready
- 데이터를 읽거나 쓰는 요청을 하고 연산이 완료될 때까지 기다린다.
Non-Blocking:
– If data cannot be read or written: immediately returns
- 데이터를 읽을 때 데이터가 존재하지 않더라도 기다리지 않고 pass.