Skip to content

Commit 0dc2356

Browse files
committed
thermal: core: Move lists of thermal instances to trip descriptors
In almost all places where a thermal zone's list of thermal instances is walked, there is a check to match a specific trip point and it is walked in vain whenever there are no cooling devices associated with the given trip. To address this, store the lists of thermal instances in trip point descriptors instead of storing them in thermal zones and adjust all code using those lists accordingly. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Lukasz Luba <[email protected]>
1 parent ee879a5 commit 0dc2356

File tree

7 files changed

+62
-64
lines changed

7 files changed

+62
-64
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static void bang_bang_control(struct thermal_zone_device *tz,
6767
const struct thermal_trip *trip,
6868
bool crossed_up)
6969
{
70+
const struct thermal_trip_desc *td = trip_to_trip_desc(trip);
7071
struct thermal_instance *instance;
7172

7273
lockdep_assert_held(&tz->lock);
@@ -75,10 +76,8 @@ static void bang_bang_control(struct thermal_zone_device *tz,
7576
thermal_zone_trip_id(tz, trip), trip->temperature,
7677
tz->temperature, trip->hysteresis);
7778

78-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
79-
if (instance->trip == trip)
80-
bang_bang_set_instance_target(instance, crossed_up);
81-
}
79+
list_for_each_entry(instance, &td->thermal_instances, trip_node)
80+
bang_bang_set_instance_target(instance, crossed_up);
8281
}
8382

8483
static void bang_bang_manage(struct thermal_zone_device *tz)
@@ -104,8 +103,8 @@ static void bang_bang_manage(struct thermal_zone_device *tz)
104103
* to the thermal zone temperature and the trip point threshold.
105104
*/
106105
turn_on = tz->temperature >= td->threshold;
107-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
108-
if (!instance->initialized && instance->trip == trip)
106+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
107+
if (!instance->initialized)
109108
bang_bang_set_instance_target(instance, turn_on);
110109
}
111110
}

drivers/thermal/gov_fair_share.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int get_trip_level(struct thermal_zone_device *tz)
4444
/**
4545
* fair_share_throttle - throttles devices associated with the given zone
4646
* @tz: thermal_zone_device
47-
* @trip: trip point
47+
* @td: trip point descriptor
4848
* @trip_level: number of trips crossed by the zone temperature
4949
*
5050
* Throttling Logic: This uses three parameters to calculate the new
@@ -61,29 +61,23 @@ static int get_trip_level(struct thermal_zone_device *tz)
6161
* new_state of cooling device = P3 * P2 * P1
6262
*/
6363
static void fair_share_throttle(struct thermal_zone_device *tz,
64-
const struct thermal_trip *trip,
64+
const struct thermal_trip_desc *td,
6565
int trip_level)
6666
{
6767
struct thermal_instance *instance;
6868
int total_weight = 0;
6969
int nr_instances = 0;
7070

71-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
72-
if (instance->trip != trip)
73-
continue;
74-
71+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
7572
total_weight += instance->weight;
7673
nr_instances++;
7774
}
7875

79-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
76+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
8077
struct thermal_cooling_device *cdev = instance->cdev;
8178
u64 dividend;
8279
u32 divisor;
8380

84-
if (instance->trip != trip)
85-
continue;
86-
8781
dividend = trip_level;
8882
dividend *= cdev->max_state;
8983
divisor = tz->num_trips;
@@ -116,7 +110,7 @@ static void fair_share_manage(struct thermal_zone_device *tz)
116110
trip->type == THERMAL_TRIP_HOT)
117111
continue;
118112

119-
fair_share_throttle(tz, trip, trip_level);
113+
fair_share_throttle(tz, td, trip_level);
120114
}
121115
}
122116

drivers/thermal/gov_power_allocator.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ struct power_allocator_params {
9797
struct power_actor *power;
9898
};
9999

