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=1796381630; b=0fC43dSxL6rpURcqAoF1gyJmSsITobvjxmzGPpfbKLYw2NN37e0De6KTMI4+MG5S1yrg I3DneLjtPJvezNmZ91aOX5Z07BuX97EUXLOfCPxxVSSdrxTDG9PTVRS184rNTMu3rZlW2 PD6jzk85iZM2wqPzmlIFSH9vbdlyCw/dtvDXzjvZ+e9eLOBXuK5JvDb2+VAETS3z6mQeh dGBO7Qrb1F1MkKNdAdu7tbIs+iioMDW7YIRQp895xF9rYD77+VTjbfOs7y+dxmVIlEbJF vfxAfQ2rEGEgDvDENAGWBKaqvCtiXiNxP4kdVWJZ5w8YvjA+4IYg4s36Z7WR+Zwr12Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381630; 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=lQTtWAJYCK+q+nuCvLMhWSgozeYDlpX0wiYOnEU+aS8=; b=V5dQlqV5dE89rlMEEhEe5oaP62MMnWgqdKB0rO4eEYo+0x0tERMbUphkrM1ZdLaZdT07 bUwkOHoLXEiwcMuvmo5KJk3AnTrmcdXic3UZnklGg7CTA4sw2Pdnx2WoG3YruaJUCHfiR onV7/ySifRsKH0qkv1B/CSKuEFiuCoa+FwZbkqJXgl4+s291Gj5ZiDgfKm4g+dIBUU5ov sA0lY2LVg45x3+vl/I9G5AHVBKkydJ3n9EfPR7z35SpJtgx4C8yVU4cxwOpW0g3P48gCu na9jRYVwJDPVyAINSIJtR1qxuZQBI3s3p3V8UzwuTirUhF/d8dyFOATXTa9QkERwLcw== 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=Ec8IgabM; 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 6B102606A32C; Fri, 4 Dec 2026 10:53:50 +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=Ec8IgabM Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAA241F0092C; Fri, 4 Dec 2026 10:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381630; bh=lQTtWAJYCK+q+nuCvLMhWSgozeYDlpX0wiYOnEU+aS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ec8IgabMw9kCDojNuX/WAYSJIQIsiHpLJzTRAqZLOTEJ7VOIZoCtovE1N54agKdFL QRM7N9MxfH6Xu8xP1Ys2Pyj8XGogNkXC2YsPqQwlb1IRUOT8iFYzgV6m4CEB6Gda4B P7XfhzKzKAUXll+fiMsr9kg23XgrVHa4QHv4omo4= 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.18 107/703] iio: inv_sensors: better timestamp alignment when using watermark Date: Fri, 4 Dec 2026 19:00:06 +0900 Message-ID: <20261204100630.632239138@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jean-Baptiste Maneyrol [ Upstream commit 8f4b627656fa1767d8337a95849fe7c895b6f68a ] Current interrupt timestamp alignment only changes the final timestamp. When the watermark is in use, we have a batch of samples for each interrupt. The current code doesn't manage to align the timestamp because the jitter is too high. Instead modify the estimated inter interrupt period and use that to adjust the timestamp alignment over the batch in a linear fashion. 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 | 51 +++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c index ecfd54ffe7e92..2aaaa8df6d03b 100644 --- a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c +++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c @@ -10,9 +10,7 @@ #include -/* compute jitter, min and max following jitter in per mille */ -#define INV_SENSORS_TIMESTAMP_JITTER(_val, _jitter) \ - (div_s64((_val) * (_jitter), 1000)) +/* compute min and max following jitter in per mille */ #define INV_SENSORS_TIMESTAMP_MIN(_val, _jitter) \ (((_val) * (1000 - (_jitter))) / 1000) #define INV_SENSORS_TIMESTAMP_MAX(_val, _jitter) \ @@ -102,34 +100,22 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts, /* update chip internal period estimation */ new_chip_period = period / ts->mult; inv_update_acc(&ts->chip_period, new_chip_period); - ts->period = ts->mult * ts->chip_period.val; return true; } -static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts) +static u32 inv_align_timestamp_it(struct inv_sensors_timestamp *ts, + unsigned int sample_nb) { const s64 period_min = (s64)ts->min_period * ts->mult; const s64 period_max = (s64)ts->max_period * ts->mult; - s64 add_max, sub_max; - s64 delta, jitter; - s64 adjust; - - /* delta time between last sample and last interrupt */ - delta = ts->it.lo - ts->timestamp; - - /* adjust timestamp while respecting jitter */ - add_max = period_max - (s64)ts->period; - sub_max = period_min - (s64)ts->period; - jitter = INV_SENSORS_TIMESTAMP_JITTER((s64)ts->period, ts->chip.jitter); - if (delta > jitter) - adjust = add_max; - else if (delta < -jitter) - adjust = sub_max; - else - adjust = 0; + s64 new_period; + + /* compute new period aligning last timestamp with interrupt timestamp */ + new_period = div_s64(ts->it.up - ts->timestamp, sample_nb); - ts->timestamp += adjust; + /* ensure that period never overflows the jitter */ + return clamp(new_period, period_min, period_max); } void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, @@ -143,6 +129,13 @@ void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, if (sample_nb == 0) return; + /* no previous data, compute theoretical value from interrupt */ + if (ts->timestamp == 0) { + /* elapsed time: sensor period * sensor samples number */ + interval = (s64)ts->period * (s64)sample_nb; + ts->timestamp = timestamp - interval; + } + /* update interrupt timestamp and compute chip and sensor periods */ it = &ts->it; it->lo = it->up; @@ -154,17 +147,11 @@ void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, valid = inv_update_chip_period(ts, period); } - /* no previous data, compute theoretical value from interrupt */ - if (ts->timestamp == 0) { - /* elapsed time: sensor period * sensor samples number */ - interval = (s64)ts->period * (s64)sample_nb; - ts->timestamp = it->up - interval; - return; - } - /* if interrupt interval is valid, sync with interrupt timestamp */ if (valid) - inv_align_timestamp_it(ts); + ts->period = inv_align_timestamp_it(ts, sample_nb); + else + ts->period = ts->mult * ts->chip_period.val; } EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_interrupt, "IIO_INV_SENSORS_TIMESTAMP"); -- 2.53.0