Wednesday, June 8, 2011

Diigo是个好东西May20-review 482


Device Controller硬件部分
I/O units typically consist of a mechanical component and an electronic component. It is often possible to separate the two portions to provide a more modular and general design. The electronic component is called the device controller or adapter.

The controller’s job is to convert the serial bit stream into a block of bytes and perform any error correction necessary. The block of bytes is typically first assembled, bit by bit, in a buffer inside the controller. After its checksum has been verified and the block declared to be error free, it can then be copied to main memory.

Memory-Mapped I/O
- a few registers used for communicating with the CPU. (知道device的state)
- data buffer that the operating system can read and write (video RAM for display pixels)
How to communicate?
- I/O port, special I/O instructions
  i) 2 address spaces (mem & I/O port)
- Mem-mapped: map all the control registers into the memory space (often top of space)
  ii) 1 address space
- hybrid
  iii) 2 address spaces (data buffers mem-mapped, control registers using I/O ports)

Software Layers (5 for I/O software system)
- User-level I/O software
- Device-independent operating system software
- Device drivers
- Interrupt handlers 
- Hardware

Device driver软件部分 -> The number of device registers and the nature of the commands vary radically from device to device.each I/O device attached to a computer needs some device-specific code for controlling it.和OS是一部分,内置在kernel。其实放在user space (w sys calls for r/w)也可,可以形成kernel-driver、driver-driver的isolation。

category: block devices (disks), character devices (keyboard, printer)
functions: 
- accept abstract read and write requests from the device-independent software above it and see that they are carried out
- initialize the device
- manage its power requirements and log events
structure:
- check parameter validity
- check vacancy of device (plan a sequence for commands)
- self-block (waken by interrupt) or finish (w no sleep)
- check for errors, report status info to caller


Device-Independent I/O Software
functions:
- Uniform interfacing for device drivers -> make all I/O devices and drivers look more- or-less the same.
- Buffering 
单个kernel buffer的问题:如果很多process同时lock住mem,反而会降低效率。办法:再来个user buffer,把kernel的数据copy过去。double buffer让2个kernel buffer轮流提供(旧的)复制和(新的)接收,效率更高。
(When the driver is called, it copies the packet to the controller for output (step 2). The reason it does not output to the wire directly from kernel memory is that once a packet transmission has been started, it must continue at a uniform speed. The driver cannot guarantee that it can get to memory at a uniform speed because DMA channels and other I/O devices may be stealing many cycles. Failing to get a word on time would ruin the packet. By buffering the packet inside the controller, this problem is avoided.)
- Error reporting 
- Allocating and releasing dedicated devices 
- Providing a device-independent block size (把各个disk不同的sector size给hide起来)
User-Space I/O Software

8.4-8.4.3

8.2.4
1.7

9


No comments:

Post a Comment