问题描述
我想创建Linux内核我自己的软中断。是不是这样做的正确方法:
I would like to create my own softirq in linux kernel. Is it the right way to do that:
在的init
模块的我想触发软中断
从我会加入到呼叫
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
功能:
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 }
和添加我的新软中断
在
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如果你想要做一个内核模块中,你必须使用微进程,它是基于软中断,做一些软中断上下文:
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_schedule()
to schedule the tasklet you register.
这篇关于如何定义和触发我自己的新的softirq Linux内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!