Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2318243rdb; Thu, 21 Sep 2023 15:18:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVg29ZZ0B8AmjSqFE0TbdSQ0UdukuJgE1ru+jT7LRrkQqIZMB2zCLmL9Tmmglg+2De8O7j X-Received: by 2002:a17:90a:9747:b0:271:8d4d:d046 with SMTP id i7-20020a17090a974700b002718d4dd046mr6781691pjw.4.1695334706582; Thu, 21 Sep 2023 15:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695334706; cv=none; d=google.com; s=arc-20160816; b=CsPqyAN6fjRFjxP66lNbfmjeLY38PIv5jcaCyVpNB6c444id1AagZoyqBf+vmWKuew sX/2RTC76WD85uwuT/wflpVmsg3mCdmnocVtirZUvGdkcs+J0FHSNLtlCAviWKiqivua PPVbbNB9yKwTua7is4FZ7wQIjUyFuloLCbe0gj2wsJZcrg2znwB3FTz6x08UiY6PMUlc GnL5AzkIYHKdGaVwZfyczfs6ykc6T/iUi3HOr9O9gR8f4XQQ3m575suVwSi/LI8j/LS+ xTw8bZmioR7uK+nUKgU5EW/mqhkKYDiAHF4IuCXw8M5DaBC66kvtLlTreIx4Fphyd2Pr hwDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ixFOR+3Lq0zpp/fWaiAdnOe96pHHdhfyMAtnK+akSEY=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=TNr0X9hCOpKhGx0AAbCR98a37GePwwx4y1rfcqELpFHAtFAm8vtLLEKurbTZ+jkw6P AcscFc1WLrQhYvlj4Hy0Zmlmk0MZXzOHzVdXe7Qy1Fy3tjxpwuzfXWykSF+qa9T0sxk/ Ljx7u0yZ5OOy0Te5Yz7snr3Z9nGfAOCW535B+PrXd2Zvm7Av2qpp5NvdEQzEZJUsMMHI MNs5KJLXV99n1sv/T9m0mYX/hHeXBs5ltqhL7vM60NCDIwTK8qCgqYfk4BBdjC2zF/r6 ffDqvoZoTTdcxtIZ2bVMDPLMAI8a04E8M9EIKIwotNBnCNtIkGI/vQ4I/gWkKf9mLFwL CBdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ca6-20020a17090af30600b00274d5eb88c4si2483955pjb.90.2023.09.21.15.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:18:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id AB787811247E; Thu, 21 Sep 2023 15:06:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232924AbjIUWGg (ORCPT + 99 others); Thu, 21 Sep 2023 18:06:36 -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 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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:06:40 -0700 (PDT) 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,