From patchwork Thu Sep 21 17:54:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 725082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CAAEE7D0AF for ; Thu, 21 Sep 2023 22:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231437AbjIUWGf (ORCPT ); Thu, 21 Sep 2023 18:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjIUWGV (ORCPT ); Thu, 21 Sep 2023 18:06:21 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A345AF941; Thu, 21 Sep 2023 11:07:29 -0700 (PDT) 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 5.2.0) id 27ba5ac5cc524f47; Thu, 21 Sep 2023 20:07:27 +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 v370.home.net.pl (Postfix) with ESMTPSA id 3400F664EC0; Thu, 21 Sep 2023 20:07:27 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 06/13] thermal: gov_fair_share: Rearrange get_trip_level() Date: Thu, 21 Sep 2023 19:54:02 +0200 Message-ID: <1882755.CQOukoFCf9@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Make get_trip_level() access the thermal zone's trip table directly instead of using __thermal_zone_get_trip() which adds overhead related to the unnecessary bounds checking and copying the trip point data. Also rearrange the code in it to make it somewhat easier to follow. The general functionality is not expected to be changed. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_fair_share.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) Index: linux-pm/drivers/thermal/gov_fair_share.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_fair_share.c +++ linux-pm/drivers/thermal/gov_fair_share.c @@ -21,23 +21,21 @@ */ static int get_trip_level(struct thermal_zone_device *tz) { - struct thermal_trip trip; - int count; + const struct thermal_trip *trip = tz->trips; + int i; - for (count = 0; count < tz->num_trips; count++) { - __thermal_zone_get_trip(tz, count, &trip); - if (tz->temperature < trip.temperature) + if (tz->temperature < trip->temperature) + return 0; + + for (i = 0; i < tz->num_trips - 1; i++) { + trip++; + if (tz->temperature < trip->temperature) break; } - /* - * count > 0 only if temperature is greater than first trip - * point, in which case, trip_point = count - 1 - */ - if (count > 0) - trace_thermal_zone_trip(tz, count - 1, trip.type); + trace_thermal_zone_trip(tz, i, tz->trips[i].type); - return count; + return i; } static long get_target_state(struct thermal_zone_device *tz,