Skip to content

Commit 8c882f1

Browse files
committed
Merge back earlier thermal core changes for v6.10.
2 parents d351eb0 + f831892 commit 8c882f1

19 files changed

+602
-416
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,11 @@
1313

1414
#include "thermal_core.h"
1515

16-
static int thermal_zone_trip_update(struct thermal_zone_device *tz,
17-
const struct thermal_trip *trip)
18-
{
19-
int trip_index = thermal_zone_trip_id(tz, trip);
20-
struct thermal_instance *instance;
21-
22-
if (!trip->hysteresis)
23-
dev_info_once(&tz->device,
24-
"Zero hysteresis value for thermal zone %s\n", tz->type);
25-
26-
dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
27-
trip_index, trip->temperature, tz->temperature,
28-
trip->hysteresis);
29-
30-
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
31-
if (instance->trip != trip)
32-
continue;
33-
34-
/* in case fan is in initial state, switch the fan off */
35-
if (instance->target == THERMAL_NO_TARGET)
36-
instance->target = 0;
37-
38-
/* in case fan is neither on nor off set the fan to active */
39-
if (instance->target != 0 && instance->target != 1) {
40-
pr_warn("Thermal instance %s controlled by bang-bang has unexpected state: %ld\n",
41-
instance->name, instance->target);
42-
instance->target = 1;
43-
}
44-
45-
/*
46-
* enable fan when temperature exceeds trip_temp and disable
47-
* the fan in case it falls below trip_temp minus hysteresis
48-
*/
49-
if (instance->target == 0 && tz->temperature >= trip->temperature)
50-
instance->target = 1;
51-
else if (instance->target == 1 &&
52-
tz->temperature < trip->temperature - trip->hysteresis)
53-
instance->target = 0;
54-
55-
dev_dbg(&instance->cdev->device, "target=%d\n",
56-
(int)instance->target);
57-
58-
mutex_lock(&instance->cdev->lock);
59-
instance->cdev->updated = false; /* cdev needs update */
60-
mutex_unlock(&instance->cdev->lock);
61-
}
62-
63-
return 0;
64-
}
65-
6616
/**
6717
* bang_bang_control - controls devices associated with the given zone
6818
* @tz: thermal_zone_device
6919
* @trip: the trip point
20+
* @crossed_up: whether or not the trip has been crossed on the way up
7021
*
7122
* Regulation Logic: a two point regulation, deliver cooling state depending
7223
* on the previous state shown in this diagram:
@@ -90,26 +41,54 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz,
9041
* (trip_temp - hyst) so that the fan gets turned off again.
9142
*
9243
*/
93-
static int bang_bang_control(struct thermal_zone_device *tz,
94-
const struct thermal_trip *trip)
44+
static void bang_bang_control(struct thermal_zone_device *tz,
45+
const struct thermal_trip *trip,
46+
bool crossed_up)
9547
{
9648
struct thermal_instance *instance;
97-
int ret;
9849

9950
lockdep_assert_held(&tz->lock);
10051

101-
ret = thermal_zone_trip_update(tz, trip);
102-
if (ret)
103-
return ret;
52+
dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
53+
thermal_zone_trip_id(tz, trip), trip->temperature,
54+
tz->temperature, trip->hysteresis);
55+
56+
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
57+
if (instance->trip != trip)
58+
continue;
59+
60+
if (instance->target == THERMAL_NO_TARGET)
61+
instance->target = 0;
62+
63+
if (instance->target != 0 && instance->target != 1) {
64+
pr_debug("Unexpected state %ld of thermal instance %s in bang-bang\n",
65+
instance->target, instance->name);
66+
67+
instance->target = 1;
68+
}
69+
70+
/*
71+
* Enable the fan when the trip is crossed on the way up and
72+
* disable it when the trip is crossed on the way down.
73+
*/
74+
if (instance->target == 0 && crossed_up)
75+
instance->target = 1;
76+
else if (instance->target == 1 && !crossed_up)
77+
instance->target = 0;
78+
79+
dev_dbg(&instance->cdev->device, "target=%ld\n", instance->target);
80+
81+
mutex_lock(&instance->cdev->lock);
82+
instance->cdev->updated = false; /* cdev needs update */
83+
mutex_unlock(&instance->cdev->lock);
84+
}
10485

10586
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
10687
thermal_cdev_update(instance->cdev);
107-
108-
return 0;
10988
}
11089

