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: 142955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5173949vqi; Thu, 21 Sep 2023 15:18:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2F9FORCuJbg8/gNafB6u54I2hWqfelPWMsERkreCFvCj2hPUw0pZSqXJLmv0/xXCmejrM X-Received: by 2002:a05:6830:22d1:b0:6b8:7d12:423d with SMTP id q17-20020a05683022d100b006b87d12423dmr6672919otc.18.1695334697742; Thu, 21 Sep 2023 15:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695334697; cv=none; d=google.com; s=arc-20160816; b=k3QxCcz0OpmZd8WyVLIRQe9BMnLStdihxby+XNcnNAGBuRLdsex/48znIvmlWB0SVJ Y9C3weQvUsiBJO+ygTj0olhbj06vP6rv7TOG3Jt8m/ajE/2jfdl79tmNiNLOJ7hGCbSZ SH+JJPDUrdZRGpXJ4ANaf6PeKHlpWV6mCXrhvW18Ws5CEEyf9MGV/e8uCL+kz9t7SqtW c9xk0/pwHGQFAfCJ2FgfniBEYG+wsOk1ir84bKoR0/BOf6dfJNgW87jNlzXaRXd7JAfk Ku8keAvbBpJSujVs8QFP+IRuVVPC/Wg2pUYGCxr+Vwby6pgtbXcQ/dU1YPH66Y+vk6vE djcQ== 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 Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ea22-20020a056a004c1600b00690f8dfb431si2385925pfb.253.2023.09.21.15.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:18:17 -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 A03D782289BF; Thu, 21 Sep 2023 15:07:01 -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 S232244AbjIUWGh (ORCPT + 29 others); Thu, 21 Sep 2023 18:06:37 -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 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:07:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777687275843441234 X-GMAIL-MSGID: 1777687275843441234 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,