drivers/base/power/wakeup.c
Source file repositories/reference/linux-study-clean/drivers/base/power/wakeup.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/power/wakeup.c- Extension
.c- Size
- 33542 bytes
- Lines
- 1246
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/slab.hlinux/sched/signal.hlinux/capability.hlinux/export.hlinux/suspend.hlinux/seq_file.hlinux/debugfs.hlinux/pm_wakeirq.htrace/events/power.hpower.hlinux/btf.h
Detected Declarations
function split_countersfunction wakeup_source_recordfunction wakeup_source_freefunction wakeup_source_createfunction wakeup_source_addfunction wakeup_source_removefunction wakeup_source_unregisterfunction wakeup_sources_read_unlockfunction wakeup_sources_read_unlockfunction wakeup_source_read_lockfunction wakeup_source_read_lockfunction device_wakeup_attachfunction device_wakeup_enablefunction device_wakeup_attach_irqfunction device_wakeup_detach_irqfunction device_wakeup_arm_wake_irqsfunction device_wakeup_disarm_wake_irqsfunction device_wakeup_disablefunction device_set_wakeup_capablefunction device_set_wakeup_enablefunction wakeup_source_not_usablefunction pm_relaxfunction wakeup_source_report_eventfunction __pm_stay_awakefunction eventfunction update_prevent_sleep_timefunction update_prevent_sleep_timefunction __pm_relaxfunction __pm_stay_awakefunction __pm_relaxfunction wakeup_source_deactivatefunction pm_wakeup_timer_fnfunction pm_wakeup_ws_eventfunction pm_print_active_wakeup_sourcesfunction ktime_to_nsfunction pm_wakeup_pendingfunction pm_system_wakeupfunction pm_system_cancel_wakeupfunction pm_wakeup_clearfunction pm_system_irq_wakeupfunction pm_wakeup_irqfunction pm_get_wakeup_countfunction pm_check_wakeup_eventsfunction pm_wakep_autosleep_enabledfunction print_wakeup_source_statsfunction list_for_each_entry_continue_rcufunction wakeup_sources_stats_seq_stopfunction wakeup_sources_stats_seq_show
Annotated Snippet
static const struct file_operations wakeup_sources_stats_fops = {
.owner = THIS_MODULE,
.open = wakeup_sources_stats_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
#ifdef CONFIG_BPF_SYSCALL
#include <linux/btf.h>
__bpf_kfunc_start_defs();
/**
* bpf_wakeup_sources_read_lock - Acquire the SRCU lock for wakeup sources
*
* The underlying SRCU lock returns an integer index. However, the BPF verifier
* requires a pointer (PTR_TO_BTF_ID) to strictly track the state of acquired
* resources using KF_ACQUIRE and KF_RELEASE semantics. We use an opaque
* structure pointer (struct bpf_ws_lock *) to satisfy the verifier while
* safely encoding the integer index within the pointer address itself.
*
* Return: An opaque pointer encoding the SRCU lock index + 1 (to avoid NULL).
*/
__bpf_kfunc struct bpf_ws_lock *bpf_wakeup_sources_read_lock(void)
{
return (struct bpf_ws_lock *)(long)(wakeup_sources_read_lock() + 1);
}
/**
* bpf_wakeup_sources_read_unlock - Release the SRCU lock for wakeup sources
* @lock: The opaque pointer returned by bpf_wakeup_sources_read_lock()
*
* The BPF verifier guarantees that @lock is a valid, unreleased pointer from
* the acquire function. We decode the pointer back into the integer SRCU index
* by subtracting 1 and release the lock.
*/
__bpf_kfunc void bpf_wakeup_sources_read_unlock(struct bpf_ws_lock *lock)
{
wakeup_sources_read_unlock((int)(long)lock - 1);
}
/**
* bpf_wakeup_sources_get_head - Get the head of the wakeup sources list
*
* Return: The head of the wakeup sources list.
*/
__bpf_kfunc void *bpf_wakeup_sources_get_head(void)
{
return &wakeup_sources;
}
__bpf_kfunc_end_defs();
BTF_KFUNCS_START(wakeup_source_kfunc_ids)
BTF_ID_FLAGS(func, bpf_wakeup_sources_read_lock, KF_ACQUIRE)
BTF_ID_FLAGS(func, bpf_wakeup_sources_read_unlock, KF_RELEASE)
BTF_ID_FLAGS(func, bpf_wakeup_sources_get_head)
BTF_KFUNCS_END(wakeup_source_kfunc_ids)
static const struct btf_kfunc_id_set wakeup_source_kfunc_set = {
.set = &wakeup_source_kfunc_ids,
};
static void __init wakeup_sources_bpf_init(void)
{
if (register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &wakeup_source_kfunc_set))
pm_pr_dbg("Wakeup: failed to register BTF kfuncs\n");
}
#else
static inline void wakeup_sources_bpf_init(void) {}
#endif /* CONFIG_BPF_SYSCALL */
static int __init wakeup_sources_init(void)
{
debugfs_create_file("wakeup_sources", 0444, NULL, NULL,
&wakeup_sources_stats_fops);
wakeup_sources_bpf_init();
return 0;
}
postcore_initcall(wakeup_sources_init);
Annotation
- Immediate include surface: `linux/device.h`, `linux/slab.h`, `linux/sched/signal.h`, `linux/capability.h`, `linux/export.h`, `linux/suspend.h`, `linux/seq_file.h`, `linux/debugfs.h`.
- Detected declarations: `function split_counters`, `function wakeup_source_record`, `function wakeup_source_free`, `function wakeup_source_create`, `function wakeup_source_add`, `function wakeup_source_remove`, `function wakeup_source_unregister`, `function wakeup_sources_read_unlock`, `function wakeup_sources_read_unlock`, `function wakeup_source_read_lock`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.