11190
static struct thermal_governor thermal_gov_bang_bang = {
11291
.name = "bang_bang",
113-
.throttle = bang_bang_control,
92+
.trip_crossed = bang_bang_control,
11493
};
11594
THERMAL_GOVERNOR_DECLARE(thermal_gov_bang_bang);

drivers/thermal/gov_fair_share.c

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,97 +17,111 @@
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_desc *level_td = NULL;
21+
const struct thermal_trip_desc *td;
2122
int trip_level = -1;
2223

23-
for_each_trip(tz, trip) {
24-
if (trip->temperature >= tz->temperature)
24+
for_each_trip_desc(tz, td) {
25+
if (td->threshold > tz->temperature)
2526
continue;
2627

2728
trip_level++;
2829

29-
if (!level_trip || trip->temperature > level_trip->temperature)
30-
level_trip = trip;
30+
if (!level_td || td->threshold > level_td->threshold)
31+
level_td = td;
3132
}
3233

3334
/* Bail out if the temperature is not greater than any trips. */
3435
if (trip_level < 0)
3536
return 0;
3637

37-
trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, level_trip),
38-
level_trip->type);
38+
trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, &level_td->trip),
39+
level_td->trip.type);
3940

4041
return trip_level;
4142
}
4243

43-
static long get_target_state(struct thermal_zone_device *tz,
44-
struct thermal_cooling_device *cdev, int percentage, int level)
45-
{
46-
return (long)(percentage * level * cdev->max_state) / (100 * tz->num_trips);
47-
}
48-
4944
/**
5045
* fair_share_throttle - throttles devices associated with the given zone
5146
* @tz: thermal_zone_device
5247
* @trip: trip point
48+
* @trip_level: number of trips crossed by the zone temperature
5349
*
5450
* Throttling Logic: This uses three parameters to calculate the new
5551
* throttle state of the cooling devices associated with the given zone.
5652
*
5753
* Parameters used for Throttling:
5854
* P1. max_state: Maximum throttle state exposed by the cooling device.
59-
* P2. percentage[i]/100:
55+
* P2. weight[i]/total_weight:
6056
* How 'effective' the 'i'th device is, in cooling the given zone.
61-
* P3. cur_trip_level/max_no_of_trips:
57+
* P3. trip_level/max_no_of_trips:
6258
* This describes the extent to which the devices should be throttled.
6359
* We do not want to throttle too much when we trip a lower temperature,
6460
* whereas the throttling is at full swing if we trip critical levels.
65-
* (Heavily assumes the trip points are in ascending order)
6661
* new_state of cooling device = P3 * P2 * P1
6762
*/
68-
static int fair_share_throttle(struct thermal_zone_device *tz,
69-
const struct thermal_trip *trip)
63+
static void fair_share_throttle(struct thermal_zone_device *tz,
64+
const struct thermal_trip *trip,
65+
int trip_level)
7066
{
7167
struct thermal_instance *instance;
7268
int total_weight = 0;
73-
int total_instance = 0;
74-
int cur_trip_level = get_trip_level(tz);
75-
76-
lockdep_assert_held(&tz->lock);
69+
int nr_instances = 0;
7770

7871
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
7972
if (instance->trip != trip)
8073
continue;
8174

8275
total_weight += instance->weight;
83-
total_instance++;
76+
nr_instances++;
8477
}
8578

8679
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
87-
int percentage;
8880
struct thermal_cooling_device *cdev = instance->cdev;
81+
u64 dividend;
82+
u32 divisor;
8983

9084
if (instance->trip != trip)
9185
continue;
9286

93-
if (!total_weight)
94-
percentage = 100 / total_instance;
95-
else
96-
percentage = (instance->weight * 100) / total_weight;
97-
98-
instance->target = get_target_state(tz, cdev, percentage,
99-
cur_trip_level);
87+
dividend = trip_level;
88+
dividend *= cdev->max_state;
89+
divisor = tz->num_trips;
90+
if (total_weight) {
91+
dividend *= instance->weight;
92+
divisor *= total_weight;
93+
} else {
94+
divisor *= nr_instances;
95+
}
96+
instance->target = div_u64(dividend, divisor);
10097

10198
mutex_lock(&cdev->lock);
10299
__thermal_cdev_update(cdev);
103100
mutex_unlock(&cdev->lock);
104101
}
102+
}
105103

