All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: William Breathitt Gray <vilhelm.gray@gmail.com>, jic23@kernel.org
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,
	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
Subject: Re: [PATCH v6 0/5] Introduce the Counter character device interface
Date: Sun, 13 Dec 2020 17:15:14 -0600	[thread overview]
Message-ID: <6f0d78ae-9724-f67f-f133-a1148a5f1688@lechnology.com> (raw)
In-Reply-To: <cover.1606075915.git.vilhelm.gray@gmail.com>

On 11/22/20 2:29 PM, William Breathitt Gray wrote:
> 
> 1. Should standard Counter component data types be defined as u8 or u32?
> 
>     Many standard Counter component types such COUNTER_COMP_SIGNAL_LEVEL
>     have standard values defined (e.g. COUNTER_SIGNAL_LEVEL_LOW and
>     COUNTER_SIGNAL_LEVEL_HIGH). These values are currently handled by the
>     Counter subsystem code as u8 data types.
> 
>     If u32 is used for these values instead, C enum structures could be
>     used by driver authors to implicitly cast these values via the driver
>     callback parameters.
> 
>     This question is primarily addressed to David Lechner. I'm somewhat
>     confused about how this setup would look in device drivers. I've gone
>     ahead and refactored the code to support u32 enums, and pushed it to
>     a separate branch on my repository called counter_chrdev_v6_u32_enum:
>     https://gitlab.com/vilhelmgray/iio/-/tree/counter_chrdev_v6_u32_enum
> 
>     Please check it out and let me know what you think. Is this the
>     support you had in mind? I'm curious to see an example of how would
>     your driver callback functions would look in this case. If everything
>     works out fine, then I'll submit this branch as v7 of this patchset.

I haven't had time to look at this in depth, but just superficially looking
at it, it is mostly there. The driver callback would just use the enum type
in place of u32. For example:

static int ti_eqep_function_write(struct counter_device *counter,
				  struct counter_count *count,
				  enum counter_function function)

and the COUNTER_FUNCTION_* constants would be defined as:

enum counter_function {
	COUNTER_FUNCTION_INCREASE,
	...
};

instead of using #define macros.

One advantage I see to using u8, at least in the user API data structures,
is that it increases the number of events that fit in the kfifo buffer by
a significant factor.

And that is not to say that we couldn't do both: have the user API structs
use u8 for enum values and still use u32/strong enum types internally in
the callback functions.



> 
> 2. How should we handle "raw" timestamps?
> 
>     Ahmad Fatoum brought up the possibility of returning "raw" timestamps
>     similar to what the network stack offers (see the network stack
>     SOF_TIMESTAMPING_{RAW,SYS}_HARDWARE support).
> 
>     I'm not very familiar with the networking stack code, but if I
>     understand correctly the SOF_TIMESTAMPING_RAW_HARDWARE timestamps are
>     values returned from the device. If so, I suspect we would be able to
>     support these "raw" timestamps by defining them as Counter Extensions
>     and returning them in struct counter_event elements similar to the
>     other Extension values.

Is nanosecond resolution good enough? In the TI eQEP driver I considered
returning the raw timer value, but quickly realized that it would not be
very nice to expect the user code to know the clock rate of the timer. It
was very easy to get the clock rate in the kernel and just convert the
timer value to nanoseconds before returning it to userspace.

So if there is some specialized case where it can be solved no other way
besides using raw timestamps, then sure, include it. Otherwise I think we
should stick with nanoseconds for time values when possible.

WARNING: multiple messages have this Message-ID (diff)
From: David Lechner <david@lechnology.com>
To: William Breathitt Gray <vilhelm.gray@gmail.com>, jic23@kernel.org
Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org,
	a.fatoum@pengutronix.de, mcoquelin.stm32@gmail.com,
	linux-iio@vger.kernel.org, patrick.havelange@essensium.com,
	alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org,
	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
Subject: Re: [PATCH v6 0/5] Introduce the Counter character device interface
Date: Sun, 13 Dec 2020 17:15:14 -0600	[thread overview]
Message-ID: <6f0d78ae-9724-f67f-f133-a1148a5f1688@lechnology.com> (raw)
In-Reply-To: <cover.1606075915.git.vilhelm.gray@gmail.com>

On 11/22/20 2:29 PM, William Breathitt Gray wrote:
> 
> 1. Should standard Counter component data types be defined as u8 or u32?
> 
>     Many standard Counter component types such COUNTER_COMP_SIGNAL_LEVEL
>     have standard values defined (e.g. COUNTER_SIGNAL_LEVEL_LOW and
>     COUNTER_SIGNAL_LEVEL_HIGH). These values are currently handled by the
>     Counter subsystem code as u8 data types.
> 
>     If u32 is used for these values instead, C enum structures could be
>     used by driver authors to implicitly cast these values via the driver
>     callback parameters.
> 
>     This question is primarily addressed to David Lechner. I'm somewhat
>     confused about how this setup would look in device drivers. I've gone
>     ahead and refactored the code to support u32 enums, and pushed it to
>     a separate branch on my repository called counter_chrdev_v6_u32_enum:
>     https://gitlab.com/vilhelmgray/iio/-/tree/counter_chrdev_v6_u32_enum
> 
>     Please check it out and let me know what you think. Is this the
>     support you had in mind? I'm curious to see an example of how would
>     your driver callback functions would look in this case. If everything
>     works out fine, then I'll submit this branch as v7 of this patchset.

