[PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources

From: Samuel Wu

Date: Fri Mar 20 2026 - 12:01:37 EST


Add a config flag that gates the creation of
/sys/class/wakeup_sources/*. This has the benefit of eliminating the
work needed to create the nodes and corresponding attributes; and
between kernfs, dentry, and malloc, there are some memory savings
depending on the number of wakeup sources.

Signed-off-by: Samuel Wu <wusamuel@xxxxxxxxxx>
---
drivers/base/power/Makefile | 3 ++-
drivers/base/power/power.h | 14 ++++++++++++++
kernel/power/Kconfig | 13 +++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 2989e42d0161..5933dadc0dd9 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
-obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o
+obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o
+obj-$(CONFIG_PM_WAKEUP_STATS_SYSFS) += wakeup_stats.o
obj-$(CONFIG_PM_TRACE_RTC) += trace.o
obj-$(CONFIG_HAVE_CLK) += clock_ops.o
obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 922ed457db19..364ca5512b4f 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -125,11 +125,25 @@ static inline bool device_pm_initialized(struct device *dev)
}

/* drivers/base/power/wakeup_stats.c */
+#ifdef CONFIG_PM_WAKEUP_STATS_SYSFS
extern int wakeup_source_sysfs_add(struct device *parent,
struct wakeup_source *ws);
extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);

extern int pm_wakeup_source_sysfs_add(struct device *parent);
+#else /* !CONFIG_PM_WAKEUP_STATS_SYSFS */
+static inline int wakeup_source_sysfs_add(struct device *parent,
+ struct wakeup_source *ws)
+{
+ return 0;
+}
+static inline void wakeup_source_sysfs_remove(struct wakeup_source *ws) {}
+
+static inline int pm_wakeup_source_sysfs_add(struct device *parent)
+{
+ return 0;
+}
+#endif /* !CONFIG_PM_WAKEUP_STATS_SYSFS */

#else /* !CONFIG_PM_SLEEP */

diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 05337f437cca..6945083ab053 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -202,6 +202,19 @@ config PM_WAKELOCKS_GC
depends on PM_WAKELOCKS
default y

+config PM_WAKEUP_STATS_SYSFS
+ bool "Sysfs wakeup statistics"
+ depends on PM_SLEEP
+ default y
+ help
+ Enable this for wakeup statistics in sysfs under /sys/class/wakeup/
+
+ Disabling this option eliminates the work of creating the wakeup
+ sources and each of their attributes in sysfs. Depending on the
+ number of wakeup sources, this can also have a non-negligible memory
+ impact. Regardless of this config option's value, wakeup statistics
+ are still available via debugfs and BPF.
+
config PM_QOS_CPU_SYSTEM_WAKEUP
bool "User space interface for CPU system wakeup QoS"
depends on CPU_IDLE
--
2.53.0.959.g497ff81fa9-goog