From patchwork Thu Oct 12 18:29:43 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: 152109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1426891vqb; Thu, 12 Oct 2023 11:35:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEhkgFWQI18j5FGDh0ncuAe2mMeyf0YO5ws7Fwm2XRuqkc1sUa75Hn9ANhTm6aBg7sTB8O X-Received: by 2002:a05:6602:140c:b0:79f:a8c2:290d with SMTP id t12-20020a056602140c00b0079fa8c2290dmr32995185iov.0.1697135736385; Thu, 12 Oct 2023 11:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697135736; cv=none; d=google.com; s=arc-20160816; b=Cm6BwKCC3TRCo/G6hG5K8wVVv9jriJPTNnStmi46dMe+5sVbagxzbFtTO6WEjCp7Ns Pv1pgA9M8xXXeqAFNqHAwVUHegInlUT5ktZdvaiQYcvSfukOt1PqlZ3h9ySgbGBpB/jb PWufJzWdovu1q4GYDz4qE+vlBvdN/OYslsdYX5BM3HV5GIlzxQEkNxRV6DVuXu/WE+ni yDeuvzR6nKFpaMNqZiL08sAlaNvIIw0ngo8Nv2s++FJBMYsVK2sYzAULhXwdD36/22Ka hOFpBk1JKPT9Iy/sYci5mpxh10OdJY4dEj5RfjFSZ1Pg8MQv/ThCnVT5ZaBf5+CMzvvK WdpA== 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=xIm+FgThSVe9Ika0DAaV5GjtK0tp2ZXBhGzMTObSvts=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=U7JP6UAdeu7Nu7sWIR0g9ErlxVJOonndIvojuEgyrcFSrvwy/sUGj/R5ZvSehZ5Q7X pmltwO0y63zhQqeEp3TW28sa1A+SLwj2UOw4F31qIEWISUK+UYrTsRhNHU8b2hh5FoNM KCNMEEOj/kS1WwHCMvFJKdgdmk8MQIC48gJH8sastPVLUgSR+NjizepjszSOq+XbWhfh i+ip66b/LZxsEDXoyf4ycdohjg5Ej6QsBBrey3ZDzwaV4S+YI8b07RxfgfaYlf2/gj/L h99+qzRFGHbDV1hSevWguIEU3aEZr/yuv3wHuj9DWDZrsNJFJus8WMVojVbyVV57F9bL vLsA== 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:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bq10-20020a056a02044a00b0057759a5b7ccsi3462655pgb.305.2023.10.12.11.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 11:35:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 3359D83C715E; Thu, 12 Oct 2023 11:35:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442048AbjJLSfM (ORCPT + 19 others); Thu, 12 Oct 2023 14:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379687AbjJLSfE (ORCPT ); Thu, 12 Oct 2023 14:35:04 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1758F83; Thu, 12 Oct 2023 11:35:02 -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 6db59e59c3a16293; Thu, 12 Oct 2023 20:35:01 +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 17E96666869; Thu, 12 Oct 2023 20:35:01 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Subject: [PATCH v2 3/6] thermal: gov_fair_share: Rearrange get_trip_level() Date: Thu, 12 Oct 2023 20:29:43 +0200 Message-ID: <2176566.irdbgypaU6@kreacher> In-Reply-To: <5734364.DvuYhMxLoT@kreacher> References: <5734364.DvuYhMxLoT@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: gggruggvucftvghtrhhoucdtuddrgedvkedriedtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Thu, 12 Oct 2023 11:35:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779575802060757979 X-GMAIL-MSGID: 1779575802060757979 From: Rafael J. Wysocki Make get_trip_level() use for_each_trip() to iterate over trip points and make it call thermal_zone_trip_id() to obtain the integer ID of a given trip point so as to avoid relying on the knowledge of struct thermal_zone_device internals. The general functionality is not expected to be changed. This change causes the governor to use trip pointers instead of trip indices everywhere except for the fair_share_throttle() second argument that will be modified subsequently along with the definition of the governor .throttle() callback. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- v1 -> v2: Eliminate redundant NULL check from the loop in get_trip_level() (Daniel). --- drivers/thermal/gov_fair_share.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 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 @@ -15,29 +15,27 @@ #include "thermal_core.h" -/** - * get_trip_level: - obtains the current trip level for a zone - * @tz: thermal zone device - */ static int get_trip_level(struct thermal_zone_device *tz) { - struct thermal_trip trip; - int count; + const struct thermal_trip *trip, *level_trip = NULL; + int trip_level; - for (count = 0; count < tz->num_trips; count++) { - __thermal_zone_get_trip(tz, count, &trip); - if (tz->temperature < trip.temperature) + for_each_trip(tz, trip) { + if (trip->temperature >= tz->temperature) break; + + level_trip = trip; } - /* - * 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); + /* Bail out if the temperature is not greater than any trips. */ + if (!level_trip) + return 0; + + trip_level = thermal_zone_trip_id(tz, level_trip); + + trace_thermal_zone_trip(tz, trip_level, level_trip->type); - return count; + return trip_level; } static long get_target_state(struct thermal_zone_device *tz,