106-
return 0;
104+
static void fair_share_manage(struct thermal_zone_device *tz)
105+
{
106+
int trip_level = get_trip_level(tz);
107+
const struct thermal_trip_desc *td;
108+
109+
lockdep_assert_held(&tz->lock);
110+
111+
for_each_trip_desc(tz, td) {
112+
const struct thermal_trip *trip = &td->trip;
113+
114+
if (trip->temperature == THERMAL_TEMP_INVALID ||
115+
trip->type == THERMAL_TRIP_CRITICAL ||
116+
trip->type == THERMAL_TRIP_HOT)
117+
continue;
118+
119+
fair_share_throttle(tz, trip, trip_level);
120+
}
107121
}
108122

109123
static struct thermal_governor thermal_gov_fair_share = {
110-
.name = "fair_share",
111-
.throttle = fair_share_throttle,
124+
.name = "fair_share",
125+
.manage = fair_share_manage,
112126
};
113127
THERMAL_GOVERNOR_DECLARE(thermal_gov_fair_share);

drivers/thermal/gov_power_allocator.c

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ static void divvy_up_power(struct power_actor *power, int num_actors,
395395
}
396396
}
397397

398-
static int allocate_power(struct thermal_zone_device *tz, int control_temp)
398+
static void allocate_power(struct thermal_zone_device *tz, int control_temp)
399399
{
400400
struct power_allocator_params *params = tz->governor_data;
401401
unsigned int num_actors = params->num_actors;
@@ -410,7 +410,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp)
410410
int i = 0, ret;
411411

412412
if (!num_actors)
413-
return -ENODEV;
413+
return;
414414

415415
/* Clean all buffers for new power estimations */
416416
memset(power, 0, params->buffer_size);
@@ -471,8 +471,6 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp)
471471
num_actors, power_range,
472472
max_allocatable_power, tz->temperature,
473473
control_temp - tz->temperature);
474-
475-
return 0;
476474
}
477475

478476
/**
@@ -496,9 +494,11 @@ static void get_governor_trips(struct thermal_zone_device *tz,
496494
const struct thermal_trip *first_passive = NULL;
497495
const struct thermal_trip *last_passive = NULL;
498496
const struct thermal_trip *last_active = NULL;
499-
const struct thermal_trip *trip;
497+
const struct thermal_trip_desc *td;
498+
499+
for_each_trip_desc(tz, td) {
500+
const struct thermal_trip *trip = &td->trip;
500501

501-
for_each_trip(tz, trip) {
502502
switch (trip->type) {
503503
case THERMAL_TRIP_PASSIVE:
504504
if (!first_passive) {
@@ -743,40 +743,29 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
743743
tz->governor_data = NULL;
744744
}
745745

746-
static int power_allocator_throttle(struct thermal_zone_device *tz,
747-
const struct thermal_trip *trip)
746+
static void power_allocator_manage(struct thermal_zone_device *tz)
748747
{
749748
struct power_allocator_params *params = tz->governor_data;
750-
bool update;
749+
const struct thermal_trip *trip = params->trip_switch_on;
751750

752751
lockdep_assert_held(&tz->lock);
753752

754-
/*
755-
* We get called for every trip point but we only need to do
756-
* our calculations once
757-
*/
758-
if (trip != params->trip_max)
759-
return 0;
760-
761-
trip = params->trip_switch_on;
762753
if (trip && tz->temperature < trip->temperature) {
763-
update = tz->passive;
764-
tz->passive = 0;
765754
reset_pid_controller(params);
766-
allow_maximum_power(tz, update);
767-
return 0;
755+
allow_maximum_power(tz, tz->passive);
756+
tz->passive = 0;
757+
return;
768758
}
769759

760+
allocate_power(tz, params->trip_max->temperature);
770761
tz->passive = 1;
771-
772-
return allocate_power(tz, params->trip_max->temperature);
773762
}
774763

775764
static struct thermal_governor thermal_gov_power_allocator = {
776765
.name = "power_allocator",
777766
.bind_to_tz = power_allocator_bind,
778767
.unbind_from_tz = power_allocator_unbind,
779-
.throttle = power_allocator_throttle,
768+
.manage = power_allocator_manage,
780769
.update_tz = power_allocator_update_tz,
781770
};
782771
THERMAL_GOVERNOR_DECLARE(thermal_gov_power_allocator);

0 commit comments

Comments
 (0)