112.1Operating System ConceptsCSMC 412CSMC 412Operating SystemsProf. Ashok K Agrawala© 2005 Ashok AgrawalaSet 1212.2Operating System ConceptsInput/Input/OOutpututput––Principles of I/O HardwarePrinciples of I/O Hardware Major components of a computer system:CPU, memories (primary/secondary), I/O system I/O devices:z Block devices – store information in fixed-sized blocks;typical sizes: 128-1024 bytesz Character devices – delivers/accepts stream of characters Device controllers:z Connects physical device to system bus (Minicomputers, PCs)z Mainframes use a more complex model:Multiple buses and specialized I/O computers (I/O channels) Communication:z Memory-mapped I/O, controller registersz Direct Memory Access - DMA212.3Operating System ConceptsI/O Hardware I/O Hardware --Single BusSingle BusCPU MemoryVideoControllerKeyboardControllerFloppyControllerDiskControllerSystem busSystem busMonitorMonitorKeyboardKeyboardFloppyFloppydrivedriveDiskDiskdrivedrive12.4Operating System ConceptsI/O Hardware I/O Hardware --Multiple BusesMultiple BusesVideocontrollerNetworkcontrollerIDE diskcontrollerUSB interfacekeyboard mouseCPUPCI bridge/memory controllerMemoryCacheSCSIcontrollerSCSI diskSCSI diskSCSI diskPCI busPCI busUSB busUSB busSCSI busSCSI busMemory busMemory bus312.5Operating System ConceptsDiversity among I/O DevicesDiversity among I/O DevicesThe I/O subsystem has to consider device characteristics: Data rate: z may vary by several orders of magnitude Complexity of control: z exclusive vs. shared devices Unit of transfer: z stream of bytes vs. block-I/O Data representations: z character encoding, error codes, parity conventions Error conditions: z consequences, range of responses Applications: z impact on resource scheduling, buffering schemes12.6Operating System ConceptsOrganization of the I/O FunctionOrganization of the I/O Function Programmed I/O with polling:z The processor issues an I/O command on behalf of a process z The process busy waits for completion of the operation before proceeding Interrupt-driven I/O:z The processor issues an I/O command and continues to executez The I/O module interrupts the processor when it has finished I/Oz The initiator process may be suspended pending the interruptDirect memory access (DMA):z A DMA module controls exchange of data between I/O module and main memoryz The processor requests transfer of a block of data from DMA and is interrupted only after the entire block has been transferred412.7Operating System ConceptsFlow of a blocking I/O requestFlow of a blocking I/O request1. Thread issues blocking read() system call2. Kernel checks parameters; may return buffered data and finish3. Thread is removed from run queue if physical I/O required; added to wait queue for device; I/O request is scheduled4. Device driver allocates kernel buffer; sends command to controller5. Device controller operates the hardware to perform data transfer6. Driver may poll for status and data; or set up DMA that will generate interrupt7. Interrupt occurs; handler stores data; signals device driver8. Device driver receives signal; determines request status; signals kernel I/O subsystem9. Kernel transfers data or return code to user space; removes thread from wait queue10. Thread resumes execution at completion of read() call12.8Operating System ConceptsPrinciples of I/O SoftwarePrinciples of I/O Software Layered organization Device independence Error handlingz Error should be handled as close to the hardware as possiblez Transparent error recovery at low level Synchronous vs. Asynchronous transfersz Most physical I/O is asynchronousz Kernel may provide synchronous I/O system calls Sharable vs. dedicated devicesz Disk vs. printerStructuring ofI/O software1. User-level software 2. Device-independentOS software3. Device drivers4. Interrupt handlers512.9Operating System ConceptsInterrupt HandlersInterrupt Handlers Should be hidden by the operating system Every thread starting an I/O operation should block until I/O has completed and interrupt occurs Interrupt handler transfers data from device (controller) and un-blocks process12.10Operating System ConceptsDevice DriverDevice Driver Contains all device-dependent code Handles one device Translates abstract requests into device commandsz Writes controller registersz Accesses mapped memoryz Queues requests Driver may block after issuing a request:z Interrupt will un-block driver (returning status information)612.11Operating System ConceptsDeviceDevice--independent I/O Softwareindependent I/O SoftwareFunctions of device-independent I/O software: Uniform interfacing for the device drivers Device naming Device protection Providing a device-independent block size Buffering Storage allocation on block devices Allocating and releasing dedicated devices Error reporting12.12Operating System ConceptsLayers of the I/O SystemLayers of the I/O SystemUser-Space I/O Software System call libraries (read, write,...) Spoolingz Managing dedicated I/O devices in a multiprogramming systemz Daemon process, spooling directoryz lpd – line printer daemon, sendmail – simple mail transfer protocolLayerUser processDevice-independentsoftwareDevice driversInterrupt handlersHardwareI/OrequestI/OreplyI/O functionsI/O calls, spoolingformat I/ONaming, protectionbuffering, blockingSetup registers,Check statusSetup registers,Check statusWakeup driverPerform I/O op.712.13Operating System ConceptsApplication I/O InterfacesApplication I/O InterfacesThe OS system call interface distinguished device classes: Character-stream or block Sequential or random-access Synchronous or asynchronous Sharable or dedicated Speed of operation Read/write, read only, write only12.14Operating System ConceptsExample: Example: 4.3 BSD kernel I/O structure4.3 BSD kernel I/O structureThe hardwaresocket Plain fileprotocols FilesystemCookedblockinterfaceRawblockinterfaceRawttyinterfacecooked TTYLinedisciplineNetworkinterfaceBlock-device driver character-device driverSystem-call interface to the kernel812.15Operating System ConceptsMassMass--Storage SystemsStorage Systems Overview of Mass Storage Structure Disk Structure Disk Attachment Disk Scheduling Disk Management Swap-Space Management RAID Structure Disk Attachment Stable-Storage Implementation Tertiary Storage Devices Operating System Issues Performance
View Full Document