Skip to content

Commit 8c35b1f

Browse files
committed
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: Rafael J. Wysocki <[email protected]> Reviewed-by: Daniel Lezcano <[email protected]>
1 parent fdcf70e commit 8c35b1f

File tree

9 files changed

+51
-45
lines changed

9 files changed

+51
-45
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
#include "thermal_core.h"
1515

16-
static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_index)
16+
static int thermal_zone_trip_update(struct thermal_zone_device *tz,
17+
const struct thermal_trip *trip)
1718
{
18-
const struct thermal_trip *trip = &tz->trips[trip_index];
19+
int trip_index = thermal_zone_trip_id(tz, trip);
1920
struct thermal_instance *instance;
2021

2122
if (!trip->hysteresis)
@@ -89,7 +90,8 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_ind
8990
* (trip_temp - hyst) so that the fan gets turned off again.
9091
*
9192
*/
92-
static int bang_bang_control(struct thermal_zone_device *tz, int trip)
93+
static int bang_bang_control(struct thermal_zone_device *tz,
94+
const struct thermal_trip *trip)
9395
{
9496
struct thermal_instance *instance;
9597
int ret;

drivers/thermal/gov_fair_share.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static long get_target_state(struct thermal_zone_device *tz,
4747
/**
4848
* fair_share_throttle - throttles devices associated with the given zone
4949
* @tz: thermal_zone_device
50-
* @trip_index: trip point index
50+
* @trip: trip point
5151
*
5252
* Throttling Logic: This uses three parameters to calculate the new
5353
* 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,
6363
* (Heavily assumes the trip points are in ascending order)
6464
* new_state of cooling device = P3 * P2 * P1
6565
*/
66-
static int fair_share_throttle(struct thermal_zone_device *tz, int trip_index)
66+
static int fair_share_throttle(struct thermal_zone_device *tz,
67+
const struct thermal_trip *trip)
6768
{
68-
const struct thermal_trip *trip = &tz->trips[trip_index];
6969
struct thermal_instance *instance;
7070
int total_weight = 0;
7171
int total_instance = 0;

drivers/thermal/gov_power_allocator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,10 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
676676
tz->governor_data = NULL;
677677
}
678678

679-
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_index)
679+
static int power_allocator_throttle(struct thermal_zone_device *tz,
680+
const struct thermal_trip *trip)
680681
{
681682
struct power_allocator_params *params = tz->governor_data;
682-
const struct thermal_trip *trip = &tz->trips[trip_index];
683683
bool update;
684684

685685
lockdep_assert_held(&tz->lock);

drivers/thermal/gov_step_wise.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ static unsigned long get_target_state(struct thermal_instance *instance,
6868
return next_target;
6969
}
7070

71-
static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
71+
static void thermal_zone_trip_update(struct thermal_zone_device *tz,
72+
const struct thermal_trip *trip)
7273
{
73-
const struct thermal_trip *trip = &tz->trips[trip_id];
74+
int trip_id = thermal_zone_trip_id(tz, trip);
7475
enum thermal_trend trend;
7576
struct thermal_instance *instance;
7677
bool throttle = false;
7778
int old_target;
7879

79-
trend = get_tz_trend(tz, trip_id);
80+
trend = get_tz_trend(tz, trip);
8081

8182
if (tz->temperature >= trip->temperature) {
8283
throttle = true;
@@ -120,15 +121,16 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id
120121
/**
121122
* step_wise_throttle - throttles devices associated with the given zone
122123
* @tz: thermal_zone_device
123-
* @trip: trip point index
124+
* @trip: trip point
124125
*
125126
* Throttling Logic: This uses the trend of the thermal zone to throttle.
126127
* If the thermal zone is 'heating up' this throttles all the cooling
127128
* devices associated with the zone and its particular trip point, by one
128129
* step. If the zone is 'cooling down' it brings back the performance of
129130
* the devices by one step.
130131
*/
131-
static int step_wise_throttle(struct thermal_zone_device *tz, int trip)
132+
static int step_wise_throttle(struct thermal_zone_device *tz,
133+
const struct thermal_trip *trip)
132134
{
133135
struct thermal_instance *instance;
134136

drivers/thermal/gov_user_space.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ static int user_space_bind(struct thermal_zone_device *tz)
2525
/**
2626
* notify_user_space - Notifies user space about thermal events
2727
* @tz: thermal_zone_device
28-
* @trip: trip point index
28+
* @trip: trip point
2929
*
3030
* This function notifies the user space through UEvents.
3131
*/
32-
static int notify_user_space(struct thermal_zone_device *tz, int trip)
32+
static int notify_user_space(struct thermal_zone_device *tz,
33+
const struct thermal_trip *trip)
3334
{
3435
char *thermal_prop[5];
3536
int i;
@@ -38,7 +39,8 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip)
3839

3940
thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
4041
thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
41-
thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
42+
thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d",
43+
thermal_zone_trip_id(tz, trip));
4244
thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
4345
thermal_prop[4] = NULL;
4446
kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);

drivers/thermal/thermal_core.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
307307
thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
308308
}
309309

310-
static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip)
310+
static void handle_non_critical_trips(struct thermal_zone_device *tz,
311+
const struct thermal_trip *trip)
311312
{
312313
tz->governor ? tz->governor->throttle(tz, trip) :
313314
def_governor->throttle(tz, trip);
@@ -329,44 +330,43 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz)
329330
EXPORT_SYMBOL(thermal_zone_device_critical);
330331

331332
static void handle_critical_trips(struct thermal_zone_device *tz,
332-
int trip, int trip_temp, enum thermal_trip_type trip_type)
333+
const struct thermal_trip *trip)
333334
{
334335
/* If we have not crossed the trip_temp, we do not care. */
335-
if (trip_temp <= 0 || tz->temperature < trip_temp)
336+
if (trip->temperature <= 0 || tz->temperature < trip->temperature)
336337
return;
337338

338-
trace_thermal_zone_trip(tz, trip, trip_type);
339+
trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type);
339340

340-
if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
341-
tz->ops->hot(tz);
342-
else if (trip_type == THERMAL_TRIP_CRITICAL)
341+
if (trip->type == THERMAL_TRIP_CRITICAL)
343342
tz->ops->critical(tz);
343+
else if (tz->ops->hot)
344+
tz->ops->hot(tz);
344345
}
345346

