This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
250
Input/Output
Chapter 5
5.1 Principles of I/O hardware5.2 Principles of I/O software5.3 I/O software layers5.4 Disks5.5 Clocks5.6 Character-oriented terminals5.7 Graphical user interfaces5.8 Network terminals5.9 Power management
251
I/O Devices
Block devices (e.g., disks)– info stored in fixed-size blocks (512-32K bytes)
– address r/w each block independent of others
Character devices (mouse, network interface)– accepts/delivers a stream of characters
– not block-addressable
Other types: clocks
2
252
I/O Devices (2)
Block
253
Principles of I/O Hardware
Some typical device, network, and data base rates
3
254
Device Controllers/Adapters
• I/O devices have components:– mechanical component– electronic component
• The electronic component is the devicecontroller– may be able to handle multiple devices
• Controller's tasks– convert serial bit stream to block of bytes– perform error correction as necessary– make available to main memory
255
Device Controllers (2)
Printed circuit board on a slot (bus) fromwhich cable goes to actual device
• between controller and device– low-level interface, typically bitstream (ECC)– controller does conversion, error correction
• device driver initializes controller with a fewhigh-level parameters, controller does rest– memory region for data specified
• controller may have its own powerfulprocessor
4
256
Memory-Mapped I/O (1)
• Separate I/O and memory space• Memory-mapped I/O• Hybrid
257
Communicating w/controllersController has• registers to comm with OS
• often data buffer (e.g., video ram)How is controller visible to OS?• dedicated I/O port, special machine inst.• memory-mappedLines are “raised” or asserted
5
258
Communicating w/controllers (2)Memory-mapped pros and cons+ use normal memory access instructions
otherwise some ops require loading, etc.
+ enforce protection via address space- caching a device control register: disaster!- complicated if more than one bus (common)
– send addresses to memory, then devices…
259
Memory-Mapped I/O (2)
(a) A single-bus architecture(b) A dual-bus memory architecture
6
260
Direct Memory Access (DMA)
• Besides control, need to move data
• Interrupt
261
Direct Memory Access (DMA)
Operation of a DMA transfer
7
262
Interrupts Revisited
How interrupts happens. Connections between devices andinterrupt controller actually use interrupt lines on the busrather than dedicated wires
263
Principles of I/O SoftwareGoals of I/O Software (1)
• Device independence– programs can access any I/O device
– without specifying device in advance· (floppy, hard drive, or CD-ROM)
• Uniform naming– name of a file or device a string or an integer
– not depending on which machine
• Error handling– handle as close to the hardware as possible
8
264
Goals of I/O Software (2)
• Synchronous vs. asynchronous transfers– blocked transfers vs. interrupt-driven
• Buffering– data coming off a device cannot be stored in
final destination
• Sharable vs. dedicated devices– disks are sharable
– tape drives would not be
265
I/O-related work
• programmed I/OCPU does all the work: polling, busy-waiting
• interrupt-driven I/OCPU interrupted by device when ready
• I/O using DMADMA controller plays CPU’s role
9
266
Programmed I/O (1)
Steps in printing a string
267
Programmed I/O (2)
Writing a string to the printer usingprogrammed I/O
10
268
Interrupt-Driven I/O
• Writing a string to the printer using interrupt-driven I/O– Code executed when print system call is made– Interrupt service procedure
269
I/O Using DMA
• Printing a string using DMA– code executed when the print system call is made
– interrupt service procedure
11
270
I/O Software Layers
Layers of the I/O Software System
271
Interrupt Handlers (1)
• Interrupt handlers are best hidden– have driver starting an I/O operation block until
interrupt notifies of completion
• Interrupt procedure does its task– then unblocks driver that started it
• Steps must be performed in software afterinterrupt completed
1. Save regs not already saved by interrupt hardware2. Set up context for interrupt service procedure
12
272
Interrupt Handlers (2)
3. Set up stack for interrupt service procedure
4. Ack interrupt controller, reenable interrupts
5. Copy registers from where saved
6. Run service procedure
7. Set up MMU context for process to run next
8. Load new process' registers
9. Start running the new process
273
Device Drivers
Communications between drivers and devicecontrollers goes over the bus
13
274
Device Drivers (ii)
• Monolithic binary OS– must recompile kernel to add a driver
• PCs, etc., dynamically load driver• Standard interface for block; for character
– driver may service several devices
• Similar general structure– validate input params, if valid translate to phys.– get & exec sequence of instructions– wait for device (block), or not; verify checksum– pass data to device-indep software, return status
275
Device-Independent I/O Software (1)
Functions of the device-independent I/O software
Providing a device-independent block size
Allocating and releasing dedicate devices
Error reporting
Buffering
Uniform interfacing for device drivers
14
276
Device-Independent I/O Software (2)
(a) Without a standard driver interface
(b) With a standard driver interface
277
Device-Independent I/O Software (3)
(a) Unbuffered input(b) Buffering in user space(c) Buffering in the kernel followed by copying to user space(d) Double buffering in the kernel
15
278
Device-Independent I/O Software (4)
Networking may involve many copies
279
User-Space I/O Software
• most I/O software within OS but librarieslinked with user programs outside kernel(syscalls effected by library procedures)– real I/O related work: formatting of strings
• spooling: daemon process and spooling dir– printing, email, news (USENET)
16
280
User-Space I/O Software (2)
Layers of the I/O system and the main functions ofeach layer