Skip to content

Commit f997e20

Browse files
sandip4nPeter Zijlstra
authored andcommitted
perf/x86/amd/uncore: Avoid PMU registration if counters are unavailable
X86_FEATURE_PERFCTR_NB and X86_FEATURE_PERFCTR_LLC are derived from CPUID leaf 0x80000001 ECX bits 24 and 28 respectively and denote the availability of DF and L3 counters. When these bits are not set, the corresponding PMUs have no counters and hence, should not be registered. Fixes: 07888da ("perf/x86/amd/uncore: Move discovery and registration") Signed-off-by: Sandipan Das <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 149fd47 commit f997e20

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

arch/x86/events/amd/uncore.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -658,17 +658,20 @@ int amd_uncore_df_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
658658
{
659659
struct attribute **df_attr = amd_uncore_df_format_attr;
660660
struct amd_uncore_pmu *pmu;
661+
int num_counters;
661662

662663
/* Run just once */
663664
if (uncore->init_done)
664665
return amd_uncore_ctx_init(uncore, cpu);
665666

667+
num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu);
668+
if (!num_counters)
669+
goto done;
670+
666671
/* No grouping, single instance for a system */
667672
uncore->pmus = kzalloc(sizeof(*uncore->pmus), GFP_KERNEL);
668-
if (!uncore->pmus) {
669-
uncore->num_pmus = 0;
673+
if (!uncore->pmus)
670674
goto done;
671-
}
672675

673676
/*
674677
* For Family 17h and above, the Northbridge counters are repurposed
@@ -678,7 +681,7 @@ int amd_uncore_df_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
678681
pmu = &uncore->pmus[0];
679682
strscpy(pmu->name, boot_cpu_data.x86 >= 0x17 ? "amd_df" : "amd_nb",
680683
sizeof(pmu->name));
681-
pmu->num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu);
684+
pmu->num_counters = num_counters;
682685
pmu->msr_base = MSR_F15H_NB_PERF_CTL;
683686
pmu->rdpmc_base = RDPMC_BASE_NB;
684687
pmu->group = amd_uncore_ctx_gid(uncore, cpu);
@@ -789,17 +792,20 @@ int amd_uncore_l3_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
789792
{
790793
struct attribute **l3_attr = amd_uncore_l3_format_attr;
791794
struct amd_uncore_pmu *pmu;
795+
int num_counters;
792796

793797
/* Run just once */
794798
if (uncore->init_done)
795799
return amd_uncore_ctx_init(uncore, cpu);
796800

801+
num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu);
802+
if (!num_counters)
803+
goto done;
804+
797805
/* No grouping, single instance for a system */
798806
uncore->pmus = kzalloc(sizeof(*uncore->pmus), GFP_KERNEL);
799-
if (!uncore->pmus) {
800-
uncore->num_pmus = 0;
807+
if (!uncore->pmus)
801808
goto done;
802-
}
803809

804810
/*
805811
* For Family 17h and above, L3 cache counters are available instead
@@ -809,7 +815,7 @@ int amd_uncore_l3_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
809815
pmu = &uncore->pmus[0];
810816
strscpy(pmu->name, boot_cpu_data.x86 >= 0x17 ? "amd_l3" : "amd_l2",
811817
sizeof(pmu->name));
812-
pmu->num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu);
818+
pmu->num_counters = num_counters;
813819
pmu->msr_base = MSR_F16H_L2I_PERF_CTL;
814820
pmu->rdpmc_base = RDPMC_BASE_LLC;
815821
pmu->group = amd_uncore_ctx_gid(uncore, cpu);

0 commit comments

Comments
 (0)