From: Josselin Costanzi <josselin.costanzi@mobile-devices.fr>
To: linux-iio@vger.kernel.org
Subject: Re: [PATCH v2] iio: make blocking read wait for data
Date: Fri, 13 Jun 2014 15:09:05 +0200 [thread overview]
Message-ID: <lnet5h$iu$1@ger.gmane.org> (raw)
In-Reply-To: 5399A09B.2070608@metafoo.de
Lars-Peter Clausen wrote:
> On 06/10/2014 06:26 PM, Josselin Costanzi wrote:
>> Currently the IIO buffer blocking read only wait until at least one
>> data element is available.
>> This patch adds the possibility for the userspace to to blocking calls
>> for multiple elements. This should limit the read() calls count when
>> trying to get data in batches.
>> This commit also fix a bug where data is lost if an error happens
>> after some data is already read.
>>
>> Signed-off-by: Josselin Costanzi <josselin.costanzi@mobile-devices.fr>
>
> This is going into the right direction. But where did that timeout come
> from? If a user wants a timeout on the read() call they should open the
> device in non-blocking mode and use poll() with a timeout. I dont think we
> should add a different way of doing this since the poll() method already
> works fine.
> Also read() should still return once it got data and not wait until the full
> buffer has been read.
The idea was to implement something like SO_RCVLOWAT and SO_RCVTIMEO (or VMIN
and VTIME for ttys) hence the two sysfs entries for watermark and timeout.
As far as I understand the problem, there is at least two ABI functions that
can be impacted by adding a watermark: poll and read.
We should change poll() to return POLLIN only when there is enough data to
reach the watermark. Non blocking read returns whatever data is available.
However, for blocking read, maybe the watermark could still be respected if
it's set? It's what is done in tcp_recvmsg but then we need the timeout so it's
maybe not worth the effort and complexity. OTOH, if we don't do this, then
the blocking read isn't really useful anymore because the userspace needs
to call poll() to check the watermark. What do you think?
> Also poll() should not return until there is more data
> than the watermark in the buffer. So this means the pollq of the buffer
> should not be woken up until more data is in the buffer then the watermark.
> E.g. in iio_store_to_kfifo
>
> if (kfifo_len(&kf->kf) >= kf->buffer.watermark)
> wake_up_interruptible_poll(&r->pollq, POLLIN | POLLRDNORM);
Indeed, this needs to be implemented.
> iio_kfifo_buf_data_available() can be re-factored to return the amount of
> data that is available rather than just if data is available or not.
>
> In iio_buffer_data_available() you can then compare the result of the
> data_available() callback with the watermark and return true or false
> depending on that.
Ok, I'll have a look.
>
> There is one more case that needs to be handled which is the buffer being
> disabled. When the buffer is disabled iio_buffer_data_available() should
> return true if there is data in the buffer regardless of whether it is above
> or below the watermark. This also means that the pollq needs to be woken up
> when the buffer is disabled. This should be done in iio_buffer_deactivate()
> before the iio_buffer_put().
Yes, will check
next prev parent reply other threads:[~2014-06-13 13:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-10 16:26 [PATCH v2] iio: make blocking read wait for data Josselin Costanzi
2014-06-12 12:44 ` Lars-Peter Clausen
2014-06-13 13:09 ` Josselin Costanzi [this message]
2014-06-14 17:08 ` Jonathan Cameron
2014-06-16 10:10 ` Josselin Costanzi
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='lnet5h$iu$1@ger.gmane.org' \
--to=josselin.costanzi@mobile-devices.fr \
--cc=linux-iio@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;
as well as URLs for NNTP newsgroup(s).