diff mbox

[v2] iio: buffer: Expose data available

Message ID 1512507416-21856-1-git-send-email-mfornero@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

mfornero@gmail.com Dec. 5, 2017, 8:56 p.m. UTC
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).

Signed-off-by: Matt Fornero <matt.fornero@mathworks.com>
---
v1 -> v2:
 - Use iio_buffer_data_available() for all buffers instead
   of only DMA buffers

 drivers/iio/industrialio-buffer.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Lars-Peter Clausen Dec. 6, 2017, 12:10 p.m. UTC | #1
On 12/05/2017 09:56 PM, 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).
> 
> Signed-off-by: Matt Fornero <matt.fornero@mathworks.com>

Looks sensible to me. I think we need an update to the ABI documentation as
well for this in Documentation/ABI/testing/sysfs-bus-iio

> ---
> v1 -> v2:
>  - Use iio_buffer_data_available() for all buffers instead
>    of only DMA buffers
> 
>  drivers/iio/industrialio-buffer.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index d80f830..e7bdfa3 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1121,6 +1121,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, "%llu\n", (unsigned long long)bytes);

Since this is the kernel we shouldn't need those MSVC workarounds ;)
"%zu" should work

> +}
[..]
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index d80f830..e7bdfa3 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1121,6 +1121,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, "%llu\n", (unsigned long long)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,
@@ -1131,11 +1143,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)