public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
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>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Zhang Rui <rui.zhang@intel.com>
Subject: [PATCH  v1 1/2] thermal: gov_fair_share: Fix dependency on trip points ordering
Date: Mon, 15 Jan 2024 18:55:13 +0100	[thread overview]
Message-ID: <4918593.31r3eYUQgx@kreacher> (raw)
In-Reply-To: <12389773.O9o76ZdvQC@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The computation in the fair share governor's get_trip_level() function
currently works under the assumption that the temperature ordering of
trips[] in a thermal zone is ascending, which need not be the case.

However, get_trip_level() can be made work regardless of whether or not
the trips table is ordered by temperature in any way, so change it
accordingly.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/gov_fair_share.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 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
@@ -18,22 +18,24 @@
 static int get_trip_level(struct thermal_zone_device *tz)
 {
 	const struct thermal_trip *trip, *level_trip = NULL;
-	int trip_level;
+	int trip_level = -1;
 
 	for_each_trip(tz, trip) {
 		if (trip->temperature >= tz->temperature)
-			break;
+			continue;
 
-		level_trip = trip;
+		trip_level++;
+
+		if (!level_trip || trip->temperature > level_trip->temperature)
+			level_trip = trip;
 	}
 
 	/*  Bail out if the temperature is not greater than any trips. */
-	if (!level_trip)
+	if (trip_level < 0)
 		return 0;
 
-	trip_level = thermal_zone_trip_id(tz, level_trip);
-
-	trace_thermal_zone_trip(tz, trip_level, level_trip->type);
+	trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, level_trip),
+				level_trip->type);
 
 	return trip_level;
 }




  reply	other threads:[~2024-01-15 17:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-15 17:52 [PATCH v1 0/2] thermal: A couple of minor governor fixes Rafael J. Wysocki
2024-01-15 17:55 ` Rafael J. Wysocki [this message]
2024-01-15 17:57 ` [PATCH v1 2/2] thermal: gov_bang_bang: Fix possible cooling device state ping-pong Rafael J. Wysocki
2024-01-29 14:36 ` [PATCH v1 0/2] thermal: A couple of minor governor fixes Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4918593.31r3eYUQgx@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox