kernel/events/hw_breakpoint.c
Source file repositories/reference/linux-study-clean/kernel/events/hw_breakpoint.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/events/hw_breakpoint.c- Extension
.c- Size
- 27320 bytes
- Lines
- 1026
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/hw_breakpoint.hlinux/atomic.hlinux/bug.hlinux/cpu.hlinux/export.hlinux/init.hlinux/irqflags.hlinux/kdebug.hlinux/kernel.hlinux/mutex.hlinux/notifier.hlinux/percpu-rwsem.hlinux/percpu.hlinux/rhashtable.hlinux/sched.hlinux/slab.h
Detected Declarations
struct bp_slots_histogramstruct bp_cpuinfofunction bp_constraints_unlockfunction bp_constraints_is_lockedfunction assert_bp_constraints_lock_heldfunction hw_breakpoint_slots_cachedfunction init_breakpoint_slotsfunction hw_breakpoint_slots_cachedfunction bp_slots_histogram_allocfunction bp_slots_histogram_freefunction init_breakpoint_slotsfunction for_each_possible_cpufunction bp_slots_histogram_addfunction bp_slots_histogram_maxfunction bp_slots_histogram_max_mergefunction hw_breakpoint_weightfunction find_slot_idxfunction max_task_bp_pinnedfunction task_bp_pinnedfunction rhl_for_each_entry_rcufunction CPUfunction for_each_cpufunction toggle_bp_slotfunction for_each_possible_cpufunction for_each_possible_cpufunction for_each_cpufunction breakpointsfunction reserve_bp_slotfunction __release_bp_slotfunction release_bp_slotfunction __modify_bp_slotfunction modify_bp_slotfunction dbg_reserve_bp_slotfunction dbg_release_bp_slotfunction hw_breakpoint_parsefunction register_perf_hw_breakpointfunction register_user_hw_breakpointfunction hw_breakpoint_copy_attrfunction modify_user_hw_breakpoint_checkfunction modify_user_hw_breakpointfunction unregister_hw_breakpointfunction register_wide_hw_breakpointfunction unregister_wide_hw_breakpointfunction hw_breakpoint_is_usedfunction for_each_possible_cpufunction bp_perf_event_destroyfunction hw_breakpoint_event_initfunction hw_breakpoint_add
Annotated Snippet
struct bp_slots_histogram {
#ifdef hw_breakpoint_slots
atomic_t count[hw_breakpoint_slots(0)];
#else
atomic_t *count;
#endif
};
/*
* Per-CPU constraints data.
*/
struct bp_cpuinfo {
/* Number of pinned CPU breakpoints in a CPU. */
unsigned int cpu_pinned;
/* Histogram of pinned task breakpoints in a CPU. */
struct bp_slots_histogram tsk_pinned;
};
static DEFINE_PER_CPU(struct bp_cpuinfo, bp_cpuinfo[TYPE_MAX]);
static struct bp_cpuinfo *get_bp_info(int cpu, enum bp_type_idx type)
{
return per_cpu_ptr(bp_cpuinfo + type, cpu);
}
/* Number of pinned CPU breakpoints globally. */
static struct bp_slots_histogram cpu_pinned[TYPE_MAX];
/* Number of pinned CPU-independent task breakpoints. */
static struct bp_slots_histogram tsk_pinned_all[TYPE_MAX];
/* Keep track of the breakpoints attached to tasks */
static struct rhltable task_bps_ht;
static const struct rhashtable_params task_bps_ht_params = {
.head_offset = offsetof(struct hw_perf_event, bp_list),
.key_offset = offsetof(struct hw_perf_event, target),
.key_len = sizeof_field(struct hw_perf_event, target),
.automatic_shrinking = true,
};
static bool constraints_initialized __ro_after_init;
/*
* Synchronizes accesses to the per-CPU constraints; the locking rules are:
*
* 1. Atomic updates to bp_cpuinfo::tsk_pinned only require a held read-lock
* (due to bp_slots_histogram::count being atomic, no update are lost).
*
* 2. Holding a write-lock is required for computations that require a
* stable snapshot of all bp_cpuinfo::tsk_pinned.
*
* 3. In all other cases, non-atomic accesses require the appropriately held
* lock (read-lock for read-only accesses; write-lock for reads/writes).
*/
DEFINE_STATIC_PERCPU_RWSEM(bp_cpuinfo_sem);
/*
* Return mutex to serialize accesses to per-task lists in task_bps_ht. Since
* rhltable synchronizes concurrent insertions/deletions, independent tasks may
* insert/delete concurrently; therefore, a mutex per task is sufficient.
*
* Uses task_struct::perf_event_mutex, to avoid extending task_struct with a
* hw_breakpoint-only mutex, which may be infrequently used. The caveat here is
* that hw_breakpoint may contend with per-task perf event list management. The
* assumption is that perf usecases involving hw_breakpoints are very unlikely
* to result in unnecessary contention.
*/
static inline struct mutex *get_task_bps_mutex(struct perf_event *bp)
{
struct task_struct *tsk = bp->hw.target;
return tsk ? &tsk->perf_event_mutex : NULL;
}
static struct mutex *bp_constraints_lock(struct perf_event *bp)
{
struct mutex *tsk_mtx = get_task_bps_mutex(bp);
if (tsk_mtx) {
/*
* Fully analogous to the perf_try_init_event() nesting
* argument in the comment near perf_event_ctx_lock_nested();
* this child->perf_event_mutex cannot ever deadlock against
* the parent->perf_event_mutex usage from
* perf_event_task_{en,dis}able().
*
* Specifically, inherited events will never occur on
* ->perf_event_list.
*/
mutex_lock_nested(tsk_mtx, SINGLE_DEPTH_NESTING);
percpu_down_read(&bp_cpuinfo_sem);
Annotation
- Immediate include surface: `linux/hw_breakpoint.h`, `linux/atomic.h`, `linux/bug.h`, `linux/cpu.h`, `linux/export.h`, `linux/init.h`, `linux/irqflags.h`, `linux/kdebug.h`.
- Detected declarations: `struct bp_slots_histogram`, `struct bp_cpuinfo`, `function bp_constraints_unlock`, `function bp_constraints_is_locked`, `function assert_bp_constraints_lock_held`, `function hw_breakpoint_slots_cached`, `function init_breakpoint_slots`, `function hw_breakpoint_slots_cached`, `function bp_slots_histogram_alloc`, `function bp_slots_histogram_free`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.