This source file includes following definitions.
- get_trip_level
- get_target_state
- fair_share_throttle
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/thermal.h>
14 #include <trace/events/thermal.h>
15
16 #include "thermal_core.h"
17
18
19
20
21
22 static int get_trip_level(struct thermal_zone_device *tz)
23 {
24 int count = 0;
25 int trip_temp;
26 enum thermal_trip_type trip_type;
27
28 if (tz->trips == 0 || !tz->ops->get_trip_temp)
29 return 0;
30
31 for (count = 0; count < tz->trips; count++) {
32 tz->ops->get_trip_temp(tz, count, &trip_temp);
33 if (tz->temperature < trip_temp)
34 break;
35 }
36
37
38
39
40
41 if (count > 0) {
42 tz->ops->get_trip_type(tz, count - 1, &trip_type);
43 trace_thermal_zone_trip(tz, count - 1, trip_type);
44 }
45
46 return count;
47 }
48
49 static long get_target_state(struct thermal_zone_device *tz,
50 struct thermal_cooling_device *cdev, int percentage, int level)
51 {
52 unsigned long max_state;
53
54 cdev->ops->get_max_state(cdev, &max_state);
55
56 return (long)(percentage * level * max_state) / (100 * tz->trips);
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
79 {
80 struct thermal_instance *instance;
81 int total_weight = 0;
82 int total_instance = 0;
83 int cur_trip_level = get_trip_level(tz);
84
85 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
86 if (instance->trip != trip)
87 continue;
88
89 total_weight += instance->weight;
90 total_instance++;
91 }
92
93 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
94 int percentage;
95 struct thermal_cooling_device *cdev = instance->cdev;
96
97 if (instance->trip != trip)
98 continue;
99
100 if (!total_weight)
101 percentage = 100 / total_instance;
102 else
103 percentage = (instance->weight * 100) / total_weight;
104
105 instance->target = get_target_state(tz, cdev, percentage,
106 cur_trip_level);
107
108 mutex_lock(&instance->cdev->lock);
109 instance->cdev->updated = false;
110 mutex_unlock(&instance->cdev->lock);
111 thermal_cdev_update(cdev);
112 }
113 return 0;
114 }
115
116 static struct thermal_governor thermal_gov_fair_share = {
117 .name = "fair_share",
118 .throttle = fair_share_throttle,
119 };
120 THERMAL_GOVERNOR_DECLARE(thermal_gov_fair_share);