preemptive kernel question



work_thread() is a kernel thread and goes to sleep using following
code:

182 static int worker_thread(void *__cwq)
183 {
...

204 set_current_state(TASK_INTERRUPTIBLE);
205 while (!kthread_should_stop()) {
206 add_wait_queue(&cwq->more_work, &wait);
207 if (list_empty(&cwq->worklist))
208 schedule();
209 else
210 __set_current_state(TASK_RUNNING);
211 remove_wait_queue(&cwq->more_work, &wait);
212
213 if (!list_empty(&cwq->worklist))
214 run_workqueue(cwq);
215 set_current_state(TASK_INTERRUPTIBLE);
216 }
217 __set_current_state(TASK_RUNNING);
218 return 0;
219 }

Linux 2.6 is a preemptive kernel, so schedule() might be called in
kernel mode while kernel thread is running.

Line 215 set the thread state into TASK_INTERRUPTIBLE and line 206 add
it into a wait queue. But the thread is running without
preempt_enable()/preempt_disable() lock, therefore consider this
scenario:

If a interrupt raised after line 215 and schedule() is called, current
task will be deleted from running list by schedule(). Client codes can
not wake up the task on time because it didn't execute line 206 - it
is not in wait queue. The task will sleep for good in that there is no
chance to change its state into TASK_RUNNING.

That's my question.

--Peter Z

.



Relevant Pages

  • weird behavior from kernel
    ... I am modifying linux-2.4.18 for ARM, ... the timer interrupt and disable all the others in "init" thread before ... Now I am trying to modify the "schedule" function. ... which is called in my kernel thread inside "eos_tail". ...
    (Linux-Kernel)
  • Re: weird behavior from kernel
    ... I am modifying linux-2.4.18 for ARM, ... the timer interrupt and disable all the others in "init" thread before ... Now I am trying to modify the "schedule" function. ... which is called in my kernel thread inside "eos_tail". ...
    (Linux-Kernel)
  • Re: Sleep and older children
    ... kids will fit it all in and still find a balance, because unlike me, I ... and the need for a manageable schedule. ... To me it's a given that teens need a lot of sleep, ...
    (misc.kids)
  • Re: Sleep and older children
    ... we'll have family time in the evening. ... You want your older kids to be on the same schedule as the toddler. ... move family time later to accomodate *their* sleep needs. ... likely have no luxury of sleeping in later since the young one gets up ...
    (misc.kids)
  • Re: Sleep and older children
    ... sleep in until whenever encourages a behavior that becomes ... the groove when the school year starts. ... natural for a teen's sleep schedule to gradually drift. ... but sleeping ...
    (misc.kids)