I/O Systems



[HAL ](https://texonom.com/hal-8414f1c7b7014f5abf567f9e18dc0da0)


[Device Driver](https://texonom.com/device-driver-c78b1565bfbb4ffc874f374e6f765ad1)

### I/O: a major factor in system performance
– Demands CPU to execute device driver, kernel I/O code
 – Mode switches due to interrupts 
– Data copying
 – Network traffic especially stressful
Guidelines 
– Reduce the number of mode switches
 – Reduce data copying 
– Reduce interrupts by using large transfers, smart controllers
 – Use DMA 
– Move processing primitives into hardware; concurrent operations of CPU and device controllers. 
– Balance CPU, memory, bus, and I/O performance for highest throughput - to no bottleneck
> ### We need to know I/O execution path
> Since there is so many i/o device, so we need i/o bus
> 
> ### I/o address
> predefined address between CPU and I/O address
> 
> ### DMA (direct memory access)
> Bypass CPU to transfer data directly between I/O device and memory. – Used to avoid programmed I/O for large data movement. – Require DMA controller
> 
> – Cycle stealing 
> •. – Burst mode • 
> Addressing in DMA
> memory region should be pinne during dma

> ![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ffe055639-5140-4e73-bbdb-90f7a805d653%2Ftemp.jpg?table=block&id=8afeef5f-31d4-47b9-8708-f2fea083b955&cache=v2)
> Typical PC Architecture
> ![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F760d1129-9ed5-44e9-8eda-8c8daee17b89%2Ftemp.jpg?table=block&id=7dc8321c-cdad-4b71-8d87-763b4fa8abf6&cache=v2)



# Interact
Three ways to interact data with hw device
1. polling (do not use) - low levelkeep checking
2. interrupt-driven I/Ointerrupt always raised by I/O



# Access
3. DMA (Direct Memory Access)
> By DMA controller, bypass CPU to transfer data directly between I/O device and memory
> since we need memory bus share - various way of technic
4. Memory-mapped I/O



# I/O Software
> i/o controller make interrupt and interrupt handler to kernel and done by device driver - device dependent code
> Always check interrupt at final red box at lower picture 
> 
> ### Device driver
> Standard driver interfaces be given like Virtual File System - to manageable by kernel architect
> ### Driver-independent I/O Software
> they are accessed through file system calls

> ![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fb036ccab-880e-4018-a275-df44ae43d1df%2Ftemp.jpg?table=block&id=037d66e8-04ec-45d3-99be-16689a75f3ad&cache=v2)
> I/O software layer
> ![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F5b010c89-ec87-4eb4-af36-bbf3a1a6cee0%2Ftemp.jpg?table=block&id=c8087403-17dd-47f2-b304-6e9c90bf56fd&cache=v2)

`In Unix devices are modeled as special files`



CPU is fast and device is slow so we buffering
- buffered in use space
- buffered in the kernel space
- double buffering in kernel



## User-space I/O Software
> ### - Provided as a library - system call
> -  fopen(), open()
> - buffering for fgetc()
> 

> ### - Spooling
> - dealing with dedicated devices in a multi-programming system
> - implemented by a daemon and spooling directory

> VFS fixed function to develop, like file interface metaphor
> so make my own backspace touch blue-tooth sticker


> ![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fa92ff712-8bfb-42ca-b8a2-356c1b22e06a%2FUntitled.png?table=block&id=5ece07c1-9346-4aed-902b-bfd9c7200fe3&cache=v2)

> ![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F9b9f8471-1d0e-45a6-98b3-270d0f111dfa%2FUntitled.png?table=block&id=eb6cafc2-18dd-414d-bdf9-14298dbca0fe&cache=v2)



# Performance
I/O is a major factor in system performance itself - bottleneck (ex. network traffic, data busing, mode switching due to interrupts, CPU to execute driver, kernel I/O code)



