From: William Breathitt Gray <wbg@kernel.org>
To: "Csókás Bence" <csokas.bence@prolan.hu>
Cc: linux-iio@vger.kernel.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
linux-arm-kernel@lists.infradead.org, timestamp@lists.linux.dev,
Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Dipen Patel <dipenp@nvidia.com>,
dlechner@baylibre.com
Subject: Re: [Q] Frequency & duty cycle measurement?
Date: Wed, 5 Feb 2025 08:37:30 +0900 [thread overview]
Message-ID: <Z6KkusvLFPcNvEfl@ishi> (raw)
In-Reply-To: <dffc0f18-799a-4fc7-a6b5-2fa270e1fc58@prolan.hu>
[-- Attachment #1: Type: text/plain, Size: 3751 bytes --]
On Thu, Jan 30, 2025 at 02:59:20PM +0100, Csókás Bence wrote:
> Hi William,
>
> On 2025. 01. 27. 16:00, William Breathitt Gray wrote:
> > If RA and RB are provided as a memory buffer on your device, you can
> > instead expose them via DEFINE_COUNTER_ARRAY_CAPTURE() such as the
> > ti-ecap-capture driver does, then perform your userspace computations
> > by utilizing those respective "capture" array attribute values (via
> > chrdev like the example above or alternatively via sysfs).
>
> Thanks for your extensive explanation! With DEFINE_COUNTER_ARRAY_CAPTURE() I
> was able to expose RA and RB as
> `/sys/bus/counter/devices/counter0/count0/capture{0,1}`, and could verify
> that by replacing `devmem` calls with read()-reopen(), our PoC code still
> works. Now I want to use the chardev interface, but I couldn't find how to
> set up the watches appropriately. So far I have:
>
> {
> .component.type = COUNTER_COMPONENT_EXTENSION,
> // also tried COUNTER_COMPONENT_COUNT
> .component.scope = COUNTER_SCOPE_COUNT,
> .component.parent = 0,
> .component.id = X, // also tried this instead:
> // .channel = X,
> .event = COUNTER_EVENT_CAPTURE,
> },
>
> However, with this, the first read() never comes back.
>
> Bence
Hi Bence,
Are you still having trouble with this? Is "X" the
capture{0,1}_component_id value?
I apologize, the Generic Counter character device interface is
underdocumented so it can be a bit confusing at first; I'll submit a
patch improving the documentation later this cycle when I get a chance.
For now, let's walk through how to create an appropriate Counter watch
for the capture extension components you have.
The first step is to decide which event we'll monitor and on which
channel: we want to monitor Capture events so that's
COUNTER_EVENT_CAPTURE, and we want event channel 0 (n.b. 0 because
that's the channel parameter value passed to counter_push_event() in the
driver).
The next step is to choose the components you wish to watch: Count 0's
capture0 and capture1 extensions. So type is COUNTER_COMPONENT_EXTENSION
because we want to watch extensions, scope is COUNTER_SCOPE_COUNT
because we want Count extensions, and parent is 0 because we want
Count 0's Count extensions.
Finally, we need to set the component id for each extension. You get a
particular component's id by reading the respective *_component_id sysfs
attribute: so for capture{0,1} you would read capture{0,1}_component_id
respectively. These component id values potentially can change with
future driver updates, so for robustness your userspace application
should read the respective *_component_id sysfs attribute itself rather
than hardcoding the component id in the Counter watch.
However, for the sake of simplicity in this example, I'll assume the
component ids are 42 and 43 respectively for capture0 and capture1. That
gives us the following two watches:
{
.component.type = COUNTER_COMPONENT_EXTENSION,
.component.scope = COUNTER_SCOPE_COUNT,
.component.parent = 0,
.component.id = 42,
.event = COUNTER_EVENT_CAPTURE,
.channel = 0,
},
{
.component.type = COUNTER_COMPONENT_EXTENSION,
.component.scope = COUNTER_SCOPE_COUNT,
.component.parent = 0,
.component.id = 43,
.event = COUNTER_EVENT_CAPTURE,
.channel = 0,
},
Does this resolve your chardev read issue? If you're still having
troubling, just let me know and we can troubleshoot further to figure
out what's going on.
William Breathitt Gray
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-02-04 23:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 15:19 [Q] Frequency & duty cycle measurement? Csókás Bence
2025-01-21 17:45 ` David Lechner
2025-01-27 15:00 ` William Breathitt Gray
2025-01-30 13:59 ` Csókás Bence
2025-02-04 23:37 ` William Breathitt Gray [this message]
2025-02-05 9:30 ` Csókás Bence
2025-02-05 9:58 ` Csókás Bence
2025-02-19 22:32 ` Dipen Patel
2025-02-26 13:56 ` Csókás Bence
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z6KkusvLFPcNvEfl@ishi \
--to=wbg@kernel.org \
--cc=csokas.bence@prolan.hu \
--cc=daniel.lezcano@linaro.org \
--cc=dipenp@nvidia.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=timestamp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).