preemptive kernel question
- From: "Peter Z" <peter.linux@xxxxxxxxx>
- Date: 26 Jan 2006 11:01:11 -0800
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
.
- Follow-Ups:
- Re: preemptive kernel question
- From: Peter Z
- Re: preemptive kernel question
- Prev by Date: invalid lvalue in unary '&' ... why? LKM
- Next by Date: Measure the Accept Queueing Time!
- Previous by thread: invalid lvalue in unary '&' ... why? LKM
- Next by thread: Re: preemptive kernel question
- Index(es):
Relevant Pages
|