Linux操作系统课程指导:Ch7-Interrupts-and-Interrupt-Handler_第1页
Linux操作系统课程指导:Ch7-Interrupts-and-Interrupt-Handler_第2页
Linux操作系统课程指导:Ch7-Interrupts-and-Interrupt-Handler_第3页
Linux操作系统课程指导:Ch7-Interrupts-and-Interrupt-Handler_第4页
Linux操作系统课程指导:Ch7-Interrupts-and-Interrupt-Handler_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

InterruptsandInterruptHandlersInterruptsandInterruptHandlersOSkernelismanagingthehardwareconnectedtothemachine,suchasharddisks,keyboards,miceandwirelessradios.CPUisfastanddeviceisalwaysslow,howtocommunicate?Polling:CPUchecksthehardwareperiodicallyInterrupt:hardwaresignalsthekernelDirectmemoryaccess(DMA):aspecialhardware2026/7/28LiangShi:LinuxOperatingSystems2OutlineInterruptsInterruptHandlersTopHalvesVs.BottomHalves(上半部和下半部)RegisteringanInterruptHandler(注册中断)WritinganInterruptHandler(编写中断)InterruptContext(中断上下文)ImplementingInterruptHandlers(实现中断)InterruptControl(中断控制)Conclusion2026/7/28LiangShi:LinuxOperatingSystems3InterruptsHardwarecangenerateinterruptsasynchronouslyatanytimeHardware->interruptcontroller->processor->kernel(handletheinterrupt)Interruptvalueassignedfordifferentinterrupt,alsocalledinterruptrequest(IRQ)lines.Hey,Ihavenewkeypresseswaiting!Readandprocessthesebadboys!Exceptions:occursynchronouslywithrespecttotheprocessorclock.(同步中断)2026/7/28LiangShi:LinuxOperatingSystems4Exceptionsoccursynchronouslywithrespecttotheprocessorclock.(同步中断)Twotypes:处理器探测异常由CPU执行指令时探测到一个反常条件时产生,如溢出、除0错等编程异常由编程者发出的特定请求产生,通常由int类指令触发通常叫做“软中断”例如系统调用对于处理器探测异常,根据异常时保存在内核堆栈中的eip的值可以进一步分为:故障(fault):eip=引起故障的指令的地址通常可以纠正,处理完异常时,该指令被重新执行例如缺页异常陷阱(trap):eip=随后要执行的指令的地址。异常中止(abort):eip=???发生严重的错误。eip值无效,只有强制终止受影响的进程2026/7/28LiangShi:LinuxOperatingSystems52026/7/28LinuxOSAnalysis6/102故障非屏蔽中断陷阱,断点调试陷阱故障,缺页异常中止异常处理程序异常处理程序发出的信号InterruptHandlersThefunctionthekernelrunsinresponsetoaspecificinterruptiscalledaninterrupthandlerorinterruptserviceroutine(ISR).Theinterrupthandlerforadeviceispartofthedevicedriver–thekernelcodethatmanagesthedevice.Interrupthandleriscalledininterruptcontext(atomiccontext),differentfromprocesscontext,interruptcontextcannotbeblocked.Interrupthandlershouldrunasfastaspossible.

Hey,hardware,Ihearya;nowgetbacktowork!However,interrupthandlershavealargeamountofworktodo.2026/7/28LiangShi:LinuxOperatingSystems7TopHalvesVersusBottomHalvesInterrupthandlerneedstoexecutefastandperformalargeamountofworkInterrupthandlersarepartitionedintotwoparts:tophalvesandbottomhalves.Tophalfisrunimmediatelyuponreceiptoftheinterruptandperformsonlytheworkthatistime-criticalBottomhalfperformstheworkthatcanbedelayed.2026/7/28LiangShi:LinuxOperatingSystems8TimeCriticalFastandnotinterruptibleNoCriticalCanbedelayedandcanbeinterruptedBottomHalfTopHalfRegisteringanInterruptHandler2026/7/28LiangShi:LinuxOperatingSystems9flags2026/7/28LiangShi:LinuxOperatingSystems10name2026/7/28LiangShi:LinuxOperatingSystems11RegisteringanInterruptHandler2026/7/28LiangShi:LinuxOperatingSystems12Irqn:therequestedinterruptlineMy_interrupt:thehandlerFlags:IRQF_SHAREDName:my_deviceDev:my_devIrq:thefreedinterruptlineDev_id:fornotsharedline,removethehandleranddisabletheline,forsharedline,onlythedev_idhandlerisremoved.WritinganInterruptHandlerIrq:interruptlineDev_instance:deviceReturn:IRQ_NONEorIRQ_HANDLEDIRQF_SHAREDExample:real-timeclock2026/7/28LiangShi:LinuxOperatingSystems13WritinganInterruptHandler2026/7/28LiangShi:LinuxOperatingSystems14InterruptContextWhenexecutinganinterrupthandler,thekernelisininterruptcontextCompareprocesscontextandinterruptcontextProcesscontextonbehalfofaprocess,cansleepandinvoketheschedulerInterruptcontextdoesnotassociateprocess,cannotsleep,scheduleInterruptcontextistimecriticalbecausetheinterrupthandlerinterruptsothercode.Sharedstackwiththeinterruptedprocessorhastheirownstack,interruptstack.2026/7/28LiangShi:LinuxOperatingSystems15ImplementingInterruptHandlers2026/7/28LiangShi:LinuxOperatingSystems16ImplementingInterruptHandlers2026/7/28LiangShi:LinuxOperatingSystems17ImplementingInterruptHandlers2026/7/28LiangShi:LinuxOperatingSystems18/proc/interrupts2026/7/28LiangShi:LinuxOperatingSystems19InterruptlineTheinterruptcontrollerhandlingtheinterruptCountersofthenumberofinterruptsreceivednameInterruptControl2026/7/28LiangShi:LinuxOperatingSystems20InterruptControlTheobjectofthecontrolistoprovidesynchronizationLocal_irq_disable()(cli)Local_irq_enable()(sti)local_irq_save(flags)Local_irq_restore(flags)CanbecallbothinprocessandinterruptcontextNomoreglobalcli()–why?Disable_irq,disable_irq_nosync,enable_irq,synchronize_irq2026/7/28LiangShi:LinuxOperatingSystems21ConclusionWhatisinterrupt?CompareinterruptwithexceptionWhatisthecharacteristicsofinterrupt?Whatthetophalfandbottomhalf,why?Whatistheprocessfordesignani

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论