1Lecture 11I/O System SoftwareNovember 18, 2003Prof. Joe PasqualeDepartment of Computer Science and EngineeringUniversity of California, San Diego© 2003 by Joseph PasqualeCSE 120: Principles of Operating Systems2Before We Begin …Read Chapter 11 (on I/O Systems)3What is I/OInput/output between CPU/memory and I/O devicesProblems• So many different types of I/O devices• Wide range in speed, operation, data transferunitsQuestions• How does a process initiate I/O?• How is synchronization achieved?• How is data transferred?4Background on I/O HardwareI/O bus interconnects CPU, memory, I/O devsA device generally connects to the bus via a controllerController has registers that CPU can read/write via• I/O instructions• memory instructions (memory-mapped)Data transfer: programmed I/O vs. DMASynchronization: polling vs. interrupts5Classifying DevicesSo many different types of devices• classify by shared characteristics• imposes structure: shared code, lower complexityDimensions• character stream vs. block• sequential vs. random-access• synchronous vs. asynchronous• sharable vs. dedicated• speed of operation6I/O Layered Software StructureDevicedriverDevice-Independent I/O(buffering, caching, block vs. char, …)User I/O (stdio library)DevicedriverDevicecontrollerDevicedriverDevice Dev DevDevicecontrollerDevicecontrollerDevicecontrollerDevice Dev DevUserKernelHardware7Device DriversEncapsulates device-dependent codeGenerally must implement a standard interfaceCode contains device-specific register reads/writesInterrupt handlers• Handler executes when I/O operation completes• May be converted to a “software interrupt”• Updates data structures• Wakes up process that was waiting8Device-Independent I/O SoftwareUniform interfacing for device driversNaming, protectionBuffering, cachingDevice-independent block sizeStorage allocation for block devicesLocking (dedicated devices)Error handling9User-Space I/O SoftwareRicher or simplified interface• e.g., putchar/getchar vs. read/writeUser-level buffering• e.g. stdio librarySpooling daemons• Printer10Overall OperationUser ProcessDevice-Independent I/ODevice Driver: Upper (synch)Interrupt Handlers (asynch)HardwarePerform I/OoperationWakeup driverwhen I/OcompletedControl via deviceregisters; checkstatusNaming, protection,blocking, buffering,allocationMake I/O call;format I./O;spoolingI/OrequestI/Oresponse11Example: Unix I/OFile SubsystemDevice DriversCharacterBlockBuffer Cache12Unix: I/O System CallsVia file system interface• open• close• read• write• Ioctl13Unix: Buffered vs. Unbuffered I/OBuffered I/O• system buffers: buffer cache, character queuesUnbuffered I/O• data transferred directly between proc and dev• can be via DMA14Unix: Standard I/O Libraryfopen, fread, fwrite, fprintf, fscanf, fclosePrivate buffer kept in user spaceMinimizes the number of I/O system calls15Unix: Block vs. Character DevicesBlock• transfer units in fixed-size blocks• blocks are addressable (random access)• kept in buffer cacheCharacter• transfer units in variable-size sequence of bytes• used for all non-block devices• linked list of character queues16Unix: The Buffer CacheCache of recently used blocksEach block has an address (device #, block #)Three lists• device list (hash table + linked lists)• free list• driver I/O queueLRU is used for
View Full Document