arch/sparc/kernel/perf_event.c
Source file repositories/reference/linux-study-clean/arch/sparc/kernel/perf_event.c
File Facts
- System
- Linux kernel
- Corpus path
arch/sparc/kernel/perf_event.c- Extension
.c- Size
- 47288 bytes
- Lines
- 1877
- Domain
- Architecture Layer
- Bucket
- arch/sparc
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/perf_event.hlinux/kprobes.hlinux/ftrace.hlinux/kernel.hlinux/kdebug.hlinux/mutex.hasm/stacktrace.hasm/cpudata.hlinux/uaccess.hlinux/atomic.hlinux/sched/clock.hasm/nmi.hasm/pcr.hasm/cacheflush.hkernel.hkstack.h
Detected Declarations
struct cpu_hw_eventsstruct perf_event_mapstruct sparc_pmufunction perf_event_encodefunction perf_event_get_mskfunction perf_event_get_encfunction sparc_default_read_pmcfunction sparc_default_write_pmcfunction sparc_vt_read_pmcfunction sparc_vt_write_pmcfunction event_encodingfunction mask_for_indexfunction nop_for_indexfunction sparc_pmu_enable_eventfunction sparc_pmu_disable_eventfunction sparc_perf_event_updatefunction sparc_perf_event_set_periodfunction read_in_all_countersfunction calculate_single_pcrfunction calculate_multiple_pcrsfunction aroundfunction sparc_pmu_enablefunction sparc_pmu_disablefunction active_event_indexfunction sparc_pmu_startfunction sparc_pmu_stopfunction sparc_pmu_delfunction sparc_pmu_readfunction perf_stop_nmi_watchdogfunction perf_event_grab_pmcfunction perf_event_release_pmcfunction hw_perf_event_destroyfunction maybe_change_configurationfunction check_excludesfunction collect_eventsfunction sparc_pmu_addfunction sparc_pmu_event_initfunction sparc_pmu_start_txnfunction sparc_pmu_cancel_txnfunction sparc_pmu_commit_txnfunction perf_event_print_debugfunction perf_event_nmi_handlerfunction supported_pmufunction init_hw_perf_eventsfunction perf_callchain_kernelfunction valid_user_framefunction perf_callchain_user_64function perf_callchain_user_32
Annotated Snippet
struct cpu_hw_events {
/* Number of events currently scheduled onto this cpu.
* This tells how many entries in the arrays below
* are valid.
*/
int n_events;
/* Number of new events added since the last hw_perf_disable().
* This works because the perf event layer always adds new
* events inside of a perf_{disable,enable}() sequence.
*/
int n_added;
/* Array of events current scheduled on this cpu. */
struct perf_event *event[MAX_HWEVENTS];
/* Array of encoded longs, specifying the %pcr register
* encoding and the mask of PIC counters this even can
* be scheduled on. See perf_event_encode() et al.
*/
unsigned long events[MAX_HWEVENTS];
/* The current counter index assigned to an event. When the
* event hasn't been programmed into the cpu yet, this will
* hold PIC_NO_INDEX. The event->hw.idx value tells us where
* we ought to schedule the event.
*/
int current_idx[MAX_HWEVENTS];
/* Software copy of %pcr register(s) on this cpu. */
u64 pcr[MAX_HWEVENTS];
/* Enabled/disable state. */
int enabled;
unsigned int txn_flags;
};
static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, };
/* An event map describes the characteristics of a performance
* counter event. In particular it gives the encoding as well as
* a mask telling which counters the event can be measured on.
*
* The mask is unused on SPARC-T4 and later.
*/
struct perf_event_map {
u16 encoding;
u8 pic_mask;
#define PIC_NONE 0x00
#define PIC_UPPER 0x01
#define PIC_LOWER 0x02
};
/* Encode a perf_event_map entry into a long. */
static unsigned long perf_event_encode(const struct perf_event_map *pmap)
{
return ((unsigned long) pmap->encoding << 16) | pmap->pic_mask;
}
static u8 perf_event_get_msk(unsigned long val)
{
return val & 0xff;
}
static u64 perf_event_get_enc(unsigned long val)
{
return val >> 16;
}
#define C(x) PERF_COUNT_HW_CACHE_##x
#define CACHE_OP_UNSUPPORTED 0xfffe
#define CACHE_OP_NONSENSE 0xffff
typedef struct perf_event_map cache_map_t
[PERF_COUNT_HW_CACHE_MAX]
[PERF_COUNT_HW_CACHE_OP_MAX]
[PERF_COUNT_HW_CACHE_RESULT_MAX];
struct sparc_pmu {
const struct perf_event_map *(*event_map)(int);
const cache_map_t *cache_map;
int max_events;
u32 (*read_pmc)(int);
void (*write_pmc)(int, u64);
int upper_shift;
int lower_shift;
int event_mask;
int user_bit;
int priv_bit;
Annotation
- Immediate include surface: `linux/perf_event.h`, `linux/kprobes.h`, `linux/ftrace.h`, `linux/kernel.h`, `linux/kdebug.h`, `linux/mutex.h`, `asm/stacktrace.h`, `asm/cpudata.h`.
- Detected declarations: `struct cpu_hw_events`, `struct perf_event_map`, `struct sparc_pmu`, `function perf_event_encode`, `function perf_event_get_msk`, `function perf_event_get_enc`, `function sparc_default_read_pmc`, `function sparc_default_write_pmc`, `function sparc_vt_read_pmc`, `function sparc_vt_write_pmc`.
- Atlas domain: Architecture Layer / arch/sparc.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.