#include <linux/perf_event.h>
#include <linux/jump_label.h>
#include <linux/export.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <asm/apicdef.h>
#include <asm/apic.h>
#include <asm/nmi.h>
#include "../perf_event.h"
static DEFINE_PER_CPU(unsigned long, perf_nmi_tstamp);
static unsigned long perf_nmi_window;
#define AMD_MERGE_EVENT …
#define AMD_MERGE_EVENT_ENABLE …
static u64 amd_pmu_global_cntr_mask __read_mostly;
static __initconst const u64 amd_hw_cache_event_ids
[PERF_COUNT_HW_CACHE_MAX]
[PERF_COUNT_HW_CACHE_OP_MAX]
[PERF_COUNT_HW_CACHE_RESULT_MAX] = …;
static __initconst const u64 amd_hw_cache_event_ids_f17h
[PERF_COUNT_HW_CACHE_MAX]
[PERF_COUNT_HW_CACHE_OP_MAX]
[PERF_COUNT_HW_CACHE_RESULT_MAX] = …;
static const u64 amd_perfmon_event_map[PERF_COUNT_HW_MAX] = …;
static const u64 amd_zen1_perfmon_event_map[PERF_COUNT_HW_MAX] = …;
static const u64 amd_zen2_perfmon_event_map[PERF_COUNT_HW_MAX] = …;
static const u64 amd_zen4_perfmon_event_map[PERF_COUNT_HW_MAX] = …;
static u64 amd_pmu_event_map(int hw_event)
{ … }
static unsigned int event_offsets[X86_PMC_IDX_MAX] __read_mostly;
static unsigned int count_offsets[X86_PMC_IDX_MAX] __read_mostly;
static inline int amd_pmu_addr_offset(int index, bool eventsel)
{ … }
static inline unsigned int amd_get_event_code(struct hw_perf_event *hwc)
{ … }
static inline bool amd_is_pair_event_code(struct hw_perf_event *hwc)
{ … }
DEFINE_STATIC_CALL_RET0(…);
static int amd_core_hw_config(struct perf_event *event)
{ … }
static inline int amd_is_nb_event(struct hw_perf_event *hwc)
{ … }
static inline int amd_has_nb(struct cpu_hw_events *cpuc)
{ … }
static int amd_pmu_hw_config(struct perf_event *event)
{ … }
static void __amd_put_nb_event_constraints(struct cpu_hw_events *cpuc,
struct perf_event *event)
{ … }
static struct event_constraint *
__amd_get_nb_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event,
struct event_constraint *c)
{ … }
static struct amd_nb *amd_alloc_nb(int cpu)
{ … }
amd_pmu_branch_reset_t;
DEFINE_STATIC_CALL_NULL(…);
static void amd_pmu_cpu_reset(int cpu)
{ … }
static int amd_pmu_cpu_prepare(int cpu)
{ … }
static void amd_pmu_cpu_starting(int cpu)
{ … }
static void amd_pmu_cpu_dead(int cpu)
{ … }
static __always_inline void amd_pmu_set_global_ctl(u64 ctl)
{ … }
static inline u64 amd_pmu_get_global_status(void)
{ … }
static inline void amd_pmu_ack_global_status(u64 status)
{ … }
static bool amd_pmu_test_overflow_topbit(int idx)
{ … }
static bool amd_pmu_test_overflow_status(int idx)
{ … }
DEFINE_STATIC_CALL(…);
#define OVERFLOW_WAIT_COUNT …
static void amd_pmu_wait_on_overflow(int idx)
{ … }
static void amd_pmu_check_overflow(void)
{ … }
static void amd_pmu_enable_event(struct perf_event *event)
{ … }
static void amd_pmu_enable_all(int added)
{ … }
static void amd_pmu_v2_enable_event(struct perf_event *event)
{ … }
static __always_inline void amd_pmu_core_enable_all(void)
{ … }
static void amd_pmu_v2_enable_all(int added)
{ … }
static void amd_pmu_disable_event(struct perf_event *event)
{ … }
static void amd_pmu_disable_all(void)
{ … }
static __always_inline void amd_pmu_core_disable_all(void)
{ … }
static void amd_pmu_v2_disable_all(void)
{ … }
DEFINE_STATIC_CALL_NULL(…);
static void amd_pmu_add_event(struct perf_event *event)
{ … }
DEFINE_STATIC_CALL_NULL(…);
static void amd_pmu_del_event(struct perf_event *event)
{ … }
static inline int amd_pmu_adjust_nmi_window(int handled)
{ … }
static int amd_pmu_handle_irq(struct pt_regs *regs)
{ … }
static int amd_pmu_v2_snapshot_branch_stack(struct perf_branch_entry *entries, unsigned int cnt)
{ … }
static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
{ … }
static struct event_constraint *
amd_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
struct perf_event *event)
{ … }
static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
struct perf_event *event)
{ … }
PMU_FORMAT_ATTR(…);
PMU_FORMAT_ATTR(…);
PMU_FORMAT_ATTR(…);
PMU_FORMAT_ATTR(…);
PMU_FORMAT_ATTR(…);
static struct attribute *amd_format_attr[] = …;
#define AMD_EVENT_TYPE_MASK …
#define AMD_EVENT_FP …
#define AMD_EVENT_LS …
#define AMD_EVENT_DC …
#define AMD_EVENT_CU …
#define AMD_EVENT_IC_DE …
#define AMD_EVENT_EX_LS …
#define AMD_EVENT_DE …
#define AMD_EVENT_NB …
static struct event_constraint amd_f15_PMC0 = …;
static struct event_constraint amd_f15_PMC20 = …;
static struct event_constraint amd_f15_PMC3 = …;
static struct event_constraint amd_f15_PMC30 = …;
static struct event_constraint amd_f15_PMC50 = …;
static struct event_constraint amd_f15_PMC53 = …;
static struct event_constraint *
amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, int idx,
struct perf_event *event)
{ … }
static struct event_constraint pair_constraint;
static struct event_constraint *
amd_get_event_constraints_f17h(struct cpu_hw_events *cpuc, int idx,
struct perf_event *event)
{ … }
static void amd_put_event_constraints_f17h(struct cpu_hw_events *cpuc,
struct perf_event *event)
{ … }
static struct event_constraint amd_fam19h_brs_cntr0_constraint = …;
static struct event_constraint amd_fam19h_brs_pair_cntr0_constraint = …;
static struct event_constraint *
amd_get_event_constraints_f19h(struct cpu_hw_events *cpuc, int idx,
struct perf_event *event)
{ … }
static ssize_t amd_event_sysfs_show(char *page, u64 config)
{ … }
static void amd_pmu_limit_period(struct perf_event *event, s64 *left)
{ … }
static __initconst const struct x86_pmu amd_pmu = …;
static ssize_t branches_show(struct device *cdev,
struct device_attribute *attr,
char *buf)
{ … }
static DEVICE_ATTR_RO(branches);
static struct attribute *amd_pmu_branches_attrs[] = …;
static umode_t
amd_branches_is_visible(struct kobject *kobj, struct attribute *attr, int i)
{ … }
static struct attribute_group group_caps_amd_branches = …;
#ifdef CONFIG_PERF_EVENTS_AMD_BRS
EVENT_ATTR_STR(branch-brs, amd_branch_brs,
"event=" __stringify(AMD_FAM19H_BRS_EVENT)"\n");
static struct attribute *amd_brs_events_attrs[] = …;
static umode_t
amd_brs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
{ … }
static struct attribute_group group_events_amd_brs = …;
#endif
static const struct attribute_group *amd_attr_update[] = …;
static int __init amd_core_pmu_init(void)
{ … }
__init int amd_pmu_init(void)
{ … }
static inline void amd_pmu_reload_virt(void)
{ … }
void amd_pmu_enable_virt(void)
{ … }
EXPORT_SYMBOL_GPL(…);
void amd_pmu_disable_virt(void)
{ … }
EXPORT_SYMBOL_GPL(…);