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 D3A0FC433DB for ; Fri, 26 Feb 2021 00:05:42 +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 84EF064F1A for ; Fri, 26 Feb 2021 00:05:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84EF064F1A 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=oFWFX3flO5VBhXaryce/r2lk9PyU1/QkwbwA06c2maU=; b=OBiCjvtRtu8c0yAKOU5TXt7Ga KLm+wlHEeC+NmAvZxBbJ0EzSrb7prjqL25l4BmKnVHhZx3yc3SiePPZYoPcXN2z1eWDpPmwSxniXB 54Ee8fZ6ThmCNsUWqJByKHyD4cXKQB6cqzji4HULkeMtOR6TpjrFspPPOOwE45fRzYu7YWt8vi6bg 2n3ZD5F9cjLI2RGCUuQOjrC9WhvGeo/C69StIktK/2ZbQAqPDS7xK2MWIi7FQ9ZiuFOhdkn+fanTQ gZjLewm9Bgs/vZjUG/9kc+4y+3677bTKQFga1zKmIGXnBrp8IN0UIwKoiUWjBqKygXJfQ3GepPrE9 Py73cnbNw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFQc0-0006BU-5I; Fri, 26 Feb 2021 00:04:04 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFQbw-0006Av-31 for linux-arm-kernel@lists.infradead.org; Fri, 26 Feb 2021 00:04:01 +0000 Received: by mail-pf1-x436.google.com with SMTP id l7so571920pfd.3 for ; Thu, 25 Feb 2021 16:03:59 -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=6xnb86RhPkQovrbj87oZceQLnvq33XU1nv/cjwf3XRI=; b=DrisM3vA7nmsgSAqf45LxyW9UBp3YtQu+vV1WkifsIIv2wfd27mahTLSXUhGQqV8+K 5RV9E9FIopEmwr1/v7ECuDr94o02uI+7bfAbnxjrgDE/nFvGiamir5Cqv3+ElwV8AHRM N1m58ZzinCQ9L5faX9r+B4X0vkG8IzMOt2KJSxK2u5b7vb+EeS3blgIePawlve4ok82B cz5rkhtvRUmMMUxiKjtus32eUZjnvUOaPN0m45XrNDZ7A8tli04CPo4RjT9dK+dFt2Iz 9hlhiaiMmYx1nc51OCVmegDB0dGGAZMqxaw60qoY87nqWqfWZHQzEL0JX7MYS6z7dQBt lpSg== 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=6xnb86RhPkQovrbj87oZceQLnvq33XU1nv/cjwf3XRI=; b=escqEKgu/R4FfxCc/19VPAai32knlIA2oiX9vGTtFVvVy2FHtaRcD6eTbkxl3lVS5s HzjYGPhtpOjRSXGcgbtejdye86JyS72tvaILDGZSeJNNEGUtXY6oYFz3nRmgc5nvFHxV OT0po5CrJXY/Su+oYEbPlgAbgvb9txr6AeEWMvWC6OVlzjAnsg1KGFAIykETcMKRO02H lmM1TKoD3jSZ4DYZ1rKrNLpVMZCAQ+LMEMD5GB85cEQ4DuFkz+g6fWSDd/hwu10WxS3p 72ivYG66EWbrqRQz7YzC7p3N5XL5QmfZEACHUt4B9HvT8rD698eS+vZTs/rN36DyxYh+ e82g== X-Gm-Message-State: AOAM532SGH/mf0MW06jFTpb5IiAhmt7s8IspV3n+93JnaB8tRNi6NVkJ tZRz34UQa782P5h05SFYByg= X-Google-Smtp-Source: ABdhPJyZR4ptosE9/NEaiXfthCao0Ri2ZmlqXid10F65SCpm3hmdwAM1dqRgjqlvxTmVJyK0f7qWJQ== X-Received: by 2002:aa7:9595:0:b029:1ee:8:2b76 with SMTP id z21-20020aa795950000b02901ee00082b76mr224566pfj.57.1614297837209; Thu, 25 Feb 2021 16:03:57 -0800 (PST) Received: from shinobu (113x37x72x20.ap113.ftth.ucom.ne.jp. [113.37.72.20]) by smtp.gmail.com with ESMTPSA id a19sm6965305pff.186.2021.02.25.16.03.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 16:03:56 -0800 (PST) Date: Fri, 26 Feb 2021 09:03:48 +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> <20210221155140.3e1ef13c@archlinux> MIME-Version: 1.0 In-Reply-To: <20210221155140.3e1ef13c@archlinux> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210225_190400_261556_158C6FCD X-CRM114-Status: GOOD ( 33.49 ) 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="===============2286577986109462660==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============2286577986109462660== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="76Dn/TuCDFUTSoIf" Content-Disposition: inline --76Dn/TuCDFUTSoIf Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 21, 2021 at 03:51:40PM +0000, Jonathan Cameron wrote: > On Thu, 18 Feb 2021 19:32:16 +0900 > William Breathitt Gray wrote: >=20 > > 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 round= ed-up > > > > to a power of 2 due to a requirement of the kfifo_alloc function ca= lled > > > > 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/Document= ation/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/cou= nter-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_devi= ce *const counter) > > > > cdev_del(&counter->chrdev); > > > > } > > > > =20 > > > > +int counter_chrdev_realloc_queue(struct counter_device *const coun= ter, > > > > + 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 > > >=20 > > > Is there any potential for losing events? =20 > >=20 > > 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. > >=20 > > 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. > >=20 > > 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. > > >=20 > Absolutely agree. As such I wonder if you are better off enforcing this > behaviour? If the cdev is open for reading, don't allow the fifo to be > resized.=20 >=20 > Jonathan I can't really think of a good reason not to, so let's enforce it: if the cdev is open, then we'll return an EINVAL if the user attempts to resize the queue. What is a good way to check for this condition? Should I just call kref_read() and see if it's greater than 1? For example, in counter_chrdev_realloc_queue(): if (kref_read(&counter->dev.kobj.kref) > 1) return -EINVAL; William Breathitt Gray --76Dn/TuCDFUTSoIf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAmA4OswACgkQhvpINdm7 VJI4LBAApcdc9OT2tNICqKgjdL9fnN1UvMR4Mymto4r9OKzes/KKt7jFjbmqsaPU IpFVtpG2apdrK7LcCnvxnSAxCwOIkM1r0TOUQjiiWKggpibCOJCXcI1UWu6FTxtX 3FcYUZZMmjFWvijm0LG3I/7UEo+wf3BcatoYSEERpok3IiPhzag+bG1WQhoirpbK 3UdOHyRkYN8kyU4pfFK+T6A2pHO09fFmSJJB2oQ9d90avrJikMkBGQp6/qpIvhPM gMxbYwDxuSG7zCqkIU/GW22VvwhehfGQaoc5u/WlCks271YWPNcMyq94479EM7q7 SP5STZczS/Jxc5Wq5HHuFsCQaSGTJ6uFIqjey88gjlkyvJ+Vzznj6OfBBRFFPPPe KL8UUXk7E9AM17u+Zoj8xV3NnBKixWTKcUnazPsM7QZSPH3fvLmdUbODFhU20gkf yYLSMZgxvkZSe3jHwaQn92MRCMPgqK2vDUIGVnvAYi+nmPQ/ly4VHwcpRi0iS2Pd p95tFoo2gD8vCwoUm4qm/h+n3WYbQZ44D53fUSAR4yQfdntmCueSFKQ1Cty/03uL BVDbwQs+GfKzPttZoChC2I4oNAyjnqrS861Q0Uz5Go1aqFE5GvfJluSrmsIYNf0u XiuOzzN/i9NOBe4GaeCeaaVQAznfbfat6Ym4nuXMOu4sV5twIJg= =vTG+ -----END PGP SIGNATURE----- --76Dn/TuCDFUTSoIf-- --===============2286577986109462660== 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 --===============2286577986109462660==--