From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3E40C43381 for ; Thu, 18 Feb 2021 12:03:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9C2B64E92 for ; Thu, 18 Feb 2021 12:03:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232317AbhBRMC7 (ORCPT ); Thu, 18 Feb 2021 07:02:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232898AbhBRKdG (ORCPT ); Thu, 18 Feb 2021 05:33:06 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 365C1C061786; Thu, 18 Feb 2021 02:32:26 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id z32so980856qtd.8; Thu, 18 Feb 2021 02:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QBpF/UnYAHGf5ye3tF7er160fB31uR/wphWC4wYVvOY=; b=hdp5dGdccPpZBRsGUZfrcOO1t19DF1z6ve2rfVbio4eLyNcgMasMEDVu1LWtiXlMHU VM/WGerj+KIm+dyw2tbDSldipRhpx4ZHmCIR82MXX57YshOieVIWl6Y2v1+e3TJXu/5H E6SmMEVSpeVRPKGL/tUxgJzuSsM/XmQDDu1ntbEPNNJwTVu62ngo8pBMP/M+Tb19PO0c BJuM9Ev2dclumrqD7SFsm8f8s22/4M1/sH3zT/Zd1UJRPVlBQHRW+f9Y2E4rcruLdqDR rptDH3qeEniByvKgWDgrh442PAu5CmA+yMHL2qAK5ujh+CjH7hVUWH7aBc89sCgpAWPa HJGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QBpF/UnYAHGf5ye3tF7er160fB31uR/wphWC4wYVvOY=; b=emf1OCTIyvVNBPfy8+Zout+qP6IG5HxJSBpCyhXRsHYz9KYwkyyh9V96RKZ381ngi7 rdDNDCZmbVK6x3gBiberEqEewKKh+7OlauxXdLuFMyQWnUcib2CF3PiooEnL84nui9np q+5dkNpVy8RWNnujhg17Vq6yV5URbwnhH4eo7EN7P9sM5splxYx3/pygj7rLD7vVw9bJ Ytofix7oVOWYVE1XmbZiLXZPz4SJ3iXF6O4ep70MyCx1gYzONlFW91G3Gsem6JWHy8G5 qK7I0c6KE6WvD07qVhIVFEMlJNaU+YIl/mC1ztKNTJf20c3/39NiHqwhzcCh9xKZqQ0B cUgQ== X-Gm-Message-State: AOAM532DU5xhCdrvA9rhq1OQbBDMSZHf4N9MqzrJ3RU7ksnBkDC7FFL8 gYHD4o4xKr7xwYfQwFqspxg= X-Google-Smtp-Source: ABdhPJxpeJvOxn5+wkohLMk++QGjYXEV+m6sdsuoygdRkAHpXCY4e6XA3/Ti9BNHd5lPJ3ItEYOTOg== X-Received: by 2002:aed:38e3:: with SMTP id k90mr3438649qte.119.1613644345405; Thu, 18 Feb 2021 02:32:25 -0800 (PST) Received: from shinobu ([193.27.12.132]) by smtp.gmail.com with ESMTPSA id g20sm3090235qtq.35.2021.02.18.02.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 02:32:24 -0800 (PST) Date: Thu, 18 Feb 2021 19:32:16 +0900 From: William Breathitt Gray To: Jonathan Cameron 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: References: <013b2b8682ddc3c85038083e6d5567696b6254b3.1613131238.git.vilhelm.gray@gmail.com> <20210214181146.66d43da7@archlinux> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9db4GuH0vsB+CvNJ" Content-Disposition: inline In-Reply-To: <20210214181146.66d43da7@archlinux> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --9db4GuH0vsB+CvNJ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 14, 2021 at 06:11:46PM +0000, Jonathan Cameron wrote: > On Fri, 12 Feb 2021 21:13:44 +0900 > William Breathitt Gray wrote: >=20 > > 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. > >=20 > > 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(+) > >=20 > > diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentatio= n/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. > > =20 > > +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); > > } > > =20 > > +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 =3D kfifo_alloc(&events, queue_size, GFP_ATOMIC); >=20 > Is there any potential for losing events? We take the events_list_lock down below so we're safe against missing an event, but past events currently unread in the queue will be lost. Shortening the size of the queue is inherently a destructive process if we have more events in the current queue than can fit in the new queue. Because we a liable to lose some events in such a case, I think it's best to keep the behavior of this reallocation consistent and have it provide a fresh empty queue every time, as opposed to sometimes dropping events and sometimes not. I also suspect an actual user would be setting the size of their queue to the required amount before they begin watching events, rather than adjusting it sporadically during a live operation. > > + 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 =3D 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); > > =20 > > #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 > > =20 > > +#include "counter-chrdev.h" > > #include "counter-sysfs.h" > > =20 > > /** > > @@ -737,12 +738,30 @@ static int counter_num_counts_read(struct counter= _device *counter, u8 *val) > > return 0; > > } > > =20 > > +static int counter_events_queue_size_read(struct counter_device *count= er, > > + u64 *val) > > +{ > > + *val =3D counter->events.kfifo.mask + 1; >=20 > kfifo_size() rather than open coding it? Ack. William Breathitt Gray > > + return 0; > > +} > > + > > +static int counter_events_queue_size_write(struct counter_device *coun= ter, > > + u64 val) > > +{ > > + return counter_chrdev_realloc_queue(counter, val); > > +} > > + > > static struct counter_comp counter_num_signals_comp =3D > > COUNTER_COMP_DEVICE_U8("num_signals", counter_num_signals_read, NULL); > > =20 > > static struct counter_comp counter_num_counts_comp =3D > > COUNTER_COMP_DEVICE_U8("num_counts", counter_num_counts_read, NULL); > > =20 > > +static struct counter_comp counter_events_queue_size_comp =3D > > + 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_d= evice *const counter, > > if (err < 0) > > return err; > > =20 > > + /* Create num_counts attribute */ > > + err =3D counter_attr_create(dev, group, &counter_events_queue_size_co= mp, > > + scope, NULL); > > + if (err < 0) > > + return err; > > + > > /* Create an attribute for each extension */ > > for (i =3D 0; i < counter->num_ext; i++) { > > ext =3D counter->ext + i; >=20 --9db4GuH0vsB+CvNJ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAmAuQjAACgkQhvpINdm7 VJLb4w//XoS0cfe5nK5uwMVsnyoHPugIaFvxzK5Bm+98z+78pkVC3MPScsWvip1T thzsY6SVy1LnrYkIihPnyFMzs+xwg6B2uyViHdXBjlQyKbEyTBsMUpHJbCsqlJDU I91rt3gP3SKYhg5e+bN0y2jFgXohy/3glP8vMoeWaUh7aJXsjnNUWNdvb4zJzn7A RlnfRvL8q0E7cU/gZ7ra0GgdTyTTTIYzdIGPyf/W9BdJxdZsr8fUStaXDWD+vutF 7TgNBJ0dLnBJotIFe9CUegCn232vmpls68SCM2eRWoo9UOJIa+IzislxvQoVOj+w gJOd1VKwmVphRc6j9myvqe8NlVeFt5bnkQdvw9Vle9qjerlUxkE5ObXH95H178uA a6QrI5REZnRU5ggfQCF9kGqy49O0ealT/+fIvrkawdd8x7Km4/Ua5h1vxzZroW2x J0P8j2+SQC0+ZiVryWAl8BL2ochZBaNdCulYAF+X5Na/ynw+WCZ8ds/dwAoY9M27 DJYvS2odf1RzZ7iOTA5l5QmFOx7r//n4eh9ViYYobB71rGDE0BYPFu+IhDod30wr TopXRBcepDLGgCRaYcmrjmXUCqIKqBqX8tC7dJqMSAQiI59bTwqQtYeb9Z54g5GL XeDYmgpZBmAp5qGgt0BMnglb/qemGvYEzqwXeOwkIe9iZoYTnW8= =ARu2 -----END PGP SIGNATURE----- --9db4GuH0vsB+CvNJ-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2803C433DB for ; Thu, 18 Feb 2021 10:34:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2858060235 for ; Thu, 18 Feb 2021 10:34:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2858060235 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JdnOQKsLJTv1/YXY1iTP/GH7HV82HRVP77tVaGLFKwg=; b=tWwEUgc6Fe/bc4LZQJBgnuImX QGqFqUrFQztheabHN7W/pkUybCufNmeKxQXqi4Jc9xjymBQjITdiO3yN04TtU2VJqXdAYzXDApVHu WiHXCWWC3iEvycMFTlZcMc7X94ENh35JKvPWe8JTkYdbSFPGfiwQn4uv29oKOi8JkwMriTotL8Nmf CnjF6k2bwHy0scYOXUP6/2AiSCy5t5nv868T+jzuIHwGm7LB/A1iqrJti5gJTyNHvfwuuZntLELkm 8K/gxk4xHOzSJ0O3qvvFrdZoB8ZFckyF5iExSuGPBrAUHyFd1/NdEPuaZL7JWuG0DlgEFEoGRNTma W4/p2O7rw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCgbm-000382-Az; Thu, 18 Feb 2021 10:32:30 +0000 Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCgbj-000374-8H for linux-arm-kernel@lists.infradead.org; Thu, 18 Feb 2021 10:32:28 +0000 Received: by mail-qt1-x836.google.com with SMTP id o21so999902qtr.3 for ; Thu, 18 Feb 2021 02:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QBpF/UnYAHGf5ye3tF7er160fB31uR/wphWC4wYVvOY=; b=hdp5dGdccPpZBRsGUZfrcOO1t19DF1z6ve2rfVbio4eLyNcgMasMEDVu1LWtiXlMHU VM/WGerj+KIm+dyw2tbDSldipRhpx4ZHmCIR82MXX57YshOieVIWl6Y2v1+e3TJXu/5H E6SmMEVSpeVRPKGL/tUxgJzuSsM/XmQDDu1ntbEPNNJwTVu62ngo8pBMP/M+Tb19PO0c BJuM9Ev2dclumrqD7SFsm8f8s22/4M1/sH3zT/Zd1UJRPVlBQHRW+f9Y2E4rcruLdqDR rptDH3qeEniByvKgWDgrh442PAu5CmA+yMHL2qAK5ujh+CjH7hVUWH7aBc89sCgpAWPa HJGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QBpF/UnYAHGf5ye3tF7er160fB31uR/wphWC4wYVvOY=; b=nmSaE2RfoD4nH0oswq3JdZeIPXtWZjSbUD4qA2/qiJHB9fbyHcwBbVMU89fAanWwC0 h1r9fcoWUBQl/9UsS3WjLHQzxJiUvn6mzNxV9072qp06h911vaBLQFkgQDcAGMcWYCuE LlNOybSuoFDcPFHU3WqUdY6QqRayXff86jSsf1f+m3M1NNFbiBbqnUtKWarq9DfcS8l2 TtMLwMqqBCmuYAr0nqayrTHneYwSkClHy5ZlO7jzeO7NwFihwBaZrHsWogUuMZGAbpMX iudCPWaY1XSXXsPqea7WFxQ2A1NTcveOpOZV403Sg9HD5y4hBwuMu9CT834jpvzMZjrG XFsA== X-Gm-Message-State: AOAM530/5+zsxlyvRDKBkEldrtD5wV6891RXliIzrn/gRn0T1EnHog6Q iP89J+xFgLTvHSJQoErrECM= X-Google-Smtp-Source: ABdhPJxpeJvOxn5+wkohLMk++QGjYXEV+m6sdsuoygdRkAHpXCY4e6XA3/Ti9BNHd5lPJ3ItEYOTOg== X-Received: by 2002:aed:38e3:: with SMTP id k90mr3438649qte.119.1613644345405; Thu, 18 Feb 2021 02:32:25 -0800 (PST) Received: from shinobu ([193.27.12.132]) by smtp.gmail.com with ESMTPSA id g20sm3090235qtq.35.2021.02.18.02.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 02:32:24 -0800 (PST) Date: Thu, 18 Feb 2021 19:32:16 +0900 From: William Breathitt Gray To: Jonathan Cameron Subject: Re: [PATCH v8 20/22] counter: Implement events_queue_size sysfs attribute Message-ID: References: <013b2b8682ddc3c85038083e6d5567696b6254b3.1613131238.git.vilhelm.gray@gmail.com> <20210214181146.66d43da7@archlinux> MIME-Version: 1.0 In-Reply-To: <20210214181146.66d43da7@archlinux> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210218_053227_346674_ACEBC66E X-CRM114-Status: GOOD ( 32.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, a.fatoum@pengutronix.de, david@lechnology.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, mcoquelin.stm32@gmail.com, linux-kernel@vger.kernel.org, o.rempel@pengutronix.de, kernel@pengutronix.de, fabrice.gasnier@st.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Content-Type: multipart/mixed; boundary="===============2064638801483315365==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============2064638801483315365== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9db4GuH0vsB+CvNJ" Content-Disposition: inline --9db4GuH0vsB+CvNJ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 14, 2021 at 06:11:46PM +0000, Jonathan Cameron wrote: > On Fri, 12 Feb 2021 21:13:44 +0900 > William Breathitt Gray wrote: >=20 > > 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. > >=20 > > 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(+) > >=20 > > diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentatio= n/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. > > =20 > > +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); > > } > > =20 > > +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 =3D kfifo_alloc(&events, queue_size, GFP_ATOMIC); >=20 > Is there any potential for losing events? We take the events_list_lock down below so we're safe against missing an event, but past events currently unread in the queue will be lost. Shortening the size of the queue is inherently a destructive process if we have more events in the current queue than can fit in the new queue. Because we a liable to lose some events in such a case, I think it's best to keep the behavior of this reallocation consistent and have it provide a fresh empty queue every time, as opposed to sometimes dropping events and sometimes not. I also suspect an actual user would be setting the size of their queue to the required amount before they begin watching events, rather than adjusting it sporadically during a live operation. > > + 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 =3D 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); > > =20 > > #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 > > =20 > > +#include "counter-chrdev.h" > > #include "counter-sysfs.h" > > =20 > > /** > > @@ -737,12 +738,30 @@ static int counter_num_counts_read(struct counter= _device *counter, u8 *val) > > return 0; > > } > > =20 > > +static int counter_events_queue_size_read(struct counter_device *count= er, > > + u64 *val) > > +{ > > + *val =3D counter->events.kfifo.mask + 1; >=20 > kfifo_size() rather than open coding it? Ack. William Breathitt Gray > > + return 0; > > +} > > + > > +static int counter_events_queue_size_write(struct counter_device *coun= ter, > > + u64 val) > > +{ > > + return counter_chrdev_realloc_queue(counter, val); > > +} > > + > > static struct counter_comp counter_num_signals_comp =3D > > COUNTER_COMP_DEVICE_U8("num_signals", counter_num_signals_read, NULL); > > =20 > > static struct counter_comp counter_num_counts_comp =3D > > COUNTER_COMP_DEVICE_U8("num_counts", counter_num_counts_read, NULL); > > =20 > > +static struct counter_comp counter_events_queue_size_comp =3D > > + 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_d= evice *const counter, > > if (err < 0) > > return err; > > =20 > > + /* Create num_counts attribute */ > > + err =3D counter_attr_create(dev, group, &counter_events_queue_size_co= mp, > > + scope, NULL); > > + if (err < 0) > > + return err; > > + > > /* Create an attribute for each extension */ > > for (i =3D 0; i < counter->num_ext; i++) { > > ext =3D counter->ext + i; >=20 --9db4GuH0vsB+CvNJ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAmAuQjAACgkQhvpINdm7 VJLb4w//XoS0cfe5nK5uwMVsnyoHPugIaFvxzK5Bm+98z+78pkVC3MPScsWvip1T thzsY6SVy1LnrYkIihPnyFMzs+xwg6B2uyViHdXBjlQyKbEyTBsMUpHJbCsqlJDU I91rt3gP3SKYhg5e+bN0y2jFgXohy/3glP8vMoeWaUh7aJXsjnNUWNdvb4zJzn7A RlnfRvL8q0E7cU/gZ7ra0GgdTyTTTIYzdIGPyf/W9BdJxdZsr8fUStaXDWD+vutF 7TgNBJ0dLnBJotIFe9CUegCn232vmpls68SCM2eRWoo9UOJIa+IzislxvQoVOj+w gJOd1VKwmVphRc6j9myvqe8NlVeFt5bnkQdvw9Vle9qjerlUxkE5ObXH95H178uA a6QrI5REZnRU5ggfQCF9kGqy49O0ealT/+fIvrkawdd8x7Km4/Ua5h1vxzZroW2x J0P8j2+SQC0+ZiVryWAl8BL2ochZBaNdCulYAF+X5Na/ynw+WCZ8ds/dwAoY9M27 DJYvS2odf1RzZ7iOTA5l5QmFOx7r//n4eh9ViYYobB71rGDE0BYPFu+IhDod30wr TopXRBcepDLGgCRaYcmrjmXUCqIKqBqX8tC7dJqMSAQiI59bTwqQtYeb9Z54g5GL XeDYmgpZBmAp5qGgt0BMnglb/qemGvYEzqwXeOwkIe9iZoYTnW8= =ARu2 -----END PGP SIGNATURE----- --9db4GuH0vsB+CvNJ-- --===============2064638801483315365== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============2064638801483315365==--