问题描述
我想在 linux 内核中创建我自己的 softirq.这样做是否正确:
I would like to create my own softirq in linux kernel. Is it the right way to do that:
在模块的 init
中,我想触发 softirq
从我将添加一个调用到:
In the init
of the module I would like to trigger the softirq
from I'll add a call to:
394 void open_softirq(int nr, void (*action)(struct softirq_action *))
395 {
396 softirq_vec[nr].action = action;
397 }
在代码片段中,我想提高 softirq,我将添加对 raise_softirq
函数的调用:
And in the snippet I would like to raise the softirq I'll add a call to raise_softirq
function:
379 void raise_softirq(unsigned int nr)
380 {
381 unsigned long flags;
382
383 local_irq_save(flags);
384 raise_softirq_irqoff(nr);
385 local_irq_restore(flags);
386 }
并将我的新 softirq
添加到:
And add my new softirq
in:
411 /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
412 frequency threaded job scheduling. For almost all the purposes
413 tasklets are more than enough. F.e. all serial device BHs et
414 al. should be converted to tasklets, not to softirqs.
415 */
416
417 enum
418 {
419 HI_SOFTIRQ=0,
420 TIMER_SOFTIRQ,
421 NET_TX_SOFTIRQ,
422 NET_RX_SOFTIRQ,
423 BLOCK_SOFTIRQ,
424 BLOCK_IOPOLL_SOFTIRQ,
425 TASKLET_SOFTIRQ,
426 SCHED_SOFTIRQ,
427 HRTIMER_SOFTIRQ,
428 RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
429 MY_NEW_SOFTIRQ
430 NR_SOFTIRQS
431 };
在这里:
60 char *softirq_to_name[NR_SOFTIRQS] = {
61 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
62 "TASKLET", "SCHED", "HRTIMER", "RCU", "MY_NEW_SOFTIRQ"
63 };
问题:
- 我是对的还是我错过了什么?
- 这样做是否正确?还有其他选择吗?
推荐答案
如果你想修补内核并重新编译它,你做的可能是正确的(除非你应该在 RCU_SOFTIRQ 之前移动它).
If you want to patch the kernel and recompile it, you are doing probably right (except you should move it before RCU_SOFTIRQ).
否则,IOW如果要在内核模块中进行,则必须使用基于SoftIRQ的tasklet在SoftIRQ上下文中进行操作:
Otherwise, IOW if you want to do it in a kernel module, you have to use tasklet, which is based on SoftIRQ, to do something in SoftIRQ context:
tasklet_init()
用于初始化你的钩子.
tasklet_init()
is used to init your hook.
tasklet_schedule()
安排你注册的tasklet.
tasklet_schedule()
to schedule the tasklet you register.
这篇关于如何在 linux 内核中定义和触发我自己的新软中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!