100-
static bool power_actor_is_valid(struct power_allocator_params *params,
101-
struct thermal_instance *instance)
100+
static bool power_actor_is_valid(struct thermal_instance *instance)
102101
{
103-
return (instance->trip == params->trip_max &&
104-
cdev_is_power_actor(instance->cdev));
102+
return cdev_is_power_actor(instance->cdev);
105103
}
106104

107105
/**
@@ -118,13 +116,14 @@ static bool power_actor_is_valid(struct power_allocator_params *params,
118116
static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
119117
{
120118
struct power_allocator_params *params = tz->governor_data;
119+
const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
121120
struct thermal_cooling_device *cdev;
122121
struct thermal_instance *instance;
123122
u32 sustainable_power = 0;
124123
u32 min_power;
125124

126-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
127-
if (!power_actor_is_valid(params, instance))
125+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
126+
if (!power_actor_is_valid(instance))
128127
continue;
129128

130129
cdev = instance->cdev;
@@ -400,6 +399,7 @@ static void divvy_up_power(struct power_actor *power, int num_actors,
400399
static void allocate_power(struct thermal_zone_device *tz, int control_temp)
401400
{
402401
struct power_allocator_params *params = tz->governor_data;
402+
const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
403403
unsigned int num_actors = params->num_actors;
404404
struct power_actor *power = params->power;
405405
struct thermal_cooling_device *cdev;
@@ -417,10 +417,10 @@ static void allocate_power(struct thermal_zone_device *tz, int control_temp)
417417
/* Clean all buffers for new power estimations */
418418
memset(power, 0, params->buffer_size);
419419

420-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
420+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
421421
struct power_actor *pa = &power[i];
422422

423-
if (!power_actor_is_valid(params, instance))
423+
if (!power_actor_is_valid(instance))
424424
continue;
425425

426426
cdev = instance->cdev;
@@ -454,10 +454,10 @@ static void allocate_power(struct thermal_zone_device *tz, int control_temp)
454454
power_range);
455455

456456
i = 0;
457-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
457+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
458458
struct power_actor *pa = &power[i];
459459

460-
if (!power_actor_is_valid(params, instance))
460+
if (!power_actor_is_valid(instance))
461461
continue;
462462

