2018-05-07 11:52:29 -06:00
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-11 00:05:25 +02:00
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 11:01:57 +02:00
|
|
|
|
thermal: core: Add user thresholds support
The user thresholds mechanism is a way to have the userspace to tell
the thermal framework to send a notification when a temperature limit
is crossed. There is no id, no hysteresis, just the temperature and
the direction of the limit crossing. That means we can be notified
when a threshold is crossed the way up only, or the way down only or
both ways. That allows to create hysteresis values if it is needed.
A threshold can be added, deleted or flushed. The latter means all
thresholds belonging to a thermal zone will be deleted.
When a threshold is added:
- if the same threshold (temperature and direction) exists, an error
is returned
- if a threshold is specified with the same temperature but a
different direction, the specified direction is added
- if there is no threshold with the same temperature then it is
created
When a threshold is deleted:
- if the same threshold (temperature and direction) exists, it is
deleted
- if a threshold is specified with the same temperature but a
different direction, the specified direction is removed
- if there is no threshold with the same temperature, then an error
is returned
When the threshold are flushed:
- All thresholds related to a thermal zone are deleted
When a threshold is crossed:
- the userspace does not need to know which threshold(s) have been
crossed, it will be notified with the current temperature and the
previous temperature
- if multiple thresholds have been crossed between two updates only
one notification will be send to the userspace, it is pointless to
send a notification per thresholds crossed as the userspace can
handle that easily when it has the temperature delta information
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20240923100005.2532430-2-daniel.lezcano@linaro.org
[ rjw: Subject edit, use BIT(0) and BIT(1) in symbol definitions ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-09-23 11:59:57 +02:00
|
|
|
|
2024-01-09 10:41:11 +01:00
|
|
|
|
2020-07-07 11:01:57 +02:00
|
|
|
|
2024-07-29 18:25:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
2024-07-29 18:25:03 +02:00
|
|
|
|
2024-10-16 13:23:27 +02:00
|
|
|
|
2024-10-04 21:39:19 +02:00
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-04 21:27:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-10 18:10:53 +02:00
|
|
|
|
2024-04-10 18:08:12 +02:00
|
|
|
|
2024-04-04 21:27:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-10 18:10:53 +02:00
|
|
|
|
|
|
|
|
|
2025-01-16 20:31:56 +01:00
|
|
|
|
2024-04-10 18:08:12 +02:00
|
|
|
|
2024-04-04 21:27:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-04 21:11:53 +02:00
|
|
|
|
|
|
|
|
|
thermal: core: Mark thermal zones as initializing to start with
After thermal_zone_device_register_with_trips() has called
device_register() and it has registered the new thermal zone device
with the driver core, user space may access its sysfs attributes and,
among other things, it may enable the thermal zone before it is ready.
To address this, introduce a new thermal zone state flag for
initialization and set it before calling device_register() in
thermal_zone_device_register_with_trips(). This causes
__thermal_zone_device_update() to return early until the new flag
is cleared.
To clear it when the thermal zone is ready, introduce a new
function called thermal_zone_init_complete() that will also invoke
__thermal_zone_device_update() after clearing that flag (both under the
thernal zone lock) and make thermal_zone_device_register_with_trips()
call the new function instead of checking need_update and calling
thermal_zone_device_update() when it is set.
After this change, if user space enables the thermal zone prematurely,
__thermal_zone_device_update() will return early for it until
thermal_zone_init_complete() is called. In turn, if the thermal zone
is not enabled by user space before thermal_zone_init_complete() is
called, the __thermal_zone_device_update() call in it will return early
because the thermal zone has not been enabled yet, but that function
will be invoked again by thermal_zone_device_set_mode() when the thermal
zone is enabled and it will not return early this time.
The checking of need_update is not necessary any more because the
__thermal_zone_device_update() calls potentially triggered by cooling
device binding take place before calling thermal_zone_init_complete(),
so they all will return early, which means that
thermal_zone_init_complete() must call __thermal_zone_device_update()
in case the thermal zone is enabled prematurely by user space.
Fixes: 203d3d4aa482 ("the generic thermal sysfs driver")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/9360231.CDJkKcVGEf@rjwysocki.net
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
2024-10-04 21:15:04 +02:00
|
|
|
|
2024-10-04 21:26:12 +02:00
|
|
|
|
2024-10-04 21:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-14 17:22:25 +02:00
|
|
|
|
2026-01-27 22:24:46 -08:00
|
|
|
|
thermal: core: Use trip lists for trip crossing detection
Modify the thermal core to use three lists of trip points:
trips_high, containing trips with thresholds strictly above the current
thermal zone temperature,
trips_reached, containing trips with thresholds at or below the current
zone temperature,
trips_invalid, containing trips with temperature equal to
THERMAL_ZONE_INVALID,
where the first two lists are always sorted by the current trip
threshold.
For each trip in trips_high, there is no mitigation under way and
the trip threshold is equal to its temperature. In turn, for each
trip in trips_reached, there is mitigation under way and the trip
threshold is equal to its low temperature. The trips in trips_invalid,
of course, need not be taken into consideration.
The idea is to make __thermal_zone_device_update() walk trips_high and
trips_reached instead of walking the entire table of trip points in a
thermal zone. Usually, it will only need to walk a few entries in one
of the lists and check one entry in the other list, depending on the
direction of the zone temperature changes, because crossing many trips
by the zone temperature in one go between two consecutive temperature
checks should be unlikely (if it occurs often, the thermal zone
temperature should probably be checked more often either or there
are too many trips).
This also helps to eliminate one temporary trip list used for trip
crossing notification (only one temporary list is needed for this
purpose instead of two) and the remaining temporary list may be sorted
by the current trip threshold value, like the trips_reached list, so
the additional notify_temp field in struct thermal_trip_desc is not
necessary any more.
Moreover, since the trips_reached and trips_high lists are sorted,
the "low" and "high" values needed by thermal_zone_set_trips() can be
determined in a straightforward way by looking at one end of each list.
Of course, additional work is needed in some places in order to
maintain the ordering of the lists, but it is limited to situations
that should be rare, like updating a trip point temperature or
hysteresis, thermal zone initialization, or system resume.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/2003443.usQuhbGJ8B@rjwysocki.net
[ rjw: Added a comment to thermal_zone_handle_trips() ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-10-16 13:35:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-18 21:01:14 +02:00
|
|
|
|
|
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-27 22:24:46 -08:00
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
2026-01-27 22:24:46 -08:00
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-04 21:11:53 +02:00
|
|
|
|
2026-01-27 22:24:46 -08:00
|
|
|
|
|
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-14 17:22:25 +02:00
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
thermal: core: Use trip lists for trip crossing detection
Modify the thermal core to use three lists of trip points:
trips_high, containing trips with thresholds strictly above the current
thermal zone temperature,
trips_reached, containing trips with thresholds at or below the current
zone temperature,
trips_invalid, containing trips with temperature equal to
THERMAL_ZONE_INVALID,
where the first two lists are always sorted by the current trip
threshold.
For each trip in trips_high, there is no mitigation under way and
the trip threshold is equal to its temperature. In turn, for each
trip in trips_reached, there is mitigation under way and the trip
threshold is equal to its low temperature. The trips in trips_invalid,
of course, need not be taken into consideration.
The idea is to make __thermal_zone_device_update() walk trips_high and
trips_reached instead of walking the entire table of trip points in a
thermal zone. Usually, it will only need to walk a few entries in one
of the lists and check one entry in the other list, depending on the
direction of the zone temperature changes, because crossing many trips
by the zone temperature in one go between two consecutive temperature
checks should be unlikely (if it occurs often, the thermal zone
temperature should probably be checked more often either or there
are too many trips).
This also helps to eliminate one temporary trip list used for trip
crossing notification (only one temporary list is needed for this
purpose instead of two) and the remaining temporary list may be sorted
by the current trip threshold value, like the trips_reached list, so
the additional notify_temp field in struct thermal_trip_desc is not
necessary any more.
Moreover, since the trips_reached and trips_high lists are sorted,
the "low" and "high" values needed by thermal_zone_set_trips() can be
determined in a straightforward way by looking at one end of each list.
Of course, additional work is needed in some places in order to
maintain the ordering of the lists, but it is limited to situations
that should be rare, like updating a trip point temperature or
hysteresis, thermal zone initialization, or system resume.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/2003443.usQuhbGJ8B@rjwysocki.net
[ rjw: Added a comment to thermal_zone_handle_trips() ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-10-16 13:35:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-18 21:01:14 +02:00
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-04 21:11:53 +02:00
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thermal: core: Add user thresholds support
The user thresholds mechanism is a way to have the userspace to tell
the thermal framework to send a notification when a temperature limit
is crossed. There is no id, no hysteresis, just the temperature and
the direction of the limit crossing. That means we can be notified
when a threshold is crossed the way up only, or the way down only or
both ways. That allows to create hysteresis values if it is needed.
A threshold can be added, deleted or flushed. The latter means all
thresholds belonging to a thermal zone will be deleted.
When a threshold is added:
- if the same threshold (temperature and direction) exists, an error
is returned
- if a threshold is specified with the same temperature but a
different direction, the specified direction is added
- if there is no threshold with the same temperature then it is
created
When a threshold is deleted:
- if the same threshold (temperature and direction) exists, it is
deleted
- if a threshold is specified with the same temperature but a
different direction, the specified direction is removed
- if there is no threshold with the same temperature, then an error
is returned
When the threshold are flushed:
- All thresholds related to a thermal zone are deleted
When a threshold is crossed:
- the userspace does not need to know which threshold(s) have been
crossed, it will be notified with the current temperature and the
previous temperature
- if multiple thresholds have been crossed between two updates only
one notification will be send to the userspace, it is pointless to
send a notification per thresholds crossed as the userspace can
handle that easily when it has the temperature delta information
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20240923100005.2532430-2-daniel.lezcano@linaro.org
[ rjw: Subject edit, use BIT(0) and BIT(1) in symbol definitions ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-09-23 11:59:57 +02:00
|
|
|
|
2024-04-02 20:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-11 00:05:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-11 00:07:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thermal: core: Allow thermal zones to tell the core to ignore them
The iwlwifi wireless driver registers a thermal zone that is only needed
when the network interface handled by it is up and it wants that thermal
zone to be effectively ignored by the core otherwise.
Before commit a8a261774466 ("thermal: core: Call monitor_thermal_zone()
if zone temperature is invalid") that could be achieved by returning
an error code from the thermal zone's .get_temp() callback because the
core did not really handle errors returned by it almost at all.
However, commit a8a261774466 made the core attempt to recover from the
situation in which the temperature of a thermal zone cannot be
determined due to errors returned by its .get_temp() and is always
invalid from the core's perspective.
That was done because there are thermal zones in which .get_temp()
returns errors to start with due to some difficulties related to the
initialization ordering, but then it will start to produce valid
temperature values at one point.
Unfortunately, the simple approach taken by commit a8a261774466,
which is to poll the thermal zone periodically until its .get_temp()
callback starts to return valid temperature values, is at odds with
the special thermal zone in iwlwifi in which .get_temp() may always
return an error because its network interface may always be down. If
that happens, every attempt to invoke the thermal zone's .get_temp()
callback resulting in an error causes the thermal core to print a
dev_warn() message to the kernel log which is super-noisy.
To address this problem, make the core handle the case in which
.get_temp() returns 0, but the temperature value returned by it
is not actually valid, in a special way. Namely, make the core
completely ignore the invalid temperature value coming from
.get_temp() in that case, which requires folding in
update_temperature() into its caller and a few related changes.
On the iwlwifi side, modify iwl_mvm_tzone_get_temp() to return 0
and put THERMAL_TEMP_INVALID into the temperature return memory
location instead of returning an error when the firmware is not
running or it is not of the right type.
Also, to clearly separate the handling of invalid temperature
values from the thermal zone initialization, introduce a special
THERMAL_TEMP_INIT value specifically for the latter purpose.
Fixes: a8a261774466 ("thermal: core: Call monitor_thermal_zone() if zone temperature is invalid")
Closes: https://lore.kernel.org/linux-pm/20240715044527.GA1544@sol.localdomain/
Reported-by: Eric Biggers <ebiggers@kernel.org>
Reported-by: Stefan Lippers-Hollmann <s.l-h@gmx.de>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=201761
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Tested-by: Stefan Lippers-Hollmann <s.l-h@gmx.de>
Cc: 6.10+ <stable@vger.kernel.org> # 6.10+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/4950004.31r3eYUQgx@rjwysocki.net
[ rjw: Rebased on top of the current mainline ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-07-17 21:45:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-28 14:10:03 +02:00
|
|
|
|
2024-07-18 21:01:14 +02:00
|
|
|
|
|
|
|
|
|
2024-06-28 14:10:03 +02:00
|
|
|
|
2024-07-18 21:01:14 +02:00
|
|
|
|
|
|
|
|
|
2024-06-28 14:10:03 +02:00
|
|
|
|
2020-04-02 16:27:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-09 14:44:08 +02:00
|
|
|
|
|
|
|
|
|
2020-04-02 16:27:39 +02:00
|
|
|
|
|
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-12 22:13:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-21 19:36:07 -07:00
|
|
|
|
2019-06-12 22:13:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-06 12:55:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-06 12:55:36 +02:00
|
|
|
|
|
|
|
|
|
2024-10-03 14:25:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-02 16:27:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-18 18:38:24 +01:00
|
|
|
|
2024-10-11 00:16:54 +02:00
|
|
|
|
2021-04-22 12:43:06 +01:00
|
|
|
|
2021-01-18 18:38:24 +01:00
|
|
|
|
2023-10-12 20:34:50 +02:00
|
|
|
|
2020-04-02 16:27:43 +02:00
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-21 19:52:44 +02:00
|
|
|
|
2015-10-30 16:31:47 +08:00
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-18 16:04:24 +00:00
|
|
|
|
|
|
|
|
|
2024-10-04 21:39:19 +02:00
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|
2015-02-18 16:04:21 +00:00
|
|
|
|
2023-03-17 18:01:26 +01:00
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|
|
|
|
|
|
2016-11-07 21:08:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-07 21:09:01 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-07 21:08:55 -08:00
|
|
|
|
2016-11-07 21:08:56 -08:00
|
|
|
|
2022-11-10 07:24:58 -08:00
|
|
|
|
|
|
|
|
|
2023-11-29 09:43:29 -03:00
|
|
|
|
2025-02-17 21:39:51 +01:00
|
|
|
|
2023-12-20 23:17:45 +00:00
|
|
|
|
|
|
|
|
|
2013-03-26 16:38:29 +08:00
|
|
|
|
2026-05-26 16:08:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-31 18:54:48 +02:00
|
|
|
|
2024-04-02 20:56:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-12 20:26:46 +02:00
|
|
|
|
2024-05-28 17:00:51 +02:00
|
|
|
|
|
|
|
|
|
2024-08-16 10:12:32 +02:00
|
|
|
|
2023-12-15 20:53:52 +01:00
|
|
|
|
2023-09-21 19:52:44 +02:00
|
|
|
|
2022-08-05 17:38:34 +02:00
|
|
|
|
2024-07-29 18:27:25 +02:00
|
|
|
|
|
|
|
|
|
2020-03-31 18:54:48 +02:00
|
|
|
|
2016-11-07 21:09:00 -08:00
|
|
|
|
2024-02-22 18:30:49 +01:00
|
|
|
|
2017-08-08 16:39:52 +02:00
|
|
|
|
2016-11-07 21:09:02 -08:00
|
|
|
|
2018-04-02 16:26:25 +05:30
|
|
|
|
2023-03-17 18:01:26 +01:00
|
|
|
|
2016-11-07 21:09:02 -08:00
|
|
|
|
2018-04-03 15:19:03 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-07 21:09:00 -08:00
|
|
|
|
2018-04-02 16:26:25 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-18 11:04:53 +05:30
|
|
|
|