본문 바로가기

Operating System Design

Operating System Design - I/O Systems

I/O hardware

 

Port : connection point for device

Bus : daisy chain or shared direct access

Controller(host adapter) : elections that operate port, bus, device

 

I/O instructions controler device (data-in-register, data-out-register, status register, control register)

Devices have addresses used by Direct I/O instructions, Memory-mapped I/O

 

Polling

 

The CPU repeatedly checks the command line bit (to see when it is available)

The controller repeatedly checks the status register, waiting for the device to complete the operation

 

1. Read busy bit from status register which is located in each device until it reaches 0 (busy-wait cycle)

2. Host sets write bit (copy write command to the command register) and copies data into data-out-register

3. Host sets command-ready bit

4. Controller executes transfer

5. Controller read command in command register and see the write command. Also, it reads the data-out-register to get the byte and does I/O to a device (executes transfer)

6. Controller clears busy bit, error bit, command-ready bit when transfer done

 

It can happen in 3 instruction cycles (Read status, logical-and to extract status bit, branch if not zero)

 

Interrupts

 

Enable overlap of cpu and i/o device operations when using interrupts (concurrently) 

Higher cpu usage than polling

However, because interrupts involve a high cost of context switching, polling is more efficient for hardware that is fast enough to end with a single polling

1. CPU provide a command to device driver (Context switching happen when it reaches system call. Then, save a current process state into a PCB block. After that, OS get cpu resource and jump to kernel space. Then, it dispatch interrupt to corresponding interrupt handler by using interrupt vector)

2. Device driver inittiates I/O (Context switching happen because CPU resource is idle)

3. Initiates I/O (I/O operation by I/O device)

4. Input ready, output complete, or error generates interrtup singal to the interrupt-request line which is in CPU

5. CPU receiving interrupt, transter controler to interrupt handler (Context switching happen. Almost same as step 1)

6. Interrupt handler processes data, returns from interrupt (Context switching happen)

7. CPU resumes processing of interrupted task(CPU restores original process' state by using the PCB block)

 

Direct Memory Access (DMA)

 

Used to avoid programmed I/O for large data movement

Writes location of command block to DMA controller

Bus mstering of DMA controller - grabs bus from CPU (Cycle stealing)

1. A host writes a DMA command block into memory (contains a pointer to the source of a transfer, a pointer to the destination of the transfer, and a count of the number of bytes to be transferred)

2. The CPU writes the address of this command block to the DMA controller, then goes on with other work 

3. The DMA controller proceeds to operate the memory bus directly, placing addresses on the bus to perform transfers without the help of the main CPU

4. The device controller places a signal on the DMA-request wire when a word of data is available for transfer

5. When the device controller receives the DMA-acknowledge signal, it transfers the word of data to memory and removes the DMA-request signal

6. When the entire transfer is finished, the DMA controller interrupts the CPU

 

Application & Kernel I/O Interface

 

I/O system call encapsulate device behavior in generic classes

Device driver layer hides differences among I/O controllers from kernel

New devices talking already-implemented protocols need no extra work

Each Operating System has its own I/O subsystem structures and device driver frameworks

Characteristics of I/O Devices

 

Block I/O : Raw I/O, direct I/O, or file-system access, memory-mapped file access possible (disk drive)

Character devices : Libraries layered on top allow line editing

Don't know what data and when they will be given as an input or output (keyboard, mice, serial port)

Network devices : Which sockets have the received packets or available buffers to send packets (prevent busy-waiting)

 

Nonblocking and Asynchronous I/O

 

Blocking(Synchronous) : process suspended until I/O completed

Easy to use and understand, insufficient for some needs

Nonblocking : I/O call returns as much as available

Asynchronous : process runs while I/O executes

Difficult to use, I/O subsystem signals process when I/O completed

 

 

Vectored I/O

 

Vectored I/O allows one system call to perform multiple I/O operations

Decreases context switching and system call overhead, some veersions provide atomicity

 

Kernel I/O Subsystem

 

Scheduling : some I/O request ordering, try fairness

Buffering : store data in memory while transfering between devices

Caching : faster device holding copy of data

Spooling : hold output for a device

Device reservation : provides exclusive access

Error handling : Operating System can revocer from disk read, device unavailble, transient write failures

I/O protection : user process may accidently or purposefully attempt to disrupts normal operation via illegal I/O instructions

Power management, management of the name space for file and devices, access control to files and devices, operation control, file-system space allocation, device allocation, device-status monitering ...

 

System call to perform I/O

 

Life Cycle of an I/O Request

 

Intercomputer Communication