arch/mips/kernel/perf_event_mipsxx.c
Source file repositories/reference/linux-study-clean/arch/mips/kernel/perf_event_mipsxx.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/kernel/perf_event_mipsxx.c- Extension
.c- Size
- 54024 bytes
- Lines
- 2056
- Domain
- Architecture Layer
- Bucket
- arch/mips
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpumask.hlinux/interrupt.hlinux/smp.hlinux/kernel.hlinux/perf_event.hlinux/uaccess.hasm/irq.hasm/irq_regs.hasm/stacktrace.hasm/time.h
Detected Declarations
struct cpu_hw_eventsstruct mips_perf_eventstruct mips_pmufunction vpe_shiftfunction counters_total_to_per_cpufunction get_loongson3_pmu_typefunction mipsxx_pmu_swizzle_perf_idxfunction mipsxx_pmu_read_counterfunction mipsxx_pmu_read_counter_64function mipsxx_pmu_write_counterfunction mipsxx_pmu_write_counter_64function mipsxx_pmu_read_controlfunction mipsxx_pmu_write_controlfunction mipsxx_pmu_alloc_counterfunction mipsxx_pmu_enable_eventfunction mipsxx_pmu_disable_eventfunction mipspmu_event_set_periodfunction mipspmu_event_updatefunction mipspmu_startfunction mipspmu_stopfunction mipspmu_addfunction mipspmu_delfunction mipspmu_readfunction mipspmu_enablefunction mipspmu_disablefunction mipspmu_get_irqfunction mipspmu_free_irqfunction hw_perf_event_destroyfunction mipspmu_event_initfunction mipspmu_perf_event_encodefunction validate_groupfunction for_each_sibling_eventfunction handle_associated_eventfunction __n_countersfunction n_countersfunction loongson3_reset_countersfunction reset_countersfunction __hw_perf_event_initfunction pause_local_countersfunction resume_local_countersfunction mipsxx_pmu_handle_shared_irqfunction mipsxx_pmu_handle_irqfunction countersfunction init_hw_perf_events
Annotated Snippet
struct cpu_hw_events {
/* Array of events on this cpu. */
struct perf_event *events[MIPS_MAX_HWEVENTS];
/*
* Set the bit (indexed by the counter number) when the counter
* is used for an event.
*/
unsigned long used_mask[BITS_TO_LONGS(MIPS_MAX_HWEVENTS)];
/*
* Software copy of the control register for each performance counter.
* MIPS CPUs vary in performance counters. They use this differently,
* and even may not use it.
*/
unsigned int saved_ctrl[MIPS_MAX_HWEVENTS];
};
DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {
.saved_ctrl = {0},
};
/* The description of MIPS performance events. */
struct mips_perf_event {
unsigned int event_id;
/*
* MIPS performance counters are indexed starting from 0.
* CNTR_EVEN indicates the indexes of the counters to be used are
* even numbers.
*/
unsigned int cntr_mask;
#define CNTR_EVEN 0x55555555
#define CNTR_ODD 0xaaaaaaaa
#define CNTR_ALL 0xffffffff
enum {
T = 0,
V = 1,
P = 2,
} range;
};
static struct mips_perf_event raw_event;
static DEFINE_MUTEX(raw_event_mutex);
#define C(x) PERF_COUNT_HW_CACHE_##x
struct mips_pmu {
u64 max_period;
u64 valid_count;
u64 overflow;
const char *name;
int irq;
u64 (*read_counter)(unsigned int idx);
void (*write_counter)(unsigned int idx, u64 val);
const struct mips_perf_event *(*map_raw_event)(u64 config);
const struct mips_perf_event (*general_event_map)[PERF_COUNT_HW_MAX];
const struct mips_perf_event (*cache_event_map)
[PERF_COUNT_HW_CACHE_MAX]
[PERF_COUNT_HW_CACHE_OP_MAX]
[PERF_COUNT_HW_CACHE_RESULT_MAX];
unsigned int num_counters;
};
static int counter_bits;
static struct mips_pmu mipspmu;
#define M_PERFCTL_EVENT(event) (((event) << MIPS_PERFCTRL_EVENT_S) & \
MIPS_PERFCTRL_EVENT)
#define M_PERFCTL_VPEID(vpe) ((vpe) << MIPS_PERFCTRL_VPEID_S)
#ifdef CONFIG_CPU_BMIPS5000
#define M_PERFCTL_MT_EN(filter) 0
#else /* !CONFIG_CPU_BMIPS5000 */
#define M_PERFCTL_MT_EN(filter) (filter)
#endif /* CONFIG_CPU_BMIPS5000 */
#define M_TC_EN_ALL M_PERFCTL_MT_EN(MIPS_PERFCTRL_MT_EN_ALL)
#define M_TC_EN_VPE M_PERFCTL_MT_EN(MIPS_PERFCTRL_MT_EN_VPE)
#define M_TC_EN_TC M_PERFCTL_MT_EN(MIPS_PERFCTRL_MT_EN_TC)
#define M_PERFCTL_COUNT_EVENT_WHENEVER (MIPS_PERFCTRL_EXL | \
MIPS_PERFCTRL_K | \
MIPS_PERFCTRL_U | \
MIPS_PERFCTRL_S | \
MIPS_PERFCTRL_IE)
#ifdef CONFIG_MIPS_MT_SMP
#define M_PERFCTL_CONFIG_MASK 0x3fff801f
#else
#define M_PERFCTL_CONFIG_MASK 0x1f
#endif
Annotation
- Immediate include surface: `linux/cpumask.h`, `linux/interrupt.h`, `linux/smp.h`, `linux/kernel.h`, `linux/perf_event.h`, `linux/uaccess.h`, `asm/irq.h`, `asm/irq_regs.h`.
- Detected declarations: `struct cpu_hw_events`, `struct mips_perf_event`, `struct mips_pmu`, `function vpe_shift`, `function counters_total_to_per_cpu`, `function get_loongson3_pmu_type`, `function mipsxx_pmu_swizzle_perf_idx`, `function mipsxx_pmu_read_counter`, `function mipsxx_pmu_read_counter_64`, `function mipsxx_pmu_write_counter`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.