From: Andrew Morton <akpm@linux-foundation.org>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
Jonathan Corbet <corbet@lwn.net>,
Davide Libenzi <davidel@xmailserver.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Enke Chen <enkechen@cisco.com>,
Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [RFCv7 PATCH 2/4] poll: add poll_requested_events() and poll_does_not_wait() functions
Date: Thu, 2 Feb 2012 14:48:35 -0800 [thread overview]
Message-ID: <20120202144835.5ccd3a76.akpm@linux-foundation.org> (raw)
In-Reply-To: <54c55b11bba94b57a76ca7553f735bcb822aa43d.1328176079.git.hans.verkuil@cisco.com>
On Thu, 2 Feb 2012 11:26:55 +0100
Hans Verkuil <hverkuil@xs4all.nl> wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
>
> In some cases the poll() implementation in a driver has to do different
> things depending on the events the caller wants to poll for. An example is
> when a driver needs to start a DMA engine if the caller polls for POLLIN,
> but doesn't want to do that if POLLIN is not requested but instead only
> POLLOUT or POLLPRI is requested. This is something that can happen in the
> video4linux subsystem.
>
> Unfortunately, the current epoll/poll/select implementation doesn't provide
> that information reliably. The poll_table_struct does have it: it has a key
> field with the event mask. But once a poll() call matches one or more bits
> of that mask any following poll() calls are passed a NULL poll_table_struct
> pointer.
>
> The solution is to set the qproc field to NULL in poll_table_struct once
> poll() matches the events, not the poll_table_struct pointer itself. That
> way drivers can obtain the mask through a new poll_requested_events inline.
>
> The poll_table_struct can still be NULL since some kernel code calls it
> internally (netfs_state_poll() in ./drivers/staging/pohmelfs/netfs.h). In
> that case poll_requested_events() returns ~0 (i.e. all events).
>
> Very rarely drivers might want to know whether poll_wait will actually wait.
> If another earlier file descriptor in the set already matched the events the
> caller wanted to wait for, then the kernel will return from the select() call
> without waiting.
>
> A new helper function poll_does_not_wait() is added that drivers can use to
> detect this situation.
>
> Drivers should no longer access any of the poll_table internals, but use the
> poll_requested_events() and poll_does_not_wait() access functions instead.
A way to communicate and enforce this is to rename the relevant fields. Prepend
a "_" to them and add a stern comment.
> Since the behavior of the qproc field changes with this patch (since this
> function pointer can now be NULL when that wasn't possible in the past) I
> have renamed that field from qproc to pq_proc. Any out-of-tree driver that
> uses it will now fail to compile.
>
> Some notes regarding the correctness of this patch: the driver's poll()
> function is called with a 'struct poll_table_struct *wait' argument. This
> pointer may or may not be NULL, drivers can never rely on it being one or
> the other as that depends on whether or not an earlier file descriptor in
> the select()'s fdset matched the requested events.
>
> ...
>
next prev parent reply other threads:[~2012-02-02 22:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 10:26 [RFCv7 PATCH 0/4] Add poll_requested_events() function Hans Verkuil
2012-02-02 10:26 ` [RFCv7 PATCH 1/4] eventpoll: set key to the correct events mask Hans Verkuil
2012-02-02 10:26 ` [RFCv7 PATCH 2/4] poll: add poll_requested_events() and poll_does_not_wait() functions Hans Verkuil
2012-02-02 22:48 ` Andrew Morton [this message]
2012-02-02 10:26 ` [RFCv7 PATCH 3/4] net/sock.h: use poll_does_not_wait() in sock_poll_wait() Hans Verkuil
2012-02-02 10:26 ` [RFCv7 PATCH 4/4] unix/af_unix.c: use poll_requested_events() in unix_dgram_poll() Hans Verkuil
2012-02-02 22:48 ` [RFCv7 PATCH 0/4] Add poll_requested_events() function Andrew Morton
2012-02-03 9:30 ` Hans Verkuil
2012-02-03 1:58 ` Enke Chen
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=20120202144835.5ccd3a76.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=davidel@xmailserver.org \
--cc=enkechen@cisco.com \
--cc=hans.verkuil@cisco.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.