如何定义和触发我自己的新的softirq Linux内核?(How to define and tr

2019-08-06 16:11发布

我想创建Linux内核我自己的软中断。 它是这样做的正确方法:

init模块的我想触发softirq从我将添加一个调用:

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 }

并加入我的新softirq在:

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 };

问题:

  • 我说得对还是我错过了什么?
  • 它是这样做的正确方法? 任何其他的选择吗?

Answer 1:

如果你想内核打补丁并重新编译它,你正在做的可能是正确的(除非你应该RCU_SOFTIRQ之前移动)。

否则,督察,如果你想要做一个内核模块中,你必须使用微进程,这是基于软中断,做一些软中断上下文:

tasklet_init()来初始化你的钩子。

tasklet_schedule()来安排您注册微进程。



Answer 2:

声明软中断静态

静态声明您的softirq( MY_NEW_SOFTIRQ通过将其添加到) enum
char *softirq_to_name[NR_SOFTIRQS] 重新编译内核。

注册软中断的飞行

一旦静态声明的,我们自己的软中断,应在内核模块在运行时使用注册open_softirq() 通过提高它在中断处理程序的退出路径raise_softirq()



文章来源: How to define and trigger my own new softirq in linux kernel?