arch/x86/events/intel/uncore_nhmex.c
Source file repositories/reference/linux-study-clean/arch/x86/events/intel/uncore_nhmex.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/events/intel/uncore_nhmex.c- Extension
.c- Size
- 37582 bytes
- Lines
- 1231
- 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.
- 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
asm/cpu_device_id.hasm/msr.huncore.h
Detected Declarations
function nhmex_uncore_msr_init_boxfunction nhmex_uncore_msr_exit_boxfunction nhmex_uncore_msr_disable_boxfunction nhmex_uncore_msr_enable_boxfunction nhmex_uncore_msr_disable_eventfunction nhmex_uncore_msr_enable_eventfunction nhmex_bbox_hw_configfunction nhmex_bbox_msr_enable_eventfunction nhmex_sbox_hw_configfunction nhmex_sbox_msr_enable_eventfunction nhmex_mbox_get_shared_regfunction nhmex_mbox_put_shared_regfunction nhmex_mbox_alter_erfunction nhmex_mbox_get_constraintfunction get_event_constraintsfunction nhmex_mbox_put_constraintfunction nhmex_mbox_extra_reg_idxfunction nhmex_mbox_hw_configfunction nhmex_mbox_shared_reg_configfunction nhmex_mbox_msr_enable_eventfunction nhmex_rbox_alter_erfunction nhmex_rbox_get_constraintfunction nhmex_rbox_put_constraintfunction nhmex_rbox_hw_configfunction nhmex_rbox_msr_enable_eventfunction nhmex_uncore_cpu_init
Annotated Snippet
if (!atomic_read(&er->ref) || er->config == config) {
atomic_inc(&er->ref);
er->config = config;
ret = true;
}
raw_spin_unlock_irqrestore(&er->lock, flags);
return ret;
}
/*
* The ZDP_CTL_FVC MSR has 4 fields which are used to control
* events 0xd ~ 0x10. Besides these 4 fields, there are additional
* fields which are shared.
*/
idx -= EXTRA_REG_NHMEX_M_ZDP_CTL_FVC;
if (WARN_ON_ONCE(idx >= 4))
return false;
/* mask of the shared fields */
if (uncore_nhmex)
mask = NHMEX_M_PMON_ZDP_CTL_FVC_MASK;
else
mask = WSMEX_M_PMON_ZDP_CTL_FVC_MASK;
er = &box->shared_regs[EXTRA_REG_NHMEX_M_ZDP_CTL_FVC];
raw_spin_lock_irqsave(&er->lock, flags);
/* add mask of the non-shared field if it's in use */
if (__BITS_VALUE(atomic_read(&er->ref), idx, 8)) {
if (uncore_nhmex)
mask |= NHMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx);
else
mask |= WSMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx);
}
if (!atomic_read(&er->ref) || !((er->config ^ config) & mask)) {
atomic_add(1 << (idx * 8), &er->ref);
if (uncore_nhmex)
mask = NHMEX_M_PMON_ZDP_CTL_FVC_MASK |
NHMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx);
else
mask = WSMEX_M_PMON_ZDP_CTL_FVC_MASK |
WSMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx);
er->config &= ~mask;
er->config |= (config & mask);
ret = true;
}
raw_spin_unlock_irqrestore(&er->lock, flags);
return ret;
}
static void nhmex_mbox_put_shared_reg(struct intel_uncore_box *box, int idx)
{
struct intel_uncore_extra_reg *er;
if (idx < EXTRA_REG_NHMEX_M_ZDP_CTL_FVC) {
er = &box->shared_regs[idx];
atomic_dec(&er->ref);
return;
}
idx -= EXTRA_REG_NHMEX_M_ZDP_CTL_FVC;
er = &box->shared_regs[EXTRA_REG_NHMEX_M_ZDP_CTL_FVC];
atomic_sub(1 << (idx * 8), &er->ref);
}
static u64 nhmex_mbox_alter_er(struct perf_event *event, int new_idx, bool modify)
{
struct hw_perf_event *hwc = &event->hw;
struct hw_perf_event_extra *reg1 = &hwc->extra_reg;
u64 idx, orig_idx = __BITS_VALUE(reg1->idx, 0, 8);
u64 config = reg1->config;
/* get the non-shared control bits and shift them */
idx = orig_idx - EXTRA_REG_NHMEX_M_ZDP_CTL_FVC;
if (uncore_nhmex)
config &= NHMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx);
else
config &= WSMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx);
if (new_idx > orig_idx) {
idx = new_idx - orig_idx;
config <<= 3 * idx;
} else {
idx = orig_idx - new_idx;
config >>= 3 * idx;
}
/* add the shared control bits back */
if (uncore_nhmex)
config |= NHMEX_M_PMON_ZDP_CTL_FVC_MASK & reg1->config;
Annotation
- Immediate include surface: `asm/cpu_device_id.h`, `asm/msr.h`, `uncore.h`.
- Detected declarations: `function nhmex_uncore_msr_init_box`, `function nhmex_uncore_msr_exit_box`, `function nhmex_uncore_msr_disable_box`, `function nhmex_uncore_msr_enable_box`, `function nhmex_uncore_msr_disable_event`, `function nhmex_uncore_msr_enable_event`, `function nhmex_bbox_hw_config`, `function nhmex_bbox_msr_enable_event`, `function nhmex_sbox_hw_config`, `function nhmex_sbox_msr_enable_event`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.