Skip to content

Commit

Permalink
thermal/debugfs: Add debugfs information
Browse files Browse the repository at this point in the history
The thermal framework does not have any debug information except a
sysfs stat which is a bit controversial. This one allocates big chunks
of memory for every cooling devices with a high number of states and
could represent on some systems in production several megabytes of
memory for just a portion of it. As the syfs is limited to a page
size, the output is not exploitable with large data array and gets
truncated.

The patch provides the same information than sysfs except the
transitions are dynamically allocated, thus they won't represent more
events than the ones which actually occured. There is no longer a size
limitation and it opens the field for more debugging information where
the debugfs is designed for, not sysfs.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
  • Loading branch information
dlezcano authored and intel-lab-lkp committed Jun 1, 2022
1 parent 5a1d30a commit 04c295f
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/thermal/Kconfig
Expand Up @@ -33,6 +33,13 @@ config THERMAL_STATISTICS

If in doubt, say N.

config THERMAL_DEBUGFS
bool "Thermal debugging file system"
depends on DEBUG_FS
help
This option provides a debugfs entry giving useful
information about the thermal framework internals.

config THERMAL_EMERGENCY_POWEROFF_DELAY_MS
int "Emergency poweroff delay in milli-seconds"
default 0
Expand Down
3 changes: 3 additions & 0 deletions drivers/thermal/Makefile
Expand Up @@ -10,6 +10,9 @@ thermal_sys-y += thermal_core.o thermal_sysfs.o \
# netlink interface to manage the thermal framework
thermal_sys-$(CONFIG_THERMAL_NETLINK) += thermal_netlink.o

# debugfs interface to investigate the behavior and statistics
thermal_sys-$(CONFIG_THERMAL_DEBUGFS) += thermal_debugfs.o

# interface to/from other layers providing sensors
thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o
thermal_sys-$(CONFIG_THERMAL_OF) += thermal_of.o
Expand Down
10 changes: 10 additions & 0 deletions drivers/thermal/thermal_core.c
Expand Up @@ -944,6 +944,8 @@ __thermal_cooling_device_register(struct device_node *np,
THERMAL_EVENT_UNSPECIFIED);
mutex_unlock(&thermal_list_lock);

thermal_debugfs_cdev_register(cdev);

return cdev;

out_kfree_type:
Expand Down Expand Up @@ -1079,6 +1081,8 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
if (!cdev)
return;

thermal_debugfs_cdev_unregister(cdev);

mutex_lock(&thermal_list_lock);
list_for_each_entry(pos, &thermal_cdev_list, node)
if (pos == cdev)
Expand Down Expand Up @@ -1311,6 +1315,8 @@ thermal_zone_device_register(const char *type, int trips, int mask,

thermal_notify_tz_create(tz->id, tz->type);

thermal_debugfs_tz_register(tz);

return tz;

unregister:
Expand Down Expand Up @@ -1340,6 +1346,8 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
if (!tz)
return;

thermal_debugfs_tz_unregister(tz);

tzp = tz->tzp;
tz_id = tz->id;

Expand Down Expand Up @@ -1485,6 +1493,8 @@ static int __init thermal_init(void)
pr_warn("Thermal: Can not register suspend notifier, return %d\n",
result);

thermal_debugfs_init();

return 0;

unregister_class:
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/thermal_core.h
Expand Up @@ -13,6 +13,7 @@
#include <linux/thermal.h>

#include "thermal_netlink.h"
#include "thermal_debugfs.h"

/* Default Thermal Governor */
#if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
Expand Down

0 comments on commit 04c295f

Please sign in to comment.