如何在linux内核中定义和触发我自己的新softirq?

0x9*_*x90 7 c android arm linux-kernel softirq

我想在linux内核中创建自己的softirq.这是正确的方法:

init模块中我想触发softirqfrom我将添加一个调用:

394 void open_softirq(int nr, void (*action)(struct softirq_action *))
395 {
396         softirq_vec[nr].action = action;
397 }
Run Code Online (Sandbox Code Playgroud)

在片段中我想提高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 }
Run Code Online (Sandbox Code Playgroud)

并添加我的新内容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 };
Run Code Online (Sandbox Code Playgroud)

在这里:

 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 };
Run Code Online (Sandbox Code Playgroud)

问题:

  • 我是对的还是我错过了什么?
  • 这是正确的方法吗?还有其他选择吗?

Con*_*ang 1

如果您想修补内核并重新编译它,您的做法可能是对的(除非您应该将其移到 RCU_SOFTIRQ 之前)。

否则,如果你想在内核模块中执行此操作,则必须使用基于 SoftIRQ 的 tasklet 在 SoftIRQ 上下文中执行某些操作:

tasklet_init()用于初始化你的钩子。

tasklet_schedule()来调度您注册的tasklet。