操作系统课件第11章 IO系统
- 格式:pdf
- 大小:6.98 MB
- 文档页数:70
第十一章 I/O管理和磁盘调度复习题11.1列出并简单定义执行I/O的三种技术。
·可编程I/O:处理器代表进程给I/O模块发送给一个I/O命令,该进程进入忙等待,等待操作的完成,然后才可以继续执行。
·中断驱动I/O:处理器代表进程向I/O模块发送一个I/O命令,然后继续执行后续指令,当I/O模块完成工作后,处理器被该模块中断。
如果该进程不需要等待I/O完成,则后续指令可以仍是该进程中的指令,否则,该进程在这个中断上被挂起,处理器执行其他工作。
·直接存储器访问(DMA):一个DMA模块控制主存和I/O模块之间的数据交换。
为传送一块数据,处理器给DMA模块发送请求,只有当整个数据块传送完成后,处理器才被中断。
11.2逻辑I/O和设备I/O有什么区别?·逻辑I/O:逻辑I/O模块把设备当作一个逻辑资源来处理,它并不关心实际控制设备的细节。
逻辑I/O模块代表用户进程管理的一般I/O功能,允许它们根据设备标识符以及诸如打开、关闭、读、写之类的简单命令与设备打交道。
·设备I/O:请求的操作和数据(缓冲的数据、记录等)被转换成适当的I/O指令序列、通道命令和控制器命令。
可以使用缓冲技术,以提高使用率。
11.3面向块的设备和面向流的设备有什么区别?请举例说明。
面向块的设备将信息保存在块中,块的大小通常是固定的,传输过程中一次传送一块。
通常可以通过块号访问数据。
磁盘和磁带都是面向块的设备。
面向流的设备以字节流的方式输入输出数据,其末使用块结构。
终端、打印机通信端口、鼠标和其他指示设备以及大多数非辅存的其他设备,都属于面向流的设备。
11.4为什么希望用双缓冲区而不是单缓冲区来提高I/O的性能?双缓冲允许两个操作并行处理,而不是依次处理。
典型的,在一个进程往一个缓冲区中传送数据(从这个缓冲区中取数据)的同时,操作系统正在清空(或者填充)另一个缓冲区。
11.5在磁盘读或写时有哪些延迟因素?寻道时间,旋转延迟,传送时间11.6简单定义图11.7中描述的磁盘调度策略。
Chapter 11: I/O Systems⏹I/O Hardware 硬件⏹Goals of I/O Software 软件的目标⏹I/O Software Layers 软件的分层⏹Application I/O Interface I/O应用接口⏹Kernel I/O Subsystem 内核I/O子系统⏹Transforming I/O Requests to Hardware Operations从I/O请求到硬件操作⏹Streams流⏹Performance性能I/O Hardware硬件Some typical device, network, and data base ratesI/O Hardware硬件⏹Incredible variety多样性of I/O devices☞Storage 存储☞Transmission 传输☞Human_interface 人机接口⏹Common concepts☞Port 端口☞Bus (daisy chain or shared direct access)总线☞Controller (host adapter)控制器⏹I/O instructions control devices指令控制设备⏹Devices have addresses, used by设备具有地址☞Direct I/O instructions直接I/O指令☞Memory-mapped I/O内存映射I/O⏹An I/O port typically consists of four registers, calledstatus, control, data-in and data-out registers一个I/O端口通常有四类寄存器(状态、控制、输入/输出)Device Controllers设备控制器⏹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使内存可用Devices Addresses设备地址⏹Separate I/O and memory space与内存分开⏹Memory-mapped I/O内存映射⏹Hybrid混合Bus Architecture总线结构⏹(a) A single-bus architecture单总线⏹(b) A dual-bus memory architecture双总线A Typical PC Bus Structure总线结构Device I/O Port Locations on PCs (partial)PC上的I/O端口I/O的控制形式Polling轮流检测⏹Determines state of device 设备状态☞command-ready就绪☞Busy忙☞Error出错⏹Busy-wait cycle忙等待循环to wait for I/O fromdeviceInterrupts中断⏹CPU Interrupt request line triggered by I/O device由I/O设备触发中断请求线⏹Interrupt handler receives interrupts中断处理函数接受中断⏹Maskable to ignore or delay some interrupts关中断⏹Interrupt vector中断向量to dispatch interrupt to correcthandler处理程序☞Based on priority按优先级☞Some unmaskable一些中断不可屏蔽⏹Interrupt mechanism also used for exceptions中断机制亦用于异常Interrupts Revisited回顾中断⏹How interrupts happens.☞Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicatedwiresInterrupt-Driven I/O Cycle 中断驱动器的I/O周期Intel Pentium Processor Event-Vector Table⏹Used to avoid programmed I/O for large datamovement用于大量数据的输入/输出⏹Requires DMA controller需要DMA控制器⏹Bypasses CPU to transfer data directly betweenI/O device and memory绕过CPU直接在内存和外设之间传递数据Six Step Process to Perform DMA Transfer 进程执行DMA传输的六个步骤Steps in printing a stringWriting a string to the printer using programmed I/OInterrupt-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中断服务例程I/O Using DMA⏹Printing a string using DMA☞code executed when the print system call is made系统调用☞interrupt service procedure中断服务例Characteristics特征of I/O DevicesGoals of I/O Software I/O软件的目标Goals of I/O SoftwareI/O软件的目标⏹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处理时离硬件越近越好.Goals of I/O Software (cont.)⏹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磁带驱动器是专用的I/O Software Layers分层I/O Software Layers分层Interrupt Handlers 中断处理⏹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中断处理程序唤醒驱动程序Interrupt Handlers (cont.)⏹Steps must be performed in software afterinterrupt completed中断完成后软件需要完成的步骤☞Save regs not already saved by interrupt hardware ☞Set up context for interrupt service procedure☞Set up stack for interrupt service procedure☞Ack interrupt controller, reenable interrupts☞Copy registers from where saved☞Run service procedure☞Set up MMU context for process to run next☞Load new process' registers☞Start running the new processDevice Drivers设备驱动程序⏹I/O system calls系统调用encapsulate封装devicebehaviors in generic classes⏹Device-driver layer设备驱动层hides differences amongI/O controllers控制器from kernel⏹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⏹Device Drivers present a uniform device access interfaceto the I/O subsystem设备驱动给I/O子系统提供统统一接口☞much as system calls provide a standard interface between the application and the OS数量跟给用户的系统调用一样多Device-Independent I/O Software设备无关I/O软件Uniform interfacing for device drivers设备驱动的统一接口Buffering缓存Error reporting错误报告Allocating and releasing dedicate devices申请/释放专用设备Providing a device-independent block size设备无关块大小Functions of the device-independent I/O software设备无关I/O软件的功能Device-Independent I/O Software (cont.)(a) Without a standard driver interface没有标准接口(b) With a standard driver interface有标准接口Device-Independent I/O Software (cont.)⏹(a) Unbuffered input未缓存的输入⏹(b) Buffering in user space在用户空间缓存⏹(c) Buffering in the kernel followed by copying to userspace在内核空间缓存,拷贝到用户空间⏹(d) Double buffering in the kernel内核空间双(交替)缓存Device-Independent I/O Software (cont) Networking may involve many copies网络引发多重缓存Layers of the I/O system and the main functions of each layerLayers of the I/O system and the main functions of each layerA Kernel I/O Structure驱动程序之间的分层Block and Character Devices块设备和字符设备⏹Block devices include disk drives(可按地址访问)☞Commands include read, write, seek☞Raw I/O or file-system access☞Memory-mapped file access possible⏹Character devices include keyboards, mice, serial ports☞Commands include get, put☞Libraries layered on top allow line editingNetwork Devices网络设备⏹Varying enough from block and character to have owninterface从块到字符变化,有自己的接口⏹Unix and Windows NT/9i/2000 include socket interface☞Separates network protocol from network operation☞Includes select functionality⏹Approaches vary widely (pipes, FIFOs, streams, queues,mailboxes)Clocks时钟and Timers定时器⏹Provide current time当前时间, elapsed time流逝时间,timer实时器⏹If programmable interval timer可编程定时器is used fortimings, periodic interrupts定期中断are needed⏹ioctl(on UNIX) covers odd不规则的aspects of I/Osuch as clocks and timers不规则的I/O操作系统通过ioctlThree ways to maintain the time of daySimulating multiple timers with a single clockBlocking and Nonblocking I/O阻塞式和非阻塞I/O⏹Blocking 阻塞-process suspended until I/O completed☞Easy to use and understand☞Insufficient for some needs⏹Nonblocking 非阻塞-I/O call returns as much as available☞User interface, data copy (buffered I/O)☞Implemented via multi-threading☞Returns quickly with count of bytes read or written⏹Asynchronous 异步-process runs while I/O executes☞Difficult to use☞I/O subsystem signals process when I/O completedApplication I/O InterfaceI/O应用接口Application I/O InterfaceI/O应用接口⏹I/O system calls系统调用encapsulate封装devicebehaviors in generic classes⏹Device-driver layer设备驱动层hides differences amongI/O controllers控制器from kernel⏹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⏹Device Drivers present a uniform device access interfaceto the I/O subsystem设备驱动给I/O子系统提供统统一接口☞much as system calls provide a standard interface between the application and the OS数量跟给用户的系统调用一样多Kernel I/O Subsystem 内核的I/O子系统Kernel I/O Subsystem内核的I/O子系统⏹Scheduling设备调度☞Some I/O request ordering via per-device queue设备排队☞Some OSs try fairness公平⏹Buffering缓存-store data in memory while transferringbetween devices☞To cope with device speed mismatch解决速度不匹配☞To cope with device transfer size mismatch解决传输块大小不匹配☞To maintain “copy semantics”Kernel I/O Subsystem (cont.)⏹Caching高速缓存-fast memory holding copy of data☞Always just a copy☞Key to performance⏹Spooling假脱机-hold output for a device☞If device can serve only one request at a time☞i.e., Printing⏹Device reservation预留-provides exclusive access to adevice☞System calls系统调用for allocation and deallocation☞Watch out for deadlock警惕死锁Sun Enterprise 6000 Device-Transfer RatesError Handling错误处理⏹OS can recover from disk read, device unavailable,transient短暂的write failures⏹Most return an error number or code when I/O requestfails返回错误号⏹System error logs hold problem reports系统错误日志。