Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp976325pxb; Thu, 26 Aug 2021 20:53:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrCZK0BM/q6vD2Zb6I4XD1jNAF61vw+ze4jL1K87qtjc0fvY7LcryQndt+qX1mmo4d1aBz X-Received: by 2002:a50:c94d:: with SMTP id p13mr7972562edh.246.1630036435277; Thu, 26 Aug 2021 20:53:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630036435; cv=none; d=google.com; s=arc-20160816; b=tGNM5Lftddufw0U68KHKZrtZEB/IQNwr5Yn8N1eZ3Fy1LE/7QJJbK6l7muqdWifMql fJKWsleIY657z34ZZYZ5Xob5bd6kU6B1Kjm89tpT5cc02b8mLl7myrJNEY7bHZDAOftp wKd2LCJzY479Nplh1IfDLO6rjLqwIKYn3HFQLeyezSJMTrAWoYRwRVMcb6Rpot1VD8Q7 8yN/eDjm3JvzI1vi3LRDcwJ8icreFXKZVh2Ervte7CLY9nzJNBLXH0RU+Q5DdicJ/hWl nHDTOH1ZFE4HZVeycXwsmi8kIbsvpZrp5W7hlEC3WDC9UwzbhDXIT3yNDcR3UX+s/JFf b3fA== 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=tqQ1m9HdH9arCV4uY9wOlyOVXDQIIQIgjKnHJp9wmXU=; b=Zg8J6lA2mxfvfUxlfYtI9aeYTnUiS9HH/vSYC8gxNvQI3ZGeXCpqgzW0q1dDfS+Ptr z/UE3GLi0c65qEp5Rx4krF3Lbeh+j2+c6TB9OvTlhhcvaafo8zTzrSGL+7o2DSQD5542 FX7DVMvxQQaqtRdRIzR4wZZzYYolKLQMY7oLYZA/N02WKbh8yuQIoKLPwOBfXzXyLnmi g1MLZGqOJYcChwrZ99UeP42Dqvmfo9QYUCoyRqJO879AQpThJSdoDl1wbuGg/ZWf5BvR Yu9FPVLAZPk5bnF35ElKOHu+V5AbKapceXCS5RfW0DZyU4oc1ILTQoRiGxeO56WVNsWK X7VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=txUHC1vN; 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 du10si4728307ejc.547.2021.08.26.20.53.32; Thu, 26 Aug 2021 20:53:55 -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=txUHC1vN; 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 S244291AbhH0DuY (ORCPT + 99 others); Thu, 26 Aug 2021 23:50:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244323AbhH0DuL (ORCPT ); Thu, 26 Aug 2021 23:50:11 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B04AC0613CF; Thu, 26 Aug 2021 20:49:17 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id j10-20020a17090a94ca00b00181f17b7ef7so8054102pjw.2; Thu, 26 Aug 2021 20:49:17 -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=tqQ1m9HdH9arCV4uY9wOlyOVXDQIIQIgjKnHJp9wmXU=; b=txUHC1vNQrWNqVLuOBkHbSKiZKi+il3a+S1OM9AJX++d9b14Fm9ecn744EsI4rC9Zc NdXFpb0aHg/bDSr3UEoaqBjtEeIXuadwmzGghj7xQDv2IkqMo6CNWxA6XkCIDSJ6sVMw hwH4ho1/Sw+zZfAp99MZqUKMdFuHJZzSMaOXatEng9DMCBbLdXjDhQEN0l4+U0EaFViJ yDMKV1yXGO3U8HNjE8+TSVhRbhoJ+6badBYCWOXE78p8IbXvjEfviycqbYzGyADQ57e5 UpPtaBrInlvhUStBMspC9Yxa/Zb2N88L5/cjQNzENC6IsOraYulzuatUuiG9g3jJBwu5 SC0Q== 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=tqQ1m9HdH9arCV4uY9wOlyOVXDQIIQIgjKnHJp9wmXU=; b=HqFD/A3k/pKYwzaSjYtly05izlQH6rB4gBERpK+Kk7sjXEwnH62wmYpA6vLUm3uxoy 5IGO9ccT+rkFzvp1JV8O3zSxlAb492SQLpUb4WWhWUagRoWbEDtMpfTr9Pcisa/fxTeD 0wTzAhIDNuW4pSEgeuKj6iswfM1+DfQhK8f+a6v57+qhTRZtXDkcET0OZvpk9y7jLmDT zcaPpsZLYpQ4Fe3LGaIonZmp4ZGokkxlLMBzWo8sglD+gcFjd1Lo4cc5GwtR1GO31bh0 wYTLrvgbB2G7UlZ0+v/kANip2wbJLOUNPcfXRPLxvBlOoMpcIY6mbBkG7kpneT21vcz0 YZ8g== X-Gm-Message-State: AOAM530HWwlPYpsZIA5l9piQQddsq1UqiAT3ZK2GGYhQ0Tco/7Ccsqpu 42sbohucYCP2OnBPTVq4TNY= X-Received: by 2002:a17:902:6b84:b029:ee:f966:1911 with SMTP id p4-20020a1709026b84b02900eef9661911mr6723009plk.69.1630036156992; Thu, 26 Aug 2021 20:49:16 -0700 (PDT) Received: from localhost.localdomain ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id o6sm4364693pjk.4.2021.08.26.20.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 20:49:16 -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 v16 12/14] counter: Implement events_queue_size sysfs attribute Date: Fri, 27 Aug 2021 12:47:56 +0900 Message-Id: X-Mailer: git-send-email 2.33.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 0ce16669157e..06c2b3e27e0b 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.16 +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 97d8d7c2a2b6..b90f404b1fa1 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 @@ -783,12 +785,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) { @@ -827,6 +866,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