[PATCH v1 0/2] *** Support BPF traversal of wakeup sources ***

From: Samuel Wu

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


This patchset adds requisite kfuncs for BPF programs to safely traverse
wakeup_sources, and puts a config flag around the sysfs interface.

Currently, a traversal of wakeup sources require going through
/sys/class/wakeup/* or /d/wakeup_sources/*. The repeated syscalls to query
sysfs is inefficient, as there can be hundreds of wakeup_sources, with each
wakeup source also having multiple attributes. debugfs is unstable and
insecure.

Adding kfuncs to lock/unlock wakeup sources allows BPF program to safely
traverse the wakeup sources list. The head address of wakeup_sources can
safely be resolved through BPF helper functions or variable attributes.

On a quiescent Pixel 6 traversing 150 wakeup_sources, I am seeing ~34x
speedup (sampled 75 times in table below). For a device under load, the
speedup is greater.
+-------+----+----------+----------+
| | n | AVG (ms) | STD (ms) |
+-------+----+----------+----------+
| sysfs | 75 | 44.9 | 12.6 |
+-------+----+----------+----------+
| BPF | 75 | 1.3 | 0.7 |
+-------+----+----------+----------+

On the memory side, between kernfs, dentry, and kmalloc, each wakeup source
removed from sysfs saves at least 10kB.

The initial attempts for BPF traversal of wakeup_sources was with BPF
iterators [1]. However, BPF already allows for traversing of a simple list
with bpf_for(), and this current patchset has the added benefit of being
~2-3x more performant than BPF iterators.

[1]: https://lore.kernel.org/all/20260225210820.177674-1-wusamuel@xxxxxxxxxx/

Samuel Wu (2):
PM: wakeup: Add kfuncs to lock/unlock wakeup_sources
PM: Add config flag to gate sysfs wakeup_sources

drivers/base/power/Makefile | 3 +-
drivers/base/power/power.h | 14 +++++++++
drivers/base/power/wakeup.c | 63 +++++++++++++++++++++++++++++++++++--
kernel/power/Kconfig | 13 ++++++++
4 files changed, 90 insertions(+), 3 deletions(-)

--
2.53.0.959.g497ff81fa9-goog