Skip to content

Commit 31a0fa0

Browse files
committed
thermal/debugfs: Pass cooling device state to thermal_debug_cdev_add()
If cdev_dt_seq_show() runs before the first state transition of a cooling device, it will not print any state residency information for it, even though it might be reasonably expected to print residency information for the initial state of the cooling device. For this reason, rearrange the code to get the initial state of a cooling device at the registration time and pass it to thermal_debug_cdev_add(), so that the latter can create a duration record for that state which will allow cdev_dt_seq_show() to print its residency information. Fixes: 755113d ("thermal/debugfs: Add thermal cooling device debugfs information") Reported-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Tested-by: Lukasz Luba <[email protected]>
1 parent f4ae18f commit 31a0fa0

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

drivers/thermal/thermal_core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ __thermal_cooling_device_register(struct device_node *np,
935935
{
936936
struct thermal_cooling_device *cdev;
937937
struct thermal_zone_device *pos = NULL;
938+
unsigned long current_state;
938939
int id, ret;
939940

940941
if (!ops || !ops->get_max_state || !ops->get_cur_state ||
@@ -972,6 +973,10 @@ __thermal_cooling_device_register(struct device_node *np,
972973
if (ret)
973974
goto out_cdev_type;
974975

976+
ret = cdev->ops->get_cur_state(cdev, &current_state);
977+
if (ret)
978+
goto out_cdev_type;
979+
975980
thermal_cooling_device_setup_sysfs(cdev);
976981

977982
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
@@ -985,6 +990,8 @@ __thermal_cooling_device_register(struct device_node *np,
985990
return ERR_PTR(ret);
986991
}
987992

993+
thermal_debug_cdev_add(cdev, current_state);
994+
988995
/* Add 'this' new cdev to the global cdev list */
989996
mutex_lock(&thermal_list_lock);
990997

@@ -1000,8 +1007,6 @@ __thermal_cooling_device_register(struct device_node *np,
10001007

10011008
mutex_unlock(&thermal_list_lock);
10021009

1003-
thermal_debug_cdev_add(cdev);
1004-
10051010
return cdev;
10061011

10071012
out_cooling_dev:

drivers/thermal/thermal_debugfs.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,9 @@ void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev,
468468
* Allocates a cooling device object for debug, initializes the
469469
* statistics and create the entries in sysfs.
470470
* @cdev: a pointer to a cooling device
471+
* @state: current state of the cooling device
471472
*/
472-
void thermal_debug_cdev_add(struct thermal_cooling_device *cdev)
473+
void thermal_debug_cdev_add(struct thermal_cooling_device *cdev, int state)
473474
{
474475
struct thermal_debugfs *thermal_dbg;
475476
struct cdev_debugfs *cdev_dbg;
@@ -486,9 +487,16 @@ void thermal_debug_cdev_add(struct thermal_cooling_device *cdev)
486487
INIT_LIST_HEAD(&cdev_dbg->durations[i]);
487488
}
488489

489-
cdev_dbg->current_state = 0;
490+
cdev_dbg->current_state = state;
490491
cdev_dbg->timestamp = ktime_get();
491492

493+
/*
494+
* Create a record for the initial cooling device state, so its
495+
* duration will be printed by cdev_dt_seq_show() as expected if it
496+
* runs before the first state transition.
497+
*/
498+
thermal_debugfs_cdev_record_get(thermal_dbg, cdev_dbg->durations, state);
499+
492500
debugfs_create_file("trans_table", 0400, thermal_dbg->d_top,
493501
thermal_dbg, &tt_fops);
494502

drivers/thermal/thermal_debugfs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#ifdef CONFIG_THERMAL_DEBUGFS
44
void thermal_debug_init(void);
5-
void thermal_debug_cdev_add(struct thermal_cooling_device *cdev);
5+
void thermal_debug_cdev_add(struct thermal_cooling_device *cdev, int state);
66
void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev);
77
void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev, int state);
88
void thermal_debug_tz_add(struct thermal_zone_device *tz);
@@ -14,7 +14,7 @@ void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
1414
void thermal_debug_update_trip_stats(struct thermal_zone_device *tz);
1515
#else
1616
static inline void thermal_debug_init(void) {}
17-
static inline void thermal_debug_cdev_add(struct thermal_cooling_device *cdev) {}
17+
static inline void thermal_debug_cdev_add(struct thermal_cooling_device *cdev, int state) {}
1818
static inline void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev) {}
1919
static inline void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev,
2020
int state) {}

0 commit comments

Comments
 (0)