Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp53334lqo; Thu, 9 May 2024 12:19:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVeGlvAOxmzvBSwtCxTexOVXkFhogOrHkUsWyaVF3lPYsOwwLm8V5nYS3n5MlVWoEyJyQxG5ejeVFuhNTAsDXuTB2edBXxZxmgrvLRCTw== X-Google-Smtp-Source: AGHT+IFOl6+QMNKG47CI07GA0xBgDAUFmGgztVMWB6mhcATK7L2tlihjwAOFJT7LUKLRsypSkbDJ X-Received: by 2002:a9d:6d95:0:b0:6f0:7f8a:af06 with SMTP id 46e09a7af769-6f0e914a090mr559678a34.17.1715282376095; Thu, 09 May 2024 12:19:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715282376; cv=pass; d=google.com; s=arc-20160816; b=b3jS/oNfirWQeqZKbUGxWCHOhgXyVZtmRcmjt5v3azbZO6Azkq9WtsMwPwZYyaNiUe lD2ylhN4BB2kpLE4GeR6Dhd6DieEvpS83rLfswmoU9FaoGEA5tAOo0PojiDO9l4+OGq7 Z3Pk8cSyUiV2PNoabtMrD64GUyJuUoOEg9FskGQFad0XXKfV8RBhugfnBNOy2KOdB4Ba TWaLElo8mPZnZTe+BotGcxlC91c1HtGcz84JCfiT1iPyj4NjNaAvjuzAmsGdGczOeV8F tPr4bukmJz6CU+rElIXNLFhD0tBmcLla1H5AGy3NemkqYe/iOy6MQsj86IWyV1tbhhXp BQ/Q== 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=r2S1NpXotkwt8Bp4mcOUbysIbj75Z2Dc1X7wG8Qk03k=; fh=HP39+yda0QHsXMT3XaLy3KM419Yj59UqEZWQZo+gOsI=; b=wuhHvSQQUOK9PHuQO+0FbN/NT+qvwM19L+PRaO3wSXIP0tZ3c53bGTRUPBIfLYFXZl 0nZCRx42XaeA+Nrae/7n5eNIbChjna+UyWgjS4O7tULhF2f0w/O+iLOgV12fe7K2H0cE Eme1HQ6bjugOSKmD8pL7LeEHxjSarm/hhv/wEbWbzsHLqm81XlEGKBaWqJU/HT1kreJY SuKgU3fIMthVAktO7RZyjt7Yw5+kUf+RjRgRQeQQyBIc9oPSodIzaFLyOToYRDDUe9tq BHl7F7fL6F0lEb6MKQERdDFFw3HdYhnLP0CjgbXJc3+/O0rtUNh6pq+1D0r9decnoMcT 1QZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=qfSfNs0k; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-174814-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174814-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 af79cd13be357-792bf38f083si178534085a.776.2024.05.09.12.19.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 12:19:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174814-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=qfSfNs0k; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-174814-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174814-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 BCB4E1C21ADA for ; Thu, 9 May 2024 19:19:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 742D685952; Thu, 9 May 2024 19:17:56 +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="qfSfNs0k" 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 DE43380604; Thu, 9 May 2024 19:17:52 +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=1715282275; cv=none; b=T+kTv2vZZKOAXa5AZTZdhwawiJDiGosslYuxR042T8hvn3dyEd4NeayWPdm3qsejsr8oOpfK4lhjaVSt68wWGckpvAgfveI5HS9o0yswsaBLWoT5Y4yMhY30Ky23qKMEgKPTtponQHFwp2t6rqDfIvdxhhNMjfMdGElS7TvAqmg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715282275; c=relaxed/simple; bh=gyTf0mMiLoT/1Ze1j88d+hcLga2cI0BYwKUz0zqJIdI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GP8kkvLTMMqq5RAsBd8Dr0BJkag2DWkOwK8be4H1OZfrQ0Nk9AQ3GTnCx+DwTwIATyAdmiEsW6OMsCEsDs0zrLo3c4V8/ZdpIBnBnr4lois9c07ba8KmgCJftgPdgIMsWXDq0FbmK44DQ7IjDK8S5eViaP5HBFj1ggtTr68P11s= 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=qfSfNs0k 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 efbe846cf3d5481b; Thu, 9 May 2024 21:17:45 +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 B788DA524E7; Thu, 9 May 2024 21:17:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1715282265; bh=gyTf0mMiLoT/1Ze1j88d+hcLga2cI0BYwKUz0zqJIdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qfSfNs0kJ+GuMqFx7Vq9boJKfTRyZq7Kvd1D6hssL4ZdzOoxKho+/ruYcjrUDYRo/ T14R+V6qrJ6O29ZyXbPkRUMadInZTMb3INLT4C+awyvx212R/WyYrBkhzRn+sp7/bZ t9Ne+9/JhA2If6jUxuFl3DrPy+My/5tVeQ15Xs/l70YzVzhn1bmEz8Fs/d/vW80rvO zic7JGRxY7vSOQ5n6aCgI7W/1exN0rJUHl94vXxkiG+SpwHrSETWVYKYhCb6caR7fv TYA3TkT2KRWJt1JKGMyKK0QI4LiVQf5bBzHtvgdOEWId4QPOl5m4sgeb/4cSApASc5 z+wFKhmOoQf2A== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano Subject: [PATCH v1 2/7] thermal/debugfs: Do not extend mitigation episodes beyond system resume Date: Thu, 09 May 2024 21:12:01 +0200 Message-ID: <2330375.ElGaqSPkdT@kreacher> In-Reply-To: <12438864.O9o76ZdvQC@kreacher> References: <12438864.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: gggruggvucftvghtrhhoucdtuddrgedvledrvdefvddgudefvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgii tggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 From: Rafael J. Wysocki Because thermal zone handling by the thermal core is started from scratch during resume from system-wide suspend, prevent the debug code from extending mitigation episodes beyond that point by ending the mitigation episode currently in progress, if any, for each thermal zone. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_core.c | 1 + drivers/thermal/thermal_debugfs.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/thermal/thermal_debugfs.h | 2 ++ 3 files changed, 39 insertions(+) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1619,6 +1619,7 @@ static void thermal_zone_device_resume(s tz->suspended = false; + thermal_debug_tz_resume(tz); thermal_zone_device_init(tz); __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); Index: linux-pm/drivers/thermal/thermal_debugfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_debugfs.c +++ linux-pm/drivers/thermal/thermal_debugfs.c @@ -922,3 +922,39 @@ void thermal_debug_tz_remove(struct ther thermal_debugfs_remove_id(thermal_dbg); kfree(trips_crossed); } + +void thermal_debug_tz_resume(struct thermal_zone_device *tz) +{ + struct thermal_debugfs *thermal_dbg = tz->debugfs; + ktime_t now = ktime_get(); + struct tz_debugfs *tz_dbg; + struct tz_episode *tze; + int i; + + if (!thermal_dbg) + return; + + mutex_lock(&thermal_dbg->lock); + + tz_dbg = &thermal_dbg->tz_dbg; + + if (!tz_dbg->nr_trips) + goto out; + + /* + * A mitigation episode was in progress before the preceding system + * suspend transition, so close it because the zone handling is starting + * over from scratch. + */ + tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node); + + for (i = 0; i < tz_dbg->nr_trips; i++) + tz_episode_close_trip(tze, tz_dbg->trips_crossed[i], now); + + tze->duration = ktime_sub(now, tze->timestamp); + + tz_dbg->nr_trips = 0; + +out: + mutex_unlock(&thermal_dbg->lock); +} Index: linux-pm/drivers/thermal/thermal_debugfs.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_debugfs.h +++ linux-pm/drivers/thermal/thermal_debugfs.h @@ -7,6 +7,7 @@ void thermal_debug_cdev_remove(struct th void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev, int state); void thermal_debug_tz_add(struct thermal_zone_device *tz); void thermal_debug_tz_remove(struct thermal_zone_device *tz); +void thermal_debug_tz_resume(struct thermal_zone_device *tz); void thermal_debug_tz_trip_up(struct thermal_zone_device *tz, const struct thermal_trip *trip); void thermal_debug_tz_trip_down(struct thermal_zone_device *tz, @@ -20,6 +21,7 @@ static inline void thermal_debug_cdev_st int state) {} static inline void thermal_debug_tz_add(struct thermal_zone_device *tz) {} static inline void thermal_debug_tz_remove(struct thermal_zone_device *tz) {} +static inline void thermal_debug_tz_resume(struct thermal_zone_device *tz) {} static inline void thermal_debug_tz_trip_up(struct thermal_zone_device *tz, const struct thermal_trip *trip) {}; static inline void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,