Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1632776lqp; Mon, 15 Apr 2024 12:03:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU3WtLdox8AluBRchrMYxcAHJ5gk1ZNzNMyyBmkw+SZEZIvxr3UFl5NX4JJis7ajKLShtwKIL7mOSBsgM1F1AL6PoQYI1HH2utwKjKOxA== X-Google-Smtp-Source: AGHT+IFeVPS7bnlQE+Pg0PxgGPDFtOaFBap0bep+KG3BTX9K6tGLBlPViiLExfGcve56OiN8G4Op X-Received: by 2002:a2e:a545:0:b0:2d8:58b6:c10d with SMTP id e5-20020a2ea545000000b002d858b6c10dmr10141461ljn.18.1713207816543; Mon, 15 Apr 2024 12:03:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713207816; cv=pass; d=google.com; s=arc-20160816; b=K4SgiKukN52NHg0mFaWdv1R+DmNYIjbH6XlB4YXSifhOa8+dyLOlhxFo0jlLVEar2l KReD0VDFhSNhLTNktS8bx6VthljgI2uow1frfXTJQH33Ke2kvw/cXUu2E9O39XGl/yI7 g8mDmV5EHncDaXwHqs6G0fJf2nYijE7c7Xelg8qjOtbAPB2pQf2l9AbLPjfdEb3DC3C7 +yrs0QokzOpkkLp/hfLbef293S4ERjUdP8iAvf9ll+EU2ki+F3Jxzv6BGxkcxIg/etbr UKgAlxYCw2Br9Uhpu1ED6Zsud+XLs3fC4/CBTbbGIeSOl1y3R0BpStfdkX+c/8dKzFEO TLZg== 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=Gdx3Zka6v1nGXka+4Qet5I77FBgWyYZ9uKkrZhcERAM=; fh=pZcN3lnDPmzrIpxf+h+NFKrBfIYpRY/C7vEftEJzZns=; b=uRC3+ANdG2x/cvVqzKdsDRgrjYZaboBIwAwdQJzsd7xfiE2cjPA8Vhh2QIUtPnzAua n36NtdrFLV/Zzn4q1HtdKqcLPd8iH2UxU7MD8dafqhX6RTEeouOmp/wsw6o0c3Lagji9 sP/LClQjaCXb1hGr+PzGzMR9RkRuKMvzLcOGDQ/mKWkwkQRXtd3VywXh8IsprXXYXRaX c+pHsb3wFYfK6UTYqek487LOazZCVFRFyygFiVwhbr41L0/R6hB6Mpdrj5NjCPLD70oP XjVCGwJMTChMAWQKNzGoshSC7uiFGQPO6BTx2yp0TJpWUG/bMd6h5IcmPe8jCSAWSK3k CWTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=M9EGh4hO; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-145743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145743-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i8-20020a17090671c800b00a51b84d4040si4933349ejk.85.2024.04.15.12.03.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 12:03:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=M9EGh4hO; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-145743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145743-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DD5CE1F22D26 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 04B12155A58; 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="M9EGh4hO" 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 67B2884D24; Mon, 15 Apr 2024 19:03:19 +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=TMeqPJah9IjtCfrwR+wtuTZJNNu04GvDRwTEpMoZeEVmmZP2+WbD8W2wjDahZxd0fl0LW4DHaH7E9zos4nNBkFwNbFJCrvToFY6Oph/GyOcEO/vE7Bw3MyZ5ol/xixi0iILYUOrp476cFpVxVoHUMmsX7nuJeTqIHJvsycPowb0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713207803; c=relaxed/simple; bh=CQNI1NZ7g4v/dwm4IEXv3eA8nBv8ecvnI47e7IY43ks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k/6n9pdD/3sl6kq6hOO+Vz9mBDV+3rKclldxvIc/zaHdNUDVY6/39ZBM2afJ4/htyTlDDRX5COUD05T5iC7ILQm3uJFw/XERHJ6tH+wVYh8FxXneLl3CmQImLba15XLZ0vgk+s4yyInO93GpbES42IKF52V/vsm3uFxUO1YqVUQ= 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=M9EGh4hO 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 e37f4f2d11543fe6; 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 8A69D66CF45; Mon, 15 Apr 2024 21:03:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1713207792; bh=CQNI1NZ7g4v/dwm4IEXv3eA8nBv8ecvnI47e7IY43ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M9EGh4hODnGqxqAYnNjSiv101bCMaZIlxWdb/zEp7XiWTnyPnayIMso9Yg8faJ9M3 r57uiL/FBfHoDW99iReGstfc/qItdgnx8rXzg/N++/zuJUXE1UtODq4AgZQIEPMYS1 xw28c7SbtnFpkVMcPKkRVfHv7NMav3jYXQnR9khHutNr7g17Cx/PTX+48/ZYN1rMUa 5LK2pvFWa81nmqDJ8cbqXxiJN5dKcYilPwr7jcT1q4QAP62Klw8fXMj7QtWhaX62G4 0hiyjWlRqfRqvk95h+slHnhKITQ20lIKONSNoNhJ4Lg9FRChX+80svF0l7W7Dwg8Y/ AQSGkIo0ekqDA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Daniel Lezcano Subject: [PATCH v1 2/2] thermal/debugfs: Add helper function for trip stats updates Date: Mon, 15 Apr 2024 21:03:06 +0200 Message-ID: <2321994.ElGaqSPkdT@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 code updating a trip_stats entry in thermal_debug_tz_trip_up() and thermal_debug_update_temp() is almost entirely duplicate, so move it to a new helper function that will be called from both these places. While at it, drop a redundant tz_dbg->nr_trips check and a label related to it from thermal_debug_update_temp(). Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_debugfs.c | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) Index: linux-pm/drivers/thermal/thermal_debugfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_debugfs.c +++ linux-pm/drivers/thermal/thermal_debugfs.c @@ -539,6 +539,19 @@ static struct tz_episode *thermal_debugf return tze; } +static struct trip_stats *update_tz_episode(struct tz_debugfs *tz_dbg, + int trip_id, int temperature) +{ + struct tz_episode *tze = list_first_entry(&tz_dbg->tz_episodes, + struct tz_episode, node); + struct trip_stats *trip_stats = &tze->trip_stats[trip_id]; + + trip_stats->max = max(trip_stats->max, temperature); + trip_stats->min = min(trip_stats->min, temperature); + trip_stats->avg += (temperature - trip_stats->avg) / ++trip_stats->count; + return trip_stats; +} + void thermal_debug_tz_trip_up(struct thermal_zone_device *tz, const struct thermal_trip *trip) { @@ -547,6 +560,7 @@ void thermal_debug_tz_trip_up(struct the struct thermal_debugfs *thermal_dbg = tz->debugfs; int temperature = tz->temperature; int trip_id = thermal_zone_trip_id(tz, trip); + struct trip_stats *trip_stats; ktime_t now = ktime_get(); if (!thermal_dbg) @@ -612,14 +626,8 @@ void thermal_debug_tz_trip_up(struct the */ tz_dbg->trips_crossed[tz_dbg->nr_trips++] = trip_id; - tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node); - 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; + trip_stats = update_tz_episode(tz_dbg, trip_id, temperature); + trip_stats->timestamp = now; unlock: mutex_unlock(&thermal_dbg->lock); @@ -686,9 +694,8 @@ out: void thermal_debug_update_temp(struct thermal_zone_device *tz) { struct thermal_debugfs *thermal_dbg = tz->debugfs; - struct tz_episode *tze; struct tz_debugfs *tz_dbg; - int trip_id, i; + int i; if (!thermal_dbg) return; @@ -697,20 +704,9 @@ void thermal_debug_update_temp(struct th tz_dbg = &thermal_dbg->tz_dbg; - if (!tz_dbg->nr_trips) - goto out; + for (i = 0; i < tz_dbg->nr_trips; i++) + update_tz_episode(tz_dbg, tz_dbg->trips_crossed[i], tz->temperature); - for (i = 0; i < tz_dbg->nr_trips; i++) { - trip_id = tz_dbg->trips_crossed[i]; - tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node); - tze->trip_stats[trip_id].count++; - tze->trip_stats[trip_id].max = max(tze->trip_stats[trip_id].max, tz->temperature); - tze->trip_stats[trip_id].min = min(tze->trip_stats[trip_id].min, tz->temperature); - tze->trip_stats[trip_id].avg = tze->trip_stats[trip_id].avg + - (tz->temperature - tze->trip_stats[trip_id].avg) / - tze->trip_stats[trip_id].count; - } -out: mutex_unlock(&thermal_dbg->lock); }