From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DF941946BC for ; Thu, 26 Mar 2026 11:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774524332; cv=none; b=mLBfH13vOyEpjeOg+iMl+XEaAGk0T2x+R6P9BTEx5cM0d0Ld4PajOs4b1ELykOyeXCI2V9UwJ7ArMynm58v1aKtAt3Zpj0DITrBc6CAFEj+K5IpAPjFrECjF7S+NyDmBj2OfMb4Ggf96iTQ3mjkGUtIG5vuxCqEmzNwbCSUAz6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774524332; c=relaxed/simple; bh=xg9KEybftToIhyeKvi3LSZ8BdXiuPOyUQjSLweID3Q8=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=NPTHJgC1u4gL1gbsgGIl2HEMZ7Km+Yw3LgxvIpYr3xx3yPNRXE9LvVRW1CRmhbORgvBXv9CJBCSx+F/O7/jQx/xfh0CO0t01bzbEkt+gZbAAbLuO0NUQVqmny/ioNeCf0pjPj1JGJ4jPsjd24AjiOYiXurrQ5ucIyh0lesZkgZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G7sdNnQ7; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G7sdNnQ7" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-128ba70cc99so520234c88.0 for ; Thu, 26 Mar 2026 04:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774524329; x=1775129129; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Ay8G1oJZ1K8BN/IzLR5Hr0MTltSuhb2JjZXdZm6J5LQ=; b=G7sdNnQ7PPRKiCxYgh50WtjrxRaZxXRmQWV0/4yjP5wGA5FT0BG+kRMBqKTHGOFezN aj1rttuqcAKz8nTnqXldE/bQ+YHNMc9faPXa2AthAtwNKbRWprwbaIFFQ7IuQSBQfKPb 8vJUu9dgY7oct9HZUZuu8C+QqcH3GYYeP8SZigmmu1HYB3LDPyB6GZJ1lSn2imB5Lpd9 AeGpjDdVulJnPgm9ki8ryU6WlKT8CsaQTohjGV2Auk9U9fNvPSK3WPV11qnlHVe5IaZK 4VKhlvpo79jXP7oGHH1sArAqktE8PgguDcEIpfDECErSUJCp17qdnfTqtIRSL2ppl4yW kUwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774524329; x=1775129129; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Ay8G1oJZ1K8BN/IzLR5Hr0MTltSuhb2JjZXdZm6J5LQ=; b=tMk2UZ3PkrY57bRFzOpmFokihc9UVMm5m6FUPEo9dcUkvroxY3zTRrLhnTh5AC+VcT rC5Ly3lmx6brApqGPfrUeE8ha+Dgvz+7UVtnvSbJektOxxj/TLwfh37n+j4rAHxUeP3q MMAMQpS9iHK939XGGDPyP34rDjV61RnaHiRLzHyo9ibYKjw+qOXeN5+RnY41TSBLT49g b1+uupE9QEUUwB+DWDTlbpK/iX4ipeBhZe6tEaiZReWN1zqdimTlsIE/9GZGYUvlgNep OtmvbVUNR5l1pSgmLEJGJi5c5wLGkdnvkJC2Aa6DPTrIO5U2YfS9alNi0g/i3k3vNkg0 AibA== X-Forwarded-Encrypted: i=1; AJvYcCVpsIimEfBNDxWanJi78sOMGw6Jq9xlPoyyM6jVuJmUsMMyvEkNbXkFjSeUKFWqKG/K/iirthk3uQH9yLo=@vger.kernel.org X-Gm-Message-State: AOJu0YxS31J0m0ZDToIdoS8fYwMiS8gUhsCjqjaNrVj7v4XyAMpH7o5k aGPaC7CZCOtXnszwCA1tOI2aPnD53RMpTaxqC7aJpK5BJPYlDr6qEhtjE1G6r9rg9VxiZskFDwT 1cQCse7fT5HsneQ== X-Received: from dlec13-n1.prod.google.com ([2002:a05:701b:428d:10b0:127:89b6:8d2a]) (user=wusamuel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:125:b0:128:d084:e921 with SMTP id a92af1059eb24-12a96e5d6famr3734825c88.14.1774524328974; Thu, 26 Mar 2026 04:25:28 -0700 (PDT) Date: Thu, 26 Mar 2026 04:25:18 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.1018.g2bb0e51243-goog Message-ID: <20260326112521.2827500-1-wusamuel@google.com> Subject: [PATCH v2 0/2] Support BPF traversal of wakeup sources From: Samuel Wu To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , Danilo Krummrich , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: memxor@gmail.com, Samuel Wu , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, driver-core@lists.linux.dev, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 | +-------+----+----------+----------+ 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@google.com/ Changes in v2: - Dropped CONFIG_PM_WAKEUP_STATS_SYSFS patch for future patchset - Added declarations for kfuncs to .h to fix sparse and checkpatch warnings - Added kfunc to get address of wakeup_source's head - Added example bpf prog selftest for traversal of wakeup sources per Kumar - Added *_fail.c selftest per Kumar - More concise commit message in patch 1/2 - v1 link: https://lore.kernel.org/all/20260320160055.4114055-1-wusamuel@google.com/ Samuel Wu (2): PM: wakeup: Add kfuncs to traverse over wakeup_sources selftests/bpf: Add tests for wakeup_sources kfuncs drivers/base/power/power.h | 7 ++ drivers/base/power/wakeup.c | 72 +++++++++++- tools/testing/selftests/bpf/config | 3 +- .../selftests/bpf/prog_tests/wakeup_source.c | 101 +++++++++++++++++ .../selftests/bpf/progs/test_wakeup_source.c | 107 ++++++++++++++++++ .../selftests/bpf/progs/wakeup_source.h | 22 ++++ .../selftests/bpf/progs/wakeup_source_fail.c | 63 +++++++++++ 7 files changed, 372 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/wakeup_source.c create mode 100644 tools/testing/selftests/bpf/progs/test_wakeup_source.c create mode 100644 tools/testing/selftests/bpf/progs/wakeup_source.h create mode 100644 tools/testing/selftests/bpf/progs/wakeup_source_fail.c -- 2.53.0.1018.g2bb0e51243-goog