From: liu pf <kernelfans@gmail.com>
To: Dmitry Adamushko <dmitry.adamushko@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Should we use preempt_disable() in sleep_on_common()?
Date: Thu, 3 Dec 2009 16:01:38 +0800 [thread overview]
Message-ID: <563a732e0912030001p11a9388o5efd836912e0cad9@mail.gmail.com> (raw)
In-Reply-To: <b647ffbd0912022357w640bea4embe42f2a83b54220d@mail.gmail.com>
On Thu, Dec 3, 2009 at 3:57 PM, Dmitry Adamushko
<dmitry.adamushko@gmail.com> wrote:
> 2009/12/3 liu pf <kernelfans@gmail.com>:
>> 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
prev parent reply other threads:[~2009-12-03 8:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-03 6:49 liu pf
2009-12-03 7:07 ` Arjan van de Ven
2009-12-03 7:12 ` Dmitry Torokhov
2009-12-03 7:15 ` Dmitry Torokhov
2009-12-03 8:15 ` liu pf
2009-12-03 8:22 ` Dmitry Torokhov
2009-12-03 8:53 ` liu pf
2009-12-03 7:57 ` Dmitry Adamushko
2009-12-03 8:01 ` liu pf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=563a732e0912030001p11a9388o5efd836912e0cad9@mail.gmail.com \
--to=kernelfans@gmail.com \
--cc=dmitry.adamushko@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®