CSE 380 Computer Operating SystemsI/O DevicesPentium Bus ArchitectureDevice ControllersAccessing the deviceMemory Mapped I/OI/O ProgrammingI/O Code with Busy WaitingI/O Code with InterruptsI/O with Direct Memory AccessMechanism of DMA TransferSecondary Storage ManagementDisk DrivesTypical Disk ParametersDisk FormattingDisk Formatting (1)Disk Formatting (2)Disk Formatting (3)Disk AccessDisk-Head SchedulingDisk-Arm Scheduling: FCFSDisk-Arm Scheduling:SSFDisk-Arm Scheduling AlgorithmsFault Tolerance for DisksError Correction Code in SectorsHamming Codes (1950’s)Error Correction in Hamming CodesError Correction ContinuedBad SectorsRead ErrorsReliability by RedundancyRAID Redundant Array of Independent DisksRAID Level 0Slide 35RAID Level 1RAID Level 2RAID Levels 3-51CSE 380Computer Operating SystemsInstructor: Insup LeeUniversity of PennsylvaniaFall 2003Lecture Note on Disk I/O2I/O DevicesStorage devicesFloppy, Magnetic disk, Magnetic tape, CD-ROM, DVD…User interactionKeyboard, mouse, monitor, sound card, printer, modem ….Significant part of OS code deals with I/O devicesCommunication with device driversError handlingInterrupt managementConvenient interfaces3Pentium Bus Architecture4Device ControllersI/O devices have components:mechanical component electronic componentThe electronic component is the device controllermay be able to handle multiple devicesShould have a standardized interfaceController's tasksconvert serial bit stream to block of bytesperform error correction as necessaryController interfaceDevice registersData buffers for reading/writing data (separate from main memory, or not?)5Accessing the device Basically, two choices: I/O instructions that read/write I/O ports, or memory mapped I/OI/O instructions can be of the formIN R, P R is a register, P is a port numberIn memory mapped I/O, no special instructions, but some addresses in virtual memory correspond to portsMOV R, L L can be an address which is reserved for a specific devicePentium provides both schemesI/O ports numbered 0 to 64K used for control informationMemory addresses from 64K to 1M used for device buffers6Memory Mapped I/OIn an instruction such as MOV R, L, L can beA location in main memory, orA control register, or address in data buffer, of a specific I/O deviceI/O space viewed as an extension of main memory, and addressed in the same wayOf course, no overlap between the two address spacesAdvantagesDevice drivers are written in CProtection managed by pages accessible in each user spaceSavings in number of instructionsIssuesCaching must be disabled for I/O pages (why?)How to separate real memory references from I/O ones7I/O Programming Uniform naming of devicesIn Unix, special directories such as /dev/lp, /dev/ttyDevice IndependenceBuffering of data user-space or kernel-space or double bufferingDriver routinesBusy waiting vs. Interrupt driven vs. DMA8I/O Code with Busy WaitingGoal: user wants to send N bytes from Buffer to an I/O device (e.g. printer or floppy)Device controller has registers for status and for putting dataBasic approach (too wasteful for CPU):Copy data into kernel buffer B;for (i=0; i< N; i++) { /* wait for device to be free */ while (*DeviceStatusReg != READY);*DeviceDataReg = B[i]; }9I/O Code with InterruptsGoal: To let CPU schedule other processes while device is busy processing dataCode for driver:Copy data into kernel buffer B while (*DeviceStatusReg != ready);*DeviceDataReg = B[0]; /* Do only the first step */ InvokeScheduler();Code for interrupt handler:if (N == 0) Wakeup(); /* unblock the process */else {DeviceDataReg = B[i];N--; i++;};ResetInterrupt(); /*Notify device as an ack */10I/O with Direct Memory AccessGoal: Device should interrupt CPU only after the entire transferSolution: Provide direct access between memory and device so that data can be copied into memoryDMA Controller: separate unit that manages thisDriver routineCopy data into kernel spaceSet up DMA controller registersSchedule another processInterrupt handlerAck the interruptWakeup User11Mechanism of DMA TransferA program running on CPU sets up the registers in DMA controller (e.g. write N bytes into memory starting at location XYZ)Is the address XYZ virtual or physical ?DMA controller sets up the registers in device controller to request the transferOriginal request may be divided into chunksDisk controller transfers the data directly into memoryBus architecture should resolve contention for memoryDisk controller notifies DMA controllerWhen the original request is entirely processed, DMA controller interrupts the CPU12Secondary Storage ManagementWhy secondary storage?1main memory too small2main memory volatileDevices: Disks, Tapes, DrumsDisks are critical components For virtual memory managementStoring filesDisk technology hasn’t changed much compared to processor technology (esp., speed)13Disk DrivesTracks and Cylinders14Typical Disk ParametersCompare Seek time, rotation time, transfer time15Disk FormattingTypical sector is 512 bytesPreamble identifying start code and sector addressDataError correction code (16 bits). At least detecting errors possible with probability almost 1Cylinder skew:After reading an entire track, as head is moved across a cylinder, seeking next sector shouldn’t cause waiting for full rotationInterleaving sectors:As a sector is copied into controller buffer, it needs to be copied into main memory. So next sector should not be adjacent if we wish to avoid waiting for one full rotation16Disk Formatting (1)A disk sector17Disk Formatting (2)An illustration of cylinder skew18Disk Formatting (3)No interleavingSingle interleavingDouble interleaving19Disk AccessPhysical address on a disk(cylinder number, head number, sector number)Sectors can be given logical numbers that get decoded by Disk ControllerDesign considerationsSeek time (moving head to correct cylinder) and rotational latency time (waiting for correct sector) are greater than data transfer time (time to read)Lots of errors possible (bad sectors, bad bits)Caching blocks that happen to pass under disk head commonly used20Disk-Head SchedulingTime required to read or write a disk block determined by 3 factors1. Seek time2. Rotational
View Full Document