Sleeping in workqueues
From: Arun Sudhilal <hidden>
Date: 2017-02-13 10:01:06
Hello Tobias, On Sun, Feb 12, 2017 at 7:15 PM, Tobias FItschen [off-list ref] wrote:
Hello people, I have a question regarding workqueues. I know it's possible to sleep in workqueue routines. Does that mean I can use:
What it means is that you are safe to use any sub routines which may sleep or which will sleep.
1. "set_current_state(TASK_INTERRUPTIBLE);" get the the task with "current" and pass it to a other task and then call "schedule();" in a workqueue routine and at a different place (perhaps another workqueue routine) use wake_up_process(task)" ? 2. initialize completions in a workqueue routine and call complete() in a different workqueue routine? I tried it in a simple example setup and both worked. I just want to
completion variables are written to hide the complexity of using set_current_state and related functions to make a thread sleep. It basically enables driver authors to reuse the same code for sleep/wake. At the heart of it, its all the same. My recommendation is to use completion.
make sure that was not just by accident. As I understand it a work item is executed on a worker, which is a unique process, but I also know that there are exceptions, e.g. I can not copy to or from user space in a workqueue routine. Also I don't know if a worker "sticks" with the current work item until it is completed or can execute multiple work items at the "same" time.
Yes a kworker sticks with current work item until it is completed. If a work item currently executed by a worker met with a sleep, another kworkers are used to process the other pending work items. Regards, Arun
3. In case completions and schedule()/wakeup() work, I would also like to know, which has the better performance. Thanks a lot already! Tobias _______________________________________________ Kernelnewbies mailing list Kernelnewbies at kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies