From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33B79226D18 for ; Sat, 18 Jul 2026 01:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784337265; cv=none; b=JZBchwlMShg6DJs5gbMQ5+LArmXdmSyvp2f0NLi+jmvQA7uMwkek4mBTTsLjE3FWbqQNOIUTBkXQm9KB/5/IHS4+vCbfb8OEXX99jza1iSlZ819G18krohqr9GSc7ouTD+1+JwDfraoKMh6huc0Dfjpnt+6NmgIdYFqvjjSM2iI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784337265; c=relaxed/simple; bh=0NH+un9zhISExEhIXrYUH9GQX5QJuIQSCrpSHBL7Lj4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=geN2ZpVn+QS0NM2lwlwD3cj1n4t6qkx73JJbslSU9QIarrgW6dXe9BCdPqP/nKKiG3VnFpwJ8Uyq6KX0YrMYOkvq6p1crXhZYn0UhHlkKnK0wSXGyuVLprsKgroJe7nY7Il24Qkhj6TxeHVhxJIQDOqjD0qIClqm1Mzvoc4eMXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=lywFv6ZX; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=jBhJTVwL; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="lywFv6ZX"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="jBhJTVwL" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66HNELgr3312511 for ; Sat, 18 Jul 2026 01:14:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= wL2nUpOxP+eB4nzmaV30SUD1ssY2RAbB+Ras+/QA9yo=; b=lywFv6ZXg91Z9uqK weL4ZnKB4zTgCL5ziOo0NLo1YXX2iloYOIC0CZHnlJumi9S4Ld3jEvfT8FModJtz mVggqYXkJEBrA0BGKBdISdk0hOZwCrYWx2ZQItfCO/wJJ5Y92lRipu8Gm2UqNXr/ 8NXUKz3YnZCVjh9nB5IKkt8KBKBrN8X5HcN6k3iw4Z3NhUwK8SGqKEBqAUNm8x5P qjifYqI5kn8cq/TEfrLpkh/blrUkGSZnzQHr43/PaaJFUfC5v0kYWGST5/FOvtVj 3ifkfMyRex6u1v3qHClVFQvx63akUiXlyTxsY2hcDmEqRevAospbCoxLZeCSf/Dp ytQJ8A== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ffhpfk920-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sat, 18 Jul 2026 01:14:21 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2ccb687f82eso122469785ad.3 for ; Fri, 17 Jul 2026 18:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1784337261; x=1784942061; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=wL2nUpOxP+eB4nzmaV30SUD1ssY2RAbB+Ras+/QA9yo=; b=jBhJTVwLxmp1z2ZMrjeCXBHuy07xYB1O2w7F0MfiGkHa9fOQw45S4LjK1i6gDUxSso e14dIaLGoPyEXwmO5dQHw6J4k8Y6N/xl9CuxsykKaKBSSZY4tJVCekA9W8SCdpk70x83 9Xhvlot+lUyXlP28Jy9es9k56LHxrVMBoRs+pnqTnvHFnFKXWNCaTbTojz9+Z8deTwxH Livt9ArVtvNLMmueUD6RWUjIj+ZiLAeFcf8I2n5V/YMh+0jOhG3dUCgke5eYcae7ukYU lsRPjgMWKdHE+Lph3wb7aLefgjJEFCOZk+YQfXHMczLSOka3ufN8FVd3G6xdDvmSBe3V nDag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784337261; x=1784942061; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=wL2nUpOxP+eB4nzmaV30SUD1ssY2RAbB+Ras+/QA9yo=; b=preZNWk+KIXzduTM3XWhRfG6HtNQ11nwWGODrB75Ai11oRPeosci9s3a8I9n/n7WZz ViiJdMxbkPnF5Qyi7BEh2bijRDBDuVLPsEVCiC2bilN2Q5Ej55+UthdD1+8RXBeBVQ5l 8/3+Y6e7lph2hiBS+ynwFgFwIGnr4krCYR/LGy6Ams4k4c1YmS9uv3VTBOR1XyWazDBd kFqr72OgNQUxpV6jeDfka5Ee9151i+qe7A4xiJCgog8/uHITZMHKfLDLImTjm7T0YMM3 2qdhn0Rq7xabaTYUtwLuigavMYgv6T+jfWlnv7TMS0JU6jv6XRKihS31RQgYkPZaPMI8 b1Pw== X-Forwarded-Encrypted: i=1; AHgh+Rrrprt9YGuVrB8aW6bgkFXT4ja1vaxLeJHoyvqh3KU6+2EShTQqJGPfAcQZogrnzADdnmls8b4E13aHGN4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx81gQQYeCgtzBrCBpfvX0pVIiFUHXu7GUgaUEj2jL24FYzhgbT Zdqa/DYt/L8lYtI7pdrkp/ZY7hQx06gyf0u+QKLNbivV0F/HpyCZwPzWdooL+KYZLjloBGKhhWt piNs/WB7m6KfwL/7Ns0W1YhnS+p/7mXVIaFX8dsx8pVmTWBjKn92xZ8zloFvSg1KGp78= X-Gm-Gg: AfdE7cl2lWVs76atDCyICCadHhLw2xECE9TeCVy8d90erGwhshEErg5TkHQha5JmMUD JWKgIJ3EeFb8rxyP7FHKtL+QqODAp7rHnvxOqX85WpjWfH++kEwbrTQ5IS+41JcQVzFI7U2+moo D3+ii1Q6drD9JfLfACzkADrbe2nxioW9LlD4dMFsECeFuacNQp2nfTXmqKTzy/JTclNsHZ/Rzqt ITFGGTaiteNGTztkpRTJVmDE6xL4bwGGFIWr2s58wc3kdRaFsEkuc4C6Yluwgq32lkDJ3RE7WX+ hiy2tOz3iCvnivEo9BS39/d4ah2Bu6VLDX26y69bO8JoNxGJw1w+z9tC8BDcRGwxyEj0sOekta6 kRBwZkBdIKcsRn1QY X-Received: by 2002:a17:902:ccc8:b0:2c9:ae0b:61e3 with SMTP id d9443c01a7336-2cf3484b193mr47502515ad.2.1784337260635; Fri, 17 Jul 2026 18:14:20 -0700 (PDT) X-Received: by 2002:a17:902:ccc8:b0:2c9:ae0b:61e3 with SMTP id d9443c01a7336-2cf3484b193mr47502205ad.2.1784337260111; Fri, 17 Jul 2026 18:14:20 -0700 (PDT) Received: from jic23-huawei ([50.35.46.84]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf344f12e0sm19364325ad.31.2026.07.17.18.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 18:14:19 -0700 (PDT) Date: Sat, 18 Jul 2026 02:14:14 +0100 From: Jonathan Cameron To: Jean-Baptiste Maneyrol via B4 Relay Cc: jean-baptiste.maneyrol@tdk.com, David Lechner , Nuno =?UTF-8?B?U8Oh?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] iio: invensense: better timestamp alignment when using watermark Message-ID: <20260718021401.7e5f54d3@jic23-huawei> In-Reply-To: <20260717-iio-common-inv-sensors-timestamp-rework-v1-1-d1afee2805cd@tdk.com> References: <20260717-iio-common-inv-sensors-timestamp-rework-v1-0-d1afee2805cd@tdk.com> <20260717-iio-common-inv-sensors-timestamp-rework-v1-1-d1afee2805cd@tdk.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzE4MDAwOSBTYWx0ZWRfX/XQaD4D+uVCg uhapffcPnnQhzx18BiE02kmUUqMxmF2WXhWb3UDyzCFKwrL9Kbp6mMwRiRFsfoclvieWT/91xL1 WpJERe2PwKaaZCGxISUz2iqeY4MB9rDgoAUfFXXAtdtN4Ef6Yc6p6C3b9qVNN2rcoDoxVHh1UUs rGGk6W3bQKZyJGHk7DTMVPFLUCtrHUqcfzYDm+F4fnupRNvTAQmrQVdHC/ntRbF4NwnLu2q47un VtwnFjBY4uy2o2eIS7ogaq3HZWipuJBxXkrrmD3yiF6H8jaBUIouH0V4BBZzWm3EReN8NdfwPnb ElR9yW0d5i2xqCnIYNY0Ul/lqq5fgaRMp0Eqa1Kmym6AxsJdcaUm2AjThhC8dtZZ4576YWmKx68 20iqVwDxHx8xolQJN81Vhbqhl0/0zNP05ROM86H0Ok2Ioc/jUnLjj0U4kuTbCJ/TXhbOV1usN2K MvoUg/8NflBUsq/mSSA== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzE4MDAwOSBTYWx0ZWRfX4SmBKUZqVjWU NcmDMikHc/zcBEcxWxGJyF25LC/mvG7y0pkO9xnrerxrzcR0IStXSBaSL64H4ElhsuOea6X4gyb VLW3Xd34PFZfXurlQ4/l6XuTCLCaTNk= X-Authority-Analysis: v=2.4 cv=YeWNIQRf c=1 sm=1 tr=0 ts=6a5ad36d cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=qC1CW/w66vtJz1P9yTJxNA==:17 a=kj9zAlcOel0A:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=VwQbUJbxAAAA:8 a=In8RU02eAAAA:8 a=ZZqDz5lU3Qu-RT7MuEQA:9 a=CjuIK1q_8ugA:10 a=1OuFwYUASf3TG4hYMiVC:22 X-Proofpoint-GUID: PROj6Ifdo6C8xOpVO9kA77uvj8d6Fsjs X-Proofpoint-ORIG-GUID: PROj6Ifdo6C8xOpVO9kA77uvj8d6Fsjs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-17_07,2026-07-17_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 spamscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607180009 On Fri, 17 Jul 2026 14:39:40 +0200 Jean-Baptiste Maneyrol via B4 Relay wrote: > From: Jean-Baptiste Maneyrol > > Current interrupt timestamp alignment only change the next coming > timestamp. For watermark where we have a batch of samples per > interrupt, it doesn't manage to align timestamp since modification > is limited because of jitter. I've read this a few times and I'm not entirely following the meaning. Please rewrite. Intent might be something close to: "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. " I'm not entirely sure however! > > Implement a better version that instead modify the period to align > to interrupt timestamp. Period is now computed by align timestamp > if interrupt interval is valid, or we use the computed estimation. > > Signed-off-by: Jean-Baptiste Maneyrol > --- > .../iio/common/inv_sensors/inv_sensors_timestamp.c | 55 ++++++++-------------- > 1 file changed, 20 insertions(+), 35 deletions(-) > > diff --git a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c > index e0b10366ed2b..2c89e0edc87d 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 uint32_t inv_align_timestamp_it(struct inv_sensors_timestamp *ts, > + unsigned int sample_nb) > { > - const int64_t period_min = (int64_t)ts->min_period * ts->mult; > - const int64_t period_max = (int64_t)ts->max_period * ts->mult; > - int64_t add_max, sub_max; > - int64_t delta, jitter; > - int64_t adjust; > - > - /* delta time between last sample and last interrupt */ > - 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 = add_max; > - else if (delta < -jitter) > - adjust = sub_max; > - else > - adjust = 0; > + const uint64_t period_min = (uint64_t)ts->min_period * ts->mult; > + const uint64_t period_max = (uint64_t)ts->max_period * ts->mult; > + uint32_t new_period; > > - ts->timestamp += adjust; > + /* compute new period aligning last timestamp with interrupt timestamp */ > + new_period = div_s64(ts->it.up - ts->timestamp, sample_nb); > + > + /* 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 = (int64_t)ts->period * (int64_t)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,9 @@ 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 = (int64_t)ts->period * (int64_t)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 = valid ? inv_align_timestamp_it(ts, sample_nb) : > + ts->mult * ts->chip_period.val; > } > EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_interrupt, "IIO_INV_SENSORS_TIMESTAMP"); > >