#include <asm/stacktrace.h>
#include <asm/nmi.h>
-static bool perf_counters_initialized __read_mostly;
static u64 perf_counter_mask __read_mostly;
struct cpu_hw_counters {
}
}
+static inline int x86_pmu_initialized(void)
+{
+ return x86_pmu.handle_irq != NULL;
+}
+
/*
* Setup the hardware configuration for a given hw_event_type
*/
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
return -ENOSYS;
- if (unlikely(!perf_counters_initialized))
- return -EINVAL;
+ if (!x86_pmu_initialized())
+ return -ENODEV;
err = 0;
if (atomic_inc_not_zero(&num_counters)) {
u64 hw_perf_save_disable(void)
{
- if (unlikely(!perf_counters_initialized))
+ if (!x86_pmu_initialized())
return 0;
-
return x86_pmu.save_disable_all();
}
/*
void hw_perf_restore(u64 ctrl)
{
- if (unlikely(!perf_counters_initialized))
+ if (!x86_pmu_initialized())
return;
-
x86_pmu.restore_all(ctrl);
}
/*
{
u64 status;
- if (unlikely(!perf_counters_initialized))
- return 0;
rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
return status;
static inline void x86_pmu_enable_counter(struct hw_perf_counter *hwc, int idx)
{
int err;
-
- if (unlikely(!perf_counters_initialized))
- return;
-
err = checking_wrmsrl(hwc->config_base + idx,
hwc->config | ARCH_PERFMON_EVENTSEL0_ENABLE);
}
static inline void x86_pmu_disable_counter(struct hw_perf_counter *hwc, int idx)
{
int err;
-
- if (unlikely(!perf_counters_initialized))
- return;
-
err = checking_wrmsrl(hwc->config_base + idx,
hwc->config);
}
{
struct cpu_hw_counters *cpuc;
- if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
+ if (!x86_pmu_initialized())
return;
- if (unlikely(!perf_counters_initialized))
+ if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
return;
cpuc = &__get_cpu_var(cpu_hw_counters);
{
u32 apic_val;
- if (!perf_counters_initialized)
+ if (!x86_pmu_initialized())
return;
+
/*
* Enable the performance counter vector in the APIC LVT:
*/
((1LL << x86_pmu.num_counters_fixed)-1) << X86_PMC_IDX_FIXED;
pr_info("... counter mask: %016Lx\n", perf_counter_mask);
- perf_counters_initialized = true;
perf_counters_lapic_init(0);
register_die_notifier(&perf_counter_nmi_notifier);