Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1454368pxb; Mon, 22 Feb 2021 02:16:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAbjtVnQV29DCInMSWx6YmuOHxGGMqH4T/s3tRUt1ALtyeR+IcpGVwhgu0i6KO9toKmL85 X-Received: by 2002:a05:6402:5112:: with SMTP id m18mr21966601edd.129.1613988961105; Mon, 22 Feb 2021 02:16:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613988961; cv=none; d=google.com; s=arc-20160816; b=CK76xkf2VA7PGudzA/QA6RbgHqBelfkBzEgsUM+MuWvE2rQZTGkePQcIOJXv7Y2iLx ELZSO7e7uR0/AsRPav9DGD15uBZnDZu8t65BNJlu3nB1JZtp0A20gJ8m13xOkontZ+fj xDYpDXqrrr/ml4oBqmkPJI1Af3mFH939tpmxZ4UwyxBjTAMRTB43/pMgEOFTNG0HeSZk f8uzBPtUl9w42PRtAMQwqHbf2eLxHzoHTLmLPSxj6GyPvtuU0ayfPa0/Vu0zPJZSzptg 3VBXnTJlao86EQaYkih/Q+IdnYvF+LdmHybh06mzv4Ft4zijEgqR8tNVUkH482g37wBW z7UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ojk4G/YkLUKbuaO2bw9GFjIQU3CkP7UCRkDgwvXCg94=; b=S5szmWNIZNECgIaMciyJCTnOOSuZeHjkDhBsJA33LlnYzNBltGLgfbD1Uz7cWzY43y p0YJ3k3pDbTTzY7avpqkp1EdMVcpk6t7O9q8PtWcl1o5uF73JpRUBQr4oJTmJKqT61yg K0l/NFJiPdnNsnMEE8oheo2ZeeH0oObUbHUEKD/WGPaBylH5oOB2SfdvkYChr/WZvvWD olEdCQXuxajEJ/f956GvXwRWaKiuKjXSLJBwqy3E4gUBvqZG813rYhO6BKfxxiK3wOtq 29aODcJtf7X80vTx7p5gqBxOhB/Rf9BggD5bIxCUTk4qCM2du1G0BFqM0IaSmJ2YaWeK 2ilA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lz10si2620828ejb.402.2021.02.22.02.15.38; Mon, 22 Feb 2021 02:16:01 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230470AbhBVKOO (ORCPT + 99 others); Mon, 22 Feb 2021 05:14:14 -0500 Received: from jabberwock.ucw.cz ([46.255.230.98]:56712 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbhBVKMS (ORCPT ); Mon, 22 Feb 2021 05:12:18 -0500 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 8B3741C0B7F; Mon, 22 Feb 2021 11:11:34 +0100 (CET) Date: Mon, 22 Feb 2021 11:11:33 +0100 From: Pavel Machek To: Jonathan Cameron Cc: William Breathitt Gray , 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 18/22] docs: counter: Document character device interface Message-ID: <20210222101133.GB14587@amd> References: <350cafba81d3220b64efdb019bd76c08eb1e5d10.1613131238.git.vilhelm.gray@gmail.com> <20210214174819.6757e2b0@archlinux> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="MfFXiAuoTsnnDAfZ" Content-Disposition: inline In-Reply-To: <20210214174819.6757e2b0@archlinux> User-Agent: Mutt/1.5.23 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --MfFXiAuoTsnnDAfZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > > +* COUNTER_ENABLE_EVENTS_IOCTL: > > + Enables monitoring the events specified by the Counter watches that > > + were queued by ``COUNTER_ADD_WATCH_IOCTL``. If events are already > > + enabled, the new set of watches replaces the old one. Calling this > > + ioctl also has the effect of clearing the queue of watches added by > > + ``COUNTER_ADD_WATCH_IOCTL``. > > + > > +* COUNTER_DISABLE_EVENTS_IOCTL: > > + Stops monitoring the previously enabled events. >=20 > Is there a way to remove a watch?=20 Is there a way to eat all kernel memory and crash the system by adding too many watches? > > +For example, the following userspace code opens ``/dev/counter0``, > > +configures the ``COUNTER_EVENT_INDEX`` event channel 0 to gather Count= 0 > > +and Count 1, and prints out the data as it becomes available on the > > +character device node:: > > + >=20 > Consider adding an example program under tools/ >=20 > > + #include > > + #include > > + #include > > + #include > > + #include > > + #include > > + > > + struct counter_watch watches[2] =3D { > > + { > > + .component.type =3D COUNTER_COMPONENT_COUNT, > > + .component.scope =3D COUNTER_SCOPE_COUNT, > > + .component.parent =3D 0, >=20 > Good to add comments on what these elements actually are? > > + fd =3D open("/dev/counter0", O_RDWR); > > + > > + ioctl(fd, COUNTER_ADD_WATCH_IOCTL, watches); > > + ioctl(fd, COUNTER_ADD_WATCH_IOCTL, watches + 1); > > + ioctl(fd, COUNTER_ENABLE_EVENTS_IOCTL); > > + for (;;) { > > + read(fd, event_data, sizeof(event_data)); If this goes to tools it really should have error handling and handling of short read. Best regards, Pavel --=20 http://www.livejournal.com/~pavelmachek --MfFXiAuoTsnnDAfZ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAmAzg1UACgkQMOfwapXb+vJsaACffCOe28RqjxELfyTkP8K3Wy+h SeYAn26EGcT9n9wUACiesQqsPDqCDl31 =ku3H -----END PGP SIGNATURE----- --MfFXiAuoTsnnDAfZ--