Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/thermal/thermal-engine: Take into account the thresholds API

Enhance the thermal-engine skeleton with the thresholds added in the
kernel and use the API exported by the thermal library.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/20241022155147.463475-6-daniel.lezcano@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Daniel Lezcano and committed by
Rafael J. Wysocki
41b89dba a2626724

+92 -13
+92 -13
tools/thermal/thermal-engine/thermal-engine.c
··· 38 38 struct thermal_handler *th; 39 39 }; 40 40 41 + static int show_threshold(struct thermal_threshold *th, __maybe_unused void *arg) 42 + { 43 + INFO("threshold temp=%d, direction=%d\n", 44 + th->temperature, th->direction); 45 + 46 + return 0; 47 + } 48 + 41 49 static int show_trip(struct thermal_trip *tt, __maybe_unused void *arg) 42 50 { 43 51 INFO("trip id=%d, type=%d, temp=%d, hyst=%d\n", ··· 78 70 79 71 for_each_thermal_trip(tz->trip, show_trip, NULL); 80 72 73 + for_each_thermal_threshold(tz->thresholds, show_threshold, NULL); 74 + 81 75 show_temp(tz, arg); 82 76 83 77 show_governor(tz, arg); 78 + 79 + return 0; 80 + } 81 + 82 + static int set_threshold(struct thermal_zone *tz, __maybe_unused void *arg) 83 + { 84 + struct thermal_handler *th = arg; 85 + int thresholds[] = { 43000, 65000, 49000, 55000, 57000 }; 86 + size_t i; 87 + 88 + INFO("Setting threshold for thermal zone '%s', id=%d\n", tz->name, tz->id); 89 + 90 + if (thermal_cmd_threshold_flush(th, tz)) { 91 + ERROR("Failed to flush all previous thresholds\n"); 92 + return -1; 93 + } 94 + 95 + for (i = 0; i < sizeof(thresholds) / sizeof(thresholds[0]); i++) 96 + if (thermal_cmd_threshold_add(th, tz, thresholds[i], 97 + THERMAL_THRESHOLD_WAY_UP | 98 + THERMAL_THRESHOLD_WAY_DOWN)) { 99 + ERROR("Failed to set threshold\n"); 100 + return -1; 101 + } 84 102 85 103 return 0; 86 104 } ··· 231 197 return 0; 232 198 } 233 199 200 + static int threshold_add(int tz_id, int temp, int direction, __maybe_unused void *arg) 201 + { 202 + INFO("Threshold added tz_id=%d: temp=%d, direction=%d\n", tz_id, temp, direction); 203 + 204 + return 0; 205 + } 206 + 207 + static int threshold_delete(int tz_id, int temp, int direction, __maybe_unused void *arg) 208 + { 209 + INFO("Threshold deleted tz_id=%d: temp=%d, direction=%d\n", tz_id, temp, direction); 210 + 211 + return 0; 212 + } 213 + 214 + static int threshold_flush(int tz_id, __maybe_unused void *arg) 215 + { 216 + INFO("Thresholds flushed tz_id=%d\n", tz_id); 217 + 218 + return 0; 219 + } 220 + 221 + static int threshold_up(int tz_id, int temp, int prev_temp, __maybe_unused void *arg) 222 + { 223 + INFO("Threshold crossed way up tz_id=%d: temp=%d, prev_temp=%d\n", 224 + tz_id, temp, prev_temp); 225 + 226 + return 0; 227 + } 228 + 229 + static int threshold_down(int tz_id, int temp, int prev_temp, __maybe_unused void *arg) 230 + { 231 + INFO("Threshold crossed way down tz_id=%d: temp=%d, prev_temp=%d\n", 232 + tz_id, temp, prev_temp); 233 + 234 + return 0; 235 + } 236 + 234 237 static struct thermal_ops ops = { 235 - .events.tz_create = tz_create, 236 - .events.tz_delete = tz_delete, 237 - .events.tz_disable = tz_disable, 238 - .events.tz_enable = tz_enable, 239 - .events.trip_high = trip_high, 240 - .events.trip_low = trip_low, 241 - .events.trip_add = trip_add, 242 - .events.trip_delete = trip_delete, 243 - .events.trip_change = trip_change, 244 - .events.cdev_add = cdev_add, 245 - .events.cdev_delete = cdev_delete, 246 - .events.cdev_update = cdev_update, 247 - .events.gov_change = gov_change 238 + .events.tz_create = tz_create, 239 + .events.tz_delete = tz_delete, 240 + .events.tz_disable = tz_disable, 241 + .events.tz_enable = tz_enable, 242 + .events.trip_high = trip_high, 243 + .events.trip_low = trip_low, 244 + .events.trip_add = trip_add, 245 + .events.trip_delete = trip_delete, 246 + .events.trip_change = trip_change, 247 + .events.cdev_add = cdev_add, 248 + .events.cdev_delete = cdev_delete, 249 + .events.cdev_update = cdev_update, 250 + .events.gov_change = gov_change, 251 + .events.threshold_add = threshold_add, 252 + .events.threshold_delete = threshold_delete, 253 + .events.threshold_flush = threshold_flush, 254 + .events.threshold_up = threshold_up, 255 + .events.threshold_down = threshold_down, 248 256 }; 249 257 250 258 static int thermal_event(__maybe_unused int fd, __maybe_unused void *arg) ··· 356 280 THERMAL_ENGINE_DAEMON_ERROR, 357 281 THERMAL_ENGINE_LOG_ERROR, 358 282 THERMAL_ENGINE_THERMAL_ERROR, 283 + THERMAL_ENGINE_THRESHOLD_ERROR, 359 284 THERMAL_ENGINE_MAINLOOP_ERROR, 360 285 }; 361 286 ··· 394 317 ERROR("No thermal zone available\n"); 395 318 return THERMAL_ENGINE_THERMAL_ERROR; 396 319 } 320 + 321 + for_each_thermal_zone(td.tz, set_threshold, td.th); 397 322 398 323 for_each_thermal_zone(td.tz, show_tz, td.th); 399 324