Skip to content

Commit 598c20f

Browse files
committed
Merge branch 'thermal-core'
Merge thermal core changes for 6.7-rc1: - Use trip pointers in thermal governors and in the related part of the thermal core (Rafael Wysocki). - Avoid updating trip points when the thermal zone temperature falls into a trip point's hysteresis range (ícolas F. R. A. Prado). * thermal-core: thermal: ACPI: Include the right header file thermal: core: Don't update trip points inside the hysteresis range thermal: core: Pass trip pointer to governor throttle callback thermal: gov_step_wise: Fold update_passive_instance() into its caller thermal: gov_power_allocator: Use trip pointers instead of trip indices thermal: gov_fair_share: Rearrange get_trip_level() thermal: trip: Define for_each_trip() macro thermal: trip: Simplify computing trip indices
2 parents 27fa2b6 + c27d08f commit 598c20f

File tree

11 files changed

+152
-170
lines changed

11 files changed

+152
-170
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: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,27 @@
1515

1616
#include "thermal_core.h"
1717

18-
/**
19-
* get_trip_level: - obtains the current trip level for a zone
20-
* @tz: thermal zone device
21-
*/
2218
static int get_trip_level(struct thermal_zone_device *tz)
2319
{
24-
struct thermal_trip trip;
25-
int count;
20+
const struct thermal_trip *trip, *level_trip = NULL;
21+
int trip_level;
2622

27-
for (count = 0; count < tz->num_trips; count++) {
28-
__thermal_zone_get_trip(tz, count, &trip);
29-
if (tz->temperature < trip.temperature)
23+
for_each_trip(tz, trip) {
24+
if (trip->temperature >= tz->temperature)
3025
break;
26+
27+
level_trip = trip;
3128
}
3229

33-
/*
34-
* count > 0 only if temperature is greater than first trip
35-
* point, in which case, trip_point = count - 1
36-
*/
37-
if (count > 0)
38-
trace_thermal_zone_trip(tz, count - 1, trip.type);
30+
/* Bail out if the temperature is not greater than any trips. */
31+
if (!level_trip)
32+
return 0;
33+
34+
trip_level = thermal_zone_trip_id(tz, level_trip);
35+
36+
trace_thermal_zone_trip(tz, trip_level, level_trip->type);
3937

40-
return count;
38+
return trip_level;
4139
}
4240

4341
static long get_target_state(struct thermal_zone_device *tz,
@@ -49,7 +47,7 @@ static long get_target_state(struct thermal_zone_device *tz,
4947
/**
5048
* fair_share_throttle - throttles devices associated with the given zone
5149
* @tz: thermal_zone_device
52-
* @trip_index: trip point index
50+
* @trip: trip point
5351
*
5452
* Throttling Logic: This uses three parameters to calculate the new
5553
* throttle state of the cooling devices associated with the given zone.
@@ -65,9 +63,9 @@ static long get_target_state(struct thermal_zone_device *tz,
6563
* (Heavily assumes the trip points are in ascending order)
6664
* new_state of cooling device = P3 * P2 * P1
6765
*/
68-
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)
6968
{
70-
const struct thermal_trip *trip = &tz->trips[trip_index];
7169
struct thermal_instance *instance;
7270
int total_weight = 0;
7371
int total_instance = 0;

drivers/thermal/gov_power_allocator.c

Lines changed: 49 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#include "thermal_core.h"
1818

19-
#define INVALID_TRIP -1
20-
2119
#define FRAC_BITS 10
2220
#define int_to_frac(x) ((x) << FRAC_BITS)
2321
#define frac_to_int(x) ((x) >> FRAC_BITS)
@@ -55,23 +53,23 @@ static inline s64 div_frac(s64 x, s64 y)
5553
* @err_integral: accumulated error in the PID controller.
5654
* @prev_err: error in the previous iteration of the PID controller.
5755
* Used to calculate the derivative term.
56+
* @sustainable_power: Sustainable power (heat) that this thermal zone can
57+
* dissipate
5858
* @trip_switch_on: first passive trip point of the thermal zone. The
5959
* governor switches on when this trip point is crossed.
6060
* If the thermal zone only has one passive trip point,
61-
* @trip_switch_on should be INVALID_TRIP.
61+
* @trip_switch_on should be NULL.
6262
* @trip_max_desired_temperature: last passive trip point of the thermal
6363
* zone. The temperature we are
6464
* controlling for.
65-
* @sustainable_power: Sustainable power (heat) that this thermal zone can
66-
* dissipate
6765
*/
6866
struct power_allocator_params {
6967
bool allocated_tzp;
7068
s64 err_integral;
7169
s32 prev_err;
72-
int trip_switch_on;
73-
int trip_max_desired_temperature;
7470
u32 sustainable_power;
71+
const struct thermal_trip *trip_switch_on;
72+
const struct thermal_trip *trip_max_desired_temperature;
7573
};
7674

7775
/**
@@ -90,14 +88,12 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
9088
u32 sustainable_power = 0;
9189
struct thermal_instance *instance;
9290
struct power_allocator_params *params = tz->governor_data;
93-
const struct thermal_trip *trip_max_desired_temperature =
94-
&tz->trips[params->trip_max_desired_temperature];
9591

9692
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
9793
struct thermal_cooling_device *cdev = instance->cdev;
9894
u32 min_power;
9995

100-
if (instance->trip != trip_max_desired_temperature)
96+
if (instance->trip != params->trip_max_desired_temperature)
10197
continue;
10298

10399
if (!cdev_is_power_actor(cdev))
@@ -116,24 +112,22 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
116112
* estimate_pid_constants() - Estimate the constants for the PID controller
117113
* @tz: thermal zone for which to estimate the constants
118114
* @sustainable_power: sustainable power for the thermal zone
119-
* @trip_switch_on: trip point number for the switch on temperature
115+
* @trip_switch_on: trip point for the switch on temperature
120116
* @control_temp: target temperature for the power allocator governor
121117
*
122118
* This function is used to update the estimation of the PID
123119
* controller constants in struct thermal_zone_parameters.
124120
*/
125121
static void estimate_pid_constants(struct thermal_zone_device *tz,
126-
u32 sustainable_power, int trip_switch_on,
122+
u32 sustainable_power,
123+
const struct thermal_trip *trip_switch_on,
127124
int control_temp)
128125
{
129-
struct thermal_trip trip;
130126
u32 temperature_threshold = control_temp;
131-
int ret;
132127
s32 k_i;
133128

134-
ret = __thermal_zone_get_trip(tz, trip_switch_on, &trip);
135-
if (!ret)
136-
temperature_threshold -= trip.temperature;
129+
if (trip_switch_on)
130+
temperature_threshold -= trip_switch_on->temperature;
137131

138132
/*
139133
* estimate_pid_constants() tries to find appropriate default
@@ -386,7 +380,7 @@ static int allocate_power(struct thermal_zone_device *tz,
386380
struct thermal_instance *instance;
387381
struct power_allocator_params *params = tz->governor_data;
388382
const struct thermal_trip *trip_max_desired_temperature =
389-
&tz->trips[params->trip_max_desired_temperature];
383+
params->trip_max_desired_temperature;
390384
u32 *req_power, *max_power, *granted_power, *extra_actor_power;
391385
u32 *weighted_req_power;
392386
u32 total_req_power, max_allocatable_power, total_weighted_req_power;
@@ -496,7 +490,7 @@ static int allocate_power(struct thermal_zone_device *tz,
496490
}
497491

498492
/**
499-
* get_governor_trips() - get the number of the two trip points that are key for this governor
493+
* get_governor_trips() - get the two trip points that are key for this governor
500494
* @tz: thermal zone to operate on
501495
* @params: pointer to private data for this governor
502496
*
@@ -513,46 +507,36 @@ static int allocate_power(struct thermal_zone_device *tz,
513507
static void get_governor_trips(struct thermal_zone_device *tz,
514508
struct power_allocator_params *params)
515509
{
516-
int i, last_active, last_passive;
517-
bool found_first_passive;
518-
519-
found_first_passive = false;
520-
last_active = INVALID_TRIP;
521-
last_passive = INVALID_TRIP;
522-
523-
for (i = 0; i < tz->num_trips; i++) {
524-
struct thermal_trip trip;
525-
int ret;
526-
527-
ret = __thermal_zone_get_trip(tz, i, &trip);
528-
if (ret) {
529-
dev_warn(&tz->device,
530-
"Failed to get trip point %d type: %d\n", i,
531-
ret);
532-
continue;
533-
}
534-
535-
if (trip.type == THERMAL_TRIP_PASSIVE) {
536-
if (!found_first_passive) {
537-
params->trip_switch_on = i;
538-
found_first_passive = true;
539-
} else {
540-
last_passive = i;
510+
const struct thermal_trip *first_passive = NULL;
511+
const struct thermal_trip *last_passive = NULL;
512+
const struct thermal_trip *last_active = NULL;
513+
const struct thermal_trip *trip;
514+
515+
for_each_trip(tz, trip) {
516+
switch (trip->type) {
517+
case THERMAL_TRIP_PASSIVE:
518+
if (!first_passive) {
519+
first_passive = trip;
520+
break;
541521
}
542-
} else if (trip.type == THERMAL_TRIP_ACTIVE) {
543-
last_active = i;
544-
} else {
522+
last_passive = trip;
523+
break;
524+
case THERMAL_TRIP_ACTIVE:
525+
last_active = trip;
526+
break;
527+
default:
545528
break;
546529
}
547530
}
548531

549-
if (last_passive != INVALID_TRIP) {
532+
if (last_passive) {
533+
params->trip_switch_on = first_passive;
550534
params->trip_max_desired_temperature = last_passive;
551-
} else if (found_first_passive) {
552-
params->trip_max_desired_temperature = params->trip_switch_on;
553-
params->trip_switch_on = INVALID_TRIP;
535+
} else if (first_passive) {
536+
params->trip_switch_on = NULL;
537+
params->trip_max_desired_temperature = first_passive;
554538
} else {
555-
params->trip_switch_on = INVALID_TRIP;
539+
params->trip_switch_on = NULL;
556540
params->trip_max_desired_temperature = last_active;
557541
}
558542
}
@@ -567,14 +551,12 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
567551
{
568552
struct thermal_instance *instance;
569553
struct power_allocator_params *params = tz->governor_data;
570-
const struct thermal_trip *trip_max_desired_temperature =
571-
&tz->trips[params->trip_max_desired_temperature];
572554
u32 req_power;
573555

574556
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
575557
struct thermal_cooling_device *cdev = instance->cdev;
576558

577-
if ((instance->trip != trip_max_desired_temperature) ||
559+
if (instance->trip != params->trip_max_desired_temperature ||
578560
(!cdev_is_power_actor(instance->cdev)))
579561
continue;
580562

@@ -636,7 +618,6 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
636618
{
637619
int ret;
638620
struct power_allocator_params *params;
639-
struct thermal_trip trip;
640621

641622
ret = check_power_actors(tz);
642623
if (ret)
@@ -661,13 +642,11 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
661642

662643
get_governor_trips(tz, params);
663644

664-
if (tz->num_trips > 0) {
665-
ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature,
666-
&trip);
667-
if (!ret)
668-
estimate_pid_constants(tz, tz->tzp->sustainable_power,
669-
params->trip_switch_on,
670-
trip.temperature);
645+
if (params->trip_max_desired_temperature) {
646+
int temp = params->trip_max_desired_temperature->temperature;
647+
648+
estimate_pid_constants(tz, tz->tzp->sustainable_power,
649+
params->trip_switch_on, temp);
671650
}
672651

673652
reset_pid_controller(params);
@@ -697,11 +676,10 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
697676
tz->governor_data = NULL;
698677
}
699678

700-
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id)
679+
static int power_allocator_throttle(struct thermal_zone_device *tz,
680+
const struct thermal_trip *trip)
701681
{
702682
struct power_allocator_params *params = tz->governor_data;
703-
struct thermal_trip trip;
704-
int ret;
705683
bool update;
706684

707685
lockdep_assert_held(&tz->lock);
@@ -710,12 +688,12 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id)
710688
* We get called for every trip point but we only need to do
711689
* our calculations once
712690
*/
713-
if (trip_id != params->trip_max_desired_temperature)
691+
if (trip != params->trip_max_desired_temperature)
714692
return 0;
715693

716-
ret = __thermal_zone_get_trip(tz, params->trip_switch_on, &trip);
717-
if (!ret && (tz->temperature < trip.temperature)) {
718-
update = (tz->last_temperature >= trip.temperature);
694+
trip = params->trip_switch_on;
695+
if (trip && tz->temperature < trip->temperature) {
696+
update = tz->last_temperature >= trip->temperature;
719697
tz->passive = 0;
720698
reset_pid_controller(params);
721699
allow_maximum_power(tz, update);
@@ -724,14 +702,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id)
724702

725703
tz->passive = 1;
726704

727-
ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, &trip);
728-
if (ret) {
729-
dev_warn(&tz->device, "Failed to get the maximum desired temperature: %d\n",
730-
ret);
731-
return ret;
732-
}
733-
734-
return allocate_power(tz, trip.temperature);
705+
return allocate_power(tz, params->trip_max_desired_temperature->temperature);
735706
}
736707

737708
static struct thermal_governor thermal_gov_power_allocator = {

0 commit comments

Comments
 (0)