[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <cc1c347a-3363-c563-de81-06dbb464a29d@lechnology.com>
Date: Sat, 27 Jun 2020 14:20:52 -0500
From: David Lechner <david@...hnology.com>
To: William Breathitt Gray <vilhelm.gray@...il.com>
Cc: jic23@...nel.org, kamel.bouhara@...tlin.com, gwendal@...omium.org,
alexandre.belloni@...tlin.com, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-stm32@...md-mailman.stormreply.com,
linux-arm-kernel@...ts.infradead.org, syednwaris@...il.com,
patrick.havelange@...ensium.com, fabrice.gasnier@...com,
mcoquelin.stm32@...il.com, alexandre.torgue@...com
Subject: Re: [PATCH v3 3/4] counter: Add character device interface
On 6/27/20 1:17 PM, William Breathitt Gray wrote:
> On Mon, Jun 22, 2020 at 09:08:48AM -0500, David Lechner wrote:
>> On 6/21/20 2:53 PM, William Breathitt Gray wrote:
>>> For example, in the dual-axes positioning table scenario, a user
>>> application would likely want to know the exact X and Y position at the
>>> time of a given event -- that means an event should provide two Count
>>> values (and possibly associated device flags) when it occurs. I'm not
>>> sure yet how the struct counter_event should be defined in order to
>>> support this; we will need to indicate the format of data as well as
>>> provide the data itself. Perhaps, we can handle this by providing an
>>> unique id field so that only a single datum (e.g. a single count value)
>>> is provided via the value field, but subsequent struct counter_event
>>> items share the same id so that the user knows that a particular datum
>>> is part of a larger group of data for a specific event.
>>
>> The timestamp could act as the "id" to correlate multiple values of a
>> single event.
>
> Okay, I see how that can work. So the /dev/counterX character nodes
> would return a stream of data structures that look something like this:
>
> struct counter_event {
> /**
> * Best approximation of when event occurred in nanoseconds.
> * Same timestamp value indicates data is part of same event.
> */
> struct timeval time;
> /**
> * Type of event that triggered. This would correlate with the
> * IRQ set up for the device.
> */
> __u16 type;
> /**
> * Type of data represented by the value member. This enables
> * the user to extract the right datatype from the value field.
> */
> __u16 code;
> /** The value recorded when the event fired. */
> __u64 value;
> };
>
> In fact, this data structure looks a lot like struct input_event; would
> it make sense to use that for this? I suppose we can't because we need
> to support 64-bit value for our use cases.
Yes, since counter is its own subsystem, it makes sense to have its own
data types.
>
> Userspace also requires a way to enable the events and configure them to
> report the data it wants. So perhaps the following sysfs attributes
> would accomplish such:
>
> * /sys/bus/devices/counterX/eventY_enable:
> Users can enable/disable event Y.
> * /sys/bus/devices/counterX/eventY_config:
> Data to get when event Y is triggered (e.g. Counts, extensions, etc.).
This is one of the questions I had too that I don't have a good answer to.
If we want to allow the use case of multiple "consumers" for a single
chardev where each consumer wants different events (e.g program X opens
/dev/counter0 and wants only events A and B while program Y opens the
same /dev/counter0 and wants only events A and C) then it would make
sense to use an ioctl for configuration of events so that each open
file descriptor could be configured differently.
But if we only want to allow one user of a counter, then configuring
via sysfs as you have suggested is probably fine.
I think I might make sense to us an ioctl in any case though if we are
going to use the same code values to configure the event.
>
> Here's another concern for latency-sensitive applications: should we
> handle writing data to the devices? While we have real-life examples of
> latency-sensitive read operations, I'm not sure if a user will ever need
> to write to a counter device within some realtime critical deadline --
> I think write operations are primarily done for the purpose of
> configuring the device for operation rather than during it. So perhaps
> we don't need to worry about this use case because users can write data
> via the existing sysfs interface.
Agreed.
Powered by blists - more mailing lists