mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Dmitry Adamushko" <dmitry.adamushko@gmail.com>
To: "Ravinandan Arakali (rarakali)" <rarakali@cisco.com>
Cc: "Linux Kernel" <linux-kernel@vger.kernel.org>
Subject: Re: Clarification required about select vs wake_up race condition
Date: Wed, 14 Mar 2007 18:08:02 +0100	[thread overview]
Message-ID: <b647ffbd0703141008o3f0d6bfsfbd9e9d793efdee@mail.gmail.com> (raw)
In-Reply-To: <FA6FB5FA4DA6BF4386D129273B2E3EC30183A411@xmb-sjc-214.amer.cisco.com>

On 12/03/07, Ravinandan Arakali (rarakali) <rarakali@cisco.com> wrote:
> Hi,
> I am facing following problem and was wondering if somebody could help
> me out.
> Our char driver(pretty much like all other char drivers) does a
> poll_wait()
> and returns status depending on whether data is available to be read.
> Even though some data is available to be read(verified using one of our
> internal
> commands), the select() never wakes up, inspite of any no. of messages
> sent.
>
> To understand this, I was looking at the code of select vs
> wake_up_interruptible().
> I feel I am misunderstanding some part of the kernel code but will be
> glad if
> somebody can point it out.
>
> My understanding:
> The do_select() sets the state of task to TASK_INTERRUPTIBLE and calls
> the driver's
> poll entry point. In our poll(), let's say immediately after we
> determine that there's
> nothing to be read, some data arrives causing a wake_up_interruptible()
> on another CPU.
> The wake up happens in the context of process sending the data. Since
> the receiving
> process was already added to the list of listeners, from looking at the
> code of
> try_to_wake_up(), it looks like it can set the state of the receiving
> process to
> TASK_RUNNING(I don't see any lock preventing this). After this happens,
> the receiving
> process goes to sleep (because of schedule_timeout called by do_select)
> but
> state is still set to TASK_RUNNING.

No, it's not going to sleep then.

The effect of schedule() being called with current->state ==
TASK_RUNNING is a re-scheduling to another task with a higher prio (if
any) or just getting back (iow, the task doesn't lose a cpu). For both
cases, the task is on the runqueue.

/ Look how/when deactivate_task() is called in schedule() /

Maybe there is a race in your code between (1) how you check "data is
available" in poll and (2) a part that sets this fact (data is
available)...


-- 
Best regards,
Dmitry Adamushko

  parent reply	other threads:[~2007-03-14 17:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-12 19:44 Ravinandan Arakali (rarakali)
2007-03-14 11:07 ` Arjan van de Ven
2007-03-14 16:33   ` Ravinandan Arakali (rarakali)
2007-03-14 17:08 ` Dmitry Adamushko [this message]
2007-03-14 18:38   ` Ravinandan Arakali (rarakali)

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=b647ffbd0703141008o3f0d6bfsfbd9e9d793efdee@mail.gmail.com \
    --to=dmitry.adamushko@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rarakali@cisco.com \
    /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®