Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp28380lqb; Tue, 28 May 2024 08:03:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXiJWB29WcMCS7q/4eMUM74Af0Rz5X8GINeN0gjOgcVnuuo29GPWUvQHSPrnPDraPjNWXiDkqeF3nXU53dXspYJ+yv6SRnFA6NllQ7T4w== X-Google-Smtp-Source: AGHT+IFDRqsDt9nRTCt5EKNZe47yyUPw2mBrkgg0sLnffcqBijnDzmyosJ/dxlDDTnSEMWrjSNf2 X-Received: by 2002:a67:c913:0:b0:48b:93c5:d75 with SMTP id ada2fe7eead31-48b93c51566mr1390777137.7.1716908597315; Tue, 28 May 2024 08:03:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716908597; cv=pass; d=google.com; s=arc-20160816; b=f716fRzZZVaO+8Abt6yeHemlluoR41zrwRxYAnJGfktbLOnZicQIdjwo557w4i4n2A Ech5/IVTChlAUbpV3iDwvxoj90NHM3LpHEfQcfk83lT1C+6Frkq3uFELmGI73MAdchdC D7kNnBF2Ron4ndKiGrDBiY4mVdS8tKIt10oXLCqm902SAM6YOppt3+sQS+zfrAyNjmUw cAc73OIFFhOLNYcxDcerKP6x4zZY2fXfahfjlhHQ6ryV/oSlJ9sARGK0TzaZ23bAqZL/ MGbZlvBWhlXRsouwuELCNUsNd5hnnT6C1gBrWXZUlnA9qx1AdK8sY5Rg6awEPYxgZu7I GD9Q== 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=6sIP+oLCLLiD+fLRRcHb9kASEhkUU21lpWheKZ4R9AE=; fh=HP39+yda0QHsXMT3XaLy3KM419Yj59UqEZWQZo+gOsI=; b=B1QL7OSaPVMCKiJCxrqR/8td6KtzIU2p/1rRKNX+MHKIZJjCz+E3Qp6qPcYpo8GGf5 EQM8Ovj+0HfEdT7Xk+xFa3eKC8zGZZNvGq5hV5TuN0921GpeeTMvz8Ql77lLKNUwPMT2 EDwjJukWrzObNjPBpRhZShXRCn3DEDsG9w8HkoBwx1dglkKxS6MP7XE4CKsqQptCiiqZ 7nZDcP82uXb9A7/uXDgp+ZiAe3c641UAQTKDzQXgl8Nsc/xSk9m7MqfCHxkMyBnBVRRR +/dOQJ0XDF87qqr/ovQsV4WmTkVxmEPbKbA7BML/3klSxVCC4spQeYq1KIxu63V+diRl H1/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=isNfKZdw; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-192594-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192594-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 ada2fe7eead31-48a3a224b1csi1923903137.215.2024.05.28.08.03.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:03:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192594-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=isNfKZdw; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-192594-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192594-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 006371C225EF for ; Tue, 28 May 2024 15:03:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE3A1173323; Tue, 28 May 2024 15:01:16 +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="isNfKZdw" 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 B933217166C; Tue, 28 May 2024 15:01:13 +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=1716908475; cv=none; b=ncSEakLhtJBIKfQgabvTyPVKtjypj3uzn5cQouALVjsLAUrYKxzYGJo6nnRdxJN7NZbUIm+NsODGSsEmbdzYaGC0pYMZb+gf4tfnsH+0bvMQCJVobquaCQaytOXqRMrye7XTtS3549q1OsCzmFBtSIfpJ+hsjcM1NZVEHi2miOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716908475; c=relaxed/simple; bh=pENZ82A7dQdj9deo3H0ub5tDzd02tnfp1eYuXbyPaD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=snQk1u4zEcZ4fqx6mlJVRcxzxnj6LnePzr5vbQ8RHzyHKSpmdsJP8gT2DO3LFJiYbNqox3Tp5TOGk6I3XbuFeWq2plvoBUEjTOI3BRnEZBDyBKMkLPpq5DzYWvKI4ZlsSMKJ2Tjg60SumTAH2JvHkVKNNAlXhl3U2lZZgqGBbZQ= 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=isNfKZdw 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.1.0) id fe7ef9829d007e61; Tue, 28 May 2024 17:01:06 +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 8BACA6A5015; Tue, 28 May 2024 17:01:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1716908466; bh=pENZ82A7dQdj9deo3H0ub5tDzd02tnfp1eYuXbyPaD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=isNfKZdw8RNrG8geFjZ0quGP+yq3K/tuSw2z9lhcMuTcsnQgP6MrFyCgMTJv6E+w/ IwdrXjQmZ+qGKGfa2A5AmvMtvrnUJzEDhQvRWutD0gjScj9UYR69gnS0IQi2xj20gc 8ysB+JL25xqdPFOHtaFmwQ651t9xXPthCCiTuPpDvp7rBhzjnLmAJTMQc+nTmuJ9Ka OTGJVPCY8lRWVaHQEHEyUQ+gfFW/4FdkE235BjcOkHGpVwUMPyBaGaTYRb5C9fjs1J Wsf1JUavUqxiNb9rgh4kAYa4Z8dunSDNczrbn+FBHIFjPrhv27MBdvuR+62N7CBmgi 3K6SagdxVR9ug== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano Subject: [PATCH v2 2/8] thermal/debugfs: Do not extend mitigation episodes beyond system resume Date: Tue, 28 May 2024 16:53:47 +0200 Message-ID: <2337425.ElGaqSPkdT@kreacher> In-Reply-To: <5794974.DvuYhMxLoT@kreacher> References: <5794974.DvuYhMxLoT@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: gggruggvucftvghtrhhoucdtuddrgedvledrvdejkedgheeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohephedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgviigt rghnoheslhhinhgrrhhordhorhhg 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 --- v1 -> v2: Rebase. --- 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 @@ -1641,6 +1641,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 @@ -926,3 +926,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,