当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Lec24_DISK MANAGEMENT AND I/O

资源类别:文库,文档格式:PDF,文档页数:19,文件大小:810.53KB,团购合买
点击下载完整版文档(PDF)

DISK MANAGEMENT AND I/O Note:Some slides and/or pictures in the following are adapted from slides 02005 Silberschatz,Galvin,and Gagne. Many slides generated from Kubiatowicz

DISK MANAGEMENT AND I/O Note: Some slides and/or pictures in the following are adapted from slides ©2005 Silberschatz, Galvin, and Gagne. Many slides generated from Kubiatowicz

MODERN I/O SYSTEMS disk snq ISOS disk disk monitor disk cache graphics bridge/memory SCSI controller controller controller PCI bus IDE disk controller expansion bus keyboard interface disk disk expansion bus disk disk parallel serial port port

MODERN I/O SYSTEMS

THE GOAL OF THE I/O SUBSYSTEM o Provide Uniform Interfaces,Despite Wide Range of Different Devices This code works on many different devices: int fd open (/dev/something"); for (int i=0;i<10;i++){ fprintf(fd,"Count &dn",i); } close(fd); Why?Because code that controls devices (device driver")implements standard interface. o We will try to get a flavor for what is involved in actually controlling devices in rest of lecture Can only scratch surface!

THE GOAL OF THE I/O SUBSYSTEM  Provide Uniform Interfaces, Despite Wide Range of Different Devices  This code works on many different devices: int fd = open(“/dev/something”); for (int i = 0; i < 10; i++) { fprintf(fd,”Count %d\n”,i); } close(fd);  Why? Because code that controls devices (“device driver”) implements standard interface.  We will try to get a flavor for what is involved in actually controlling devices in rest of lecture  Can only scratch surface!

