https://blog.csdn.net/boogie0207/article/details/112285491
谈谈我的分析:
while (!kthread_should_stop()) {
dosomething();
set_current_state(TASK_INTERRUPTIBLE);
schedule();
}
__set_current_state(TASK_RUNNING);
作者想要在中断到来的时候,调用wake_up_process去唤醒这个kthread来执行dosomething
dosomething 执行可能稍微比较耗时,出现了当中断比较频繁的时候,不能每次都调用 dosomething 的情况
这样做合理吗?
不合理
哪里不合理?
作者的初步意图:
中断到来的时候,作者的意图是用 wake_up_process 唤醒一个别的 task 执行 dosomething
来一个中断执行一次 wake_up_process ,每次 wake_up_process 都要唤醒睡眠的task执行dosomething
实际上,有如下地方不成立:
- 中断到来的时候,用 wake_up_process 唤醒一个别的 task 时,发现人家没睡,还在执行 dosomething
所以此时去叫醒,是个没意义的动作 - 在1的情况下,dosomething 不能执行完再执行一遍吧,所以 wake_up_process 和 dosomething 不是一一对应
总不能让被唤醒的task执行完后强制睡了再被叫醒吧
/**
* wake_up_process - Wake up a specific process
* @p: The process to be woken up.
*
* Attempt to wake up the nominated process and move it to the set of runnable
* processes.
*
* Return: 1 if the process was woken up, 0 if it was already running.
*
* This function executes a full memory barrier before accessing the task state.
*/
int wake_up_process(struct task_struct *p)
合理的方案:
(1)每来一个中断, 在中断下文执行 dosomething 操作
(2)dosomething 执行比较耗时时,中断下文只将该动作入队到queuework,在work handler中慢慢去拷贝
(3)非要这么用,那只能中断做生产者,kthread做消费者,用计数方式同步