我想在Linux内核中创建自己的softirq。是这样做的正确方法:
在模块的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 };
问题:
最佳答案
如果要修补内核并重新编译,则可能做对了(除非您应将其移到RCU_SOFTIRQ之前)。
否则,如果要在内核模块中执行IOW,则必须使用基于SoftIRQ的tasklet在SoftIRQ上下文中执行以下操作:tasklet_init()
用于初始化您的钩子(Hook)。tasklet_schedule()
安排您注册的Tasklet。
关于android - 如何在Linux内核中定义和触发我自己的新softirq?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14301331/