WANT STANDARD INTERFACES TO DEVICES o Block Devices:e.g.disk drives,tape drives,Cdrom ·Access blocks of data Commands include open(),read(),write(),seek() Raw I/O or file-system access Memory-mapped file access possible Character Devices:e.g.keyboards,mice,serial ports,some USB devices Single characters at a time Commands include get(),put ( Libraries layered on top allow line editing o Network Devices:e.g.Ethernet,Wireless,Bluetooth Different enough from block/character to have own interface Unix and Windows include socket interface o Separates network protocol from network operation o Includes select (functionality Usage:pipes,FIFOs,streams,queues,mailboxes

WANT STANDARD INTERFACES TO DEVICES  Block Devices: e.g. disk drives, tape drives, Cdrom  Access blocks of data  Commands include open(), read(), write(), seek()  Raw I/O or file-system access  Memory-mapped file access possible  Character Devices: e.g. keyboards, mice, serial ports, some USB devices  Single characters at a time  Commands include get(), put()  Libraries layered on top allow line editing  Network Devices: e.g. Ethernet, Wireless, Bluetooth  Different enough from block/character to have own interface  Unix and Windows include socket interface  Separates network protocol from network operation  Includes select() functionality  Usage: pipes, FIFOs, streams, queues, mailboxes

HOW DOES USER DEAL WITH TIMING? o Blocking Interface:“Wait” When request data (e.g.read()system call),put process to sleep until data is ready When write data (e.g.write (system call),put process to sleep until device is ready for data oNon-blocking Interface:“Don't Wait'” Returns quickly from read or write request with count of bytes successfully transferred Read may return nothing,write may write nothing o Asynchronous Interface:"Tell Me Later" When request data,take pointer to user's buffer,return immediately;later kernel fills buffer and notifies user When send data,take pointer to user's buffer,return immediately;later kernel takes data and notifies user

HOW DOES USER DEAL WITH TIMING?  Blocking Interface: “Wait”  When request data (e.g. read() system call), put process to sleep until data is ready  When write data (e.g. write() system call), put process to sleep until device is ready for data  Non-blocking Interface: “Don’t Wait”  Returns quickly from read or write request with count of bytes successfully transferred  Read may return nothing, write may write nothing  Asynchronous Interface: “Tell Me Later”  When request data, take pointer to user’s buffer, return immediately; later kernel fills buffer and notifies user  When send data, take pointer to user’s buffer, return immediately; later kernel takes data and notifies user

HOW DOES THE PROCESSOR TALK TO THE DEVICE? Processor Memory Bus Regular Memory CPU Bus Bus Adaptor Adaptor Device Address+ Controller Other Devices Data Bus Hardware Interrup or Buses Controlle Interfade Controller Interrupt Request read write Addressable 0 CPU interacts with a Controller control Memory Contains a set of registers that status and/or can be read and written Registers Queues 0 May contain memory for request (por叶0x Memory Mapped queues or bit-mapped images Beaian:0x8f008020 o Regardless of the complexity of the connections and buses, processor accesses registers in two ways: I/O instructions:in/out instructions o Example from the Intel architecture:out 0x21,AL Memory mapped I/O:load/store instructions o Registers/memory appear in physical address space o I/O accomplished with load and store instructions

Device Controller read write control status Addressable Memory and/or Registers Queues (port 0x20) Hardware Controller Memory Mapped Region: 0x8f008020 Bus Interface HOW DOES THE PROCESSOR TALK TO THE DEVICE?  CPU interacts with a Controller  Contains a set of registers that can be read and written  May contain memory for request queues or bit-mapped images  Regardless of the complexity of the connections and buses, processor accesses registers in two ways:  I/O instructions: in/out instructions  Example from the Intel architecture: out 0x21,AL  Memory mapped I/O: load/store instructions  Registers/memory appear in physical address space  I/O accomplished with load and store instructions Address+ Data Interrupt Request Processor Memory Bus CPU Regular Memory Interrupt Controller Bus Adaptor Bus Adaptor Other Devices or Buses

MEMORY-MAPPED DISPLAY CONTROLLER EXAMPLE o Memory-Mapped: Hardware maps control registers and display memory to physical address 0x80020000 Graphics space o Addresses set by hardware jumpers or Command programming at boot time Queue Simply writing to display memory (also 0x80010000 called the "frame buffer")changes image Display on screen Memory oAddr:0x8000F000-0x8000FFFF 0x8000F000 Writing graphics description to command-queue area o Say enter a set of triangles that describe 0x0007F004 Command some scene Addr:0x80010000-0x8001FFFF 0x0007F000 Status Writing to the command register may cause on-board graphics hardware to do something o Say render the above scene 。Addr:0x0007F004 Physical Address o Can protect with page tables Space

MEMORY-MAPPED DISPLAY CONTROLLER EXAMPLE  Memory-Mapped:  Hardware maps control registers and display memory to physical address space  Addresses set by hardware jumpers or programming at boot time  Simply writing to display memory (also called the “frame buffer”) changes image on screen  Addr: 0x8000F000—0x8000FFFF  Writing graphics description to command-queue area  Say enter a set of triangles that describe some scene  Addr: 0x80010000—0x8001FFFF  Writing to the command register may cause on-board graphics hardware to do something  Say render the above scene  Addr: 0x0007F004  Can protect with page tables Display Memory 0x8000F000 0x80010000 Physical Address Space 0x0007F000 Status 0x0007F004 Command Graphics Command Queue 0x80020000

TRANSFERRING DATA TO/FROM CONTROLLER o Programmed I/O: Each byte transferred via processor in/out or load/store Pro:Simple hardware,easy to program Con:Consumes processor cycles proportional to data size o Direct Memory Access: Give controller access to memory bus Ask it to transfer data to/from memory directly o Sample interaction with DMA controller (from book): 1.device driver is told to transfer disk data CPU to buffer at address X 5.DMA controller 2.device driver tells transfers bytes to disk controller to buffer X,increasing transfer C bytes memory address from disk to buffer cache and decreasing C at address X until C=0 6.when C=0,DMA DMA/bus/ interrupts CPU to signal interrupt CPU memory bus memory buffer transfer completion controller PCI bus 3.disk controller initiates IDE disk DMA transfer controller 4.disk controller sends each byte to DMA disk dis controller disk) disk

TRANSFERRING DATA TO/FROM CONTROLLER  Programmed I/O:  Each byte transferred via processor in/out or load/store  Pro: Simple hardware, easy to program  Con: Consumes processor cycles proportional to data size  Direct Memory Access:  Give controller access to memory bus  Ask it to transfer data to/from memory directly  Sample interaction with DMA controller (from book):

DEVICE DRIVERS 0 Device Driver:Device-specific code in the kernel that interacts directly with the device hardware ● Supports a standard,internal interface Same kernel I/O system can interact easily with different device drivers e Special device-specific configuration supported with the ioct1() system call o Device Drivers typically divided into two pieces: Top half:accessed in call path from system calls o implements a set of standard,cross-device calls like open ()close () read(),write(),ioctl(),strategy() o This is the kernel's interface to the device driver o Top half will start I/O to device,may put thread to sleep until finished Bottom half:run as interrupt routine o Gets input or transfers next block of output o May wake sleeping threads if I/O now complete

DEVICE DRIVERS  Device Driver: Device-specific code in the kernel that interacts directly with the device hardware  Supports a standard, internal interface  Same kernel I/O system can interact easily with different device drivers  Special device-specific configuration supported with the ioctl() system call  Device Drivers typically divided into two pieces:  Top half: accessed in call path from system calls  implements a set of standard, cross-device calls like open(), close(), read(), write(), ioctl(), strategy()  This is the kernel’s interface to the device driver  Top half will start I/O to device, may put thread to sleep until finished  Bottom half: run as interrupt routine  Gets input or transfers next block of output  May wake sleeping threads if I/O now complete

LIFE CYCLE OF AN I/O REQUEST User user 1/O completed. request I/O process input data avallable.or output completed Program system call return from system call 义 kemel transfer data can already I/O subsystem (if appropriate)to process, satisfy request? yes retumn completion Kernel I/O or error code no Subsystem send request to device driver.block process if kemel appropriate VO subsystem 。11年 ■■■至年■■■内量■■国 Device Driver process reguest.issue commands to controller. determine which 1/O device configure controller to completed.indicate state driver Top Half block until interrupted change to l/O subsystem Device Driver recelve interrupt,store interrupt device-controller commands data in device-driver buffer handler If input,signal to unblock Bottom Half device driver 年8g■5g■ n0gg,月nn device Device monitor device. controller interrupt when I/O 1/O completed. completed generate interrupt Hardware time

LIFE CYCLE OF AN I/O REQUEST Device Driver Top Half Device Driver Bottom Half Device Hardware Kernel I/O Subsystem User Program

点击下载完整版文档(PDF)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共19页,试读已结束,阅读完整版请下载
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有