版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 炼钢设备项目可行性研究报告
- 混合硝基氯苯项目可行性研究报告
- 四维发力推进学校教育高质量发展
- 儿童颅型异常诊断与治疗中国专家共识(2025)解读
- 2026党建理论面试题目及答案
- 2026辅助监察面试题及答案
- 2026公务员农村面试题及答案
- 2026合同管理部面试题及答案
- 2026基础电信面试题目及答案
- 国际货运代理公司营销代表述职报告
- 2026年国企党风廉政考核试题及答案
- 2025年甘肃省定西市事业单位人员招聘考试试题及答案详解
- 2026年高考全国1卷语文高考真题含答案
- 性激素六项规范化检测与解读
- 篮球教学团队教练员管理办法
- 2026年危险货物水路运输从业人员资格复习提分资料带答案详解(研优卷)
- 2026年上海公务员考试申论试题含答案
- 西安市高新第一中学新初一分班英语试卷含答案
- 交通安全分心驾驶课件
- 商场保密知识培训
- 眼镜验光员(四级)2025年考试真题及模拟试卷
评论
0/150
提交评论