public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org, hverkuil@xs4all.nl,
	teemux.tuominen@intel.com
Subject: Re: [RFC v2 0/4]
Date: Wed, 02 Oct 2013 23:22:43 +0300	[thread overview]
Message-ID: <524C8093.909@linux.intel.com> (raw)
In-Reply-To: <13152311.59C5UI1BDX@avalon>

Hi Laurent,

Laurent Pinchart wrote:
> On Wednesday 02 October 2013 16:45:12 Sakari Ailus wrote:
>> Hi all,
>>
>> This is the second RFC set after the initial patch that makes poll return
>> POLLERR if no events are subscribed. There are other issues as well which
>> these patches address.
>>
>> The original RFC patch is here:
>>
>> <URL:http://www.spinics.net/lists/linux-media/msg68077.html>
>>
>> poll(2) and select(2) can both be used for I/O multiplexing. While both
>> provide slightly different semantics. man 2 select:
>>
>>         select() and  pselect()  allow  a  program  to  monitor  multiple
>> file descriptors,  waiting  until one or more of the file descriptors
>> become "ready" for some class of I/O operation (e.g., input possible).  A
>> file descriptor  is considered ready if it is possible to perform the
>> corre‐ sponding I/O operation (e.g., read(2)) without blocking.
>>
>> The two system calls provide slightly different semantics: poll(2) can
>> signal POLLERR related to a file handle but select(2) does not: instead, on
>> POLLERR it sets a bit corresponding to a file handle in the read and write
>> sets. This is somewhat confusing since with the original patch --- using
>> select(2) would suggest that there's something to read or write instead of
>> knowing no further exceptions are coming.
>>
>> Thus, also denying polling a subdev file handle using select(2) will mean
>> the POLLERR never gets through in any form.
>>
>> So the meaningful alternatives I can think of are:
>>
>> 1) Use POLLERR | POLLPRI. When the last event subscription is gone and
>> select(2) IOCTL is issued, all file descriptor sets are set for a file
>> handle. Users of poll(2) will directly see both of the flags, making the
>> case visible to the user immediately in some cases. On sub-devices this is
>> obvious but on V4L2 devices the user should poll(2) (or select(2)) again to
>> know whether there's I/O waiting to be read, written or whether buffers are
>> ready.
>>
>> 2) Use POLLPRI only. While this does not differ from any regular event at
>> the level of poll(2) or select(2), the POLLIN or POLLOUT flags are not
>> adversely affected.
>>
>> In each of the cases to ascertain oneself in a generic way of whether events
>> cannot no longer be obtained one has to call VIDIOC_DQEVENT IOCTL, which
>> currently may block. A patch in the set makes VIDIOC_DQEVENT to signal EIO
>> error code if no events are subscribed.
>>
>> The videobuf2 changes are untested at the moment since I didn't have a
>> device using videobuf2 at hand right now.
>>
>> Comments and questions are very welcome.
>
> What's the behaviour of select(2) and poll(2) after this patch set when
> polling an fd for both read and events, when no event has been subscribed to ?

The first one. If you're using select(2), you'll get the fd-specific bit 
set in all three sets. For poll(2), you'll get POLLERR and POLLPRI set 
for the fd.

No poll nor select can directly tell that there are no further events; 
instead they intend to say that the corresponding operations on the file 
descriptor wouldn't block. Events are a little funny in this respect; 
the difference of behaviour must be documented in select(2) V4L2 
documentation which currently is missing entirely (I'll send a patch).

An alternative would be indeed use POLLPRI only. The only way the user 
would know there are no further events coming would be to use 
VIDIOC_DQEVENT then. As a matter of fact, this way the behaviour of 
select(2) would better conform to what the POSIX standard specifies but 
OTOH would not allow to tell about the situation using poll(2) only in 
any case since it'd look like the same as any event. But I don't think 
it'd be a problem either.

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

      reply	other threads:[~2013-10-02 20:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-02 13:45 [RFC v2 0/4] Sakari Ailus
2013-10-02 13:45 ` [RFC v2 1/4] v4l: return POLLERR on V4L2 sub-devices if no events are subscribed Sakari Ailus
2013-10-02 14:05   ` Hans Verkuil
2013-10-02 13:45 ` [RFC v2 2/4] v4l: vb2: Only poll for events if the user is interested in them Sakari Ailus
2013-10-02 14:07   ` Hans Verkuil
2013-10-02 13:45 ` [RFC v2 3/4] v4l: vb2: Return POLLERR when polling for events and none are subscribed Sakari Ailus
2013-10-02 13:59   ` Hans Verkuil
2013-10-02 14:21     ` Sakari Ailus
2013-10-02 13:45 ` [RFC v2 4/4] v4l: events: Don't sleep in dequeue if " Sakari Ailus
2013-10-02 14:04   ` Hans Verkuil
2013-10-02 14:18     ` Sakari Ailus
2013-10-02 14:37       ` Hans Verkuil
2013-10-02 14:45         ` Sakari Ailus
2013-10-03  9:29           ` Hans Verkuil
2013-10-02 14:49         ` Sakari Ailus
2013-10-03  9:49           ` Hans Verkuil
2013-10-02 18:12   ` Laurent Pinchart
2013-10-02 20:23     ` Sakari Ailus
2013-10-02 14:00 ` [RFC v2 0/4] Hans Verkuil
2013-10-02 18:15 ` Laurent Pinchart
2013-10-02 20:22   ` Sakari Ailus [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=524C8093.909@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=teemux.tuominen@intel.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