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 701E844CAEA for ; Thu, 30 Apr 2026 15:51:14 +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=1777564275; cv=none; b=L5dMMZWRdP/yGpdsWCZv9QrjBVthXO/34WVSZ0fDdOg2X65toJkGJUPB6jTMGCmxPdL0BDTRRBvmh727Dn5GXkpw9wczcWbbnOYqyYL4mXPLMbnhe/vQQHQ+XDkoK47iJX3/p5kNjKh3Tqruyo9MUzEaGxI9p9IbjAn71KNrTk4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777564275; c=relaxed/simple; bh=3hQgKR0g5jfMrI+q77PgcAXwQDpxg6YjEW9egm9jAd8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YLlaWT0RUh/27k6kHs2NlKaegIAgjGE86/yvCJi4OBGH+a2yb7kUl6ztzP0KuYCoH9jihY28/NCS92ebORh8FRFMsZd+iIXCsHdmgasB2rk53EugHB1KUXOTgLWjsErS/xEz6OnqiPjxccLzWnHaQd29XDIlbXWk89FeDhb/qyw= 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=ZILPw7ZS; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=QuX8stYg; 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="ZILPw7ZS"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="QuX8stYg" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63UF0qCv810269 for ; Thu, 30 Apr 2026 15:51:13 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= PMY7fcF21Ezzzra23e7CLhxBaPs0P38IfMIcVh77jDI=; b=ZILPw7ZSkEal2Lau PG3ItfOQ6FrZe6KI4aoAyJKHDctxT8wrythccjAenJ/r0qDWpK+uI6v8iI79jQlC NzgQhK9k0KSIzOc++fIS2+MG3szrQbjeUucTtUHt00k84NLj+2d2HAf1RkXi6xzI JGpG9MmH9nGcLqCu0/4Lob0pJxNcFrNib00GXvMFK1wP3oIyfg9lFaa+sJxkqQJ1 uMuu7xAkmJUK7XlkKnI8+c7HeafafrW3bxKJwPccd+5M98GiP92tquiksXFXQY+i 8fP33S8uUPRT84dCPT6VDy+wBiJiKuVmBuvP8ulcsu8fgLCqAq7mHgQ0u5h8reEK m+x7sQ== Received: from mail-vs1-f69.google.com (mail-vs1-f69.google.com [209.85.217.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4duv3q3mdf-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 30 Apr 2026 15:51:13 +0000 (GMT) Received: by mail-vs1-f69.google.com with SMTP id ada2fe7eead31-6055c46b2c8so90723137.0 for ; Thu, 30 Apr 2026 08:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777564273; x=1778169073; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=PMY7fcF21Ezzzra23e7CLhxBaPs0P38IfMIcVh77jDI=; b=QuX8stYg/SO6qFdiZVNGIMgPh/ua+OmBAIXUvHGRsGGyHzTwaonS5Ea1SV2nrVN8D9 vOEkjUSggUFpwPIkkfTUQO6wXMotL3JVx0UOZNgGKZHxlq00tgwp5G5vsNZZu8UrI28j KPwSqXTVz4GJnFHdjhK7HvKU3OIvFCaN4CsMwS4tWbUaUwocEND84VUK1xg9y2tNe+iu lCfw7oLQZ6XrhMfHkBnCgf3eH3aMScRQ9mS1kXenK57V144r7jki3ksbiJOUb4i+pVRk UPN900u50WFoWHBIvWw5Z11PQHrdbc+LCqbHAor9tI40fRTxZeGRIAf781svyaeJTv7K ca0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777564273; x=1778169073; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PMY7fcF21Ezzzra23e7CLhxBaPs0P38IfMIcVh77jDI=; b=ZMKU73GZ8PLFS13R/2L84wjwWXAde0Z02IApjh0Z/W7S4akiGsyWHwdL28SKyCs2xl ZoecEWgQdgq3yLApcZ20WdRgkSST6Brm7tpbyqNiKdazqC7WInng9GQ26SSVw/HOggFK NQg4hfqSwPTEgLoUcqUc+IJhsHuv9qPer4/tmnqoUwATkZd1Q0zP6fDoHoipit4IMIph tuSEgZA9JluLP7nqF96ep2hV0uLKWN9lgJp/FlQCkVHygqpB47EyR/xIjnyds7KEggW2 x4IZBlFpYsktCLllZCLsCJ7ZjrVam2Yo18m3T6V0v+x7eJ4Ur/fs+t6UpDt/+l28fWA+ UZag== X-Forwarded-Encrypted: i=1; AFNElJ+EwQwTOmnidrlWla8bM6htkuvyIo8VzS+/Q6RVZ6oXWrksviN046QTF9fiXQ7DtfxPww68UJFHoLpZVQM=@vger.kernel.org X-Gm-Message-State: AOJu0Yypoqaya6DMl/KJbiinTXgLZfq4kFd2b9jfSb/GS12I55Cu4506 xbVxXLiQCWGE4ABJ9oBc03W/6xs2A2Xq7bKvqOepii8epliw/zUwfpbpc/LhZp9zGG5ANpDc05b AcHAjnFPF8rlRMgQYKyPKCcLqiB7MskmwrHG7WHV+jtdd2BNe36QSyyRGEab3gwAg/LA= X-Gm-Gg: AeBDietEQBgrtFM+t6RPixTgtxsW5F/JNh/0FBR68557X4lQkMyrU03Rj7KX0JVjnFT nzsp7wKoeDergAeGb7ZeHwiJYpBD6t5BAna3nyP9Ev3H9BRVktyJwrEh/yTsG+Nu2x/semrocfr ueHDYJkEVlvDhHeAgLbRG9bJwqhUgiLVEj4XMXMIi9Qm/OL+CFAzae56C4C/Vvkm8GrK8tNRoNK yLWBsGi8WGfy1sTGvSeJhssAGYztcY3RT73OPfUBBfL6kcgAgXAV9wAeB9L4tPFWPzWvkP5pmgm TLjR9nG7fwcUnn1mDOPleKyyspqzj3SwPvzYsMxAQxc4IUsx/X7e+e3pLAAdvwimN3OpVPHw9hG pG3/n1RBDy8Oth92hV6Eb9UVth1ND1kL1axk4QZu4BOtwo9rnU/SqcW9f3Wf6C0cxmdY46RUXQx LE22FAUQoBnPERcg== X-Received: by 2002:a05:6102:4a17:b0:606:2f5:7b49 with SMTP id ada2fe7eead31-62ad6327779mr749684137.7.1777564272683; Thu, 30 Apr 2026 08:51:12 -0700 (PDT) X-Received: by 2002:a05:6102:4a17:b0:606:2f5:7b49 with SMTP id ada2fe7eead31-62ad6327779mr749669137.7.1777564272198; Thu, 30 Apr 2026 08:51:12 -0700 (PDT) Received: from [192.168.119.254] (078088045245.garwolin.vectranet.pl. [78.88.45.245]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-bbe6d977b7esm12941866b.48.2026.04.30.08.51.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Apr 2026 08:51:11 -0700 (PDT) Message-ID: Date: Thu, 30 Apr 2026 17:51:09 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] thermal: qcom: tsens: atomic temperature read with hardware-guided retries To: Priyansh Jain , Amit Kucheria , Thara Gopinath , "Rafael J . Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, manaf.pallikunhi@oss.qualcomm.com References: <20260430054422.2461150-1-priyansh.jain@oss.qualcomm.com> <20260430054422.2461150-2-priyansh.jain@oss.qualcomm.com> Content-Language: en-US From: Konrad Dybcio In-Reply-To: <20260430054422.2461150-2-priyansh.jain@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: jU18BdP-0srZM2P1kxj3yD8hEhKmA64r X-Authority-Analysis: v=2.4 cv=dOyWXuZb c=1 sm=1 tr=0 ts=69f37a71 cx=c_pps a=5HAIKLe1ejAbszaTRHs9Ug==:117 a=FpWmc02/iXfjRdCD7H54yg==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=CBS10BAP3JayAQFiZAsA:9 a=QEXdDO2ut3YA:10 a=gYDTvv6II1OnSo0itH1n:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDMwMDE2NCBTYWx0ZWRfX4fNx8s3SnGNy dzxbYK4uSKGeeIKP3pbeiBW30ZFQkS2xtxp9ashxtAspu65UpKFHnXaxa1g9g8P6yAKeTujjDGx PKN0QjPR/FM8JSde8YF8CLgKE4pEmNnZ4lxf7Q4bYzafsanJE494vfBioQwsLRjQ84aOp/SEH3X EoZjfIsJ8P0tqXWUnrX9NIgJAfq1eYDdMo0RcKhRegPd+7zcSxt85+qI0QT411SyHGRNY+efySW +TY2LmaxDcvyC6xNYL/sZNzZfISTTRfigJldcNtcnyKSCyKX2QgvfHyzfxBpUQQF3mcll45JDHL X83FNytfwfsxkkYa2MZNU0y6e9R8bLurrPczyiHgv+WtE0u+/iIrpBO3p/hYmWvSTjlRI/hV+T0 U28KyFWP7VJzAnB0larMJI3ExFs5kYsDAhGBUZc3bDsiQ7O489PnILfHv3al/UULn1qf9D7Fam/ +GYH5tULL0nzhlS9/LA== X-Proofpoint-ORIG-GUID: jU18BdP-0srZM2P1kxj3yD8hEhKmA64r X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-30_04,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 adultscore=0 spamscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 phishscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604300164 On 4/30/26 7:44 AM, Priyansh Jain wrote: > The existing TSENS temperature read logic polls the valid bit and then > reads the temperature register. When temperature reads are triggered > at very short intervals, this can race with hardware updates and allow > the temperature field to be read while it is still being updated. > > In this case, the valid bit may already be asserted even though the > temperature value is transitioning, resulting in an incorrect reading. > > Hardware programming guidelines require the temperature value and the > valid bit to be sampled atomically in the same read transaction. A > reading is considered valid only if the valid bit is observed set in > that same sample. > > The guidelines further specify that software should attempt the > temperature read up to three times to account for transient update > windows. If none of the attempts observe a valid sample, a stable > fallback value must be returned: if the first and second samples match, > the second value is returned; otherwise, if the second and third > samples match, the third value is returned. > > Update the TSENS sensor read logic to implement atomic sampling along > with the recommended retry-and-compare fallback behavior. This removes > the race window and ensures deterministic temperature values in > accordance with hardware requirements. > > Signed-off-by: Priyansh Jain > --- [...] > static struct tsens_features tsens_v1_no_rpm_feat = { This struct also needs the same adjustment [...] > static struct tsens_features ipq8074_feat = { And other structs in tsens-v2.c, but.. > @@ -125,8 +128,7 @@ static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = { > [WDOG_BARK_COUNT] = REG_FIELD(TM_WDOG_LOG_OFF, 0, 7), > > /* Sn_STATUS */ > - REG_FIELD_FOR_EACH_SENSOR16(LAST_TEMP, TM_Sn_STATUS_OFF, 0, 11), > - REG_FIELD_FOR_EACH_SENSOR16(VALID, TM_Sn_STATUS_OFF, 21, 21), > + REG_FIELD_FOR_EACH_SENSOR16(LAST_TEMP, TM_Sn_STATUS_OFF, 0, 21), ..this change feels rather odd - the existing regfields seem like a good place to handle this register map difference [...] > +static int tsens_read_temp(const struct tsens_sensor *s, int field, int *temp) > +{ > + struct tsens_priv *priv = s->priv; > + int temp_val[3] = {0}; > + unsigned int status = 0; > + int ret = 0, i; > + int max_retry = 3; > + > + ret = regmap_field_read(priv->rf[field], &status); > + if (ret) > + return ret; > + > + /* VER_0 doesn't have VALID bit */ > + if (tsens_version(priv) == VER_0) { Then, we can check for if (!priv->rf[field]) instead of checking the ver explicitly Konrad