463463
power_actor_set_power(instance->cdev, instance,
@@ -538,12 +538,13 @@ static void reset_pid_controller(struct power_allocator_params *params)
538538
static void allow_maximum_power(struct thermal_zone_device *tz)
539539
{
540540
struct power_allocator_params *params = tz->governor_data;
541+
const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
541542
struct thermal_cooling_device *cdev;
542543
struct thermal_instance *instance;
543544
u32 req_power;
544545

545-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
546-
if (!power_actor_is_valid(params, instance))
546+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
547+
if (!power_actor_is_valid(instance))
547548
continue;
548549

549550
cdev = instance->cdev;
@@ -581,13 +582,11 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
581582
static int check_power_actors(struct thermal_zone_device *tz,
582583
struct power_allocator_params *params)
583584
{
585+
const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
584586
struct thermal_instance *instance;
585587
int ret = 0;
586588

587-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
588-
if (instance->trip != params->trip_max)
589-
continue;
590-
589+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
591590
if (!cdev_is_power_actor(instance->cdev)) {
592591
dev_warn(&tz->device, "power_allocator: %s is not a power actor\n",
593592
instance->cdev->type);
@@ -635,14 +634,15 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
635634
enum thermal_notify_event reason)
636635
{
637636
struct power_allocator_params *params = tz->governor_data;
637+
const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
638638
struct thermal_instance *instance;
639639
int num_actors = 0;
640640

641641
switch (reason) {
642642
case THERMAL_TZ_BIND_CDEV:
643643
case THERMAL_TZ_UNBIND_CDEV:
644-
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
645-
if (power_actor_is_valid(params, instance))
644+
list_for_each_entry(instance, &td->thermal_instances, trip_node)
645+
if (power_actor_is_valid(instance))
646646
num_actors++;
647647

648648
if (num_actors == params->num_actors)
@@ -652,8 +652,8 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
652652
break;
653653
case THERMAL_INSTANCE_WEIGHT_CHANGED:
654654
params->total_weight = 0;
655-
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
656-
if (power_actor_is_valid(params, instance))
655+
list_for_each_entry(instance, &td->thermal_instances, trip_node)
656+
if (power_actor_is_valid(instance))
657657
params->total_weight += instance->weight;
658658
break;
659659
default:

drivers/thermal/gov_step_wise.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ static unsigned long get_target_state(struct thermal_instance *instance,
6666
}
6767

6868
static void thermal_zone_trip_update(struct thermal_zone_device *tz,
69-
const struct thermal_trip *trip,
69+
const struct thermal_trip_desc *td,
7070
int trip_threshold)
7171
{
72+
const struct thermal_trip *trip = &td->trip;
7273
enum thermal_trend trend = get_tz_trend(tz, trip);
7374
int trip_id = thermal_zone_trip_id(tz, trip);
7475
struct thermal_instance *instance;
@@ -82,12 +83,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz,
8283
dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
8384
trip_id, trip->type, trip_threshold, trend, throttle);
8485

85-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
86+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
8687
int old_target;
8788

88-
if (instance->trip != trip)
89-
continue;
90-
9189
old_target = instance->target;
9290
instance->target = get_target_state(instance, trend, throttle);
9391

@@ -127,11 +125,13 @@ static void step_wise_manage(struct thermal_zone_device *tz)
127125
trip->type == THERMAL_TRIP_HOT)
128126
continue;
129127

130-
thermal_zone_trip_update(tz, trip, td->threshold);
128+
thermal_zone_trip_update(tz, td, td->threshold);
131129
}
132130

133-
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
134-
thermal_cdev_update(instance->cdev);
131+
for_each_trip_desc(tz, td) {
132+
list_for_each_entry(instance, &td->thermal_instances, trip_node)
133+
thermal_cdev_update(instance->cdev);
134+
}
135135
}
136136

137137
static struct thermal_governor thermal_gov_step_wise = {

drivers/thermal/thermal_core.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,20 @@ static void thermal_zone_device_check(struct work_struct *work)
490490

491491
static void thermal_zone_device_init(struct thermal_zone_device *tz)
492492
{
493-
struct thermal_instance *pos;
493+
struct thermal_trip_desc *td;
494494

495495
INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check);
496496

497497
tz->temperature = THERMAL_TEMP_INIT;
498498
tz->passive = 0;
499499
tz->prev_low_trip = -INT_MAX;
500500
tz->prev_high_trip = INT_MAX;
501-
list_for_each_entry(pos, &tz->thermal_instances, tz_node)
502-
pos->initialized = false;
501+
for_each_trip_desc(tz, td) {
502+
struct thermal_instance *instance;
503+
504+
list_for_each_entry(instance, &td->thermal_instances, trip_node)
505+
instance->initialized = false;
506+
}
503507
}
504508

505509
static void thermal_governor_trip_crossed(struct thermal_governor *governor,
@@ -766,12 +770,12 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
766770
* Return: 0 on success, the proper error value otherwise.
767771
*/
768772
static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
769-
const struct thermal_trip *trip,
773+
struct thermal_trip *trip,
770774
struct thermal_cooling_device *cdev,
771775
struct cooling_spec *cool_spec)
772776
{
773-
struct thermal_instance *dev;
774-
struct thermal_instance *pos;
777+
struct thermal_trip_desc *td = trip_to_trip_desc(trip);
778+
struct thermal_instance *dev, *instance;
775779
bool upper_no_limit;
776780
int result;
777781

@@ -834,13 +838,13 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
834838
goto remove_trip_file;
835839

836840
mutex_lock(&cdev->lock);
837-
list_for_each_entry(pos, &tz->thermal_instances, tz_node)
838-
if (pos->trip == trip && pos->cdev == cdev) {
841+
list_for_each_entry(instance, &td->thermal_instances, trip_node)
842+
if (instance->cdev == cdev) {
839843
result = -EEXIST;
840844
break;
841845
}
842846
if (!result) {
843-
list_add_tail(&dev->tz_node, &tz->thermal_instances);
847+
list_add_tail(&dev->trip_node, &td->thermal_instances);
844848
list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
845849

846850
thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
@@ -873,15 +877,16 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
873877
* This function is usually called in the thermal zone device .unbind callback.
874878
*/
875879
static void thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
876-
const struct thermal_trip *trip,
880+
struct thermal_trip *trip,
877881
struct thermal_cooling_device *cdev)
878882
{
883+
struct thermal_trip_desc *td = trip_to_trip_desc(trip);
879884
struct thermal_instance *pos, *next;
880885

881886
mutex_lock(&cdev->lock);
882-
list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
883-
if (pos->trip == trip && pos->cdev == cdev) {
884-
list_del(&pos->tz_node);
887+
list_for_each_entry_safe(pos, next, &td->thermal_instances, trip_node) {
888+
if (pos->cdev == cdev) {
889+
list_del(&pos->trip_node);
885890
list_del(&pos->cdev_node);
886891

887892
thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
@@ -1462,7 +1467,6 @@ thermal_zone_device_register_with_trips(const char *type,
14621467
}
14631468
}
14641469

1465-
INIT_LIST_HEAD(&tz->thermal_instances);
14661470
INIT_LIST_HEAD(&tz->node);
14671471
ida_init(&tz->ida);
14681472
mutex_init(&tz->lock);
@@ -1486,6 +1490,7 @@ thermal_zone_device_register_with_trips(const char *type,
14861490
tz->num_trips = num_trips;
14871491
for_each_trip_desc(tz, td) {
14881492
td->trip = *trip++;
1493+
INIT_LIST_HEAD(&td->thermal_instances);
14891494
/*
14901495
* Mark all thresholds as invalid to start with even though
14911496
* this only matters for the trips that start as invalid and

drivers/thermal/thermal_core.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct thermal_trip_desc {
3131
struct thermal_trip trip;
3232
struct thermal_trip_attrs trip_attrs;
3333
struct list_head notify_list_node;
34+
struct list_head thermal_instances;
3435
int notify_temp;
3536
int threshold;
3637
};
@@ -100,7 +101,6 @@ struct thermal_governor {
100101
* @tzp: thermal zone parameters
101102
* @governor: pointer to the governor for this thermal zone
102103
* @governor_data: private pointer for governor data
103-
* @thermal_instances: list of &struct thermal_instance of this thermal zone
104104
* @ida: &struct ida to generate unique id for this zone's cooling
105105
* devices
106106
* @lock: lock to protect thermal_instances list
@@ -133,7 +133,6 @@ struct thermal_zone_device {
133133
struct thermal_zone_params *tzp;
134134
struct thermal_governor *governor;
135135
void *governor_data;
136-
struct list_head thermal_instances;
137136
struct ida ida;
138137
struct mutex lock;
139138
struct list_head node;
@@ -231,7 +230,7 @@ struct thermal_instance {
231230
struct device_attribute attr;
232231
char weight_attr_name[THERMAL_NAME_LENGTH];
233232
struct device_attribute weight_attr;
234-
struct list_head tz_node; /* node in tz->thermal_instances */
233+
struct list_head trip_node; /* node in trip->thermal_instances */
235234
struct list_head cdev_node; /* node in cdev->thermal_instances */
236235
unsigned int weight; /* The weight of the cooling device */
237236
bool upper_no_limit;

drivers/thermal/thermal_helpers.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ static bool thermal_instance_present(struct thermal_zone_device *tz,
4343
struct thermal_cooling_device *cdev,
4444
const struct thermal_trip *trip)
4545
{
46+
const struct thermal_trip_desc *td = trip_to_trip_desc(trip);
4647
struct thermal_instance *ti;
4748

48-
list_for_each_entry(ti, &tz->thermal_instances, tz_node) {
49-
if (ti->trip == trip && ti->cdev == cdev)
49+
list_for_each_entry(ti, &td->thermal_instances, trip_node) {
50+
if (ti->cdev == cdev)
5051
return true;
5152
}
5253

0 commit comments

Comments
 (0)