Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4437024pxb; Sun, 14 Feb 2021 10:14:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzx3y6l2f+PrrOLFl7xDonNwADAa5cx2N5dybbE90EpT5RPkVJZZ5rAIv50vNHuXTU+mv52 X-Received: by 2002:a05:6402:3589:: with SMTP id y9mr12625858edc.344.1613326480014; Sun, 14 Feb 2021 10:14:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613326480; cv=none; d=google.com; s=arc-20160816; b=kI49N1XJXigPj9m4jDcmAUkBMg2A8YIeViRFLZVnqavUZtTig3s/vsqpuPZVwVQ3D4 huVNmx7kTfCuhwTYLiPUFKtGZoz4Ag2/ndaMEawJt2UlGl24yZ4KbU7pCFRmANcmhMU2 snPKd8eHqcXMAH1pTzCzuPWWLjMtDFOKBBH60QAEH/ZGBdj3lQLcsNDnrhJTz8UumbUr TdPs7S47lB60/TvQ16S0LgqQK7gzs6SLtX48dFknlpQyKoEFQ26/So55d+T7fhLPXdR4 I29k7Eu0ARtYM/zD60LbPF07mY0yPsN1aJ90cm0iyqhXwAMKvl+dJYQbAISej5p+NxYY YwAQ== 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:subject:cc:to:from:date; bh=/7BYCbfLJNyDBxJqwd2Sd+97n9kMQLcx1XgIoI6kVPk=; b=tae+hEmSwN1Qvy2gQswm8OrxGJpIo2iOIOUNxAR/i1GjmFAwjgjWgRm34xf09aqFnW Gvo2DqZ8VPHOwLASTAUGEjx7vf28o/45Xu4RnsRppF0xvSJT1zYH2w41a0yZmxLyNGYg tIx7uCeOV1UNgaxD0aglKVa9OJOLEOtTn0UaAXhS/kq0O4JFIwKDWVHBq9Ed4J/quskD EyDlbSlaS84+oRzbGicx7iShOx2qQEmLoyt+PV0ISC9vydg8655GsPMb4u8i74OycJvw 2wltdu0l1d1USsQR969VND2pBouXcIPZ46DiF0anRRa3f1Z1LcsgkB8mf6TEFKmHbzS8 biBw== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z13si9885636edc.537.2021.02.14.10.14.16; Sun, 14 Feb 2021 10:14:39 -0800 (PST) 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; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbhBNSMe (ORCPT + 99 others); Sun, 14 Feb 2021 13:12:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:55282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbhBNSMd (ORCPT ); Sun, 14 Feb 2021 13:12:33 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 551FD64E29; Sun, 14 Feb 2021 18:11:50 +0000 (UTC) Date: Sun, 14 Feb 2021 18:11:46 +0000 From: Jonathan Cameron To: William Breathitt Gray Cc: kernel@pengutronix.de, linux-stm32@st-md-mailman.stormreply.com, 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 Subject: Re: [PATCH v8 20/22] counter: Implement events_queue_size sysfs attribute Message-ID: <20210214181146.66d43da7@archlinux> In-Reply-To: <013b2b8682ddc3c85038083e6d5567696b6254b3.1613131238.git.vilhelm.gray@gmail.com> References: <013b2b8682ddc3c85038083e6d5567696b6254b3.1613131238.git.vilhelm.gray@gmail.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 12 Feb 2021 21:13:44 +0900 William Breathitt Gray wrote: > 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-chrdev.c | 23 +++++++++++++++++++ > drivers/counter/counter-chrdev.h | 2 ++ > drivers/counter/counter-sysfs.c | 25 +++++++++++++++++++++ > 4 files changed, 58 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/ABI/testing/sysfs-bus-counter > index 847e96f19d19..f6cb2a8b08a7 100644 > --- a/Documentation/ABI/testing/sysfs-bus-counter > +++ b/Documentation/ABI/testing/sysfs-bus-counter > @@ -212,6 +212,14 @@ Description: > both edges: > Any state transition. > > +What: /sys/bus/counter/devices/counterX/events_queue_size > +KernelVersion: 5.13 > +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-chrdev.c b/drivers/counter/counter-chrdev.c > index 16f02df7f73d..53eea894e13f 100644 > --- a/drivers/counter/counter-chrdev.c > +++ b/drivers/counter/counter-chrdev.c > @@ -375,6 +375,29 @@ void counter_chrdev_remove(struct counter_device *const counter) > cdev_del(&counter->chrdev); > } > > +int counter_chrdev_realloc_queue(struct counter_device *const counter, > + size_t queue_size) > +{ > + int err; > + DECLARE_KFIFO_PTR(events, struct counter_event); > + unsigned long flags; > + > + /* Allocate new events queue */ > + err = kfifo_alloc(&events, queue_size, GFP_ATOMIC); Is there any potential for losing events? > + if (err) > + return err; > + > + raw_spin_lock_irqsave(&counter->events_list_lock, flags); > + > + /* Swap in new events queue */ > + kfifo_free(&counter->events); > + counter->events.kfifo = events.kfifo; > + > + raw_spin_unlock_irqrestore(&counter->events_list_lock, flags); > + > + return 0; > +} > + > static int counter_get_data(struct counter_device *const counter, > const struct counter_comp_node *const comp_node, > u64 *const value) > diff --git a/drivers/counter/counter-chrdev.h b/drivers/counter/counter-chrdev.h > index cf5a318fe540..ff7fb0191852 100644 > --- a/drivers/counter/counter-chrdev.h > +++ b/drivers/counter/counter-chrdev.h > @@ -12,5 +12,7 @@ > int counter_chrdev_add(struct counter_device *const counter, > const dev_t counter_devt); > void counter_chrdev_remove(struct counter_device *const counter); > +int counter_chrdev_realloc_queue(struct counter_device *const counter, > + size_t queue_size); > > #endif /* _COUNTER_CHRDEV_H_ */ > diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c > index 0cb3dba950bc..9abc821a3871 100644 > --- a/drivers/counter/counter-sysfs.c > +++ b/drivers/counter/counter-sysfs.c > @@ -13,6 +13,7 @@ > #include > #include > > +#include "counter-chrdev.h" > #include "counter-sysfs.h" > > /** > @@ -737,12 +738,30 @@ 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 = counter->events.kfifo.mask + 1; kfifo_size() rather than open coding it? > + return 0; > +} > + > +static int counter_events_queue_size_write(struct counter_device *counter, > + u64 val) > +{ > + return counter_chrdev_realloc_queue(counter, val); > +} > + > 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 *group) > { > @@ -781,6 +800,12 @@ static int counter_sysfs_attr_add(struct counter_device *const counter, > if (err < 0) > return err; > > + /* Create num_counts attribute */ > + err = counter_attr_create(dev, 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;