Moving interrupts to threads

Thomas Gleixner 提出了一套补丁和请求评论,旨在通过引入线程化中断处理器来减少内核中与硬件处理中断相关的延迟。这一改进不仅降低了中断处理时系统的响应时间,还简化了复杂性并减少了锁定操作。Gleixner 的提案允许内核驱动程序选择是否使用线程化中断处理器,从而提供了灵活性和效率的提升。此外,它还可能最终导致 Linux 中任务轮换的移除。

Moving interrupts to threads

By Jake Edge
October 8, 2008
http://lwn.net/Articles/302043/

Processing interrupts from the hardware is a major source of latency in thekernel, because other interrupts are blocked while doing that processing.For this reason, the realtime tree has a feature, called threadedinterrupt handlers, that seeks to reduce the time spent with interruptsdisabled to a bare minimum—pushing the rest of the processing outinto kernel threads. But it is not just realtime kernels that areinterested in lower latencies, so threaded handlers are being proposed foraddition to the mainline.

Reducing latency in the kernel is one of the benefits, but there are otheradvantages as well. The biggest is probably reducing complexity by simplifying or avoiding locking between the "hard"and "soft" parts of interrupt handling. Threaded handlers will also help thedebuggability of the kernel and may eventually lead to the removal of tasklets from Linux. Forthese reasons, and a few others as well, Thomas Gleixner has posted a set of patches and a"request for comments" to add threaded interrupt handlers.

Traditionally, interrupt handling has been done with top half(i.e. the "hard" irq) that actually responds to the hardware interrupt and a bottom half (or"soft" irq) that is scheduled by the top half to do additional processing. The top halfexecutes with interrupts disabled, so it is imperative that it do as littleas possible to keep the system responsive. Threadedinterrupt handlers reduce that work evenfurther, so the top half would consist of a "quick check handler" that justensures the interrupt is from the device; if so, it simply acknowledges theinterrupt to the hardware and tells the kernel to wake the interrupt handler thread.

In the realtime tree, nearly all drivers were mass converted to usethreads, but the patch Gleixner proposes makes it optional—drivermaintainers can switch if they wish to. Automatically converting driversis not necessarily popular with all maintainers, but it has an additionaldownside as Gleixner notes: "Converting an interrupt to threadedmakes only sense when the handler code takes advantage of it by integrating tasklet/softirqfunctionality and simplifying the locking."

A driver that wishes to request a threaded interrupt handler will use:

    int request_threaded_irq(unsigned int irq, irq_handler_t handler,
	    		     irq_handler_t quick_check_handler,
			     unsigned long flags, const char *name, void *dev)
This is essentially the same as request_irq() with the addition ofthe quick_check_handler. As requested by Linus Torvalds atthis year's Kernel Summit, a new function was introduced rather thanchanging countless drivers to use a new request_irq().

The quick_check_handler checks to see if the interrupt was fromthe device, returning IRQ_NONE if it isn't. It can also returnIRQ_HANDLED if no further processing is required orIRQ_WAKE_THREAD to wake the handler thread. One other return codewas added to simplify converting to a threaded handler. Aquick_check_handler can be developed prior to the handler being converted; in that case, it returnsIRQ_NEEDS_HANDLING (instead of IRQ_WAKE_THREAD) whichwill call the handler in the usual way.

request_threaded_irq() will create a thread for the interrupt andput a pointer to it in the struct irqaction. In addition, apointer to the struct irqaction has been added to thetask_struct so that handlers can check the action flagsfor newly arrived interrupts. That reference is also used to preventthread crashes from causing an oops. Oneof the few complaints seen so far about the proposal was a concern about wasting four or eight bytes in eachtask_struct that was not an interrupt handler (i.e. the vastmajority). That structure could be split into two types, one for thekernel and one for user space, but it is unclear whether that will be necessary.

Andi Kleen has a more general concern that threaded interrupt handlers willlead to bad code: "to be honest my opinion is that it will encourage badly written interrupt code longer term," but he seems to be in the minority. There wererelatively few comments, but most seemed in favor—perhaps many arewaiting to see the converted driver as Gleixner promises to deliver "realsoon". If major obstacles don't materialize, one would guess the linux-next treewould be a logical next step, possibly followed by mainline merging for 2.6.29.


需求响应动态冰蓄冷系统与需求响应策略的优化研究(Matlab代码实现)内容概要:本文围绕“需求响应动态冰蓄冷系统与需求响应策略的优化研究”展开,基于Matlab代码实现,重点探讨了冰蓄冷系统在电力需求响应背景下的动态建模与优化调度策略。研究结合实际电力负荷与电价信号,构建系统能耗模型,利用优化算法对冰蓄冷系统的运行策略进行求解,旨在降低用电成本、平衡电网负荷,并提升能源利用效率。文中还提及该研究为博士论文复现,涉及系统建模、优化算法应用与仿真验证等关键技术环节,配套提供了完整的Matlab代码资源。; 适合人群:具备一定电力系统、能源管理或优化算法基础,从事科研或工程应用的研究生、高校教师及企业研发人员,尤其适合开展需求响应、综合能源系统优化等相关课题研究的人员。; 使用场景及目标:①复现博士论文中的冰蓄冷系统需求响应优化模型;②学习Matlab在能源系统建模与优化中的具体实现方法;③掌握需求响应策略的设计思路与仿真验证流程,服务于科研项目、论文写作或实际工程方案设计。; 阅读建议:建议结合提供的Matlab代码逐模块分析,重点关注系统建模逻辑与优化算法的实现细节,按文档目录顺序系统学习,并尝试调整参数进行仿真对比,以深入理解不同需求响应策略的效果差异。
综合能源系统零碳优化调度研究(Matlab代码实现)内容概要:本文围绕“综合能源系统零碳优化调度研究”,提供了基于Matlab代码实现的完整解决方案,重点探讨了在高比例可再生能源接入背景下,如何通过优化调度实现零碳排放目标。文中涉及多种先进优化算法(如改进遗传算法、粒子群优化、ADMM等)在综合能源系统中的应用,涵盖风光场景生成、储能配置、需求响应、微电网协同调度等多个关键技术环节,并结合具体案例(如压缩空气储能、光热电站、P2G技术等)进行建模与仿真分析,展示了从问题建模、算法设计到结果验证的全流程实现过程。; 适合人群:具备一定电力系统、能源系统或优化理论基础,熟悉Matlab/Simulink编程,从事新能源、智能电网、综合能源系统等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①开展综合能源系统低碳/零碳调度的科研建模与算法开发;②复现高水平期刊(如SCI/EI)论文中的优化模型与仿真结果;③学习如何将智能优化算法(如遗传算法、灰狼优化、ADMM等)应用于实际能源系统调度问题;④掌握Matlab在能源系统仿真与优化中的典型应用方法。; 阅读建议:建议结合文中提供的Matlab代码与网盘资源,边学习理论模型边动手调试程序,重点关注不同优化算法在调度模型中的实现细节与参数设置,同时可扩展应用于自身研究课题中,提升科研效率与模型精度。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值