Re: [PATCH v2] thermal: add sysfs_notify on some attributes

From: Pandruvada, Srinivas
Date: Tue Mar 15 2016 - 19:08:07 EST


On Mon, 2016-03-14 at 11:12 -0700, Srikar Srimath Tirumala wrote:
> Add a sysfs_notify on thermal_zone*/temp and cooling_device*/
> cur_state whenever any trip is triggered or cur state is changed.
>
> This change allows usermode apps to register themselves to get
> notified, when certain thermal conditions occur and reduce their
> workload. This workload throttling allows usermode to react before
> hardware clocks are throttled and keep some critical apps running
> reliably longer.
I think we need a combination of proposal inÂ
https://patchwork.kernel.org/patch/7876351/Âand this.

For example this patch notifies that some trip is violated, but that is
not enough for user space application to take any action. Some trips
violations user space may not care as this may be a transient one. The
patch fromÂEduardo address that by providing trip, temperature and last
temperature information. But that patch only address hot trips. I
understand why Eduardo doesn't want to be notified for passive trips as
there will be too many.

So IMO we need some mechanism to turn off notification and decide what
notification will result in user space notifications.
On some x86 systems we have 10+ passive/active trips, this will results
in too many notifications. We may be in thermally sensitive zone, where
more code excecution is more heat.

We may have some mask of trips for which will result in notifications.
By default no notifications, unless some user space requests.

During last LPC we discussed about using IIO for temperature threshold
notifications and I submitted multiple changes for that. Looks like we
also care of trip point changes. So I think we need more comprehensive
mechanism to address this.

May be we should have thermal mini summit during LPC again and decide a
comprehensive plan to address all asynchronous thermal notifications.


Thanks,
Srinivas

>
> Signed-off-by: Srikar Srimath Tirumala <srikars@xxxxxxxxxx>
> ---
>
> Changes from v1:
> Â- Calling sysfs_notify for thermal_zone*/temp only when there is a
> ÂÂÂtrip violated on the thermal zone.
> Â- Modified commit message.
>
> Âdrivers/thermal/thermal_core.c | 34 ++++++++++++++++++++++++++----
> ----
> Â1 file changed, 26 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/thermal/thermal_core.c
> b/drivers/thermal/thermal_core.c
> index a0a8fd1..f54519e 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -419,14 +419,23 @@ static void monitor_thermal_zone(struct
> thermal_zone_device *tz)
> Â mutex_unlock(&tz->lock);
> Â}
> Â
> -static void handle_non_critical_trips(struct thermal_zone_device
> *tz,
> +static int handle_non_critical_trips(struct thermal_zone_device *tz,
> Â int trip, enum thermal_trip_type trip_type)
> Â{
> + int trip_temp;
> + int ret = 0;
> +
> Â tz->governor ? tz->governor->throttle(tz, trip) :
> Â ÂÂÂÂÂÂÂdef_governor->throttle(tz, trip);
> +
> + tz->ops->get_trip_temp(tz, trip, &trip_temp);
> + if (tz->temperature >= trip_temp)
> + ret = 1;
> +
> + return ret;
> Â}
> Â
> -static void handle_critical_trips(struct thermal_zone_device *tz,
> +static int handle_critical_trips(struct thermal_zone_device *tz,
> Â int trip, enum thermal_trip_type
> trip_type)
> Â{
> Â int trip_temp;
> @@ -435,7 +444,7 @@ static void handle_critical_trips(struct
> thermal_zone_device *tz,
> Â
> Â /* If we have not crossed the trip_temp, we do not care. */
> Â if (trip_temp <= 0 || tz->temperature < trip_temp)
> - return;
> + return 0;
> Â
> Â trace_thermal_zone_trip(tz, trip, trip_type);
> Â
> @@ -448,23 +457,28 @@ static void handle_critical_trips(struct
> thermal_zone_device *tz,
> Â ÂÂtz->temperature / 1000);
> Â orderly_poweroff(true);
> Â }
> +
> + return 1;
> Â}
> Â
> -static void handle_thermal_trip(struct thermal_zone_device *tz, int
> trip)
> +static int handle_thermal_trip(struct thermal_zone_device *tz, int
> trip)
> Â{
> + int ret = 0;
> Â enum thermal_trip_type type;
> Â
> Â tz->ops->get_trip_type(tz, trip, &type);
> Â
> Â if (type == THERMAL_TRIP_CRITICAL || type ==
> THERMAL_TRIP_HOT)
> - handle_critical_trips(tz, trip, type);
> + ret = handle_critical_trips(tz, trip, type);
> Â else
> - handle_non_critical_trips(tz, trip, type);
> + ret = handle_non_critical_trips(tz, trip, type);
> Â /*
> Â Â* Alright, we handled this trip successfully.
> Â Â* So, start monitoring again.
> Â Â*/
> Â monitor_thermal_zone(tz);
> +
> + return ret;
> Â}
> Â
> Â/**
> @@ -556,7 +570,7 @@ static void thermal_zone_device_reset(struct
> thermal_zone_device *tz)
> Âvoid thermal_zone_device_update(struct thermal_zone_device *tz)
> Â{
> Â int count;
> -
> + int trips = 0;
> Â if (atomic_read(&in_suspend))
> Â return;
> Â
> @@ -566,7 +580,10 @@ void thermal_zone_device_update(struct
> thermal_zone_device *tz)
> Â update_temperature(tz);
> Â
> Â for (count = 0; count < tz->trips; count++)
> - handle_thermal_trip(tz, count);
> + trips += handle_thermal_trip(tz, count);
> +
> + if (trips)
> + sysfs_notify(&tz->device.kobj, NULL, "temp");
> Â}
> ÂEXPORT_SYMBOL_GPL(thermal_zone_device_update);
> Â
> @@ -1638,6 +1655,7 @@ void thermal_cdev_update(struct
> thermal_cooling_device *cdev)
> Â cdev->updated = true;
> Â trace_cdev_update(cdev, target);
> Â dev_dbg(&cdev->device, "set to state %lu\n", target);
> + sysfs_notify(&cdev->device.kobj, NULL, "cur_state");
> Â}
> ÂEXPORT_SYMBOL(thermal_cdev_update);
> Â