From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383332; b=ICNi6jshEVpEcoolbUZheuDwzrq4sY9rQooGZB7xbqNS5MjzOmO5D2fK/GOqUOTJmG5M 9hsm/g0WbWfVMUitfnEjO8mWzglQeq0ofvhzGhn3SScm7vNAawIqDdsisoIRNwfXlihUQ bt5oZ/tDxuCiq/nSyJZTou7jBBRO3RFwW8QRlSdsJCjatg48LjrF+RcFNICbcbd745e/+ eH4ET1L+231Q2REWDA3PDgkbRBZiHbe8mjOthpSmblFrFO7rylzsjrWVNpnh4Fe+/B9zZ OAKGXoY7nh33M2pbBZp0GRqKFHHrIqXRIxlL/x0xHenNoSyFBtizAJnZ/8jxqyR8YOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383332; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=vjm+zdrqERkWuEywJZuB+5ZkIrkQPeTFTLnRD+ho9sg=; b=wKHyUVdgUneFU0ZcFAcw8JAgZyDuVNVNAuukOplzVptD2LQ6fgTeiACct1dJ16V3XDTU PR4COQN3wMNSY9QEMr8orBr3j29L/Lmlr/iAYk/MykX3I1s2gM7yX6No1wVznYQ0gH15n 2TSvysPpLtVi6ksnTMjRB85U9jIxFZWw/mh/rfixCsoYTjv/morUBhRqzwvQkHlxemhE5 f/F4L/qbAuJnegBgMXWyQFNlDvcPxZqyWsd1+9EmFtASWEOVFPLnI21Csj7c5EU5+t0AP YWcGf7QqfwoiXzebUbwxxiXYEkdLtvPei4xZ8nXuqXky2K3+c4C9jbRiDf+lRv6kjLA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=R8zD1F6o; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D9AC606A32D; Fri, 4 Dec 2026 11:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=R8zD1F6o Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCFEF1F000C2; Fri, 4 Dec 2026 11:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383332; bh=vjm+zdrqERkWuEywJZuB+5ZkIrkQPeTFTLnRD+ho9sg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=R8zD1F6oGzDyb3I0LHiAay+lp3dTkIq8myEnLYurIJxoJtYg5Gnk3vS4u195a5oG2 RP6E38SoZiRGHgo24av7WyGXD0tWGWGbX5o+hgDr/X8j++pNwO3xrFm7hWhtjwEVg/ gu8Cj5oLXO3TDli7ei3xUs0rEXJ9A5X0+NwrsuFw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jean-Baptiste Maneyrol , Jonathan Cameron , Sasha Levin Subject: [PATCH 6.12 139/555] iio: inv_sensors: improve period measurement by using a longer delay Date: Fri, 4 Dec 2026 19:03:02 +0900 Message-ID: <20261204100613.023780422@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jean-Baptiste Maneyrol [ Upstream commit 82bd09ce4fd3b15680735eaeafe2e688901e3b00 ] Period measurement can be difficult when using high sampling frequency where the jitter criteria is hard to meet because of the system jitter. This new version is using the delta time between 2 distant interrupts to measure an interval of at least 20ms. 20ms is a good compromise between the mitigation of system jitter and the delay to update period. This way we decorrelate the period measurement from the interrupt timestamps syncing using only the 2 last interrupts. Signed-off-by: Jean-Baptiste Maneyrol Signed-off-by: Jonathan Cameron Stable-dep-of: 3785dffc7c68 ("iio: inv_sensors: prevent timestamps going back in time in transitions") Signed-off-by: Sasha Levin --- .../inv_sensors/inv_sensors_timestamp.c | 26 ++++++++++++++++--- .../linux/iio/common/inv_sensors_timestamp.h | 6 +++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c index 88ad439ac14c6..aacc56d1a2c77 100644 --- a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c +++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c @@ -16,6 +16,9 @@ #define INV_SENSORS_TIMESTAMP_MAX(_val, _jitter) \ (((_val) * (1000 + (_jitter))) / 1000) +/* minimum timestamp delta between 2 interrupts for measuring period (20ms) */ +#define INV_SENSORS_MIN_IT_DELTA (20 * NSEC_PER_MSEC) + /* Add a new value inside an accumulator and update the estimate value */ static void inv_update_acc(struct inv_sensors_timestamp_acc *acc, u32 val) { @@ -122,7 +125,7 @@ void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, size_t sample_nb, s64 timestamp) { struct inv_sensors_timestamp_interval *it; - s64 delta, interval; + s64 delta, delta_threshold, interval; u32 period; bool valid = false; @@ -136,15 +139,32 @@ void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, ts->timestamp = timestamp - interval; } + /* update delta timestamps and estimated period */ + it = &ts->delta; + ts->delta_counter += sample_nb; + delta = timestamp - it->up; + delta_threshold = INV_SENSORS_TIMESTAMP_MIN(INV_SENSORS_MIN_IT_DELTA, ts->chip.jitter); + if (delta >= delta_threshold) { + it->lo = it->up; + it->up = timestamp; + if (it->lo != 0) { + /* compute period: delta time divided by number of samples */ + delta = it->up - it->lo; + period = div_s64(delta, ts->delta_counter); + inv_update_chip_period(ts, period); + } + ts->delta_counter = 0; + } + /* update interrupt timestamp and compute chip and sensor periods */ it = &ts->it; it->lo = it->up; it->up = timestamp; delta = it->up - it->lo; if (it->lo != 0) { - /* compute period: delta time divided by number of samples */ + /* compute period and check validity */ period = div_s64(delta, sample_nb); - valid = inv_update_chip_period(ts, period); + valid = inv_validate_period(ts, period); } /* if interrupt interval is valid, sync with interrupt timestamp */ diff --git a/include/linux/iio/common/inv_sensors_timestamp.h b/include/linux/iio/common/inv_sensors_timestamp.h index e4e720e6f4b72..4f08204ede3b4 100644 --- a/include/linux/iio/common/inv_sensors_timestamp.h +++ b/include/linux/iio/common/inv_sensors_timestamp.h @@ -46,6 +46,8 @@ struct inv_sensors_timestamp_acc { * @min_period: minimal acceptable clock period * @max_period: maximal acceptable clock period * @it: interrupts interval timestamps + * @delta: interval timestamps between several interrupts + * @delta_counter: number of data samples in the delta interval * @timestamp: store last timestamp for computing next data timestamp * @mult: current internal period multiplier * @new_mult: new set internal period multiplier (not yet effective) @@ -57,6 +59,8 @@ struct inv_sensors_timestamp { u32 min_period; u32 max_period; struct inv_sensors_timestamp_interval it; + struct inv_sensors_timestamp_interval delta; + u32 delta_counter; s64 timestamp; u32 mult; u32 new_mult; @@ -88,6 +92,8 @@ static inline void inv_sensors_timestamp_reset(struct inv_sensors_timestamp *ts) const struct inv_sensors_timestamp_interval interval_init = {0LL, 0LL}; ts->it = interval_init; + ts->delta = interval_init; + ts->delta_counter = 0; ts->timestamp = 0; } -- 2.53.0