Silberschatz,Galvin,and Gagne?199912.1Applied Operating System Concepts
Module 12,I/O Systems(I/O系统)
I/O hardwared( I/O硬件)
Application I/O Interface( 应用程序 I/O接口)
Kernel I/O Subsystem( 核心 I/O子系统)
Transforming I/O Requests to Hardware Operations
( 转换 I/O请求为硬件操作)
Performance( 性能)
Silberschatz,Galvin,and Gagne?199912.2Applied Operating System Concepts
I/O Hardware(I/O硬件)
Incredible variety of I/O devices( 难以置信的 I/O设备种类)
Common concepts( 基本概念)
– Port ( 端口)
– Bus (daisy chain or shared direct access)
( 总线:菊花链或者共享总线)
– Controller (host adapter)( 控制器,主机适配器)
I/O instructions control devices( I/O指令控制设备)
Devices have addresses,used by ( 设备的寻址方式)
– Direct I/O instructions( 直接 I/O指令)
– Memory-mapped I/O( 存储器映射 I/O指令)
Silberschatz,Galvin,and Gagne?199912.3Applied Operating System Concepts
Polling( 轮询)
Determines state of device ( 决定设备的状态)
– command-ready( 等待命令)
– Busy( 忙)
– Error( 错误)
Busy-wait cycle to wait for I/O from device
( 忙等待循环等待设备的 I/O操作)
Silberschatz,Galvin,and Gagne?199912.4Applied Operating System Concepts
Interrupts( 中断)
CPU Interrupt request line triggered by I/O device
( CPU的中断需要有 I/O设备的触发)
Interrupt handler receives interrupts
( 中断处理例程接收中断)
Maskable to ignore or delay some interrupts
( 通过屏蔽来忽略或者延迟某些中断)
Interrupt vector to dispatch interrupt to correct handler
( 中断向量给中断分配正确的中断处理例程)
– Based on priority( 以优先级为基础)
– Some unmaskable( 某些中断不可屏蔽)
Interrupt mechanism also used for exceptions
( 中断机制也用在异常)
Silberschatz,Galvin,and Gagne?199912.5Applied Operating System Concepts
Interrupt-drive I/O Cycle( 中断驱动的 I/O循环)
Silberschatz,Galvin,and Gagne?199912.6Applied Operating System Concepts
Direct Memory Access( 直接内存存取)
Used to avoid programmed I/O for large data movement
( 用来避免编程 I/O来传输大量的数据)
Requires DMA controller( 需要 DMA控制器)
Bypasses CPU to transfer data directly between I/O device
and memory ( 绕过 CPU来在 I/O设备和内存之间直接传输数据)
Silberschatz,Galvin,and Gagne?199912.7Applied Operating System Concepts
Six step process to perform DMA transfer
(通过六步来完成 DMA传输 )
Silberschatz,Galvin,and Gagne?199912.8Applied Operating System Concepts
Application I/O Interface( 应用程序 I/O接口)
I/O system calls encapsulate device behaviors in generic
classes
( I/O子系统设备行为精简成几个常用的类别)
Device-driver layer hides differences among I/O controllers
from kernel( 设备驱动层对核心隐藏了 I/O控制器的不同细节)
Devices vary in many dimensions( 设备变化范围非常大)
– Character-stream or block( 字符流或者块设备)
– Sequential or random-access( 顺序或随机设备)
– Sharable or dedicated( 共享或独占设备)
– Speed of operation( 操作速度的不同)
– read-write,read only,or write only( 读写,只读,只写)
Silberschatz,Galvin,and Gagne?199912.9Applied Operating System Concepts
Block and Character Devices( 块或字符设备)
Block devices include disk drives( 块设备包括磁盘)
– Commands include read,write,seek
( 命令包括读,写,搜寻)
– Raw I/O or file-system access
( 原始的 I/O或文件系统存取)
– Memory-mapped file access possible
( 存储器映射文件访问的可能性)
Character devices include keyboards,mice,serial ports
( 字符设备包括键盘,鼠标和串口设备)
– Commands include get,put( 命令有 get,put)
– Libraries layered on top allow line editing
( 顶层的函数库允许行编辑)
Silberschatz,Galvin,and Gagne?199912.10Applied Operating System Concepts
Network Devices( 网络设备)
Varying enough from block and character to have own
interface
( 从块设备和字符设备变化而来,有独自的接口)
Unix and Windows/NT include socket interface
( Unix和 Windows/NT包括 socket接口)
– Separates network protocol from network operation
( 分离网络协议于网络操作)
– Includes select functionality( 包括 select功能)
Approaches vary widely (pipes,FIFOs,streams,queues,
mailboxes)( 方式广泛:管道,FIFOs,流,队列,邮箱)
Silberschatz,Galvin,and Gagne?199912.11Applied Operating System Concepts
Clocks and Timers( 时钟和记时器)
Provide current time,elapsed time,timer
( 提供当前的时间,经过的时间,计时器)
if programmable interval time used for timings,periodic
interrupts( 如果把可编程的时间间隔用于计时,那么定期中断)
ioctl (on UNIX) covers odd aspects of I/O such as clocks
and timers
( 在 UNIX中,ioct1掩盖了 I/O设备(象时钟和计时器)之间区别)
Silberschatz,Galvin,and Gagne?199912.12Applied Operating System Concepts
Blocking and Nonblocking I/O
阻塞和非阻塞 I/O
Blocking - process suspended until I/O completed
( 阻塞 —进程挂起直到 I/O完成)
– Easy to use and understand( 容易使用和理解)
– Insufficient for some needs( 在某些场合没有效率)
Nonblocking - I/O call returns as much as available
( 非阻塞 —I/O调用返回一个代表是否成功的值)
– User interface,data copy (buffered I/O)
(用户界面,数据拷贝(对 I/O缓冲))
– Implemented via multi-threading( 通过多线程来实现)
– Returns quickly with count of bytes read or written
( 迅速的返回读写的字节数)
Asynchronous - process runs while I/O executes
( 异步:在 I/O处理的时候进程同时运行)
– Difficult to use( 难以使用)
– I/O subsystem signals process when I/O completed
( 当 I/O操作完成的时候,I/O子系统向进程发信号)
Silberschatz,Galvin,and Gagne?199912.13Applied Operating System Concepts
Kernel I/O Subsystem( 核心 I/O子系统)
Scheduling( 调度)
– Some I/O request ordering via per-device queue
( 某些 I/O需要按设备队列的顺序)
– Some OSs try fairness( 某些操作系统尝试着公平)
Buffering - store data in memory while transferring between
devices( 缓冲 —当设备间传输数据的时候,暂时存放在内存中)
– To cope with device speed mismatch
( 解决设备速度不匹配)
– To cope with device transfer size mismatch
( 解决设备传输块的大小不匹配)
– To maintain,copy semantics”
( 为了维持拷贝语句的语义要求)
Silberschatz,Galvin,and Gagne?199912.14Applied Operating System Concepts
Kernel I/O Subsystem( 核心 I/O子系统)
Caching - fast memory holding copy of data
( 高速缓存 —存放数据的快速存储器)
– Always just a copy( 总是数据的拷贝)
– Key to performance( 性能的关键)
Spooling - hold output for a device
( spooling—保存设备的输出)
– If device can serve only one request at a time
( 如果设备一次只能服务于一个请求)
– i.e.,Printing( 比如,打印机)
Device reservation - provides exclusive access to a device
( 设备预定 —提供对设备的独占访问)
– System calls for allocation and deallocation
( 分配和再分配的系统调用)
– Watch out for deadlock( 小心死锁)
Silberschatz,Galvin,and Gagne?199912.15Applied Operating System Concepts
Error Handling( 错误处理)
OS can recover from disk read,device unavailable,transient
write failures
( 操作系统可以恢复磁盘读,设备无效,暂时的失败)
Most return an error number or code when I/O request fails
( 当 I/O失败时,大多数返回一个错误码 )
System error logs hold problem reports
( 系统日志记录了出错报告)
Silberschatz,Galvin,and Gagne?199912.16Applied Operating System Concepts
Kernel Data Structures( 核心数据结构)
Kernel keeps state info for I/O components,including open
file tables,network connections,character device state
( 核心保存着 I/O组件的状态,包括打开文件表,网络连接,字符设备状态)
Many,many complex data structures to track buffers,
memory allocation,“dirty” blocks
( 许多的数据结构是为了记录缓冲,内存分配和“脏”块)
Some use object-oriented methods and message passing to
implement I/O( 有些用面向对象的方法和消息机制来实现 I/O)
Silberschatz,Galvin,and Gagne?199912.17Applied Operating System Concepts
I/O Requests to Hardware Operations
I/O请求到硬件操作
Consider reading a file from disk for a process
( 考虑一个进程从磁盘中读取一个文件)
– Determine device holding file ( 决定保存文件的设备)
– Translate name to device representation
( 转换名字到设备使用的表示法)
– Physically read data from disk into buffer
( 把数据从磁盘读到缓冲区中)
– Make data available to requesting process
( 通知进程数据现在是有效的)
– Return control to process
( 把控制权返回给进程)
Silberschatz,Galvin,and Gagne?199912.18Applied Operating System Concepts
Life Cycle of an I/O Request( I/O请求的周期)
Silberschatz,Galvin,and Gagne?199912.19Applied Operating System Concepts
Performance( 性能)
I/O a major factor in system performance
( I/O是系统性能的主要因素)
– Demands CPU to execute device driver,kernel I/O code
( 需要 CPU执行设备驱动,核心 I/O代码)
– Context switches due to interrupts
( 因为中断而导致的上下文转换)
– Data copying( 数据拷贝)
– Network traffic especially stressful( 网络状况尤其重要)
Silberschatz,Galvin,and Gagne?199912.20Applied Operating System Concepts
Intercomputer communications
Silberschatz,Galvin,and Gagne?199912.21Applied Operating System Concepts
Improving Performance( 改进性能)
Reduce number of context switches( 减少上下文转换)
Reduce data copying ( 减少数据的拷贝量)
Reduce interrupts by using large transfers,smart
controllers,polling
( 通过使用一次大量数据传输,智能控制器和轮换来减少中断)
Use DMA( 使用 DMA)
Balance CPU,memory,bus,and I/O performance for highest
throughput( 平衡 CPU,内存,总线和 I/O性能以达到高吞吐率)