static int __init amd_core_pmu_init(void)
 {
+       union cpuid_0x80000022_ebx ebx;
        u64 even_ctr_mask = 0ULL;
        int i;
 
 
        /* Check for Performance Monitoring v2 support */
        if (boot_cpu_has(X86_FEATURE_PERFMON_V2)) {
+               ebx.full = cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES);
+
                /* Update PMU version for later usage */
                x86_pmu.version = 2;
 
+               /* Find the number of available Core PMCs */
+               x86_pmu.num_counters = ebx.split.num_core_pmc;
+
                amd_pmu_global_cntr_mask = (1ULL << x86_pmu.num_counters) - 1;
        }
 
 
        unsigned int            full;
 };
 
+/*
+ * AMD "Extended Performance Monitoring and Debug" CPUID
+ * detection/enumeration details:
+ */
+union cpuid_0x80000022_ebx {
+       struct {
+               /* Number of Core Performance Counters */
+               unsigned int    num_core_pmc:4;
+       } split;
+       unsigned int            full;
+};
+
 struct x86_pmu_capability {
        int             version;
        int             num_counters_gp;
        u64 xmm[16*2];  /* two entries for each register */
 };
 
+/*
+ * AMD Extended Performance Monitoring and Debug cpuid feature detection
+ */
+#define EXT_PERFMON_DEBUG_FEATURES             0x80000022
+
 /*
  * IBS cpuid feature detection
  */