arch/x86/events/intel/lbr.c
Source file repositories/reference/linux-study-clean/arch/x86/events/intel/lbr.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/events/intel/lbr.c- Extension
.c- Size
- 45296 bytes
- Lines
- 1715
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kvm_types.hlinux/perf_event.hlinux/types.hasm/cpu_device_id.hasm/cpuid/api.hasm/perf_event.hasm/msr.h../perf_event.h
Detected Declarations
function is_lbr_call_stack_bit_setfunction __intel_pmu_lbr_enablefunction intel_pmu_lbr_reset_32function intel_pmu_lbr_reset_64function intel_pmu_arch_lbr_resetfunction intel_pmu_lbr_resetfunction intel_pmu_lbr_tosfunction rdmsrfunction lbr_from_signext_quirk_wrfunction lbr_from_signext_quirk_rdfunction wrlbr_fromfunction wrlbr_tofunction wrlbr_infofunction rdlbr_fromfunction rdlbr_tofunction rdlbr_infofunction wrlbr_allfunction rdlbr_allfunction intel_pmu_lbr_restorefunction intel_pmu_arch_lbr_restorefunction intel_pmu_arch_lbr_xrstorsfunction lbr_is_reset_in_cstatefunction has_lbr_callstack_usersfunction __intel_pmu_lbr_restorefunction intel_pmu_lbr_savefunction intel_pmu_arch_lbr_savefunction intel_pmu_arch_lbr_xsavesfunction __intel_pmu_lbr_savefunction intel_pmu_lbr_sched_taskfunction branch_user_callstackfunction intel_pmu_lbr_addfunction release_lbr_buffersfunction for_each_possible_cpufunction reserve_lbr_buffersfunction for_each_possible_cpufunction intel_pmu_lbr_delfunction vlbr_exclude_hostfunction intel_pmu_lbr_enable_allfunction intel_pmu_lbr_disable_allfunction intel_pmu_lbr_read_32function addressfunction get_lbr_br_typefunction get_lbr_mispredfunction get_lbr_cyclesfunction intel_pmu_store_lbrfunction intel_pmu_lbr_counters_reorderfunction for_each_sibling_eventfunction intel_pmu_lbr_save_brstack
Annotated Snippet
task_context_opt(ctx)->lbr_stack_state == LBR_NONE) {
intel_pmu_lbr_reset();
return;
}
/*
* Does not restore the LBR registers, if
* - No one else touched them, and
* - Was not cleared in Cstate
*/
if ((ctx == cpuc->last_task_ctx) &&
(task_context_opt(ctx)->log_id == cpuc->last_log_id) &&
!lbr_is_reset_in_cstate(ctx)) {
task_context_opt(ctx)->lbr_stack_state = LBR_NONE;
return;
}
x86_pmu.lbr_restore(ctx);
task_context_opt(ctx)->lbr_stack_state = LBR_NONE;
}
void intel_pmu_lbr_save(void *ctx)
{
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
struct x86_perf_task_context *task_ctx = ctx;
bool need_info = x86_pmu.lbr_has_info;
unsigned lbr_idx, mask;
u64 tos;
int i;
mask = x86_pmu.lbr_nr - 1;
tos = intel_pmu_lbr_tos();
for (i = 0; i < x86_pmu.lbr_nr; i++) {
lbr_idx = (tos - i) & mask;
if (!rdlbr_all(&task_ctx->lbr[i], lbr_idx, need_info))
break;
}
task_ctx->valid_lbrs = i;
task_ctx->tos = tos;
if (cpuc->lbr_select)
rdmsrq(MSR_LBR_SELECT, task_ctx->lbr_sel);
}
static void intel_pmu_arch_lbr_save(void *ctx)
{
struct x86_perf_task_context_arch_lbr *task_ctx = ctx;
struct lbr_entry *entries = task_ctx->entries;
int i;
for (i = 0; i < x86_pmu.lbr_nr; i++) {
if (!rdlbr_all(&entries[i], i, true))
break;
}
/* LBR call stack is not full. Reset is required in restore. */
if (i < x86_pmu.lbr_nr)
entries[x86_pmu.lbr_nr - 1].from = 0;
}
/*
* Save the Architecture LBR state to the xsave area in the perf
* context data for the task via the XSAVES instruction.
*/
static void intel_pmu_arch_lbr_xsaves(void *ctx)
{
struct x86_perf_task_context_arch_lbr_xsave *task_ctx = ctx;
xsaves(&task_ctx->xsave, XFEATURE_MASK_LBR);
}
static void __intel_pmu_lbr_save(void *ctx)
{
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
if (!has_lbr_callstack_users(ctx)) {
task_context_opt(ctx)->lbr_stack_state = LBR_NONE;
return;
}
x86_pmu.lbr_save(ctx);
task_context_opt(ctx)->lbr_stack_state = LBR_VALID;
cpuc->last_task_ctx = ctx;
cpuc->last_log_id = ++task_context_opt(ctx)->log_id;
}
void intel_pmu_lbr_sched_task(struct perf_event_pmu_context *pmu_ctx,
Annotation
- Immediate include surface: `linux/kvm_types.h`, `linux/perf_event.h`, `linux/types.h`, `asm/cpu_device_id.h`, `asm/cpuid/api.h`, `asm/perf_event.h`, `asm/msr.h`, `../perf_event.h`.
- Detected declarations: `function is_lbr_call_stack_bit_set`, `function __intel_pmu_lbr_enable`, `function intel_pmu_lbr_reset_32`, `function intel_pmu_lbr_reset_64`, `function intel_pmu_arch_lbr_reset`, `function intel_pmu_lbr_reset`, `function intel_pmu_lbr_tos`, `function rdmsr`, `function lbr_from_signext_quirk_wr`, `function lbr_from_signext_quirk_rd`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.