346-
static void handle_thermal_trip(struct thermal_zone_device *tz, int trip_id)
347+
static void handle_thermal_trip(struct thermal_zone_device *tz,
348+
const struct thermal_trip *trip)
347349
{
348-
struct thermal_trip trip;
349-
350-
__thermal_zone_get_trip(tz, trip_id, &trip);
351-
352-
if (trip.temperature == THERMAL_TEMP_INVALID)
350+
if (trip->temperature == THERMAL_TEMP_INVALID)
353351
return;
354352

355353
if (tz->last_temperature != THERMAL_TEMP_INVALID) {
356-
if (tz->last_temperature < trip.temperature &&
357-
tz->temperature >= trip.temperature)
358-
thermal_notify_tz_trip_up(tz->id, trip_id,
354+
if (tz->last_temperature < trip->temperature &&
355+
tz->temperature >= trip->temperature)
356+
thermal_notify_tz_trip_up(tz->id,
357+
thermal_zone_trip_id(tz, trip),
359358
tz->temperature);
360-
if (tz->last_temperature >= trip.temperature &&
361-
tz->temperature < (trip.temperature - trip.hysteresis))
362-
thermal_notify_tz_trip_down(tz->id, trip_id,
359+
if (tz->last_temperature >= trip->temperature &&
360+
tz->temperature < trip->temperature - trip->hysteresis)
361+
thermal_notify_tz_trip_down(tz->id,
362+
thermal_zone_trip_id(tz, trip),
363363
tz->temperature);
364364
}
365365

366-
if (trip.type == THERMAL_TRIP_CRITICAL || trip.type == THERMAL_TRIP_HOT)
367-
handle_critical_trips(tz, trip_id, trip.temperature, trip.type);
366+
if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT)
367+
handle_critical_trips(tz, trip);
368368
else
369-
handle_non_critical_trips(tz, trip_id);
369+
handle_non_critical_trips(tz, trip);
370370
}
371371

372372
static void update_temperature(struct thermal_zone_device *tz)
@@ -403,7 +403,7 @@ static void thermal_zone_device_init(struct thermal_zone_device *tz)
403403
void __thermal_zone_device_update(struct thermal_zone_device *tz,
404404
enum thermal_notify_event event)
405405
{
406-
int count;
406+
const struct thermal_trip *trip;
407407

408408
if (atomic_read(&in_suspend))
409409
return;
@@ -422,8 +422,8 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
422422

423423
tz->notify_event = event;
424424

425-
for (count = 0; count < tz->num_trips; count++)
426-
handle_thermal_trip(tz, count);
425+
for_each_trip(tz, trip)
426+
handle_thermal_trip(tz, trip);
427427

428428
monitor_thermal_zone(tz);
429429
}

drivers/thermal/thermal_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
7070
void thermal_cdev_update(struct thermal_cooling_device *);
7171
void __thermal_cdev_update(struct thermal_cooling_device *cdev);
7272

73-
int get_tz_trend(struct thermal_zone_device *tz, int trip_index);
73+
int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip);
7474

7575
struct thermal_instance *
7676
get_thermal_instance(struct thermal_zone_device *tz,

drivers/thermal/thermal_helpers.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
#include "thermal_core.h"
2323
#include "thermal_trace.h"
2424

25-
int get_tz_trend(struct thermal_zone_device *tz, int trip_index)
25+
int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip)
2626
{
27-
struct thermal_trip *trip = tz->trips ? &tz->trips[trip_index] : NULL;
2827
enum thermal_trend trend;
2928

3029
if (tz->emul_temperature || !tz->ops->get_trend ||

include/linux/thermal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ struct thermal_governor {
199199
char name[THERMAL_NAME_LENGTH];
200200
int (*bind_to_tz)(struct thermal_zone_device *tz);
201201
void (*unbind_from_tz)(struct thermal_zone_device *tz);
202-
int (*throttle)(struct thermal_zone_device *tz, int trip);
202+
int (*throttle)(struct thermal_zone_device *tz,
203+
const struct thermal_trip *trip);
203204
struct list_head governor_list;
204205
};
205206

0 commit comments

Comments
 (0)