mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Richard B. Johnson" <root@chaos.analogic.com>
To: John Muir <muirj@nortelnetworks.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: poll() in 2.6 and beyond
Date: Tue, 2 Mar 2004 20:18:01 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.53.0403022006250.9695@chaos> (raw)
In-Reply-To: <404521B2.2030504@americasm01.nt.com>

On Tue, 2 Mar 2004, John Muir wrote:

> Richard B. Johnson wrote:
>
> > > Could you maybe go back to the initial report, which is that after
> > > poll() gets wrong status? It's nice to argue about where the process
> > > waits, but the issue is if it gets the same status with 2.4 and 2.6,
> > and
> > > if not which one should be fixed.
> > >
> > > Richard: can you show this with a small demo program? I assume you
> > > didn't find this just by reading code ;-)
> >
> > Yes. The code I attached earlier shows that the poll() in a driver
> > gets called (correctly), then it calls poll_wait(). Unfortunately
> > the call to poll_wait() returns immediately so that the return
> > value from the driver's poll() is whatever it was before some
> > event occurred that the driver was going to signal with
> > wake_up_interruptible().
> >
> The documentation referred to earlier
> (http://www.xml.com/ldd/chapter/book/ch05.html#t3) clearly states that
> the poll function implementation for a device should:
> "1. Call /poll_wait/ on one or more wait queues that could indicate a
> change in the poll status.
> 2. Return a bit mask describing operations that could be immediately
> performed without blocking."
> What happens is if your device has data ready RIGHT NOW (without any
> waiting), the information regarding that is returned.
>
> Now, if you look closely at the implementation of do_poll(), it will
> loop forever until any device returns that data is available (or the
> timeout occurs). After data is available, do_pollfd() function no longer
> adds the devices to the wait queue.
>
> What this means is that the first time through each device is added to
> the wait queue. After the process is woken up from schedule_timeout (or
> the timeout occurs), then it will loop through each device again to
> either add that device to the wait queue again, or determine that there
> is data ready to be read/written, or an error or whatever. do_pollfd()
> then increases count, and do_poll() exits from it's loop (and wait
> queues are cleaned-up in sys_poll()).
>
> So, yes, the poll_wait() returns immediately, it should not wait, and
> your poll method should return the device's CURRENT status in the poll
> mask. Don't worry, because when your device wakes the waiting process
> when data is ready, the device's poll function is called again and you
> again can return the CURRENT status.
>

Well the device's poll function isn't getting called the second time
with 2.6.0. I never checked it in 2.4.x because it always worked.
This problem occurs in a driver that only returns the fact that
one event occurred. When it failed to report the event when built
with a newer kernel, I added diagnostics which showed that the
poll in the driver was only called once --and that the return from
poll_wait happened immediately.

So, if the poll_wait isn't a wait-function, but just some add-wakeup
to the queue function, then its name probably should have been
changed when it changed. At one time it did, truly, wait until
it was awakened with wake_up_interruptible.

> Please let me know if I'm misunderstanding this, but quite frankly,
> poll_wait CANNOT wait, for the very reasons described in previous posts:
> when multiple devices are polled, then poll_wait is called FOR EACH DEVICE.
>
> Cheers,
>
> ..John
>
>

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



  reply	other threads:[~2004-03-03  1:16 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1vmPm-4lU-11@gated-at.bofh.it>
     [not found] ` <1vonq-6dr-37@gated-at.bofh.it>
     [not found]   ` <1voGY-6vC-41@gated-at.bofh.it>
     [not found]     ` <1vpjt-7dl-17@gated-at.bofh.it>
     [not found]       ` <1vpCV-7wY-41@gated-at.bofh.it>
     [not found]         ` <1vpWa-7Py-19@gated-at.bofh.it>
2004-03-02 22:53           ` Bill Davidsen
2004-03-02 22:57             ` Roland Dreier
2004-03-02 23:32             ` Richard B. Johnson
2004-03-03  0:07               ` John Muir
2004-03-03  1:18                 ` Richard B. Johnson [this message]
2004-03-03  4:04                   ` Roland Dreier
2004-03-03 12:38                     ` Richard B. Johnson
2004-03-03 14:29                       ` Davide Libenzi
2004-03-03  3:57               ` David Dillow
2004-03-03 18:23                 ` Richard B. Johnson
2004-03-03 19:29                   ` Dave Dillow
2004-03-03 20:10                     ` Richard B. Johnson
2004-03-03 22:25                   ` Linus Torvalds
2004-03-03 22:42                     ` Richard B. Johnson
2004-03-03 23:14                       ` Linus Torvalds
2004-03-03 22:52                     ` Linus Torvalds
2004-03-03 23:07                       ` Richard B. Johnson
2004-03-03  3:06 linux
  -- strict thread matches above, loose matches on Subject: below --
2004-03-02 18:21 Richard B. Johnson
2004-03-02 20:04 ` Roland Dreier
2004-03-02 20:24   ` Richard B. Johnson
2004-03-02 21:00     ` Roland Dreier
2004-03-02 21:26       ` Richard B. Johnson
2004-03-02 21:39         ` Roland Dreier
2004-03-02 21:59           ` Richard B. Johnson
2004-03-02 22:41             ` Dave Dillow
2004-03-02 22:56             ` Roland Dreier
2004-03-02 23:16               ` Richard B. Johnson
2004-03-02 23:21                 ` Roland Dreier

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=Pine.LNX.4.53.0403022006250.9695@chaos \
    --to=root@chaos.analogic.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muirj@nortelnetworks.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®