From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 D14B93793D4 for ; Mon, 4 May 2026 10:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777890864; cv=none; b=QC8CSPV2RFe3z7u0s/boD494HOSzCOQN8QZTgXwcb2ELs8rYlnBqpFww4YAEi44XTNx6D4Hg0TF0C43hwPbug9CparWhpGrCRZV6TAAVPBFrRr9txNtHq07TgGW8BCKtlvHXAKC1AN8aPL975EgD+OhalphKWn6mpwGILEMhdxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777890864; c=relaxed/simple; bh=hglptU7g2QB7mh3FCsH9iFMs6qsEX5uAMiVaW/R0P0A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pChO2ZlXXo3bmp+ZCgG7+iA+TGhLAHc6rPe/kvSb+nG4X3W8RDJh4uI2V9IypL+N4sGOnWMnukjGje64LW8SB75vQrjwp9tsoTazFVT/gzof1JeB4Zg38k+RLeu7qbt4ROOXrqMbhQgcAx+3OIQYxOIeiAoa5qb1ouBoXPpnI9g= 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=hk7YjzWf; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=LdYNic7Y; arc=none smtp.client-ip=205.220.168.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="hk7YjzWf"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="LdYNic7Y" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6448fXNp1219127 for ; Mon, 4 May 2026 10:34: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= jRsOTIc4cMSBxuEr1E3SbSoZgphqegltfvq2CcDf89c=; b=hk7YjzWfRB/eYdH6 CxoU1gblt0JlqmGylHMg3pNpeOGbEXxye2yOXIJCpsY5V85o2Etj92mTyw7cdT2I 1mnDz04iE3T0pl8f9dRoHKy4KKtqj5ChoT752QbHpIjj7ORvdQv2kjqsWSpxfMEi 3QuJoiJlvPaogdqnfQQ2x4Jz8uas88KgS7CVuh/7iXOv5tfH4zChwM+9i7kCacwu HdQOgNTJVRr4Qi6HxyGCZnmJXCFxdxsbgWIpdT2Pe9Ucc+jFpbzKO55Qus7L7vGl npLRU+ftL3AfvdIHtKx37NOR1ECVSZTUng7E/6L912PzXVUqbLxkEgilI5tfhv4f CG7q5w== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dwa1en8ej-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 04 May 2026 10:34:21 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2b4530a90fdso68890685ad.1 for ; Mon, 04 May 2026 03:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777890861; x=1778495661; 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=jRsOTIc4cMSBxuEr1E3SbSoZgphqegltfvq2CcDf89c=; b=LdYNic7YChYYVUYxE1hont0V4ZfV7VXueHw53RH/JWNl497KFpvrOaEEb0AnthtgNM IZ+q30bfsOWy/S/LXabSP0C0xmwa6Swnb27BedUCXuOsDkX/KHAklnNmhUrty/0pjgd/ hwvoC9cdwsQeDC0sOzg/OLF13FNV+i46J35Zqoqsy51DZdCs6SoxtWeKPs59TPkXq6Yk GHKKeT4HeRVYZFdAQdOj1Kp0pdPJx0Xdyhh7mtDoMeob+qX+lHOGg18klq8iycFnHvLX 8BT0C0I6UZ4Us3SoWVRjaFjXCLqshbFqPDawFFfKvPxDrn/+EdOCHqzATWzPy8N/+Igq dO1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777890861; x=1778495661; 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=jRsOTIc4cMSBxuEr1E3SbSoZgphqegltfvq2CcDf89c=; b=o1yhGuF1RGd48a7DanvvaFjBiCmyGmtt8VKdFwodRnLJZldOfRGCwk9DEeS4UUvZJc eLX8vQFlB/OlM/s3F21SaRqOoAL7KEptlp2EpL1DIihVlmcYA1gVgv/kZ5vOX3h3MO9n 7T2ZL9Gm8HH9NyKMCM4Hg5Meg7AXoDnJ5c8RI44kQ/AeJQiuXjchnjhYhKBr/2VvY5NV aNrO3PQ2yiuDp4hUtCO0d2ve9kwQdmRplMBqzxd8TgTzfNqQ3QGe7dpOWRrtl4KAaYKQ Kac4sfDxJeqERQBmXwF+Tx8Tvvmmyneh8NNJvbNgV8/my7WnxE1g1QNfA4EUGyKkpeni XWEQ== X-Forwarded-Encrypted: i=1; AFNElJ+K4tAJNx7roG/46n+9oQW7CUtBbQAaRML9h+aB8f4djBix52hLT9c/rK3ogTXNZNB8jIp4MUauJl1ZqaQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7yEBqYFsqEUMwKCtxX+bYM+3sM9Ow1flrT8LZw4+Gw9ycn8qt 9SHxN8qXEnG70IdFyE8fnukSAI68l4wwqSctERyTDzKvOEN6DP8xu0QB1xoJ4OL3BOYwS7jLciZ ISiOFfKn2eKdE5+1xTwPboDU5e0+Wr1JSPHU8K9bVXpOOCDW+xF2p17iN/PS4r65lVJo= X-Gm-Gg: AeBDieuTj8oY/Lh1qrLmO/pB1BoeCzZEcvTxvGTsUANx9xT3qxncKNkJjhFUz2lZmK5 4bFbQkyvITF74EcKGfGT2f1tPFAKMBZBOJW+55R0Vom/ZJujU2pf85ssLkmHQ+QXewxaIQUlnar NZV/Ke9IYHpsWhZZWtG2lIulhOK3jTdlQ6kqnlh2REnY59h8UdnLv5LQvrwRthRMKfDBoaGhlME np84mpkwN34qZHI7G5EgzGT447+V/4Pg0aXfPScS23KGN3HuTTuueGlF+aumCgOgWV445AbAWOF ck3nvl2fotxwlp3WN/l3FXfW+TYcAxijZngLNJrAIJghkbz1KfL8ESN+ODwchNRvAg6IRcj9PXL uPJzaoyij/U5LEw9VhjfDVZy53s1aXzzrlfxcdRRsx9TKwmeBA8R63ibOyBfQOA== X-Received: by 2002:a17:902:ed0a:b0:2b9:87e0:1f80 with SMTP id d9443c01a7336-2b9f25e667emr65107355ad.24.1777890861297; Mon, 04 May 2026 03:34:21 -0700 (PDT) X-Received: by 2002:a17:902:ed0a:b0:2b9:87e0:1f80 with SMTP id d9443c01a7336-2b9f25e667emr65107105ad.24.1777890860821; Mon, 04 May 2026 03:34:20 -0700 (PDT) Received: from [10.218.50.10] ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9caa8c3f2sm120191565ad.4.2026.05.04.03.34.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2026 03:34:20 -0700 (PDT) Message-ID: <05346f88-4ffe-495a-af0e-ff5e0371c03c@oss.qualcomm.com> Date: Mon, 4 May 2026 16:04:14 +0530 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: Konrad Dybcio , 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> <10c07347-a0df-42d3-b216-5150817b9ed2@oss.qualcomm.com> Content-Language: en-US From: Priyansh Jain In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: yekV2yJsILXtxLt1M04nxrUI_yfm9z5W X-Proofpoint-GUID: yekV2yJsILXtxLt1M04nxrUI_yfm9z5W X-Authority-Analysis: v=2.4 cv=e7U2j6p/ c=1 sm=1 tr=0 ts=69f8762e cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=gIxJPFuM_M9iIqC3imoA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=324X-CrmTo6CU4MGRt3R:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA0MDExMiBTYWx0ZWRfXz122PLVGkdvM UZKePghUf+FrobpQZmuRpDpoRcegYER8lprEdL7WjooMuBA5LKo5eaYnsoOS387uNPZ6oGokBPp eX6QyFY/Y76ZyVcnEzI7n0gSvkBUdEtgc+l8CPUnaoNWskVpgkrBtbhTMj/P4Krd+aHq4qXMkdb 7Hia/Ek5JpJskTvOlsJsM7NprHNMfCxU69CW7zQRN7V1f9xc+JkZVCGxs1xJMVu4HZgqXCWwWrq SJWrOwag0GZ6cdYZDN9ayWeIk2RdJzNrzXaA5c0Tr9SA6zvTw5H/+0SncNI9GTBnhsf1ewZ1cbl 24wZcrOPzuPSNDn3VysgLrU395klcm6O9BGaQyOilDXfBVEQbXUFqjBeQD5KyojKBW+r+yHN8Hi hI+u5IewMl861ASKFrl2yRjvl6OKHEXHuZYAo33stN6md7aFN4DdBmaHWoTw0Ql5vqD/v8Cl5Ni 9zSKO+iKX32ayycwZpQ== 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-05-04_03,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 impostorscore=0 malwarescore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605040112 On 04-05-2026 03:29 pm, Konrad Dybcio wrote: > On 5/4/26 11:42 AM, Priyansh Jain wrote: >> >> On 30-04-2026 09:21 pm, Konrad Dybcio wrote: >>> 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 >>>> --- > > [...] > >>>> @@ -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 >> This change is required to ensure that both the VALID bit and LAST_TEMP >> are read as part of a single transaction, in order to avoid a race condition where >> the VALID bit may already be asserted while the temperature value is still transitioning, >> potentially resulting in an incorrect reading. If needed, I can rename the field from >> LAST_TEMP to something that more clearly reflects a combined representation >> of the temperature value and the VALID bit. >> >> Let me know you thoughts on this. > > Hm, I somehow managed to skip the connection between the two.. > > I think we could retain the current (pretty good) containment of all > register differences between the versions as-is, with something like > this diff: > > - ret = regmap_field_read(priv->rf[field], &status); > + /* Fields within the STATUS register are only valid if read atomically */ > + ret = regmap_read(priv->rf[field].reg, &status); > if (ret) > return ret; > > and then falling back to the prior definitions of the VALID mask etc. Thanks for this feedback , this seems correct approach, i will update as per the suggestion provided Thanks, Priyansh > > Konrad