Skip to content

Commit daeeb03

Browse files
committed
thermal: core: Move threshold out of struct thermal_trip
The threshold field in struct thermal_trip is only used internally by the thermal core and it is better to prevent drivers from misusing it. It also takes some space unnecessarily in the trip tables passed by drivers to the core during thermal zone registration. For this reason, introduce struct thermal_trip_desc as a wrapper around struct thermal_trip, move the threshold field directly into it and make the thermal core store struct thermal_trip_desc objects in the internal thermal zone trip tables. Adjust all of the code using trip tables in the thermal core accordingly. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]>
1 parent 053b852 commit daeeb03

File tree

10 files changed

+78
-52
lines changed

10 files changed

+78
-52
lines changed

drivers/thermal/gov_fair_share.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
static int get_trip_level(struct thermal_zone_device *tz)
1919
{
20-
const struct thermal_trip *trip, *level_trip = NULL;
20+
const struct thermal_trip *level_trip = NULL;
21+
const struct thermal_trip_desc *td;
2122
int trip_level = -1;
2223

23-
for_each_trip(tz, trip) {
24+
for_each_trip_desc(tz, td) {
25+
const struct thermal_trip *trip = &td->trip;
26+
2427
if (trip->temperature >= tz->temperature)
2528
continue;
2629

drivers/thermal/gov_power_allocator.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,11 @@ static void get_governor_trips(struct thermal_zone_device *tz,
496496
const struct thermal_trip *first_passive = NULL;
497497
const struct thermal_trip *last_passive = NULL;
498498
const struct thermal_trip *last_active = NULL;
499-
const struct thermal_trip *trip;
499+
const struct thermal_trip_desc *td;
500+
501+
for_each_trip_desc(tz, td) {
502+
const struct thermal_trip *trip = &td->trip;
500503

501-
for_each_trip(tz, trip) {
502504
switch (trip->type) {
503505
case THERMAL_TRIP_PASSIVE:
504506
if (!first_passive) {

drivers/thermal/thermal_core.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,19 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
361361
}
362362

363363
static void handle_thermal_trip(struct thermal_zone_device *tz,
364-
struct thermal_trip *trip)
364+
struct thermal_trip_desc *td)
365365
{
366+
const struct thermal_trip *trip = &td->trip;
367+
366368
if (trip->temperature == THERMAL_TEMP_INVALID)
367369
return;
368370

369371
if (tz->last_temperature == THERMAL_TEMP_INVALID) {
370372
/* Initialization. */
371-
trip->threshold = trip->temperature;
372-
if (tz->temperature >= trip->threshold)
373-
trip->threshold -= trip->hysteresis;
374-
} else if (tz->last_temperature < trip->threshold) {
373+
td->threshold = trip->temperature;
374+
if (tz->temperature >= td->threshold)
375+
td->threshold -= trip->hysteresis;
376+
} else if (tz->last_temperature < td->threshold) {
375377
/*
376378
* The trip threshold is equal to the trip temperature, unless
377379
* the latter has changed in the meantime. In either case,
@@ -382,9 +384,9 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
382384
if (tz->temperature >= trip->temperature) {
383385
thermal_notify_tz_trip_up(tz, trip);
384386
thermal_debug_tz_trip_up(tz, trip);
385-
trip->threshold = trip->temperature - trip->hysteresis;
387+
td->threshold = trip->temperature - trip->hysteresis;
386388
} else {
387-
trip->threshold = trip->temperature;
389+
td->threshold = trip->temperature;
388390
}
389391
} else {
390392
/*
@@ -400,9 +402,9 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
400402
if (tz->temperature < trip->temperature - trip->hysteresis) {
401403
thermal_notify_tz_trip_down(tz, trip);
402404
thermal_debug_tz_trip_down(tz, trip);
403-
trip->threshold = trip->temperature;
405+
td->threshold = trip->temperature;
404406
} else {
405-
trip->threshold = trip->temperature - trip->hysteresis;
407+
td->threshold = trip->temperature - trip->hysteresis;
406408
}
407409
}
408410

@@ -458,7 +460,7 @@ static void thermal_zone_device_init(struct thermal_zone_device *tz)
458460
void __thermal_zone_device_update(struct thermal_zone_device *tz,
459461
enum thermal_notify_event event)
460462
{
461-
struct thermal_trip *trip;
463+
struct thermal_trip_desc *td;
462464

463465
if (tz->suspended)
464466
return;
@@ -472,8 +474,8 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
472474

473475
tz->notify_event = event;
474476

475-
for_each_trip(tz, trip)
476-
handle_thermal_trip(tz, trip);
477+
for_each_trip_desc(tz, td)
478+
handle_thermal_trip(tz, td);
477479

478480
monitor_thermal_zone(tz);
479481
}
@@ -766,7 +768,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
766768
if (trip_index < 0 || trip_index >= tz->num_trips)
767769
return -EINVAL;
768770

769-
return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev,
771+
return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index].trip, cdev,
770772
upper, lower, weight);
771773
}
772774
EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
@@ -825,7 +827,7 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
825827
if (trip_index < 0 || trip_index >= tz->num_trips)
826828
return -EINVAL;
827829

828-
return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev);
830+
return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index].trip, cdev);
829831
}
830832
EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);
831833

@@ -1221,16 +1223,19 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms
12211223

12221224
int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp)
12231225
{
1224-
int i, ret = -EINVAL;
1226+
const struct thermal_trip_desc *td;
1227+
int ret = -EINVAL;
12251228

12261229
if (tz->ops.get_crit_temp)
12271230
return tz->ops.get_crit_temp(tz, temp);
12281231

12291232
mutex_lock(&tz->lock);
12301233

1231-
for (i = 0; i < tz->num_trips; i++) {
1232-
if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
1233-
*temp = tz->trips[i].temperature;
1234+
for_each_trip_desc(tz, td) {
1235+
const struct thermal_trip *trip = &td->trip;
1236+
1237+
if (trip->type == THERMAL_TRIP_CRITICAL) {
1238+
*temp = trip->temperature;
12341239
ret = 0;
12351240
break;
12361241
}
@@ -1274,7 +1279,9 @@ thermal_zone_device_register_with_trips(const char *type,
12741279
const struct thermal_zone_params *tzp,
12751280
int passive_delay, int polling_delay)
12761281
{
1282+
const struct thermal_trip *trip = trips;
12771283
struct thermal_zone_device *tz;
1284+
struct thermal_trip_desc *td;
12781285
int id;
12791286
int result;
12801287
struct thermal_governor *governor;
@@ -1339,7 +1346,8 @@ thermal_zone_device_register_with_trips(const char *type,
13391346
tz->device.class = thermal_class;
13401347
tz->devdata = devdata;
13411348
tz->num_trips = num_trips;
1342-
memcpy(tz->trips, trips, num_trips * sizeof(*trips));
1349+
for_each_trip_desc(tz, td)
1350+
td->trip = *trip++;
13431351

13441352
thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
13451353
thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);

drivers/thermal/thermal_core.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ void thermal_governor_update_tz(struct thermal_zone_device *tz,
120120
enum thermal_notify_event reason);
121121

122122
/* Helpers */
123-
#define for_each_trip(__tz, __trip) \
124-
for (__trip = __tz->trips; __trip - __tz->trips < __tz->num_trips; __trip++)
123+
#define for_each_trip_desc(__tz, __td) \
124+
for (__td = __tz->trips; __td - __tz->trips < __tz->num_trips; __td++)
125+
126+
#define trip_to_trip_desc(__trip) \
127+
container_of(__trip, struct thermal_trip_desc, trip)
125128

126129
void __thermal_zone_set_trips(struct thermal_zone_device *tz);
127130
int thermal_zone_trip_id(const struct thermal_zone_device *tz,

drivers/thermal/thermal_debugfs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ static void tze_seq_stop(struct seq_file *s, void *v)
744744
static int tze_seq_show(struct seq_file *s, void *v)
745745
{
746746
struct thermal_zone_device *tz = s->private;
747-
struct thermal_trip *trip;
747+
struct thermal_trip_desc *td;
748748
struct tz_episode *tze;
749749
const char *type;
750750
int trip_id;
@@ -757,7 +757,9 @@ static int tze_seq_show(struct seq_file *s, void *v)
757757

758758
seq_printf(s, "| trip | type | temp(°mC) | hyst(°mC) | duration | avg(°mC) | min(°mC) | max(°mC) |\n");
759759

760-
for_each_trip(tz, trip) {
760+
for_each_trip_desc(tz, td) {
761+
const struct thermal_trip *trip = &td->trip;
762+
761763
/*
762764
* There is no possible mitigation happening at the
763765
* critical trip point, so the stats will be always

drivers/thermal/thermal_helpers.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ get_thermal_instance(struct thermal_zone_device *tz,
5050
mutex_lock(&tz->lock);
5151
mutex_lock(&cdev->lock);
5252

53-
trip = &tz->trips[trip_index];
53+
trip = &tz->trips[trip_index].trip;
5454

5555
list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
5656
if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
@@ -82,7 +82,7 @@ EXPORT_SYMBOL(get_thermal_instance);
8282
*/
8383
int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
8484
{
85-
const struct thermal_trip *trip;
85+
const struct thermal_trip_desc *td;
8686
int crit_temp = INT_MAX;
8787
int ret = -EINVAL;
8888

@@ -91,7 +91,9 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
9191
ret = tz->ops.get_temp(tz, temp);
9292

9393
if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
94-
for_each_trip(tz, trip) {
94+
for_each_trip_desc(tz, td) {
95+
const struct thermal_trip *trip = &td->trip;
96+
9597
if (trip->type == THERMAL_TRIP_CRITICAL) {
9698
crit_temp = trip->temperature;
9799
break;

drivers/thermal/thermal_netlink.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int thermal_genl_cmd_tz_get_id(struct param *p)
445445
static int thermal_genl_cmd_tz_get_trip(struct param *p)
446446
{
447447
struct sk_buff *msg = p->msg;
448-
const struct thermal_trip *trip;
448+
const struct thermal_trip_desc *td;
449449
struct thermal_zone_device *tz;
450450
struct nlattr *start_trip;
451451
int id;
@@ -465,7 +465,9 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
465465

466466
mutex_lock(&tz->lock);
467467

468-
for_each_trip(tz, trip) {
468+
for_each_trip_desc(tz, td) {
469+
const struct thermal_trip *trip = &td->trip;
470+
469471
if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_ID,
470472
thermal_zone_trip_id(tz, trip)) ||
471473
nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_TYPE, trip->type) ||

drivers/thermal/thermal_sysfs.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
8888
if (sscanf(attr->attr.name, "trip_point_%d_type", &trip_id) != 1)
8989
return -EINVAL;
9090

91-
switch (tz->trips[trip_id].type) {
91+
switch (tz->trips[trip_id].trip.type) {
9292
case THERMAL_TRIP_CRITICAL:
9393
return sprintf(buf, "critical\n");
9494
case THERMAL_TRIP_HOT:
@@ -120,7 +120,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
120120

121121
mutex_lock(&tz->lock);
122122

123-
trip = &tz->trips[trip_id];
123+
trip = &tz->trips[trip_id].trip;
124124

125125
if (temp != trip->temperature) {
126126
if (tz->ops.set_trip_temp) {
@@ -150,7 +150,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
150150
if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
151151
return -EINVAL;
152152

153-
return sprintf(buf, "%d\n", tz->trips[trip_id].temperature);
153+
return sprintf(buf, "%d\n", tz->trips[trip_id].trip.temperature);
154154
}
155155

156156
static ssize_t
@@ -171,7 +171,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
171171

172172
mutex_lock(&tz->lock);
173173

174-
trip = &tz->trips[trip_id];
174+
trip = &tz->trips[trip_id].trip;
175175

176176
if (hyst != trip->hysteresis) {
177177
trip->hysteresis = hyst;
@@ -194,7 +194,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
194194
if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
195195
return -EINVAL;
196196

197-
return sprintf(buf, "%d\n", tz->trips[trip_id].hysteresis);
197+
return sprintf(buf, "%d\n", tz->trips[trip_id].trip.hysteresis);
198198
}
199199

200200
static ssize_t
@@ -393,7 +393,7 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = {
393393
*/
394394
static int create_trip_attrs(struct thermal_zone_device *tz)
395395
{
396-
const struct thermal_trip *trip;
396+
const struct thermal_trip_desc *td;
397397
struct attribute **attrs;
398398

399399
/* This function works only for zones with at least one trip */
@@ -429,8 +429,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
429429
return -ENOMEM;
430430
}
431431

432-
for_each_trip(tz, trip) {
433-
int indx = thermal_zone_trip_id(tz, trip);
432+
for_each_trip_desc(tz, td) {
433+
int indx = thermal_zone_trip_id(tz, &td->trip);
434434

435435
/* create trip type attribute */
436436
snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
@@ -452,7 +452,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
452452
tz->trip_temp_attrs[indx].name;
453453
tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
454454
tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
455-
if (trip->flags & THERMAL_TRIP_FLAG_RW_TEMP) {
455+
if (td->trip.flags & THERMAL_TRIP_FLAG_RW_TEMP) {
456456
tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
457457
tz->trip_temp_attrs[indx].attr.store =
458458
trip_point_temp_store;
@@ -467,7 +467,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
467467
tz->trip_hyst_attrs[indx].name;
468468
tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
469469
tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
470-
if (trip->flags & THERMAL_TRIP_FLAG_RW_HYST) {
470+
if (td->trip.flags & THERMAL_TRIP_FLAG_RW_HYST) {
471471
tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
472472
tz->trip_hyst_attrs[indx].attr.store =
473473
trip_point_hyst_store;

drivers/thermal/thermal_trip.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ int for_each_thermal_trip(struct thermal_zone_device *tz,
1313
int (*cb)(struct thermal_trip *, void *),
1414
void *data)
1515
{
16-
struct thermal_trip *trip;
16+
struct thermal_trip_desc *td;
1717
int ret;
1818

19-
for_each_trip(tz, trip) {
20-
ret = cb(trip, data);
19+
for_each_trip_desc(tz, td) {
20+
ret = cb(&td->trip, data);
2121
if (ret)
2222
return ret;
2323
}
@@ -63,7 +63,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_num_trips);
6363
*/
6464
void __thermal_zone_set_trips(struct thermal_zone_device *tz)
6565
{
66-
const struct thermal_trip *trip;
66+
const struct thermal_trip_desc *td;
6767
int low = -INT_MAX, high = INT_MAX;
6868
int ret;
6969

@@ -72,7 +72,8 @@ void __thermal_zone_set_trips(struct thermal_zone_device *tz)
7272
if (!tz->ops.set_trips)
7373
return;
7474

75-
for_each_trip(tz, trip) {
75+
for_each_trip_desc(tz, td) {
76+
const struct thermal_trip *trip = &td->trip;
7677
int trip_low;
7778

7879
trip_low = trip->temperature - trip->hysteresis;
@@ -110,7 +111,7 @@ int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
110111
if (!tz || trip_id < 0 || trip_id >= tz->num_trips || !trip)
111112
return -EINVAL;
112113

113-
*trip = tz->trips[trip_id];
114+
*trip = tz->trips[trip_id].trip;
114115
return 0;
115116
}
116117
EXPORT_SYMBOL_GPL(__thermal_zone_get_trip);
@@ -135,7 +136,7 @@ int thermal_zone_trip_id(const struct thermal_zone_device *tz,
135136
* Assume the trip to be located within the bounds of the thermal
136137
* zone's trips[] table.
137138
*/
138-
return trip - tz->trips;
139+
return trip_to_trip_desc(trip) - tz->trips;
139140
}
140141
void thermal_zone_trip_updated(struct thermal_zone_device *tz,
141142
const struct thermal_trip *trip)

0 commit comments

Comments
 (0)