Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: mfornero@gmail.com
Cc: lars@metafoo.de, linux-iio@vger.kernel.org,
	Matt Fornero <matt.fornero@mathworks.com>
Subject: Re: [PATCH v3] iio: buffer: Expose data available
Date: Sun, 10 Dec 2017 16:21:14 +0000	[thread overview]
Message-ID: <20171210162114.7928d9ed@archlinux> (raw)
In-Reply-To: <1512589410-9087-1-git-send-email-mfornero@gmail.com>

On Wed,  6 Dec 2017 14:43:30 -0500
mfornero@gmail.com wrote:

> From: Matt Fornero <matt.fornero@mathworks.com>
> 
> Add a sysfs attribute that exposes buffer data available to userspace.
> This attribute can be checked at runtime to determine the overall buffer
> fill level (across all allocated buffers).

There are a few odd cases where we don't actually know the right answer
to this case, but we can 'estimate it'.  The classic would be a hardware
fifo like the sca3000 where (IIRC) you don't have the ability to query the
fill level of the buffer, but only whether it is empty.  You also have
watershed interrupts that let you know there is 'at least' this much in the
buffer.  Currently we route that one through a software kfifo anyway so
it doesn't matter here  - just thought I'd mention it ;)

Anyhow, looks fine to me.  The description including output buffers
 is good future proofing but that code isn't yet upstream.

I don't have an issue with having it in the description though!

Applied to the togreg branch of iio.git and pushed out as testing.
Lars, if you would like to add a tag let me know as I won't be pushing this
out in non rebasing form until at least next weekend.  Obviously I can
also back it out of change things if you have comments that require it
as well!

Thanks,

Jonathan

> 
> Signed-off-by: Matt Fornero <matt.fornero@mathworks.com>
> ---
> v2 -> v3:
>  - Use %zu for sprintf instead of %llu
>  - Add documentation
> 
>  Documentation/ABI/testing/sysfs-bus-iio | 10 ++++++++++
>  drivers/iio/industrialio-buffer.c       | 15 +++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index a478740..9cc0ea1 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -1413,6 +1413,16 @@ Description:
>  		the available samples after the timeout expires and thus have a
>  		maximum delay guarantee.
>  
> +What:		/sys/bus/iio/devices/iio:deviceX/buffer/data_available
> +KernelVersion: 4.16
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		A read-only value indicating the bytes of data available in the
> +		buffer. In the case of an output buffer, this indicates the
> +		amount of empty space available to write data to. In the case of
> +		an input buffer, this indicates the amount of data available for
> +		reading.
> +
>  What:		/sys/bus/iio/devices/iio:deviceX/buffer/hwfifo_enabled
>  KernelVersion: 4.2
>  Contact:	linux-iio@vger.kernel.org
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index d2b4651..eda2a0f 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1198,6 +1198,18 @@ static ssize_t iio_buffer_store_watermark(struct device *dev,
>  	return ret ? ret : len;
>  }
>  
> +static ssize_t iio_dma_show_data_available(struct device *dev,
> +						struct device_attribute *attr,
> +						char *buf)
> +{
> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> +	size_t bytes;
> +
> +	bytes = iio_buffer_data_available(indio_dev->buffer);
> +
> +	return sprintf(buf, "%zu\n", bytes);
> +}
> +
>  static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length,
>  		   iio_buffer_write_length);
>  static struct device_attribute dev_attr_length_ro = __ATTR(length,
> @@ -1208,11 +1220,14 @@ static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR,
>  		   iio_buffer_show_watermark, iio_buffer_store_watermark);
>  static struct device_attribute dev_attr_watermark_ro = __ATTR(watermark,
>  	S_IRUGO, iio_buffer_show_watermark, NULL);
> +static DEVICE_ATTR(data_available, S_IRUGO,
> +		iio_dma_show_data_available, NULL);
>  
>  static struct attribute *iio_buffer_attrs[] = {
>  	&dev_attr_length.attr,
>  	&dev_attr_enable.attr,
>  	&dev_attr_watermark.attr,
> +	&dev_attr_data_available.attr,
>  };
>  
>  int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)


      reply	other threads:[~2017-12-10 16:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-01 20:46 [PATCH] iio: buffer-dma: Expose data available mfornero
2017-12-02 11:52 ` Jonathan Cameron
2017-12-05  9:32   ` Lars-Peter Clausen
2017-12-05 18:01     ` Matthew Fornero
2017-12-05 18:08       ` Lars-Peter Clausen
2017-12-05 18:11         ` Matthew Fornero
2017-12-05 18:38           ` Lars-Peter Clausen
2017-12-05 18:05     ` Matthew Fornero
2017-12-05 20:56 ` [PATCH v2] iio: buffer: " mfornero
2017-12-06 12:10   ` Lars-Peter Clausen
2017-12-06 19:43 ` [PATCH v3] " mfornero
2017-12-10 16:21   ` Jonathan Cameron [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=20171210162114.7928d9ed@archlinux \
    --to=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=matt.fornero@mathworks.com \
    --cc=mfornero@gmail.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