input / output cs 537 – introduction to operating systems
TRANSCRIPT
![Page 1: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/1.jpg)
Input / Output
CS 537 – Introduction to Operating Systems
![Page 2: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/2.jpg)
Basic I/O Hardware
• Many modern system have multiple busses– memory bus
• direct connection between CPU and memory only
• high speed
– I/O bus• connection between CPU, memory, and I/O
• low speed
![Page 3: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/3.jpg)
Basic I/O Hardware
Memory Bus
I/O Bus
CPU Memory I/O
![Page 4: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/4.jpg)
Device Controllers
• I/O devices have controllers– disk controller, monitor controller, etc.
• Controller manipulates/interprets electrical signals to/from the device
• Controller accepts commands from CPU or provides data to CPU
• Controller and CPU communicate over I/O ports– control, status, input, and output ports
![Page 5: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/5.jpg)
Adding the Device Controller
Memory Bus
I/O Bus
CPU Memory
I/O
command register
status register
input register
output register
Device Controller
![Page 6: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/6.jpg)
Communicating with I/O
• Two major techniques for communicating with I/O ports
1. Special Instructions
2. Memory Mapped I/O
![Page 7: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/7.jpg)
Special Instructions
• Each port is given a special address• Use an assembly instruction to read/write a
port• Examples:
– OUT port, reg• writes the value in CPU register reg to I/O port port
– IN reg, port• reads the value at I/O port port into CPU register reg
![Page 8: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/8.jpg)
Special Instructions
• Major Issues1. communication requires the programmer to use
assembly code• C/C++/Java and other high-level languages only work
with main memory
2. how to do protection?• users should have access to some I/O devices but not to
others
![Page 9: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/9.jpg)
Memory Mapped I/O
• I/O ports are mapped directly into memory space
• Use standard load and store instructions• Examples:
– ST port, reg• stores the value at CPU register reg to I/O port port
– LD reg, port• reads the value at I/O port port into CPU register reg
• Can now use high-level language to communicate directly with I/O devices
![Page 10: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/10.jpg)
Memory Mapped I/O
• Requires special hardware to map specific addresses to I/O controllers instead of memory– this can be tricky with 2 busses
• Part of the address space is now unusable– this does not mean part of physical memory is
unusable
![Page 11: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/11.jpg)
Memory Mapped I/O
• Major Issues1.caching of memory values in CPU
• do not want to cache I/O port values in memory because they may change
• imagine a busy wait – the value it is checking will never change if it is cached
• hardware must allow some values to not be cached
2.how to do mapping of addresses to ports• with two busses this can be tricky
• need to do some kind of “snooping” on address bus
![Page 12: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/12.jpg)
Transferring Data (read request)
1. CPU issues command to I/O device controller to retrieve data
• this is slow
2. Device places data into controller buffer3. Device controller interrupts the CPU4. CPU issues command to read a single byte (or
word) of data from controller buffer5. Controller places data into data register6. CPU reads data into memory7. Repeat steps 4, 5 and 6 until all data is read
![Page 13: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/13.jpg)
Transferring Data (read request)
CPU Memory
I/O
command register
status register
input register
output register
buffer
Device Controller
1
3
4
2
6 5
![Page 14: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/14.jpg)
Direct Memory Access
• Problem with previous approach:– if CPU must issue all commands to I/O devices,
it can’t do anything else– it may take a long time to transfer all data
• Solution:– allow I/O to communicate directly with
memory (Direct Memory Access – DMA)
![Page 15: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/15.jpg)
DMA Controller
• Need a special hardware device to communicate between CPU and I/O
• DMAC has several registers1. memory address to read/write from/to
2. I/O port to communicate with
3. number of bytes to transfer
4. direction of transfer (read or write)
![Page 16: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/16.jpg)
Basic Hardware with DMA
CPU Memory
I/O
command register
status register
input register
output register
buffer
Device Controller
DMAC
1
2
3
4
5
6
![Page 17: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/17.jpg)
Basic Hardware with DMA
1. CPU instructs device controller to read• device controller informs CPU when the read is complete –
data in controller buffer
2. CPU programs the DMAC
3. DMAC asks for byte (or word) of data to be written to memory
4. Device controller writes data to memory
5. Device gives acknowledgement to DMAC• repeat steps 3, 4, and 5 until all data is transferred
6. DMAC interrupts CPU when transfer complete
![Page 18: Input / Output CS 537 – Introduction to Operating Systems](https://reader036.vdocument.in/reader036/viewer/2022081002/56649dd35503460f94ac9ffd/html5/thumbnails/18.jpg)
More on DMAC’s
• Some DMA controllers have multiple “channels”– can allow communication with more than one
device simultaneously
• Some systems choose not to use DMA at all– why?