Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp534327lqo; Fri, 10 May 2024 07:21:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhAU4l1QH5zg5Q+NyauKZeNB2Lhi9NozGZs143Y6+m7EyqwVZERxQoTs/CkQ+6cxsxfcE0s8fxH+tUve6gkA4bpY37vvY9r/P1M8EP/g== X-Google-Smtp-Source: AGHT+IGAfOMElJ+vgH9VY21GAb8MsyB3XqZbEgDCprrLqET6CFcHv7G0DPfF8dEiuGgEWjzCT7G4 X-Received: by 2002:a05:6214:4903:b0:6a0:e5cd:a66a with SMTP id 6a1803df08f44-6a16798b72cmr45268566d6.24.1715350905394; Fri, 10 May 2024 07:21:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715350905; cv=pass; d=google.com; s=arc-20160816; b=SfZX9lIAxv2pKmtZy0uxUdFHh7Nb83/BjOkfC3DOJ9OI3qCGrWgY0cKw77HRWOF8P9 OyyUNiZ8LUKc4XpVwTq1/MjkvY6dPfLT83fpPRDfWNaF5b7W9Wb7cJngLnGiGF4MgKSe zvOtdPEYCEj3yen61+JKVqUBl4/KJHzPKnU3Dt6lI3XnWOPlqz9oLGbObmeUHmFjV5W1 WY5rio1BdKnDyqJmVGgcaC1uZ1/S7m/Eh3TVSRGhPjTbQnBRXxqIWaNwkKMoaLr5s5XM +yel00eDmxVoQ85yLAtlewYFEBk8BTdVx6ED0kPNxIGy0SYc3qG2J/ih8MiTiRo4ausu jC8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ITfhYxewN4ymvglr8xKZMHNjyqb5FslvVJqICtKSa5Q=; fh=GzCkp9dboMjnsRASvUnR8RkBPyyMxU6lLzxcgnbmqi0=; b=MDFq+YtiBiHhleTyTEp0aYzqjYnUSACDFfsLNCUITJ6zqBsEbydpyDM9r5+a3XwsxO BX7fzOr4CvrO5fjitJPattYwmxhw278pmLzPR1XgzvSRDFNGF5tK0thx14dMXCWeMnsb IqRGYmJudcHzy1xElxpcnciP/AR1iuJXTt8E6ZvpOP0umS1/BDLNN7HcWwIntb3+MXS+ 4WO3e4KgQOyJfSk+OVwVdft5zBIWKPekBS1Qk4bRSSleUxdZ/pnaSlStnYDiHjHvkn8y iahg9Jv2NKRk2o4TUHRGUleTGxgAscCscGYA4ApQI+UU8MzxQleKLyN61Yynn67+mtWn tPZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=gJs39LlX; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-175888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175888-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43dfaac5929si25253821cf.575.2024.05.10.07.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 07:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=gJs39LlX; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-175888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175888-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 245F51C21ACE for ; Fri, 10 May 2024 14:21:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AF91171E48; Fri, 10 May 2024 14:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="gJs39LlX" Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (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 9F70A170843; Fri, 10 May 2024 14:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715350846; cv=none; b=dtuHku4COO9nU8lPvPxY8S0seMceA4taunjToJlzVEG31oKv0I40Uuzzuvqv3pydzwVphE+L8TwL78bff1P/3zncxjLDkQLN3o++/lwOkdMA/djS/sfokLzUYnR+443GkP4ieWX12Bb8SvmcflGbo6JHWheIlMbL8dJD1vu665c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715350846; c=relaxed/simple; bh=RsE8cY+fp2GsTqdqdSmy9XchkKlPuwqpX3nJ/Sby/c0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jBqDkCdnPXEx5IL+U/5bHBJd/WtaejgKv8motTRKlU4Yncm8ToWPVP9GwDWJ+7RUmNi/eQJ4UOvA2BhuNgPp7PP/n/+KXqkdAbpnSgAWsej3EAdhXs3T4sJsSLQW/lpkMZyylIZXC/snz4JEf/pwoGSaljDE5LybVpkT9NyswGk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=gJs39LlX reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.0.0) id c0c6590cd904fc47; Fri, 10 May 2024 16:20:42 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 2AC5C2102F3F; Fri, 10 May 2024 16:20:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1715350842; bh=RsE8cY+fp2GsTqdqdSmy9XchkKlPuwqpX3nJ/Sby/c0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gJs39LlX+gm5mot3VuKjk7JtsjYE7kKdUs3E/eX8Azo6uadQsN3/O6fT27anfIy57 NwJzpf5BqcuI/nYFGsiVv2JdM7KORjjekgdYcvjpksUAtDwOYfloIsbHtyAi9fOIyu HI6/XSgCqJeCPA7gnWR7PNy2LtTNv3KMSBkv9DdOpHV6fzggSwA3nceMOZcJBS0w5M QQf7PC5IRM0y8oJW0ajQ1w7CtgsnK25PtEP7ps60qVmV+tyAKw8YLEgnMbzYXqF/2D udalKxaoUugRQPDQC/hxVz1bVGHIzbM4VziUWxjjK5s8+SMPRvo87cGsrRyyJWpK7T vib2FzKSGb7og== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v1 1/6] thermal: sysfs: Trigger zone temperature updates on sysfs reads Date: Fri, 10 May 2024 16:13:31 +0200 Message-ID: <3304112.44csPzL39Z@kreacher> In-Reply-To: <13518388.uLZWGnKmhe@kreacher> References: <13518388.uLZWGnKmhe@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgjeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgviigt rghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 From: Rafael J. Wysocki Reading the zone temperature via sysfs causes the driver callback to be invoked, but it does not cause the thermal zone object to be updated. This is problematic if the zone temperature read via sysfs differs from the temperature value stored in the thermal zone object as it may cause the kernel and user space to act against each other in some cases. For this reason, make temp_show() trigger a zone temperature update if the temperature returned by thermal_zone_get_temp() is different from the temperature value stored in the thermal zone object. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_core.c | 2 +- drivers/thermal/thermal_sysfs.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -42,6 +42,9 @@ temp_show(struct device *dev, struct dev if (ret) return ret; + if (temperature != READ_ONCE(tz->temperature)) + thermal_zone_device_update(tz, THERMAL_EVENT_TEMP_SAMPLE); + return sprintf(buf, "%d\n", temperature); } Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -429,7 +429,7 @@ static void update_temperature(struct th } tz->last_temperature = tz->temperature; - tz->temperature = temp; + WRITE_ONCE(tz->temperature, temp); trace_thermal_temperature(tz);