linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: invensense: fix interrupt timestamp alignment
@ 2024-04-26 13:58 inv.git-commit
  2024-04-28 11:56 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: inv.git-commit @ 2024-04-26 13:58 UTC (permalink / raw)
  To: jic23; +Cc: lars, linux-iio, stable, Jean-Baptiste Maneyrol

From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>

Restrict interrupt timestamp alignment for not overflowing max/min
period thresholds.

Fixes: 0ecc363ccea7 ("iio: make invensense timestamp module generic")
Cc: stable@vger.kernel.org
Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
---
 drivers/iio/common/inv_sensors/inv_sensors_timestamp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
index 3b0f9598a7c7..4b8ec16240b5 100644
--- a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
+++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
@@ -101,6 +101,9 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts,

 static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
 {
+	const int64_t period_min = ts->min_period * ts->mult;
+	const int64_t period_max = ts->max_period * ts->mult;
+	int64_t add_max, sub_max;
 	int64_t delta, jitter;
 	int64_t adjust;

@@ -108,11 +111,13 @@ static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
 	delta = ts->it.lo - ts->timestamp;

 	/* adjust timestamp while respecting jitter */
+	add_max = period_max - (int64_t)ts->period;
+	sub_max = period_min - (int64_t)ts->period;
 	jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter);
 	if (delta > jitter)
-		adjust = jitter;
+		adjust = add_max;
 	else if (delta < -jitter)
-		adjust = -jitter;
+		adjust = sub_max;
 	else
 		adjust = 0;

--
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: invensense: fix interrupt timestamp alignment
  2024-04-26 13:58 [PATCH] iio: invensense: fix interrupt timestamp alignment inv.git-commit
@ 2024-04-28 11:56 ` Jonathan Cameron
  2024-05-02  8:59   ` Jean-Baptiste Maneyrol
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2024-04-28 11:56 UTC (permalink / raw)
  To: inv.git-commit; +Cc: lars, linux-iio, stable, Jean-Baptiste Maneyrol

On Fri, 26 Apr 2024 13:58:14 +0000
inv.git-commit@tdk.com wrote:

> From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
> 
> Restrict interrupt timestamp alignment for not overflowing max/min
> period thresholds.
> 
> Fixes: 0ecc363ccea7 ("iio: make invensense timestamp module generic")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Hi Jean-Baptiste,

I'll pick this up, but for future similar cases, please make a clear
statement in the patch description on whether this is a theoretical
problem, one found by some tooling, or (the most important bit) something
that actually happens in real usage!

That info helps people decided on how aggressively to backport that change.

Applied to the fixes-togreg branch of iio.git.  Given that has a link
tag to this thread, replying here with the above will make that info
somewhat available.  We are late in cycle, so I may just move this to the
final pull request for the merge window if I don't have many other fixes
queued up.

Thanks,

Jonathan


> ---
>  drivers/iio/common/inv_sensors/inv_sensors_timestamp.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> index 3b0f9598a7c7..4b8ec16240b5 100644
> --- a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> +++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> @@ -101,6 +101,9 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts,
> 
>  static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
>  {
> +	const int64_t period_min = ts->min_period * ts->mult;
> +	const int64_t period_max = ts->max_period * ts->mult;
> +	int64_t add_max, sub_max;
>  	int64_t delta, jitter;
>  	int64_t adjust;
> 
> @@ -108,11 +111,13 @@ static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
>  	delta = ts->it.lo - ts->timestamp;
> 
>  	/* adjust timestamp while respecting jitter */
> +	add_max = period_max - (int64_t)ts->period;
> +	sub_max = period_min - (int64_t)ts->period;
>  	jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter);
>  	if (delta > jitter)
> -		adjust = jitter;
> +		adjust = add_max;
>  	else if (delta < -jitter)
> -		adjust = -jitter;
> +		adjust = sub_max;
>  	else
>  		adjust = 0;
> 
> --
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: invensense: fix interrupt timestamp alignment
  2024-04-28 11:56 ` Jonathan Cameron
@ 2024-05-02  8:59   ` Jean-Baptiste Maneyrol
  0 siblings, 0 replies; 3+ messages in thread
From: Jean-Baptiste Maneyrol @ 2024-05-02  8:59 UTC (permalink / raw)
  To: Jonathan Cameron, INV Git Commit; +Cc: lars, linux-iio, stable

Hello Jonathan,

this is a bug that happens in real usage, especially when using high frequencies or low-end system.

The delta timestamps between 2 samples periodically exceeds the configured jitter when doing interrupt timestamp alignment, while this timestamping method should assure it never happens. This is one of the goals of this timestamping module.

I will make sure to mention that in future patches.

Thanks for the guidance,
JB

________________________________________
From: Jonathan Cameron <jic23@kernel.org>
Sent: Sunday, April 28, 2024 13:56
To: INV Git Commit <INV.git-commit@tdk.com>
Cc: lars@metafoo.de <lars@metafoo.de>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; stable@vger.kernel.org <stable@vger.kernel.org>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>
Subject: Re: [PATCH] iio: invensense: fix interrupt timestamp alignment
 
This Message Is From an External Sender
This message came from outside your organization.
 
On Fri, 26 Apr 2024 13:58:14 +0000
inv.git-commit@tdk.com wrote:

> From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
> 
> Restrict interrupt timestamp alignment for not overflowing max/min
> period thresholds.
> 
> Fixes: 0ecc363ccea7 ("iio: make invensense timestamp module generic")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Hi Jean-Baptiste,

I'll pick this up, but for future similar cases, please make a clear
statement in the patch description on whether this is a theoretical
problem, one found by some tooling, or (the most important bit) something
that actually happens in real usage!

That info helps people decided on how aggressively to backport that change.

Applied to the fixes-togreg branch of iio.git.  Given that has a link
tag to this thread, replying here with the above will make that info
somewhat available.  We are late in cycle, so I may just move this to the
final pull request for the merge window if I don't have many other fixes
queued up.

Thanks,

Jonathan


> ---
>  drivers/iio/common/inv_sensors/inv_sensors_timestamp.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> index 3b0f9598a7c7..4b8ec16240b5 100644
> --- a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> +++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> @@ -101,6 +101,9 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts,
> 
>  static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
>  {
> +	const int64_t period_min = ts->min_period * ts->mult;
> +	const int64_t period_max = ts->max_period * ts->mult;
> +	int64_t add_max, sub_max;
>  	int64_t delta, jitter;
>  	int64_t adjust;
> 
> @@ -108,11 +111,13 @@ static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
>  	delta = ts->it.lo - ts->timestamp;
> 
>  	/* adjust timestamp while respecting jitter */
> +	add_max = period_max - (int64_t)ts->period;
> +	sub_max = period_min - (int64_t)ts->period;
>  	jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter);
>  	if (delta > jitter)
> -		adjust = jitter;
> +		adjust = add_max;
>  	else if (delta < -jitter)
> -		adjust = -jitter;
> +		adjust = sub_max;
>  	else
>  		adjust = 0;
> 
> --
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-02 10:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26 13:58 [PATCH] iio: invensense: fix interrupt timestamp alignment inv.git-commit
2024-04-28 11:56 ` Jonathan Cameron
2024-05-02  8:59   ` Jean-Baptiste Maneyrol

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).