Re: Should we use preempt_disable() in sleep_on_common()?

From: liu pf
Date: Thu Dec 03 2009 - 03:01:43 EST


On Thu, Dec 3, 2009 at 3:57 PM, Dmitry Adamushko
<dmitry.adamushko@xxxxxxxxx> wrote:
> 2009/12/3 liu pf <kernelfans@xxxxxxxxx>:
>> Hi:
>>
>> I am puzzled with the following scenario. Could anyone enlighten me?
>>
>> Thanks
>> pfliu
>>
>>
>> static long __sched
>> sleep_on_common(wait_queue_head_t *q, int state, long timeout)
>> {
>> Â Âunsigned long flags;
>> Â Âwait_queue_t wait;
>>
>> Â Âinit_waitqueue_entry(&wait, current);
>>
>> Â Â__set_current_state(state);
>>
>> Â Â==========>suppose that after task A Âset state=TASK_INTERRUPTIBLE
>> , it is preempted by task B.
>>
>> Â Âspin_lock_irqsave(&q->lock, flags);
>> ...............................................................
>> }
>>
>> asmlinkage void __sched schedule(void)
>> {
>> .......................................................................................................
>> Â Âif (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
>> Â Â Â Âif (unlikely(signal_pending_state(prev->state, prev)))
>> Â Â Â Â Â Âprev->state = TASK_RUNNING;
>> Â Â Â Âelse
>> Â Â Â Â Â Âdeactivate_task(rq, prev, 1);
>> Â Â Â =============>This will remove task A from rq, but there are no
>> wait queue referring to A, so we lose A.
>> Â Â Â Âswitch_count = &prev->nvcsw;
>> Â Â}
>
> In this case, (preempt_count() & PREEMPT_ACTIVE) == 1(see
> preempt_schedule_irq() and other use-cases of PREEMPT_ACTIVE) so we
> don't Âenter this block.
>
> i.e. a preempted task stays on its queue (with state != TASK_RUNNING
> but that doesn't really matter).
>
>
> -- Dmitry
>


Thank you very much
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/