您好,欢迎访问三七文档
当前位置:首页 > 医学/心理学 > 药学 > 浙大操作系统 (12)
CHAPTER13:I/OSYSTEMSOverviewI/OHardwareI/OAPII/OSubsystemTransformingI/ORequeststoHardwareOperationsStreamsPerformanceOVERVIEWIncrediblevarietyofI/OdevicesIncreasingstandardizationofI/OhardwareandsoftwareinterfaceIncreasinglybroadvarietyofI/OdevicesCommonconceptsPortBus(daisychainorshareddirectaccess)PCI,ISA,SCSIController(hostadapter)Serialportcontroller,SCSIcontroller,IDEcontroller,I/OHARDWAREIntroductionPollingInterruptsDMAI/OHardwareAtypicalPCbusstructureI/OHardwareHowcantheprocessorgivecommandsanddatatoacontrollertoaccomplishanI/OtransferDirectI/OinstructionsMemory-mappedI/ODirectI/O+memorymappedI/OI/Ocontrollerhas4typesofregistersStatusregistersControlregistersData-inregistersData-outregistersI/OHardwareSometypicalportsonPCsI/OHardwareThreeinteractionmodelsbetweenI/OcontrollersandCPUsPollingInterruptDMAI/OHardware:PollingTwobitsThebusybitindicatesifthecontrollerisbusyornotworking.Thecommand-readybitindicatesiftheacommandisavailableornotforthecontrollertoexecute.AnexampleThehostrepeatedlyreadsthebusybituntilthatitbecomesclear(busywaitingorpolling)Thehostsetsthewritebitinthecommandregisterandwritesabyteintothedata-outregisterI/OHardware:PollingThehostsetsthecommand-readybitWhenthecontrollernoticesthatthecommand-readybitisset,itsetsthebusybitThecontrollerreadsthecommandregisterandseesthewritecommand.Itreadsthedata-outregistertogetthebyte,anddoestheI/Otothedevice.Thecontrollerclearsthecommand-readybit,clearstheerrorbitinthestatusregistertoindicatethatthedeviceI/Osucceeded,andclearsthebusybittoindicatethatitisfinished.I/OHardware:InterruptsCPUInterruptrequestlinetriggeredbyI/OdeviceInterrupthandlerreceivesinterruptsMaskabletoignoreordelaysomeinterruptsInterruptvectortodispatchinterrupttocorrecthandlerBasedonprioritySomeunmaskable,somemaskableInterruptmechanismalsousedforexceptionsandsystemcallsInterrupthandlerscanbedividedintotwoTophalfBottomhalfI/OHardware:InterruptsI/OHardware:InterruptsI/OHardware:DMAUsedtoavoidprogrammedI/OforlargedatamovementRequiresDMAcontrollerBypassesCPUtotransferdatadirectlybetweenI/OdeviceandmemoryCyclestealingI/OHardware:DMAI/OAPII/Osystemcallsencapsulatedevicebehaviorsingenericclasses.Device-driverlayerhidesdifferencesamongI/Ocontrollersfromkernel.I/OAPII/OAPIOnonehand,therearesomanydifferentI/Odevices.Ontheotherhand,theOSshouldprovideasimple,uniformI/OAPI.ThesolutionistheOSshouldhide(encapsulate)thesedifferencesandprovidejustafewtypesofdeviceaccess.BlockandcharacterdevicesNetworkDevicesClocksandTimersI/OAPI:BlockandCharacterDeviceInterfacesBlockdevicesincludediskdrivesandotherblock-orienteddevices:Commandsincluderead,write,seekRawI/Oorfile-systemaccessMemory-mappedfileaccesspossibleCharacterdevicesincludekeyboards,mice,serialportsCommandsincludeget,putLibrarieslayeredontopallowlineeditingI/OAPI:NetworkDeviceInterfacesVaryingenoughfromblockandcharactertohaveowninterfaceUnixandWindowsNT/9i/2000includesocketinterfaceSeparatesnetworkprotocolfromnetworkoperationIncludesselectfunctionalityManotherapproaches(pipes,FIFOs,streams,queues,mailboxes)I/OAPI:ClocksandTimersProvidecurrenttime,elapsedtime,timerIfprogrammableintervaltimeusedfortimings,periodicinterruptsioctl(onUNIX)coversoddaspectsofI/OsuchasclocksandtimersI/OAPI:Blockingandnon-blockingI/OBlocking-processsuspendeduntilI/OcompletedEasytouseandunderstandInsufficientforsomeneedsNonblocking-I/OcallreturnsasmuchasavailableUserinterface,datacopy(bufferedI/O)Implementedviamulti-threadingReturnsquicklywithcountofbytesreadorwrittenAsynchronous-processrunswhileI/OexecutesDifficulttouseI/OsubsystemsignalsprocesswhenI/OcompletedI/OKERNELSUBSYSTEMI/OschedulingBufferingCachingSpoolinganddevicereservationErrorhandlingKerneldatastructuresI/OKernelSubsystemSchedulingI/OrequestqueueforadeviceSomeOSstryfairness(diskI/O)Buffering-storedatainmemorywhiletransferringbetweendevicesTocopewithdevicespeedmismatch(modemvsdisk)Tocopewithdevicetransfersizemismatch(packetvsframes)Tomaintain“copysemantics”(kernelmemoryspacev.s.usermemoryspace)I/OKernelSubsystemCaching-fastmemoryholdingcopyofdataAlwaysjustacopyKeytoperformanceNote:Abuffermayholdtheonlyexistingcopyofadataitem,whereasacachejustholdsacopyonafasterstorageofanitemthatthatresideselsewhere.Spooling-holdoutputforadeviceIfadevicecanserveonlyonerequestatatimei.e.,PrintingDevicereservation-providesexclusiveaccesstoadeviceSystemcallsforallocationanddeallocationWatchoutfordeadlockI/OKernelSubsystemErrorhandlingOScanrecoverfromdiskread,deviceunavailable,transientwritefailuresMostreturnanerrornumberorcodewhenI/OrequestfailsSystemerrorlogsholdproblemreportsI/OKernelSubsystemKernelkeepsstateinfoforI/Ocomponents,includingopenfiletables,networkconnections,characterdevicestateMany,manycomplexdatastructurestotrackbuffers,memoryallocation,“dirty”blocksSomeuseobject-orientedmethodsandmessagepassingtoimplementI/OI/OKernelSubsystemTRANSFORMINGI/OTOHARDWAREOPERATIONSConsiderreadingafilefromdiskfor
本文标题:浙大操作系统 (12)
链接地址:https://www.777doc.com/doc-5898884 .html