Which context are softirq and tasklet in?

荒凉一梦 提交于 2019-11-29 22:33:22

The softirq and tasklet are both kind of bottom-halves mechanism. Sleep is not allowed becuase they run under interrupt context not process context. If sleep is allowed, then the linux cannot schedule them and finally cause a kernel panic with a dequeue_task error. The interrupt context does not even have a data structure describing the register info, so they can never be scheduled by linux. If it is designed to have that structure and can be scheduled, the performance for interrupt handling process will be effected.

@kai: your qs reg which context bottom-halves execute in?

Technically, softirq's do run in an interrupt context - the "softirq" context; it's just that it's not "hard-irq" context (which is the context when a hardware interrupt occurs).

So, in a softirq handler, in terms of the 'lookup' macros Linux provides:

in_interrupt: yes | in_irq: no | in_softirq: yes | in_serving_softirq: yes

But be aware (beware!!! :): "all of the restrictions that apply to interrupt handlers also apply to bottom halves. Thus, bottom halves cannot sleep, cannot access user space, and cannot invoke the scheduler." -- LDD3.

Jermaine answers the rest of your question.

[Update] In addition, I'd like to point out that one can define simple and elegant macros that help print debug info as and when required. Over the years, I've put these macros and convenience routines into a header file; you can check it out and download it here: "A Header of Convenience".

There are macros / functions to:

  • make debug prints along with funcname / line# info (via the usual printk() or trace_printk()) and only if DEBUG mode is On
    • dump the kernel-mode stack
    • print the current context (process or interrupt along with flags in the form that ftrace uses)
    • a simple assert() macro (!)
    • a cpu-intensive DELAY_LOOP (useful for test rigs that must spin on the processor)
    • an equivalent to usermode sleep functionality
    • a function to calculate the time delta given two timestamps (timeval structs)
    • convert decimal to binary, and
    • a few more.

Whew :-)

I agree with the accepted answer and Kaiwan's answer, but they did not mention ksoftirqd. If the CPU is under heavy load of softirqs and/or tasklets, it schedules its ksfotirqd thread which process the raised softirqs and tasklets in process context.

So I guess the answer to the OP's question would be: softirqs can run in either interrupt or process contexts.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!