Re: [PATCH v3] thermal: core: Call monitor_thermal_zone() if zone temperature is invalid
From: Rafael J. Wysocki
Date: Tue Jul 16 2024 - 10:04:36 EST
On Tue, Jul 16, 2024 at 3:20 PM Stefan Lippers-Hollmann <s.l-h@xxxxxx> wrote:
>
> Hi
>
> On 2024-07-16, Rafael J. Wysocki wrote:
> > On Tue, Jul 16, 2024 at 1:36 PM Rafael J. Wysocki <rafael@xxxxxxxxxx> wrote:
> > > On Tue, Jul 16, 2024 at 1:15 PM Stefan Lippers-Hollmann <s.l-h@xxxxxx> wrote:
> > > > On 2024-07-16, Stefan Lippers-Hollmann wrote:
> > > > > On 2024-07-16, Rafael J. Wysocki wrote:
> > > > > > On Tue, Jul 16, 2024 at 1:48 AM Stefan Lippers-Hollmann <s.l-h@xxxxxx> wrote:
> > > > > > > On 2024-07-15, Rafael J. Wysocki wrote:
> > > > > > > > On Mon, Jul 15, 2024 at 2:54 PM Stefan Lippers-Hollmann <s.l-h@xxxxxx> wrote:
> > > > > > > > > On 2024-07-15, Rafael J. Wysocki wrote:
> > > > > > > > > > On Mon, Jul 15, 2024 at 11:09 AM Daniel Lezcano
> > > > > > > > > > <daniel.lezcano@xxxxxxxxxx> wrote:
> > > > > > > > > > > On 15/07/2024 06:45, Eric Biggers wrote:
> > > > > > > > > > > > On Thu, Jul 04, 2024 at 01:46:26PM +0200, Rafael J. Wysocki wrote:
> > > > > > > > > > > >> From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
> > > > > > > [...]
> > > > > > > > > Silencing the warnings is already a big improvement - and that patch
> > > > > > > > > works to this extent for me with an ax200, thanks.
> > > > > > > >
> > > > > > > > So attached is a patch that should avoid enabling the thermal zone
> > > > > > > > when it is not ready for use in the first place, so it should address
> > > > > > > > both the message and the useless polling.
> > > > > > > >
> > > > > > > > I would appreciate giving it a go (please note that it hasn't received
> > > > > > > > much testing so far, though).
> > > > > > >
> > > > > > > Sadly this patch doesn't seem to help:
> > > > > >
> > > > > > This is likely because it is missing checks for firmware image type.
> > > > > > I've added them to the attached new version. Please try it.
> > > > > >
> > > > > > I've also added two pr_info() messages to get a better idea of what's
> > > > > > going on, so please grep dmesg for "Thermal zone not ready" and
> > > > > > "Enabling thermal zone".
> > > > >
> > > > > This is the output with the patch applied:
> > > >
> > > > The ax200 wlan interface is currently not up/ configured (system
> > > > using its wired ethernet cards instead), the thermal_zone1 stops
> > > > if I manually enable the interface (ip link set dev wlp4s0 up)
> > > > after booting up:
> > >
> > > This explains it, thanks!
> > >
> > > The enabling of the thermal zone in iwl_mvm_load_ucode_wait_alive() is
> > > premature or it should get disabled in the other two places that clear
> > > the IWL_MVM_STATUS_FIRMWARE_RUNNING bit.
> > >
> > > I'm not sure why the thermal zone depends on whether or not this bit
> > > is set, though. Is it really a good idea to return errors from it if
> > > the interface is not up?
> [...]
> > > > [ 22.033468] thermal thermal_zone1: failed to read out thermal zone (-61)
> > > > [ 22.213120] thermal thermal_zone1: Enabling thermal zone
> > > > [ 22.283954] iwlwifi 0000:04:00.0: Registered PHC clock: iwlwifi-PTP, with index: 0
> > >
> > > Thanks for this data point!
> > >
> > > AFAICS the thermal zone in iwlwifi is always enabled, but only valid
> > > if the interface is up. It looks to me like the thermal core needs a
> > > special "don't poll me" error code to be returned in such cases.
> >
> > Attached is a thermal core patch with an iwlwifi piece along the lines
> > above (tested lightly). It adds a way for a driver to indicate that
> > temperature cannot be provided at the moment, but that's OK and the
> > core need not worry about that.
> >
> > Please give it a go.
>
> This seems to fail to build on top of v6.10, should I test Linus' HEAD
> or some staging tree instead?
No, it's missing one hunk, sorry about that.
> [ I will be offline for the next few hours now, but will test it as soon
> as possible, probably in ~9-10 hours ]
No worries and thanks for your persistence!
> CC drivers/thermal/thermal_core.o
> drivers/thermal/thermal_core.c: In function 'handle_thermal_trip':
> drivers/thermal/thermal_core.c:383:37: error: 'THERMAL_TEMP_INIT' undeclared (first use in this function); did you mean 'THERMAL_TEMP_INVALID'?
> 383 | tz->last_temperature != THERMAL_TEMP_INIT) {
> | ^~~~~~~~~~~~~~~~~
> | THERMAL_TEMP_INVALID
> drivers/thermal/thermal_core.c:383:37: note: each undeclared identifier is reported only once for each function it appears in
> drivers/thermal/thermal_core.c: In function 'thermal_zone_device_init':
> drivers/thermal/thermal_core.c:432:27: error: 'THERMAL_TEMP_INIT' undeclared (first use in this function); did you mean 'THERMAL_TEMP_INVALID'?
> 432 | tz->temperature = THERMAL_TEMP_INIT;
> | ^~~~~~~~~~~~~~~~~
> | THERMAL_TEMP_INVALID
>
Attached is a new version that builds for me on top of plain 6.10.
---
drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 7 +++
drivers/thermal/thermal_core.c | 51 +++++++++++++---------------
drivers/thermal/thermal_core.h | 3 +
3 files changed, 33 insertions(+), 28 deletions(-)
Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -300,8 +300,6 @@ static void monitor_thermal_zone(struct
thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);
else if (tz->polling_delay_jiffies)
thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
- else if (tz->temperature == THERMAL_TEMP_INVALID)
- thermal_zone_device_set_polling(tz, msecs_to_jiffies(THERMAL_RECHECK_DELAY_MS));
}
static struct thermal_governor *thermal_get_tz_governor(struct thermal_zone_device *tz)
@@ -382,7 +380,7 @@ static void handle_thermal_trip(struct t
td->threshold = trip->temperature;
if (tz->last_temperature >= old_threshold &&
- tz->last_temperature != THERMAL_TEMP_INVALID) {
+ tz->last_temperature != THERMAL_TEMP_INIT) {
/*
* Mitigation is under way, so it needs to stop if the zone
* temperature falls below the low temperature of the trip.
@@ -417,27 +415,6 @@ static void handle_thermal_trip(struct t
}
}
-static void update_temperature(struct thermal_zone_device *tz)
-{
- int temp, ret;
-
- ret = __thermal_zone_get_temp(tz, &temp);
- if (ret) {
- if (ret != -EAGAIN)
- dev_warn(&tz->device,
- "failed to read out thermal zone (%d)\n",
- ret);
- return;
- }
-
- tz->last_temperature = tz->temperature;
- tz->temperature = temp;
-
- trace_thermal_temperature(tz);
-
- thermal_genl_sampling_temp(tz->id, temp);
-}
-
static void thermal_zone_device_check(struct work_struct *work)
{
struct thermal_zone_device *tz = container_of(work, struct
@@ -452,7 +429,7 @@ static void thermal_zone_device_init(str
INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check);
- tz->temperature = THERMAL_TEMP_INVALID;
+ tz->temperature = THERMAL_TEMP_INIT;
tz->passive = 0;
tz->prev_low_trip = -INT_MAX;
tz->prev_high_trip = INT_MAX;
@@ -501,6 +478,7 @@ void __thermal_zone_device_update(struct
struct thermal_trip_desc *td;
LIST_HEAD(way_down_list);
LIST_HEAD(way_up_list);
+ int temp, ret;
if (tz->suspended)
return;
@@ -508,10 +486,29 @@ void __thermal_zone_device_update(struct
if (!thermal_zone_device_is_enabled(tz))
return;
- update_temperature(tz);
+ ret = __thermal_zone_get_temp(tz, &temp);
+ if (ret) {
+ if (ret != -EAGAIN)
+ dev_info(&tz->device, "Temperature check failed (%d)\n", ret);
- if (tz->temperature == THERMAL_TEMP_INVALID)
+ thermal_zone_device_set_polling(tz, msecs_to_jiffies(THERMAL_RECHECK_DELAY_MS));
+ return;
+ } else if (temp <= THERMAL_TEMP_INVALID) {
+ /*
+ * Special case: No valid temperature value is available, but
+ * the zone owner does not want the core to do anything about
+ * it. Continue regular zone polling if needed, so that this
+ * function can be called again, but skip everything else.
+ */
goto monitor;
+ }
+
+ tz->last_temperature = tz->temperature;
+ tz->temperature = temp;
+
+ trace_thermal_temperature(tz);
+
+ thermal_genl_sampling_temp(tz->id, temp);
__thermal_zone_set_trips(tz);
Index: linux-pm/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
===================================================================
--- linux-pm.orig/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
+++ linux-pm/drivers/net/wireless/intel/iwlwifi/mvm/tt.c
@@ -622,7 +622,12 @@ static int iwl_mvm_tzone_get_temp(struct
if (!iwl_mvm_firmware_running(mvm) ||
mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) {
- ret = -ENODATA;
+ /*
+ * Tell the core that there is no valid temperature value to
+ * return, but it need not worry about this.
+ */
+ *temperature = THERMAL_TEMP_INVALID;
+ ret = 0;
goto out;
}
Index: linux-pm/drivers/thermal/thermal_core.h
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.h
+++ linux-pm/drivers/thermal/thermal_core.h
@@ -133,6 +133,9 @@ struct thermal_zone_device {
struct thermal_trip_desc trips[] __counted_by(num_trips);
};
+/* Initial thermal zone temperature. */
+#define THERMAL_TEMP_INIT INT_MIN
+
/*
* Default delay after a failing thermal zone temperature check before
* attempting to check it again.