arch/x86/events/intel/pt.c
Source file repositories/reference/linux-study-clean/arch/x86/events/intel/pt.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/events/intel/pt.c- Extension
.c- Size
- 46947 bytes
- Lines
- 1894
- 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.
- 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/types.hlinux/bits.hlinux/limits.hlinux/slab.hlinux/device.hlinux/kvm_types.hasm/cpuid/api.hasm/perf_event.hasm/insn.hasm/io.hasm/intel_pt.hasm/cpu_device_id.hasm/msr.h../perf_event.hpt.h
Detected Declarations
struct topastruct topa_pagefunction intel_pt_validate_capfunction intel_pt_validate_hw_capfunction pt_cap_showfunction pt_timing_attr_showfunction pt_pmu_hw_initfunction pt_event_validfunction pt_config_startfunction pt_config_filtersfunction pt_configfunction pt_event_validfunction pt_config_stopfunction topa_pfnfunction pt_config_bufferfunction topa_allocfunction topa_freefunction topa_insert_tablefunction topa_table_fullfunction topa_insert_pagesfunction pt_topa_dumpfunction list_for_each_entryfunction pt_buffer_advancefunction pt_update_headfunction pt_buffer_regionfunction pt_buffer_region_sizefunction pt_handle_statusfunction pt_buffer_region_sizefunction pt_read_offsetfunction pt_topa_entry_for_pagefunction pt_topa_prev_entryfunction pt_buffer_reset_markersfunction pt_buffer_reset_offsetsfunction pt_buffer_fini_topafunction list_for_each_entry_safefunction pt_buffer_init_topafunction pt_buffer_try_singlefunction pt_buffer_setup_auxfunction pt_buffer_free_auxfunction pt_addr_filters_initfunction pt_addr_filters_finifunction clamp_to_ge_canonical_addrfunction clamp_to_le_canonical_addrfunction pt_event_addr_filters_validatefunction list_for_each_entryfunction pt_event_addr_filters_syncfunction list_for_each_entryfunction intel_pt_interrupt
Annotated Snippet
struct topa {
struct list_head list;
u64 offset;
size_t size;
int last;
unsigned int z_count;
};
/*
* Keep ToPA table-related metadata on the same page as the actual table,
* taking up a few words from the top
*/
#define TENTS_PER_PAGE \
((PAGE_SIZE - sizeof(struct topa)) / sizeof(struct topa_entry))
/**
* struct topa_page - page-sized ToPA table with metadata at the top
* @table: actual ToPA table entries, as understood by PT hardware
* @topa: metadata
*/
struct topa_page {
struct topa_entry table[TENTS_PER_PAGE];
struct topa topa;
};
static inline struct topa_page *topa_to_page(struct topa *topa)
{
return container_of(topa, struct topa_page, topa);
}
static inline struct topa_page *topa_entry_to_page(struct topa_entry *te)
{
return (struct topa_page *)((unsigned long)te & PAGE_MASK);
}
static inline phys_addr_t topa_pfn(struct topa *topa)
{
return PFN_DOWN(virt_to_phys(topa_to_page(topa)));
}
/* make -1 stand for the last table entry */
#define TOPA_ENTRY(t, i) \
((i) == -1 \
? &topa_to_page(t)->table[(t)->last] \
: &topa_to_page(t)->table[(i)])
#define TOPA_ENTRY_SIZE(t, i) (sizes(TOPA_ENTRY((t), (i))->size))
#define TOPA_ENTRY_PAGES(t, i) (1 << TOPA_ENTRY((t), (i))->size)
static void pt_config_buffer(struct pt_buffer *buf)
{
struct pt *pt = this_cpu_ptr(&pt_ctx);
u64 reg, mask;
void *base;
if (buf->single) {
base = buf->data_pages[0];
mask = (buf->nr_pages * PAGE_SIZE - 1) >> 7;
} else {
base = topa_to_page(buf->cur)->table;
mask = (u64)buf->cur_idx;
}
reg = virt_to_phys(base);
if (pt->output_base != reg) {
pt->output_base = reg;
wrmsrq(MSR_IA32_RTIT_OUTPUT_BASE, reg);
}
reg = 0x7f | (mask << 7) | ((u64)buf->output_off << 32);
if (pt->output_mask != reg) {
pt->output_mask = reg;
wrmsrq(MSR_IA32_RTIT_OUTPUT_MASK, reg);
}
}
/**
* topa_alloc() - allocate page-sized ToPA table
* @cpu: CPU on which to allocate.
* @gfp: Allocation flags.
*
* Return: On success, return the pointer to ToPA table page.
*/
static struct topa *topa_alloc(int cpu, gfp_t gfp)
{
int node = cpu_to_node(cpu);
struct topa_page *tp;
struct page *p;
p = alloc_pages_node(node, gfp | __GFP_ZERO, 0);
Annotation
- Immediate include surface: `linux/types.h`, `linux/bits.h`, `linux/limits.h`, `linux/slab.h`, `linux/device.h`, `linux/kvm_types.h`, `asm/cpuid/api.h`, `asm/perf_event.h`.
- Detected declarations: `struct topa`, `struct topa_page`, `function intel_pt_validate_cap`, `function intel_pt_validate_hw_cap`, `function pt_cap_show`, `function pt_timing_attr_show`, `function pt_pmu_hw_init`, `function pt_event_valid`, `function pt_config_start`, `function pt_config_filters`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
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.