关于request_threaded_irq行为的澄清 [英] Clarification about the behaviour of request_threaded_irq

查看:157
本文介绍了关于request_threaded_irq行为的澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在网上进行搜索,但是还没有找到关于"request_threaded_irq"功能的几个相关问题的令人信服的答案.

I have scoured the web, but haven't found a convincing answer to a couple of related questions I have, with regard to the "request_threaded_irq" feature.

问题1: 首先,我正在阅读这篇有关线程IRQ的文章:

Question1: Firstly, I was reading this article, regarding threaded IRQ's:

http://lwn.net/Articles/302043/

还有我不清楚的那一行:

and there is this one line that isn't clear to me:

仅当处理程序将中断转换为线程时才有意义 代码通过集成tasklet/softirq来利用它 功能并简化锁定."

"Converting an interrupt to threaded makes only sense when the handler code takes advantage of it by integrating tasklet/softirq functionality and simplifying the locking."

我知道,如果我们继续采用传统",上半部/下半部的方法,我们将需要自旋锁或禁用本地IRQ来掺入共享数据.但是,我不了解的是,线程中断如何通过集成tasklet/softirq功能来简化对锁定的需求.

I understand had we gone ahead with a "traditional", top half/bottom half approach, we would have needed either spin-locks or disable local IRQ to meddle with shared data. But, what I don't understand is, how would threaded interrupts simplify the need for locking by integrating tasklet/softirq functionality.

问题2: 其次,与基于work_queue的下半部分方法相比,request_threaded_handler方法具有什么优势(如果有)?在这两种情况下,似乎工作"都推迟到专用线程进行.那么,有什么区别?

Question2: Secondly, what advantage (if any), does a request_threaded_handler approach have over a work_queue based bottom half approach ? In both cases it seems, as though the "work" is deferred to a dedicated thread. So, what is the difference ?

问题3: 最后,在以下原型中:

Question3: Lastly, in the following prototype:

int request_threaded_irq(unsigned int irq, irq_handler_t handler, irq_handler_t thread_fn, unsigned long irqflags, const char *devname, void *dev_id)

即使"thread_fn"(将rx个字节写入循环缓冲区)中,IRQ的处理程序"部分是否有可能被相关的IRQ连续触发(例如UART以高速率接收字符) )部分中断处理程序正忙于处理先前唤醒中的IRQ?因此,处理程序是否会尝试唤醒"已经运行的"thread_fn"?在这种情况下,正在运行的irq thread_fn会如何表现?

Is it possible that the "handler" part of the IRQ is continuously triggered by the relevant IRQ (say a UART receving characters at a high rate), even while the "thread_fn"(writing rx'd bytes to a circular buffer) part of the interrupt handler is busy processing IRQ's from previous wakeups ? So, wouldn't the handler be trying to "wakeup" an already running "thread_fn" ? How would the running irq thread_fn behave in that case ?

如果有人可以帮助我理解我,我将非常感谢.

I would really appreciate if someone can help me understand this.

谢谢, vj

推荐答案

对于问题2, 与工作队列不同,创建时创建的IRQ线程具有更高的优先级. 在kernel/irq/manage.c中,您将看到一些类似于以下代码的代码,用于为线程化IRQ创建内核线程:

For Question 2, An IRQ thread on creation is setup with a higher priority, unlike workqueues. In kernel/irq/manage.c, you'll see some code like the following for creation of kernel threads for threaded IRQs:

            static const struct sched_param param = {
                    .sched_priority = MAX_USER_RT_PRIO/2,
            };


            t = kthread_create(irq_thread, new, "irq/%d-%s", irq,
                               new->name);
            if (IS_ERR(t)) {
                    ret = PTR_ERR(t);
                    goto out_mput;
            }

            sched_setscheduler_nocheck(t, SCHED_FIFO, &param);

在这里,您可以看到内核线程的调度策略设置为RT 1(SCHED_FIFO),线程的优先级设置为MAX_USER_RT_PRIO/2,高于常规进程.

Here you can see, the scheduling policy of the kernel thread is set to an RT one (SCHED_FIFO) and the priority of the thread is set to MAX_USER_RT_PRIO/2 which is higher than regular processes.

对于问题3, 您描述的情况也可能在正常中断下发生.通常在内核中,在执行ISR时会禁用中断.在执行ISR的过程中,即使禁用了中断,字符也可以继续填充设备的缓冲区,并且设备可以而且必须继续断言中断.

For Question 3, The situation you described can also occur with normal interrupts. Typically in the kernel, interrupts are disabled while an ISR executes. During the execution of the ISR, characters can keep filling the device's buffer and the device can and must continue to assert an interrupt even while interrupts are disabled.

设备的工作是确保IRQ行保持断言,直到读取所有字符并且ISR完成任何处理为止.同样重要的是,中断必须是电平触发的,或者根据设计由中断控制器来锁存.

It is the job of the device to make sure the IRQ line is kept asserted till all the characters are read and any processing is complete by the ISR. It is also important that the interrupt is level triggered, or depending on the design be latched by the interrupt controller.

最后,设备/外围设备应具有足够大小的FIFO,以使以高速率传送的字符不会因慢速ISR而丢失. ISR还应设计为在执行时读取尽可能多的字符.

Lastly, the device/peripheral should have an adequately sized FIFO so that characters delivered at a high rate are not lost by a slow ISR. The ISR should also be designed to read as many characters as possible when it executes.

一般来说,我所看到的是,控制器将具有一定大小的FIFO X,并且当FIFO被填充X/2时,它将触发一个中断,该中断将导致ISR抢占尽可能多的空间.尽可能的数据. ISR会读取尽可能多的内容,然后清除中断.同时,如果FIFO仍为X/2,则设备将保持中断线有效,从而使ISR重新执行.

Generally speaking what I've seen is, a controller would have a FIFO of a certain size X, and when the FIFO is filled X/2, it would fire an interrupt that would cause the ISR to grab as much data as possible. The ISR reads as much as possible and then clears the interrupt. Meanwhile, if the FIFO is still X/2, the device would keep the interrupt line asserted causing the ISR to execute again.

这篇关于关于request_threaded_irq行为的澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