arch/x86/kernel/cpu/resctrl/pseudo_lock.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/resctrl/pseudo_lock.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/resctrl/pseudo_lock.c- Extension
.c- Size
- 15484 bytes
- Lines
- 518
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cacheflush.hlinux/cpu.hlinux/perf_event.hlinux/pm_qos.hlinux/resctrl.hasm/cpu_device_id.hasm/perf_event.hasm/msr.h../../events/perf_event.hinternal.hpseudo_lock_trace.h
Detected Declarations
struct residency_countsfunction resctrl_arch_get_prefetch_disable_bitsfunction resctrl_arch_pseudo_lock_fnfunction resctrl_arch_measure_cycles_lat_fnfunction measure_residency_fnfunction resctrl_arch_measure_l2_residencyfunction Manualfunction resctrl_arch_measure_l3_residency
Annotated Snippet
struct residency_counts {
u64 miss_before, hits_before;
u64 miss_after, hits_after;
};
static int measure_residency_fn(struct perf_event_attr *miss_attr,
struct perf_event_attr *hit_attr,
struct pseudo_lock_region *plr,
struct residency_counts *counts)
{
u64 hits_before = 0, hits_after = 0, miss_before = 0, miss_after = 0;
struct perf_event *miss_event, *hit_event;
int hit_pmcnum, miss_pmcnum;
u32 saved_low, saved_high;
unsigned int line_size;
unsigned int size;
unsigned long i;
void *mem_r;
u64 tmp;
miss_event = perf_event_create_kernel_counter(miss_attr, plr->cpu,
NULL, NULL, NULL);
if (IS_ERR(miss_event))
goto out;
hit_event = perf_event_create_kernel_counter(hit_attr, plr->cpu,
NULL, NULL, NULL);
if (IS_ERR(hit_event))
goto out_miss;
local_irq_disable();
/*
* Check any possible error state of events used by performing
* one local read.
*/
if (perf_event_read_local(miss_event, &tmp, NULL, NULL)) {
local_irq_enable();
goto out_hit;
}
if (perf_event_read_local(hit_event, &tmp, NULL, NULL)) {
local_irq_enable();
goto out_hit;
}
/*
* Disable hardware prefetchers.
*/
rdmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
wrmsrq(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits);
/* Initialize rest of local variables */
/*
* Performance event has been validated right before this with
* interrupts disabled - it is thus safe to read the counter index.
*/
miss_pmcnum = x86_perf_rdpmc_index(miss_event);
hit_pmcnum = x86_perf_rdpmc_index(hit_event);
line_size = READ_ONCE(plr->line_size);
mem_r = READ_ONCE(plr->kmem);
size = READ_ONCE(plr->size);
/*
* Read counter variables twice - first to load the instructions
* used in L1 cache, second to capture accurate value that does not
* include cache misses incurred because of instruction loads.
*/
hits_before = rdpmc(hit_pmcnum);
miss_before = rdpmc(miss_pmcnum);
/*
* From SDM: Performing back-to-back fast reads are not guaranteed
* to be monotonic.
* Use LFENCE to ensure all previous instructions are retired
* before proceeding.
*/
rmb();
hits_before = rdpmc(hit_pmcnum);
miss_before = rdpmc(miss_pmcnum);
/*
* Use LFENCE to ensure all previous instructions are retired
* before proceeding.
*/
rmb();
for (i = 0; i < size; i += line_size) {
/*
* Add a barrier to prevent speculative execution of this
* loop reading beyond the end of the buffer.
*/
rmb();
asm volatile("mov (%0,%1,1), %%eax\n\t"
:
Annotation
- Immediate include surface: `linux/cacheflush.h`, `linux/cpu.h`, `linux/perf_event.h`, `linux/pm_qos.h`, `linux/resctrl.h`, `asm/cpu_device_id.h`, `asm/perf_event.h`, `asm/msr.h`.
- Detected declarations: `struct residency_counts`, `function resctrl_arch_get_prefetch_disable_bits`, `function resctrl_arch_pseudo_lock_fn`, `function resctrl_arch_measure_cycles_lat_fn`, `function measure_residency_fn`, `function resctrl_arch_measure_l2_residency`, `function Manual`, `function resctrl_arch_measure_l3_residency`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.