版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1Input/OutputChapter 5Principles of I/O hardwarePrinciples of I/O softwareI/O software layersDisks2OS and I/OOne of the main functions of OS is to control all the I/O devicesIssue commands to the devicesCatch interruptsHandle errorsProvide an interface between the devices and the rest of OSMake devi
2、ce independent3I/O HardwareHardware viewsChips, circuits, power supplies, motors, wires, etcThis is inside of a device (electrical engineers concerned)Programming I/O devices is what an OS designer interested inThe commands the hardware acceptsThe functions it carries outThe errors reported back4I/O
3、 DevicesIncredible variety of I/O devicesStorage Devices (Disk, tape)Transmission Devices (Network Card, Modem)Human Interface Devices (Screen, Keyboard, mouse)Specialized Devices (Joystick)Devices ClassificationBlock or character-stream Sequential or random-accessSynchronous or asynchronous devices
4、Sharable or dedicatedread-write, read only, or write onlySpeed of operation5I/O DevicesBlock DevicesStores information in fixed-size blocks, each one with its own address512B32KB per blockIts possible to read or write each block independently of all the other onesE.g. DisksCharacter device Delivers
5、or accepts a stream of charactersNot addressable and no seek operationE.g. Printers, network interfaces, mouse, etc6I/O DevicesSome typical device, network, and bus data rates7Device ControllersI/O devices have components:mechanical component (the device itself)electronic componentThe electronic com
6、ponent is the device controller or adapter.On PCs, it often takes the form of a chip on the parentboard or a printed circuit card that can be inserted into an expansion slot.May be able to handle multiple devices8Device ControllersControllers tasks (e.g. disk)convert serial bit stream to block of by
7、tesperform error correction as necessarymake available to main memory9Device ControllersEach controller have a few registers that are used for communicating with the CPU. The operating system can command the device by writing into these registers and learn the devices state by reading from these reg
8、isters.CPU外部设备控制逻辑电路控制寄存器状态寄存器数据寄存器10Device ControllersProblems:How to addresses these control registers and data buffersHow to transfer data between controller and memoryMethods:Separate I/O and memory spaceMemory-mapped I/OHybrid Scheme11Separate I/O and memory spaceEach control register is assign
9、ed a special address called I/O port number, an 8- or 16-bit integer.Special I/O instructions are used to read/write from/into these control registersIN REG, PORTRead a byte or word from control register addresses as PORT into the CPU register REG.OUT REG, PORT Write the content of CPU register REG
10、into the control register addresses as PORT.Separate I/O and memory spaceMost early computers worked this way12Separate I/O and memory spaceSeparate I/O and memory space (e.g. IBM 360)IN R0, 4MOV R0, 4are completely different.4 in the first instruction refers to control register whose address is 4.4
11、 in the second instruction refers to main memory location whose address is 413All the control registers are mapped into the memory space, but separating I/O ports from memoryController Registers are part of regular address spaceEach control register is assigned a unique memory address to which no ph
12、ysical memory is assignedUsually the addresses assigned to control registers are on top of the address spaceUsually flags in special registers indicate that the memory access is for memory-mapped I/OMemory-mapped I/O14Memory-Mapped I/OMemory-mapped I/O (e.g. PDP-11)Portion that is used by control re
13、gistersPortion that is used by memory locationsMain Memory Address Space15Hybrid SchemeData buffers use memory-mapped addressesControl registers use addresses from a separate address space Pentium use this scheme064K: I/O port address space640K1M: reserved main memory address space part that is used
14、 by data buffers16Hybrid scheme (e.g. Pentium)Hybrid Scheme17How these schemes work18How these schemes work- Separate I/O and memory spaceAssume we will do a read operationCPU puts the address on the busCPU activates the read lineCPU asserts a signal line that says whether we will read from memory o
15、r I/O deviceIf we will read from memoryAddress lines contain a memory address from the memory address spaceMain Memory responds.If we will read from I/O deviceAddress lines contain an address from I/O port address space.Respective device controller responds19How these schemes work- Memory-mapped I/O
16、 Assume we will do a read operationCPU puts the address on the busCPU activates the read lineIf we will read from memoryAddress lines contain an address from part of address space for main memory Main Memory responds.If we will read from I/O deviceAddress lines contain an address from part of addres
17、s space for device controllersRespective device controller responds20Advantages of Memory-mapped I/ONo special instructions are needed to read and write from/to control registersNo special protection mechanism is necessary to protect control registers from direct access of usersEvery instruction tha
18、t references memory can also reference control registers.21Disadvantages of Memory-mapped I/OCachingIf device controller register values are caches, this can be problematic.We dont want to read cached soft copy, but we want to read the control register content.Solution: Disable caching for some virt
19、ual pages that correspond to control registers.Because of only one address space, all main memory modules and all I/O device controllers must examine all memory references to see which one to respond to.22Disadvantages of Memory-mapped I/OThis can be easy or difficult depending on the architecture o
20、f the systemNo problem in this single-bus architecture23Disadvantages of Memory-mapped I/OThis can be easy or difficult depending on the architecture of the systemIn this dual-bus memory architecture, how can I/O controllers see the addresses that are used for control registers, as all memory addres
21、ses go by on thememory bus.24Disadvantages of Memory-mapped I/OSolution 1CPU sends an address to main memory over the memory bus. If main memory does not respond (since address range is for I/O), the CPU will put the address on the other buses.25Disadvantages of Memory-mapped I/OSolution 2A snooping
22、 device on the memory bus can be used to pass all addresses in I/O range to the I/O bus.26Disadvantages of Memory-mapped I/OSolution 3A bridge filters all memory addresses. If addresses are in main memory address range, then it passes the addresses to the memory bus; if addresses are in I/O space th
23、en it passes the addresses to the I/O bus. (e.g. Pentium)Bridge(filters)27Principles of I/O SoftwareGoals of I/O SoftwareI/O OperationsProgrammed I/OInterrupt-driven I/OI/O using DMA28Goals of I/O Software (1)Device independenceprograms can access any I/O device without specifying device in advance
24、(USB device, hard drive, or CD-ROM)Uniform namingname of a file or device a string or an integernot depending on which machineError handlinghandle as close to the hardware as possible29Goals of I/O Software (2)Synchronous vs. asynchronous transfersblocked transfers vs. interrupt-drivenBufferingdata
25、coming off a device cannot be stored in final destinationSharable vs. dedicated devicesdisks are sharabletape drives would not be30Programmed I/O (1)CPU is always busy with I/O until I/O gets completed.Fine for single process systemsMS-DOSEmbedded systemsBut not a good approach for multi-programming
26、 and time-sharing systems31Programmed I/O (2)Assume a program that wants to print a string to a printer.Assume string is “ABCDEFGH”, 8 character long stringAssume printer has 1 byte of data buffer to put the character that needs to be printed.32Programmed I/O (3)Steps in printing a string33Programme
27、d I/O (4)Writing a string to the printer using programmed I/O/*buffer is user bufferp is kernel buffercount is number of bytes to be copied*/34Programmed I/O (5)Polling: CPU busy with checking the status register of printer to determine its stateReady BusyError Busy-wait cycle to wait for I/O from d
28、evice, waste of CPU 35Interrupt-Driven I/O (1)After copying application buffer content into kernel buffer, and sending 1 character to printer,CPU does not wait until printer is READY again.Instead, the scheduler() is called and some other process is run.The current process is put into blocked state.
29、Printer controller generates an hardware interrupt:When the character is written to the printer and the printer becomes READY again.36Interrupt-Driven I/O (2)Writing a string to the printer using interrupt-driven I/O(a) Code executed when print system call is made(b) Interrupt service procedure37Int
30、erruptHow interrupts happens. Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wiresBus38I/O using DMA (1)Disadvantage of Interrupt-Driven I/O is that interrupt occurs on every character.DMA controller will feed the characters from ke
31、rnel buffer to the printer controller.CPU is not bothered during this transferAfter transfer of whole buffer (string) is completed, then the CPU is interrupted.39I/O using DMA (2)Printing a string using DMAcode executed when the print system call is madeinterrupt service procedure40Direct Memory Acc
32、ess (DMA)Operation of a DMA transfer41I/O Software LayersLayers of the I/O Software SystemUser SpaceKernel Space42Interrupt Handlers (1)Interrupt handlers are best hiddenhave driver starting an I/O operation block until interrupt notifies of completionInterrupt procedure does its taskthen unblocks d
33、river that started it43Interrupt Handlers (2)Steps must be performed in software after interrupt completedSave regs not already saved by interrupt hardwareSet up context for interrupt service procedureSet up stack for interrupt service procedureAck interrupt controller, reenable interruptsCopy regis
34、ters from where savedRun service procedure Choose which process to run next.Set up MMU context for process to run nextLoad new process registersStart running the new process44Device Drivers (1)Encapsulates routines that handle low-level device operationsGenerally written by device manufacturersNot n
35、ecessarily by OS writersA driver can be written for more than one OSEach driver can handle one type of deviceWe need to have a well-defined model of what a driver does and how it integrates with the rest of the OS.This is because, OS implementers and drivers implementers may be different.OSs usually
36、 classify drivers into two classesDrivers for block devicesDrivers for character devices45Device Drivers (2)Logical position of device drivers is shown hereCommunications between drivers and device controllers goes over the bus46Device Drivers (3)Device Driver FunctionsAccept abstract read and write
37、 requests from rest of the OS (device-independent part).Translate from abstract terms to concrete terms.Example: A disk driver translates from a linear block address to a physical head, track, sector, and cylinder number.Initialize the devices if necessaryCheck if the device is currently in use for
38、some other request.If so, enqueue the request.Issue sequence of commands to control the deviceCheck errors47Device-Independent I/O SoftwareFunctions of the device-independent I/O software Uniform interfacing for device drivers Buffering Error reporting Allocating and releasing dedicate devices Provi
39、ding a device-independent block size48Uniform Interfacing (1)(a) Without a standard driver interface(b) With a standard driver interface49Drivers need to have uniform interface. The benefits are:The driver implementers know what is expected from themThe OS implementers can developed device-independe
40、nt I/O function on top of a well-defined lower-layer driver interface.They know which functions each driver implements and the pro-types of these function.Uniform Interfacing (2)50In Unix, devices are modeled as special files.They are accessed through the use of system calls such as open(), read(),
41、write(), close(), ioctl(), etc.A file name is associated with each device.Major device number locates the appropriate driver.Minor device number (stored in i-node) is passed as a parameter to the driver in order to specify the unit to be read or written.The usual protection rules for files also appl
42、y to I/O devicesUniform Interfacing (3)51Uniform Interfacing: Mapping symbolic I/O device names to their appropriate driversUniform Interfacing (4)52Buffering (1)(a) Unbuffered input(b) Buffering in user space(c) Buffering in the kernel followed by copying to user space(d) Double buffering in the ke
43、rnel53Buffering (2)Networking may involve many copies54Some errors are handled by device-controllersExample: Checksum incorrect, re-correct the block by using redundant bitsSome by device deriversExample: disk block could not be read, re-issue the read operation for block from diskSome by the device
44、-independent software layer of OS.Programming errorsExample: Attempt to write to a read-only deviceActual I/O errorsExample: The camcorder is shut-off, therefore we could not read. Return an indication of this error to the calling application.Error Reporting55Do not allow concurrent accesses to dedi
45、cated devices such as CD-RWs.Allocating Dedicated Devices56There are different kind of disk drives. Each may have a different physical sector size.A file system uses a block size while mapping files into logical disk blocks.This layer can hide the physical sector size of different disks and can prov
46、ide a fixed and uniform disk block size for higher layers, like the file systemSeveral sectors can be treated as a single logical block.Device-independent Block Size57This includesThe I/O libraries that provides the implementation of I/O functions which in turn call the respective I/O system calls.T
47、hese libraries also implemented formatted I/O functions such as printf() and scanf()Some programs that does not directly write to the I/O device, but writes to a spooler.User-Space I/O Software58Summary of I/O Software Layers of the I/O system and the main functions of each layer59DisksDisks have ma
48、ny typesMagnetic disksHard diskFloppy diskOptical disksCD-ROMCD-WritableCD-Recordable DVDs60Magnetic Disks (1)Organized into cylindersEach cylinders contains tracksEach track is divided into a number of sectorsThe sector size is usually 512 bytes.There are IDE, SATA, SCSI, SAS and Fiber Channel hard
49、 disks.61Magnetic Disks (2)62Read-write head Positioned very close to the platter surface (almost touching it)Reads or writes magnetically encoded information.Surface of platter divided into circular tracksOver 16,000 tracks per platter on typical hard disksEach track is divided into sectors. A sect
50、or is the smallest unit of data that can be read or written.Sector size typically 512 bytesTypical sectors per track: 200 (on inner tracks) to 400 (on outer tracks)To read/write a sectordisk arm swings to position head on right trackplatter spins continually; data is read/written as sector passes un
51、der headHead-disk assemblies multiple disk platters on a single spindle (typically 2 to 4)one head per platter, mounted on a common arm.Cylinder i consists of ith track of all the platters Disk Hardware63Disk parameters for the original IBM PC floppy disk and a Western Digital WD 18300 hard diskMagn
52、etic Disks (3)64Magnetic Disks (4)Physical geometry of a disk with two zonesA possible virtual geometry for this disk65RAID (1)RAID levels 0 through 2 (Backup and parity drives are shaded)66RAID (2)RAID levels 3 through 5(Backup and parity drives are shaded)67Disk Formatting (1)After manufacturing,
53、there is no information on the diskJust empty bitsEach platter need to haveA low-level formatA high-level formatbefore disk can be used68Disk Formatting (2)Each track should have formatted in the following way:Sectors and inter-sector-gap between themA sector will be have format like the following:P
54、reamble data (512 bytes) Checksum69Cylinder SkewAn illustration of cylinder skew(柱面斜进)Example10,000rpm disk drive (6ms/round)300 sectors per track (20 s/sector)Seek time: 800 sCylinder skew: 40secotrs 70Interleaving (1)If we have ONE sector buffer in the disk controller:After we have transferred one
55、 sector of data from hard-disk to controller buffer:We will copy the controller buffer to the memoryDuring this time, the disk-head will pass the start of the next sector.Therefore, the next logical sector, should not be the next physical sector in hard-disk.There should be some interleaving.71Inter
56、leaving (2)72No interleavingSingle interleavingDouble interleavingInterleaving (3)73Performance Measures of Disks (1)Access time the time it takes from when a read or write request is issued to when data transfer begins. Consists of: Seek time time it takes to reposition the arm over the correct tra
57、ck. Average seek time is 1/2 the worst case seek time.Would be 1/3 if all tracks had the same number of sectors, and we ignore the time to start and stop arm movement4 to 10 milliseconds on typical disksRotational latency time it takes for the sector to be accessed to appear under the head. Average
58、latency is 1/2 of the worst case latency.4 to 11 milliseconds on typical disks (5400 to 15000 r.p.m.)74Performance Measures of Disks (2)Data-transfer rate the rate at which data can be retrieved from or stored to the disk.4 to 8 MB per second is typicalMean time to failure (MTTF) the average time th
59、e disk is expected to run continuously without any failure.Typically 3 to 5 years75Disk Arm Scheduling Algorithms (1)Time required to read or write a disk block determined by 3 factorsSeek timeMove arm to the correct cylinderRotational delayWait until correct sector comes under head.Actual data tran
60、sfer timeFor most systems, the seek time dominates the other two times.76Disk Arm Scheduling Algorithms (2)Assume the disk is heavily loaded.There are a lot requests for disk blocks that are arriving to the hard disk driver.The drivers queues the requests.The driver knows for each block request, whe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- DB3502∕T 072.2-2021 公共安全视频图像系统运维技术规范 第2部分:接口
- 2024年塘口租赁协议范本
- 2024年专业司机劳动协议模板
- 2024年度FOB装运条件协议范本
- 2024装饰装修工程承包协议范例
- 2024年专业汽车物流服务协议模板
- 发型师雇佣协议示范文本2024年
- 2024预包装食品订货协议模板
- 2024跨境电子商务合作协议汇编
- 大班学前课件教学课件
- 饲料行业会计科目表B
- 河北省保定市药品零售药店企业药房名单目录
- 广西基本医疗保险门诊特殊慢性病申报表
- 分包单位资格报审表-填写模板
- 城市经济学习题与答案
- 马工程《马克思主义发展史》课后习题答案
- 《培养良好的卫生习惯》主题班会(30张)课件
- 医学学员沟通和接诊能力面试评分表
- 创业指导师培训计划
- 幼儿园中班数学《有趣的图形》课件
- 四年级上册数学课件-4.6 整数的四则运算(运算定律)▏沪教版 (共15张PPT)
评论
0/150
提交评论