Message ID | 2244940.iZASKD2KPV@kreacher |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp499132vqo; Fri, 6 Oct 2023 10:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyLfTlzptA1SNglN6BoHl4blbl9Ur6F6zLJR/b84i1mcNjHIuUGWR4vOfAqPJJfn5sC2yb X-Received: by 2002:a17:902:d2cd:b0:1c3:94a4:34bf with SMTP id n13-20020a170902d2cd00b001c394a434bfmr10427337plc.66.1696614733419; Fri, 06 Oct 2023 10:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614733; cv=none; d=google.com; s=arc-20160816; b=p8OO/scPNMYafFOW4FKCYlH94G+vSLQdiGu0uA0DtSnm5FZD4yFJWgwKMiEG5AsjrL 2WLJMONrHdKweY5L9skTa/6BREivtTrE+Eanoi62uHG7K4eAYZdGkFFXr6SEA6lDwucp 6TlK9sWl5tRzO3WHbneoByC4bmdBfHueSgPeKTJ0WsBZIPQ7pJwEOvZ2WCL3qV7vcovG nkOc2TfxCYFJsKTiPvmsvExwrlE1Zjg835y5ldC4+/GSm0I4NlH3alm6W/tM+1KA9QNN TLBX9VSElFTA3NHIdL7OXX9Jx0N0uOp5MLVchbLBWpoju/7Re/T0nbOXIgfvnaHF4b/N anQw== 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=dt51t1EARwQbB7qGxOBEKKgazunXET8SMXJBhbaUkuc=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=vU0OhUCpJkxh6oDFaAnTW3KP7AoFLh5/STa6fldG5Ss5N0oR+mVZrHOWyIW/eqSXFC K0kUd+PsS1yz9IHFW9tx16EmoZVt59ThdrfqmzZZ7e18ZlMhspfdheOi5ReWs9Ac2GuT Vpk1ahYxh/jaowSkvaIMRt25PweQrHMr8VNvtu/0H9syg0td7PZJZ2zUTeSwNNEOGgrp A5f2dwK4kFrPKCNuX+JNiMGrBOpInEoO4JH+peM+KGuV3HLU5w64HpZANQoh+BPCFvRx S4zaD75CtyQDFOCTo45jLBU2ug6LoZS/sUuIapux6oawoYsQKv9ZsFpxaW0oJdU/NweM Y6ng== 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:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id n14-20020a170902968e00b001c774a25b3bsi4096700plp.233.2023.10.06.10.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:52:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 32E178262E0E; Fri, 6 Oct 2023 10:52:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233105AbjJFRvj (ORCPT <rfc822;ezelljr.billy@gmail.com> + 18 others); Fri, 6 Oct 2023 13:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233058AbjJFRvb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 6 Oct 2023 13:51:31 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A782FB6; Fri, 6 Oct 2023 10:51:30 -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 6f63dadd0b78c61c; Fri, 6 Oct 2023 19:51:29 +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 9AD47665D08; Fri, 6 Oct 2023 19:51:28 +0200 (CEST) From: "Rafael J. Wysocki" <rjw@rjwysocki.net> To: Linux PM <linux-pm@vger.kernel.org> Cc: LKML <linux-kernel@vger.kernel.org>, Daniel Lezcano <daniel.lezcano@linaro.org>, Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>, Zhang Rui <rui.zhang@intel.com>, Lukasz Luba <lukasz.luba@arm.com> Subject: [PATCH v1 3/6] thermal: gov_fair_share: Rearrange get_trip_level() Date: Fri, 06 Oct 2023 19:42:48 +0200 Message-ID: <2244940.iZASKD2KPV@kreacher> In-Reply-To: <13365827.uLZWGnKmhe@kreacher> References: <13365827.uLZWGnKmhe@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: gggruggvucftvghtrhhoucdtuddrgedvkedrgeeigdduudehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 06 Oct 2023 10:52:07 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029490916993739 X-GMAIL-MSGID: 1779029490916993739 |
Series |
thermal: core: Pass trip pointers to governor .throttle() callbacks
|
|
Commit Message
Rafael J. Wysocki
Oct. 6, 2023, 5:42 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> 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 <rafael.j.wysocki@intel.com> --- drivers/thermal/gov_fair_share.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
Comments
On 06/10/2023 19:42, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > 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 <rafael.j.wysocki@intel.com> > --- > 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 (level_trip && trip->temperature >= tz->temperature) > break; Even if very likely the trip points are ordered by the hardware enumeration, strictly we don't have yet the guarantee the trips are ordered (as that is the final goal to correctly detect thresholds crossing with the generic trip). We should go through all the trip points, no? > + 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->temperature >= tz->temperature) > + return 0; Isn't simpler to remove the test level_trip != NULL in the loop and then check here if it is NULL and then 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, > > >
On Thu, Oct 12, 2023 at 5:04 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 06/10/2023 19:42, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > 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 <rafael.j.wysocki@intel.com> > > --- > > 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 (level_trip && trip->temperature >= tz->temperature) > > break; > > Even if very likely the trip points are ordered by the hardware > enumeration, strictly we don't have yet the guarantee the trips are > ordered (as that is the final goal to correctly detect thresholds > crossing with the generic trip). We should go through all the trip > points, no? Well, I just retained the existing logic, because changing it is not the purpose of this patch. Such a change can certainly be considered, but not in this patch and not in this patch series. > > + 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->temperature >= tz->temperature) > > + return 0; > > Isn't simpler to remove the test level_trip != NULL in the loop and then > check here if it is NULL and then return 0. Yes, good point. > > + 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, > > > > > > > > --
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 (level_trip && 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->temperature >= tz->temperature) + 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,