Skip to content

Commit 4c8a7c9

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Refine the init_hw_perf_events() function
(1) Use the existing CPUCFG6_PMNUM_SHIFT macro definition instead of the magic value 4 to get the PMU number. (2) Detect the value of PMU bits via CPUCFG instruction according to the ISA manual instead of hard-coded as 64, because the value may be different for various micro-architectures. Link: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_cpucfg Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 17f8385 commit 4c8a7c9

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

arch/loongarch/include/asm/loongarch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
#define CPUCFG6_PMNUM GENMASK(7, 4)
129129
#define CPUCFG6_PMNUM_SHIFT 4
130130
#define CPUCFG6_PMBITS GENMASK(13, 8)
131+
#define CPUCFG6_PMBITS_SHIFT 8
131132
#define CPUCFG6_UPM BIT(14)
132133

133134
#define LOONGARCH_CPUCFG16 0x10

arch/loongarch/kernel/perf_event.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,13 +845,14 @@ static const struct loongarch_perf_event *loongarch_pmu_map_raw_event(u64 config
845845

846846
static int __init init_hw_perf_events(void)
847847
{
848-
int counters;
848+
int bits, counters;
849849

850850
if (!cpu_has_pmp)
851851
return -ENODEV;
852852

853853
pr_info("Performance counters: ");
854-
counters = ((read_cpucfg(LOONGARCH_CPUCFG6) & CPUCFG6_PMNUM) >> 4) + 1;
854+
bits = ((read_cpucfg(LOONGARCH_CPUCFG6) & CPUCFG6_PMBITS) >> CPUCFG6_PMBITS_SHIFT) + 1;
855+
counters = ((read_cpucfg(LOONGARCH_CPUCFG6) & CPUCFG6_PMNUM) >> CPUCFG6_PMNUM_SHIFT) + 1;
855856

856857
loongarch_pmu.num_counters = counters;
857858
loongarch_pmu.max_period = (1ULL << 63) - 1;
@@ -867,7 +868,7 @@ static int __init init_hw_perf_events(void)
867868
on_each_cpu(reset_counters, NULL, 1);
868869

869870
pr_cont("%s PMU enabled, %d %d-bit counters available to each CPU.\n",
870-
loongarch_pmu.name, counters, 64);
871+
loongarch_pmu.name, counters, bits);
871872

872873
perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
873874

0 commit comments

Comments
 (0)