Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1632770lqp; Mon, 15 Apr 2024 12:03:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXJmsjreErr37h5kbCJ8lfcsA9XLjrirMaSgnA45b5iF7zKTv1XIKcUaHYDbtiirViXYmeurjcalVcmf20ZhoygeMbgAbJjRBBMcmshwQ== X-Google-Smtp-Source: AGHT+IEBZXsCVbe2fyQnTIRuXo9juwJW8VxE/mezXmcdWK3RNED8fPtFb540sQ9TPlCw3o6c29Jl X-Received: by 2002:a05:6102:5127:b0:47a:43a3:977f with SMTP id bm39-20020a056102512700b0047a43a3977fmr10213777vsb.6.1713207815811; Mon, 15 Apr 2024 12:03:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713207815; cv=pass; d=google.com; s=arc-20160816; b=UuUGYlF5JvBsAZqX6jbzOz38VpYmTUjr9y750YCScKMrXACzKAJblUxRCYbfmFGF+h Pe9BYf9y/WarbAOvBMoZ2w3R4eMe3cR02yCZv53K48g6T3lygZ0mHZ7Tq6IHQsrcLnJK VuCKYc/tlKgPbUbxBuwm5k108etV1z9TdN8SISDGD3yAZ3CAJyq2l96qIwFUZJ+hSm8T 6secH6B4fJj/RK1YHFUkGoduH7mgQhE72/gExjyWV0dGr0JnFLdHUU7+6h/bZ3cmXXEt C6WgIDsdYNJpUe2yZTIgmYLeO5uA+R3V/g8VYUHWOF6qa5CoO4mdr/ZOJYn+ZXLu3GF/ G1gg== 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=yAlK3UYr6GL8dLZtb+zPeD8n0mHhUMVmOG3buw2LfsQ=; fh=pZcN3lnDPmzrIpxf+h+NFKrBfIYpRY/C7vEftEJzZns=; b=qvkB38zBTxwCQlci2Ca5ks84wvlUnz5Wb50VyJLzJNFaF62Ud1LhCtkyovUvn7v3xT TecIcJROEgcGMM1EMrt1a0P6bF2UgSKqjIRmJ81SlK9nwhs6T24UkrkY2qCobHtN19RD MDRmkTFNG0lhj/u1nJsqK3foj1lhGlu76QE+MPFp8Gk/vy2znvDpPN9cPRQFAyic8Pve +N9ioHBH870LugKBiE3fB2URU45DkrA4WPdJzGVedCHxujIn+2mrN3q5lo5eIbTX1C1W OasWdmNmMEyg8jWluv1V8WuplRJIjzsjCjFORzYbzVsh5kttfqP5dl1aHowA+UQVcU2v HDKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=Nxf8k2NC; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-145744-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145744-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bm37-20020a056102512500b0047a4797c05dsi1486964vsb.689.2024.04.15.12.03.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 12:03:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145744-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=Nxf8k2NC; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-145744-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145744-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 809351C220F2 for ; Mon, 15 Apr 2024 19:03:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14E60155A59; Mon, 15 Apr 2024 19:03:24 +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="Nxf8k2NC" 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 0BA0B13B78F; Mon, 15 Apr 2024 19:03:20 +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=1713207803; cv=none; b=vAPIaEP78AEZR/fA93CuGyGXLExjvBo5IkVJ4Jc3XTx1QQOxnWu/+VCZDWkxe2vXktNUVM5/olxXozIROZ9I43acYn/ZVFQxeIexla5AwckucXLBwg2A5G2TVuJKWW5q4IUSncuau4uRiJGG6JKkL8aEAsJyM+TFQMWRnvUd2tc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713207803; c=relaxed/simple; bh=R5j1i6fx4eY28IZJTdMlNFW1/w7oGnarF5KekQdrVhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E60K7Gxxl0m4/s0YvSpZrp4/gny6lxx5aOMd7m3MNVOoUaXQwFNhA+SpeNVrBmpGKrDFukDNnxx90vx7EuCqYSohuaTtH3eBZ593WtkgQ/5+P+GaJ3ii6duSFs9OzRU36uSKlB6KhNC7QbnkWkkzmPgQ0xLO5CNq04QEMyVNyY8= 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=Nxf8k2NC 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 a459e9c29f1a53e7; Mon, 15 Apr 2024 21:03:12 +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 5C83D66CF48; Mon, 15 Apr 2024 21:03:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1713207792; bh=R5j1i6fx4eY28IZJTdMlNFW1/w7oGnarF5KekQdrVhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Nxf8k2NCcan69GF2dTpbwl/A9AWr7/Xk04tst6/6igviEAa8f+7qd9+CczqrGq6+8 ZRCD+5ZDwPulOVqfZEaam5nsYO7msSc6CkSJYnEnumXlkqn7OAAJHqNODIpcg6/K8n 6pdV450uZ3TqGl2lxrPDJwdTTlv9SEJfthY+prSNH8gmi7dlADiNtI+WPYxZCa62qH 0QO33YQRNVwR3196zDpRLfnvtcZh8uCX59jiaMWa1PQE8qJ86Au+CqxM3T7u7voGOH 4nbAuMmeNPUNMYDPDDUZXqRO+hhlrHpHWGSggQfeTswTYtkkXMhMui8dFnb+Mfz+/p nUAqiI6pjdXvA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Daniel Lezcano Subject: [PATCH v1 1/2] thermal/debugfs: Add missing count increment to thermal_debug_tz_trip_up() Date: Mon, 15 Apr 2024 21:02:12 +0200 Message-ID: <4912620.31r3eYUQgx@kreacher> In-Reply-To: <12418263.O9o76ZdvQC@kreacher> References: <12418263.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedvledrudejvddgudeffecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeegpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=4 Fuz1=4 Fuz2=4 From: Rafael J. Wysocki The count field in struct trip_stats, representing the number of times the zone temperature was above the trip point, needs to be incremented in thermal_debug_tz_trip_up(), for two reasons. First, if a trip point is crossed on the way up for the first time, thermal_debug_update_temp() called from update_temperature() does not see it because it has not been added to trips_crossed[] array in the thermal zone's struct tz_debugfs object yet. Therefore, when thermal_debug_tz_trip_up() is called after that, the trip point's count value is 0, and the attempt to divide by it during the average temperature computation leads to a divide error which causes the kernel to crash. Setting the count to 1 before the division by incrementing it fixes this problem. Second, if a trip point is crossed on the way up, but it has been crossed on the way up already before, its count value needs to be incremented to make a record of the fact that the zone temperature is above the trip now. Without doing that, if the mitigations applied after crossing the trip cause the zone temperature to drop below its threshold, the count will not be updated for this episode at all and the average temperature in the trip statistics record will be somewhat smaller than it should be. Fixes: 7ef01f228c9f ("thermal/debugfs: Add thermal debugfs information for mitigation episodes") Cc :6.8+ # 6.8+ Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_debugfs.c | 1 + 1 file changed, 1 insertion(+) Index: linux-pm/drivers/thermal/thermal_debugfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_debugfs.c +++ linux-pm/drivers/thermal/thermal_debugfs.c @@ -616,6 +616,7 @@ void thermal_debug_tz_trip_up(struct the tze->trip_stats[trip_id].timestamp = now; tze->trip_stats[trip_id].max = max(tze->trip_stats[trip_id].max, temperature); tze->trip_stats[trip_id].min = min(tze->trip_stats[trip_id].min, temperature); + tze->trip_stats[trip_id].count++; tze->trip_stats[trip_id].avg = tze->trip_stats[trip_id].avg + (temperature - tze->trip_stats[trip_id].avg) / tze->trip_stats[trip_id].count;