Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2378441pxy; Tue, 3 Aug 2021 05:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRTGXDGiSaB/qk24zvpcv/XvdZZJXtsahNdia9tPms0YtmL16HKRh3gq/EeB+XVh0tV8X9 X-Received: by 2002:a17:906:af77:: with SMTP id os23mr19751743ejb.427.1627992654061; Tue, 03 Aug 2021 05:10:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627992654; cv=none; d=google.com; s=arc-20160816; b=VXF42DeHmQqcOmeO5OHgCzrLCBSkE0q3RY/8wbPZOabB0kOrCPyWGSNWZgCboIXihD 3qlH7L/bxMCFW8a3J4bpzpjUYBHrKeyXtkROqF6Eal9qxY/1FhCAipTrZRGwwucGdHcV RCQU4tsldLg3g0sWdwmJMREzOT2PCCLNlTMch7YMlAjpUU7Z6/9CNxyNwcqWx/e9/8R+ Ry5D4vQPX3T4IyEq4n6bwwuW6hCqVQlr+ZONxUQVm50VZy1mXEdeCe9cH10YXVAtVvG5 X5C2cmU1Dlt7qE4lJ/FV4LrqdSOgpTNDhCSWm23vopeHZj7RrOSro0aZwqOJqbyTB6QR fpww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=501FGUGr+wDXj4ObY1nsPy9qx/iYl7JAzl3fYbbvm8A=; b=i5zfmIeuSBVxzkPqGcgt32KB+PMlvcTqPBM5eX9J+YQjkn+Foro89WsjV9tBbSHTFr u5ne4EZfO7I3sUuGk1YpjzcmyTkpkQGGPPU4aK2Kgsu3OEcxM2qOPOeGFSqqAjqIrdwH 4Mwf5RoxX7DNO8fqExHgMbbj5WnaAUpaipdHe/6LNv3vYFXwxwPPYtjOPmck7HMzf0zc qTm3t5sIyAtxLFER/80zxqlmLbaBwm1q1W5gKu5d6atdkKHQxDzyRVq+Ce3QLFTWoyK+ IfCY7ShSYARqoQ9aQpC8MxQtqZyqDNIoLNDtSp30kIAmChvw7EESoQZvKe0sh7IYLIB8 Y+ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qlb0Pg8Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jw3si12125718ejc.625.2021.08.03.05.10.30; Tue, 03 Aug 2021 05:10:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qlb0Pg8Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236040AbhHCMI3 (ORCPT + 99 others); Tue, 3 Aug 2021 08:08:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236011AbhHCMIW (ORCPT ); Tue, 3 Aug 2021 08:08:22 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C234CC06175F; Tue, 3 Aug 2021 05:08:08 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id j3so8336228plx.4; Tue, 03 Aug 2021 05:08:08 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=501FGUGr+wDXj4ObY1nsPy9qx/iYl7JAzl3fYbbvm8A=; b=qlb0Pg8Z2sxZpfE/7kIP6ga7BhRE5IJQlkgcnqMCeqNiCjf4m9HF2R+mjiVDr0GOC3 5xWEtOiqQFNSWUpLJedN/vFXJju301LT1izE/p+EoP50OSZgnjQiksRe4PSMAzBssOrn CkW7tIDUYzkAicGr+GvST9ocGtlkiEGmx4FMXAMWXy/Ej65lMjpwnmnJKuCpUdRmAhsF WY5dQtpAhrCuZXVi3tiqVViSUabSxp9rTckn8BJIBDtFtnAQM1lCb33fiBQDOVqMuOCE yOZ3sUVbuqL1j8UVpJaqOSH0hKAY+aGHMoG4L7qmZc6QYglYBs9HFlA7TMyWDgpNj8y0 0ykg== 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:mime-version:content-transfer-encoding; bh=501FGUGr+wDXj4ObY1nsPy9qx/iYl7JAzl3fYbbvm8A=; b=gHlOSZG8HeGK8Ez2ewjE8A/sH7cFnPvds96xEKH5V1Xi4LBU5Hx4VunblP65+99PfG AhroWfsShtLL5emPBLHNW1beeCr0h4T+UA16zvI6EpCgdiLhA1RPSZILDFfhK1J0VJJv 6oHs7u/9GditC5dzYtLPLKl+z+gClNC55rjCIVIxo6QbZ/veGjuq5CHZUUZ23VS5AV2r exRivc+9QCWP7MNCeL8s45D2m6HyZGIc5ybWe4Nkbu2TanrRMs9KJxmffJXXAS3Nt1k5 YuGzEk5/rddGZSWxndzusIBe2o59DV1VYgL0wUx2zLeCxcoDCVsGlowUrv4Ds8AaUeEi mDEQ== X-Gm-Message-State: AOAM532b4Ld+wb7jn21HChi6DXdSm67ce2mqfKX1gEHY6vAhiy/t/ZEw c41b6mImI2rN0mGHdBQn43w= X-Received: by 2002:a17:90a:fd10:: with SMTP id cv16mr4132237pjb.134.1627992488359; Tue, 03 Aug 2021 05:08:08 -0700 (PDT) Received: from localhost.localdomain ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id n35sm7197502pfv.152.2021.08.03.05.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 05:08:07 -0700 (PDT) From: William Breathitt Gray To: jic23@kernel.org Cc: linux-stm32@st-md-mailman.stormreply.com, kernel@pengutronix.de, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, david@lechnology.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, o.rempel@pengutronix.de, jarkko.nikula@linux.intel.com, William Breathitt Gray Subject: [PATCH v14 15/17] counter: Implement events_queue_size sysfs attribute Date: Tue, 3 Aug 2021 21:06:25 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The events_queue_size sysfs attribute provides a way for users to dynamically configure the Counter events queue size for the Counter character device interface. The size is in number of struct counter_event data structures. The number of elements will be rounded-up to a power of 2 due to a requirement of the kfifo_alloc function called during reallocation of the queue. Cc: Oleksij Rempel Signed-off-by: William Breathitt Gray --- Documentation/ABI/testing/sysfs-bus-counter | 8 ++++ drivers/counter/counter-sysfs.c | 45 +++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/ABI/testing/sysfs-bus-counter index e0e99adb0ecc..84ebb1ed28ed 100644 --- a/Documentation/ABI/testing/sysfs-bus-counter +++ b/Documentation/ABI/testing/sysfs-bus-counter @@ -233,6 +233,14 @@ Description: shorter or equal to configured value are ignored. Value 0 means filter is disabled. +What: /sys/bus/counter/devices/counterX/events_queue_size +KernelVersion: 5.15 +Contact: linux-iio@vger.kernel.org +Description: + Size of the Counter events queue in number of struct + counter_event data structures. The number of elements will be + rounded-up to a power of 2. + What: /sys/bus/counter/devices/counterX/name KernelVersion: 5.2 Contact: linux-iio@vger.kernel.org diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c index df1d75e0d7b8..d2d6495f73c5 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -3,11 +3,13 @@ * Generic Counter sysfs interface * Copyright (C) 2020 William Breathitt Gray */ +#include #include #include #include #include #include +#include #include #include #include @@ -785,12 +787,49 @@ static int counter_num_counts_read(struct counter_device *counter, u8 *val) return 0; } +static int counter_events_queue_size_read(struct counter_device *counter, + u64 *val) +{ + *val = kfifo_size(&counter->events); + return 0; +} + +static int counter_events_queue_size_write(struct counter_device *counter, + u64 val) +{ + DECLARE_KFIFO_PTR(events, struct counter_event); + int err = 0; + + /* Verify chrdev is not currently being used */ + if (test_and_set_bit_lock(0, counter->chrdev_lock)) + return -EBUSY; + + /* Allocate new events queue */ + err = kfifo_alloc(&events, val, GFP_KERNEL); + if (err) + goto exit_early; + + /* Swap in new events queue */ + kfifo_free(&counter->events); + counter->events.kfifo = events.kfifo; + +exit_early: + clear_bit_unlock(0, counter->chrdev_lock); + + return err; +} + static struct counter_comp counter_num_signals_comp = COUNTER_COMP_DEVICE_U8("num_signals", counter_num_signals_read, NULL); static struct counter_comp counter_num_counts_comp = COUNTER_COMP_DEVICE_U8("num_counts", counter_num_counts_read, NULL); +static struct counter_comp counter_events_queue_size_comp = + COUNTER_COMP_DEVICE_U64("events_queue_size", + counter_events_queue_size_read, + counter_events_queue_size_write); + static int counter_sysfs_attr_add(struct counter_device *const counter, struct counter_attribute_group *cattr_group) { @@ -829,6 +868,12 @@ static int counter_sysfs_attr_add(struct counter_device *const counter, if (err < 0) return err; + /* Create events_queue_size attribute */ + err = counter_attr_create(dev, cattr_group, + &counter_events_queue_size_comp, scope, NULL); + if (err < 0) + return err; + /* Create an attribute for each extension */ for (i = 0; i < counter->num_ext; i++) { ext = &counter->ext[i]; -- 2.32.0