From patchwork Wed Dec 6 19:43:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mfornero@gmail.com X-Patchwork-Id: 10096887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 83A83602BF for ; Wed, 6 Dec 2017 19:43:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7494F28ABD for ; Wed, 6 Dec 2017 19:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66E1E28B18; Wed, 6 Dec 2017 19:43:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCBBE28ABD for ; Wed, 6 Dec 2017 19:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751463AbdLFTnr (ORCPT ); Wed, 6 Dec 2017 14:43:47 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:43732 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751208AbdLFTnr (ORCPT ); Wed, 6 Dec 2017 14:43:47 -0500 Received: by mail-qt0-f193.google.com with SMTP id w10so11814348qtb.10 for ; Wed, 06 Dec 2017 11:43:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Zw6KtZjelDiVELY7dqUajpDFd8BDIvaO6DhvLPoIhwI=; b=Jm3v7VtuMMvdQQJxuUnM+Vm6K1A01T3nA5+UL8gq9y+PNIyIsJN1DO2yyBWYxs+Dd4 yMY4iMgw96nM4qb9A+uhEjDMxw4ut3PyCLPzgqRFC4coDPsmADksi+xKbPFiC4RYjyMe 3pIK4yJpUaG3fw+/C+XDOo0oVeYGdbFk+YLc4D2RfPu7rYN4rg8qWQINbsIcHr/xkPuS ImiUYpmAFgriZZ3+qh+IwgJGinu+KxdTPsZFrIdxsS9/wdgnbOGfOsLudkfqcQXTXyBa e5Qe6ga6EfqOfhyMv5lVpZQ4FT/GTFtknAVj5mVQxS9SBeNZrnhMein9V1XXJ17ZXDag Euxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Zw6KtZjelDiVELY7dqUajpDFd8BDIvaO6DhvLPoIhwI=; b=EXOVnQaS5DN0qUy3uFTbRgC4k17YvkR0tVk/AYUaY2pAZk74G0DNYX+pW+bl889d8Q XZvrvzIl/CSQ92LYuc0H7OVa4mkU3gZmRY5r4snZZLU46mKH/EvidSLaee71vhZjuYF9 HxQ9GIKCvVzPqiazO9d7bOEJVy1lSYorxqSrWQkepvkK0JSvxY5us4lSRwE5PU2k83Qs X97yfeKV04+CCPhe5JpcaQ9MbA0R0QlE1G2elphmYrL+tjJuYQ1RJvr7K5IpXpqZTvDX pM5/AWgOMnpDXPor8VTM8oi2WClo66MBhhRsNnfEDvNLYUuPIyU0U15O63LQobaLOOhv JRMw== X-Gm-Message-State: AKGB3mLamaewtZMyKmeIbc6Ggi81ZzUSFrPB3mmfIHJZaKyfXsufmzyU PAX+VrvnkdkRrJ5lrygx5y/Is5ickwU= X-Google-Smtp-Source: AGs4zMb+2sgpeGQaW4N5oBNAfWfpKhQMJhDkfOoqyd2Gdc64gnlwFEIA8NDMzKehEyBOIjs48Nk69w== X-Received: by 10.200.24.171 with SMTP id s40mr5473373qtj.292.1512589426353; Wed, 06 Dec 2017 11:43:46 -0800 (PST) Received: from mfornero-centos7-64.home (99-124-156-181.lightspeed.sntcca.sbcglobal.net. [99.124.156.181]) by smtp.gmail.com with ESMTPSA id y124sm1865340qkd.82.2017.12.06.11.43.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Dec 2017 11:43:45 -0800 (PST) From: mfornero@gmail.com To: jic23@kernel.org, lars@metafoo.de Cc: linux-iio@vger.kernel.org, Matt Fornero Subject: [PATCH v3] iio: buffer: Expose data available Date: Wed, 6 Dec 2017 14:43:30 -0500 Message-Id: <1512589410-9087-1-git-send-email-mfornero@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1512161180-30116-1-git-send-email-mfornero@gmail.com> References: <1512161180-30116-1-git-send-email-mfornero@gmail.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matt Fornero 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 --- 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)