I haven't had time to look at this in depth, but just superficially looking
at it, it is mostly there. The driver callback would just use the enum type
in place of u32. For example:

static int ti_eqep_function_write(struct counter_device *counter,
				  struct counter_count *count,
				  enum counter_function function)

and the COUNTER_FUNCTION_* constants would be defined as:

enum counter_function {
	COUNTER_FUNCTION_INCREASE,
	...
};

instead of using #define macros.

One advantage I see to using u8, at least in the user API data structures,
is that it increases the number of events that fit in the kfifo buffer by
a significant factor.

And that is not to say that we couldn't do both: have the user API structs
use u8 for enum values and still use u32/strong enum types internally in
the callback functions.



> 
> 2. How should we handle "raw" timestamps?
> 
>     Ahmad Fatoum brought up the possibility of returning "raw" timestamps
>     similar to what the network stack offers (see the network stack
>     SOF_TIMESTAMPING_{RAW,SYS}_HARDWARE support).
> 
>     I'm not very familiar with the networking stack code, but if I
>     understand correctly the SOF_TIMESTAMPING_RAW_HARDWARE timestamps are
>     values returned from the device. If so, I suspect we would be able to
>     support these "raw" timestamps by defining them as Counter Extensions
>     and returning them in struct counter_event elements similar to the
>     other Extension values.

Is nanosecond resolution good enough? In the TI eQEP driver I considered
returning the raw timer value, but quickly realized that it would not be
very nice to expect the user code to know the clock rate of the timer. It
was very easy to get the clock rate in the kernel and just convert the
timer value to nanoseconds before returning it to userspace.

So if there is some specialized case where it can be solved no other way
besides using raw timestamps, then sure, include it. Otherwise I think we
should stick with nanoseconds for time values when possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-12-13 23:17 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-22 20:29 [PATCH v6 0/5] Introduce the Counter character device interface William Breathitt Gray
2020-11-22 20:29 ` William Breathitt Gray
2020-11-22 20:29 ` [PATCH v6 1/5] counter: Internalize sysfs interface code William Breathitt Gray
2020-11-22 23:57   ` kernel test robot
2020-11-24 20:55   ` kernel test robot
2020-11-25 13:02     ` William Breathitt Gray
2020-11-25 13:07   ` William Breathitt Gray
2020-11-25 13:07     ` William Breathitt Gray
2020-12-13 23:15   ` David Lechner
2020-12-13 23:15     ` David Lechner
2020-12-20 22:11     ` William Breathitt Gray
2020-12-20 22:11       ` William Breathitt Gray
2020-12-21 15:26       ` David Lechner
2020-12-21 15:26         ` David Lechner
2020-11-22 20:29 ` [PATCH v6 2/5] docs: counter: Update to reflect sysfs internalization William Breathitt Gray
2020-11-22 20:29   ` William Breathitt Gray
2020-11-22 20:29 ` [PATCH v6 3/5] counter: Add character device interface William Breathitt Gray
2020-11-22 20:29   ` William Breathitt Gray
2020-12-13 23:58   ` David Lechner
2020-12-13 23:58     ` David Lechner
2020-12-25 17:30     ` William Breathitt Gray
2020-12-25 17:30       ` William Breathitt Gray
2021-01-19  9:20   ` Oleksij Rempel
2021-01-19  9:20     ` Oleksij Rempel
2021-01-21  8:03     ` William Breathitt Gray
2021-01-21  8:03       ` William Breathitt Gray
2021-01-21 18:26       ` Jonathan Cameron
2021-01-21 18:26         ` Jonathan Cameron
2020-11-22 20:29 ` [PATCH v6 4/5] docs: counter: Document " William Breathitt Gray
2020-11-22 20:29   ` William Breathitt Gray
2020-11-22 20:29 ` [PATCH v6 5/5] counter: 104-quad-8: Add IRQ support for the ACCES 104-QUAD-8 William Breathitt Gray
2020-11-22 20:29   ` William Breathitt Gray
2020-12-13 23:15 ` David Lechner [this message]
2020-12-13 23:15   ` [PATCH v6 0/5] Introduce the Counter character device interface David Lechner
2020-12-20 21:44   ` William Breathitt Gray
2020-12-20 21:44     ` William Breathitt Gray
2020-12-21 15:19     ` David Lechner
2020-12-21 15:19       ` David Lechner

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=6f0d78ae-9724-f67f-f133-a1148a5f1688@lechnology.com \
    --to=david@lechnology.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandre.torgue@st.com \
    --cc=fabrice.gasnier@st.com \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=kamel.bouhara@bootlin.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=patrick.havelange@essensium.com \
    --cc=syednwaris@gmail.com \
    --cc=vilhelm.gray@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.