Commit 8c35b1f4 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

thermal: core: Pass trip pointer to governor throttle callback

Modify the governor .throttle() callback definition so that it takes a
trip pointer instead of a trip index as its second argument, adjust the
governors accordingly and update the core code invoking .throttle().

This causes the governors to become independent of the representation
of the list of trips in the thermal zone structure.

This change is not expected to alter the general functionality.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent fdcf70ed
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
#include "thermal_core.h" #include "thermal_core.h"
static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_index) static int thermal_zone_trip_update(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
const struct thermal_trip *trip = &tz->trips[trip_index]; int trip_index = thermal_zone_trip_id(tz, trip);
struct thermal_instance *instance; struct thermal_instance *instance;
if (!trip->hysteresis) if (!trip->hysteresis)
...@@ -89,7 +90,8 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_ind ...@@ -89,7 +90,8 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_ind
* (trip_temp - hyst) so that the fan gets turned off again. * (trip_temp - hyst) so that the fan gets turned off again.
* *
*/ */
static int bang_bang_control(struct thermal_zone_device *tz, int trip) static int bang_bang_control(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
struct thermal_instance *instance; struct thermal_instance *instance;
int ret; int ret;
......
...@@ -47,7 +47,7 @@ static long get_target_state(struct thermal_zone_device *tz, ...@@ -47,7 +47,7 @@ static long get_target_state(struct thermal_zone_device *tz,
/** /**
* fair_share_throttle - throttles devices associated with the given zone * fair_share_throttle - throttles devices associated with the given zone
* @tz: thermal_zone_device * @tz: thermal_zone_device
* @trip_index: trip point index * @trip: trip point
* *
* Throttling Logic: This uses three parameters to calculate the new * Throttling Logic: This uses three parameters to calculate the new
* throttle state of the cooling devices associated with the given zone. * throttle state of the cooling devices associated with the given zone.
...@@ -63,9 +63,9 @@ static long get_target_state(struct thermal_zone_device *tz, ...@@ -63,9 +63,9 @@ static long get_target_state(struct thermal_zone_device *tz,
* (Heavily assumes the trip points are in ascending order) * (Heavily assumes the trip points are in ascending order)
* new_state of cooling device = P3 * P2 * P1 * new_state of cooling device = P3 * P2 * P1
*/ */
static int fair_share_throttle(struct thermal_zone_device *tz, int trip_index) static int fair_share_throttle(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
const struct thermal_trip *trip = &tz->trips[trip_index];
struct thermal_instance *instance; struct thermal_instance *instance;
int total_weight = 0; int total_weight = 0;
int total_instance = 0; int total_instance = 0;
......
...@@ -676,10 +676,10 @@ static void power_allocator_unbind(struct thermal_zone_device *tz) ...@@ -676,10 +676,10 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
tz->governor_data = NULL; tz->governor_data = NULL;
} }
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_index) static int power_allocator_throttle(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
struct power_allocator_params *params = tz->governor_data; struct power_allocator_params *params = tz->governor_data;
const struct thermal_trip *trip = &tz->trips[trip_index];
bool update; bool update;
lockdep_assert_held(&tz->lock); lockdep_assert_held(&tz->lock);
......
...@@ -68,15 +68,16 @@ static unsigned long get_target_state(struct thermal_instance *instance, ...@@ -68,15 +68,16 @@ static unsigned long get_target_state(struct thermal_instance *instance,
return next_target; return next_target;
} }
static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id) static void thermal_zone_trip_update(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
const struct thermal_trip *trip = &tz->trips[trip_id]; int trip_id = thermal_zone_trip_id(tz, trip);
enum thermal_trend trend; enum thermal_trend trend;
struct thermal_instance *instance; struct thermal_instance *instance;
bool throttle = false; bool throttle = false;
int old_target; int old_target;
trend = get_tz_trend(tz, trip_id); trend = get_tz_trend(tz, trip);
if (tz->temperature >= trip->temperature) { if (tz->temperature >= trip->temperature) {
throttle = true; throttle = true;
...@@ -120,7 +121,7 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id ...@@ -120,7 +121,7 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id
/** /**
* step_wise_throttle - throttles devices associated with the given zone * step_wise_throttle - throttles devices associated with the given zone
* @tz: thermal_zone_device * @tz: thermal_zone_device
* @trip: trip point index * @trip: trip point
* *
* Throttling Logic: This uses the trend of the thermal zone to throttle. * Throttling Logic: This uses the trend of the thermal zone to throttle.
* If the thermal zone is 'heating up' this throttles all the cooling * If the thermal zone is 'heating up' this throttles all the cooling
...@@ -128,7 +129,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id ...@@ -128,7 +129,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id
* step. If the zone is 'cooling down' it brings back the performance of * step. If the zone is 'cooling down' it brings back the performance of
* the devices by one step. * the devices by one step.
*/ */
static int step_wise_throttle(struct thermal_zone_device *tz, int trip) static int step_wise_throttle(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
struct thermal_instance *instance; struct thermal_instance *instance;
......
...@@ -25,11 +25,12 @@ static int user_space_bind(struct thermal_zone_device *tz) ...@@ -25,11 +25,12 @@ static int user_space_bind(struct thermal_zone_device *tz)
/** /**
* notify_user_space - Notifies user space about thermal events * notify_user_space - Notifies user space about thermal events
* @tz: thermal_zone_device * @tz: thermal_zone_device
* @trip: trip point index * @trip: trip point
* *
* This function notifies the user space through UEvents. * This function notifies the user space through UEvents.
*/ */
static int notify_user_space(struct thermal_zone_device *tz, int trip) static int notify_user_space(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
char *thermal_prop[5]; char *thermal_prop[5];
int i; int i;
...@@ -38,7 +39,8 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip) ...@@ -38,7 +39,8 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip)
thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type); thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature); thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip); thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d",
thermal_zone_trip_id(tz, trip));
thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event); thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
thermal_prop[4] = NULL; thermal_prop[4] = NULL;
kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop); kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
......
...@@ -307,7 +307,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz) ...@@ -307,7 +307,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
} }
static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip) static void handle_non_critical_trips(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
tz->governor ? tz->governor->throttle(tz, trip) : tz->governor ? tz->governor->throttle(tz, trip) :
def_governor->throttle(tz, trip); def_governor->throttle(tz, trip);
...@@ -329,44 +330,43 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz) ...@@ -329,44 +330,43 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz)
EXPORT_SYMBOL(thermal_zone_device_critical); EXPORT_SYMBOL(thermal_zone_device_critical);
static void handle_critical_trips(struct thermal_zone_device *tz, static void handle_critical_trips(struct thermal_zone_device *tz,
int trip, int trip_temp, enum thermal_trip_type trip_type) const struct thermal_trip *trip)
{ {
/* If we have not crossed the trip_temp, we do not care. */ /* If we have not crossed the trip_temp, we do not care. */
if (trip_temp <= 0 || tz->temperature < trip_temp) if (trip->temperature <= 0 || tz->temperature < trip->temperature)
return; return;
trace_thermal_zone_trip(tz, trip, trip_type); trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type);
if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) if (trip->type == THERMAL_TRIP_CRITICAL)
tz->ops->hot(tz);
else if (trip_type == THERMAL_TRIP_CRITICAL)
tz->ops->critical(tz); tz->ops->critical(tz);
else if (tz->ops->hot)
tz->ops->hot(tz);
} }
static void handle_thermal_trip(struct thermal_zone_device *tz, int trip_id) static void handle_thermal_trip(struct thermal_zone_device *tz,
const struct thermal_trip *trip)
{ {
struct thermal_trip trip; if (trip->temperature == THERMAL_TEMP_INVALID)
__thermal_zone_get_trip(tz, trip_id, &trip);
if (trip.temperature == THERMAL_TEMP_INVALID)
return; return;
if (tz->last_temperature != THERMAL_TEMP_INVALID) { if (tz->last_temperature != THERMAL_TEMP_INVALID) {
if (tz->last_temperature < trip.temperature && if (tz->last_temperature < trip->temperature &&
tz->temperature >= trip.temperature) tz->temperature >= trip->temperature)
thermal_notify_tz_trip_up(tz->id, trip_id, thermal_notify_tz_trip_up(tz->id,
thermal_zone_trip_id(tz, trip),
tz->temperature); tz->temperature);
if (tz->last_temperature >= trip.temperature && if (tz->last_temperature >= trip->temperature &&
tz->temperature < (trip.temperature - trip.hysteresis)) tz->temperature < trip->temperature - trip->hysteresis)
thermal_notify_tz_trip_down(tz->id, trip_id, thermal_notify_tz_trip_down(tz->id,
thermal_zone_trip_id(tz, trip),
tz->temperature); tz->temperature);
} }
if (trip.type == THERMAL_TRIP_CRITICAL || trip.type == THERMAL_TRIP_HOT) if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT)
handle_critical_trips(tz, trip_id, trip.temperature, trip.type); handle_critical_trips(tz, trip);
else else
handle_non_critical_trips(tz, trip_id); handle_non_critical_trips(tz, trip);
} }
static void update_temperature(struct thermal_zone_device *tz) static void update_temperature(struct thermal_zone_device *tz)
...@@ -403,7 +403,7 @@ static void thermal_zone_device_init(struct thermal_zone_device *tz) ...@@ -403,7 +403,7 @@ static void thermal_zone_device_init(struct thermal_zone_device *tz)
void __thermal_zone_device_update(struct thermal_zone_device *tz, void __thermal_zone_device_update(struct thermal_zone_device *tz,
enum thermal_notify_event event) enum thermal_notify_event event)
{ {
int count; const struct thermal_trip *trip;
if (atomic_read(&in_suspend)) if (atomic_read(&in_suspend))
return; return;
...@@ -422,8 +422,8 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz, ...@@ -422,8 +422,8 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
tz->notify_event = event; tz->notify_event = event;
for (count = 0; count < tz->num_trips; count++) for_each_trip(tz, trip)
handle_thermal_trip(tz, count); handle_thermal_trip(tz, trip);
monitor_thermal_zone(tz); monitor_thermal_zone(tz);
} }
......
...@@ -70,7 +70,7 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev) ...@@ -70,7 +70,7 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
void thermal_cdev_update(struct thermal_cooling_device *); void thermal_cdev_update(struct thermal_cooling_device *);
void __thermal_cdev_update(struct thermal_cooling_device *cdev); void __thermal_cdev_update(struct thermal_cooling_device *cdev);
int get_tz_trend(struct thermal_zone_device *tz, int trip_index); int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip);
struct thermal_instance * struct thermal_instance *
get_thermal_instance(struct thermal_zone_device *tz, get_thermal_instance(struct thermal_zone_device *tz,
......
...@@ -22,9 +22,8 @@ ...@@ -22,9 +22,8 @@
#include "thermal_core.h" #include "thermal_core.h"
#include "thermal_trace.h" #include "thermal_trace.h"
int get_tz_trend(struct thermal_zone_device *tz, int trip_index) int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip)
{ {
struct thermal_trip *trip = tz->trips ? &tz->trips[trip_index] : NULL;
enum thermal_trend trend; enum thermal_trend trend;
if (tz->emul_temperature || !tz->ops->get_trend || if (tz->emul_temperature || !tz->ops->get_trend ||
......
...@@ -199,7 +199,8 @@ struct thermal_governor { ...@@ -199,7 +199,8 @@ struct thermal_governor {
char name[THERMAL_NAME_LENGTH]; char name[THERMAL_NAME_LENGTH];
int (*bind_to_tz)(struct thermal_zone_device *tz); int (*bind_to_tz)(struct thermal_zone_device *tz);
void (*unbind_from_tz)(struct thermal_zone_device *tz); void (*unbind_from_tz)(struct thermal_zone_device *tz);
int (*throttle)(struct thermal_zone_device *tz, int trip); int (*throttle)(struct thermal_zone_device *tz,
const struct thermal_trip *trip);
struct list_head governor_list; struct list_head governor_list;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment