Skip to contentSkip to conversation

MIPS: perf: Add hardware perf events support for new Loongson-3

PATCH Superseded Huacai Chen 2 participants 3 messages Apr 27, 2020 – Apr 29, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: perf: Add hardware perf events support for new Loongson-3

New Loongson-3 means Loongson-3A R2 (Loongson-3A2000) and newer CPUs. Loongson-3 processors have three types of PMU types (so there are three event maps): Loongson-3A1000/Loonngson-3B1000/Loongson-3B1500 is Type-1, Loongson-3A2000/Loongson-3A3000 is Type-2, Loongson-3A4000+ is Type-3.

---
 .../asm/mach-loongson64/cpu-feature-overrides.h    |   1 +
 arch/mips/kernel/perf_event_mipsxx.c               | 358 +++++++++++++++++++--
 2 files changed, 330 insertions(+), 29 deletions(-)
arch/mips/include/asm/mach-loongson64/cpu-feature-overrides.h +1 -0
index 4fab38c..b6e9c99 100644
@@ -48,5 +48,6 @@
 #define cpu_hwrena_impl_bits	0xc0000000
 #define cpu_has_mac2008_only	1
 #define cpu_has_mips_r2_exec_hazard 0
+#define cpu_has_perf_cntr_intr_bit	0
 
 #endif /* __ASM_MACH_LOONGSON64_CPU_FEATURE_OVERRIDES_H */
arch/mips/kernel/perf_event_mipsxx.c +329 -29

503 lines not on this page · raw message

Signature · 1 line
2.7.0
#1 lore raw

arch/mips/kernel/perf_event_mipsxx.c struct mips_pmu { · line 93

Quoted 10 lines · Huacai Chen
arch/mips/kernel/perf_event_mipsxx.c +4 -1
index 128fc99..c96eb03 100644
@@ -90,6 +90,7 @@ struct mips_pmu {
-	unsigned long cntr_mask = (hwc->event_base >> 8) & 0xffff;
+	if (get_loongson3_pmu_type() != LOONGSON_PMU_TYPE2)
+		cntr_mask = (hwc->event_base >> 8) & 0xffff;
+	else
+		cntr_mask = (hwc->event_base >> 10) & 0xffff;

please invert the logic and do

	 if (get_loongson3_pmu_type() == LOONGSON_PMU_TYPE2)
		cntr_mask = (hwc->event_base >> 10) & 0xffff;
	else
		cntr_mask = (hwc->event_base >> 8) & 0xffff;

arch/mips/kernel/perf_event_mipsxx.c static void mipsxx_pmu_enable_event(struct hw_perf_event *evt, int idx) · line 365

Quoted 10 lines
arch/mips/kernel/perf_event_mipsxx.c +10 -0
+	if (get_loongson3_pmu_type() != LOONGSON_PMU_TYPE2)
+		cpuc->saved_ctrl[idx] = M_PERFCTL_EVENT(evt->event_base & 0xff) |
+			(evt->config_base & M_PERFCTL_CONFIG_MASK) |
+			/* Make sure interrupt enabled. */
+			MIPS_PERFCTRL_IE;
+	else
+		cpuc->saved_ctrl[idx] = M_PERFCTL_EVENT(evt->event_base & 0x3ff) |
+			(evt->config_base & M_PERFCTL_CONFIG_MASK) |
+			/* Make sure interrupt enabled. */
+			MIPS_PERFCTRL_IE;

same here

arch/mips/kernel/perf_event_mipsxx.c static unsigned int mipspmu_perf_event_encode(const struct mips_perf_event *pev) · line 718

Quoted 10 lines
arch/mips/kernel/perf_event_mipsxx.c +6 -2
 	else
 #endif /* CONFIG_MIPS_MT_SMP */
-		return ((pev->cntr_mask & 0xffff00) |
-			(pev->event_id & 0xff));
+	if (get_loongson3_pmu_type() != LOONGSON_PMU_TYPE2)
+		return (pev->cntr_mask & 0xffff00) |
+			(pev->event_id & 0xff);
+	else
+		return (pev->cntr_mask & 0xfffc00) |
+			(pev->event_id & 0x3ff);

and here.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#2 lore raw

Hi, Thomas,

Thanks for your suggestion, I'll send V2.

Quoted 51 lines · Thomas Bogendoerfer

arch/mips/kernel/perf_event_mipsxx.c struct mips_pmu { · line 93

Quoted 10 lines · Huacai Chen
arch/mips/kernel/perf_event_mipsxx.c +4 -1
index 128fc99..c96eb03 100644
@@ -90,6 +90,7 @@ struct mips_pmu {
-     unsigned long cntr_mask = (hwc->event_base >> 8) & 0xffff;
+     if (get_loongson3_pmu_type() != LOONGSON_PMU_TYPE2)
+             cntr_mask = (hwc->event_base >> 8) & 0xffff;
+     else
+             cntr_mask = (hwc->event_base >> 10) & 0xffff;

please invert the logic and do

         if (get_loongson3_pmu_type() == LOONGSON_PMU_TYPE2)
                cntr_mask = (hwc->event_base >> 10) & 0xffff;
        else
                cntr_mask = (hwc->event_base >> 8) & 0xffff;

arch/mips/kernel/perf_event_mipsxx.c static void mipsxx_pmu_enable_event(struct hw_perf_event *evt, int idx) · line 365

Quoted 10 lines
arch/mips/kernel/perf_event_mipsxx.c +10 -0
+     if (get_loongson3_pmu_type() != LOONGSON_PMU_TYPE2)
+             cpuc->saved_ctrl[idx] = M_PERFCTL_EVENT(evt->event_base & 0xff) |
+                     (evt->config_base & M_PERFCTL_CONFIG_MASK) |
+                     /* Make sure interrupt enabled. */
+                     MIPS_PERFCTRL_IE;
+     else
+             cpuc->saved_ctrl[idx] = M_PERFCTL_EVENT(evt->event_base & 0x3ff) |
+                     (evt->config_base & M_PERFCTL_CONFIG_MASK) |
+                     /* Make sure interrupt enabled. */
+                     MIPS_PERFCTRL_IE;

same here

arch/mips/kernel/perf_event_mipsxx.c static unsigned int mipspmu_perf_event_encode(const struct mips_perf_event *pev) · line 718

Quoted 10 lines

else
#endif /* CONFIG_MIPS_MT_SMP */

arch/mips/kernel/perf_event_mipsxx.c +6 -2
-             return ((pev->cntr_mask & 0xffff00) |
-                     (pev->event_id & 0xff));
+     if (get_loongson3_pmu_type() != LOONGSON_PMU_TYPE2)
+             return (pev->cntr_mask & 0xffff00) |
+                     (pev->event_id & 0xff);
+     else
+             return (pev->cntr_mask & 0xfffc00) |
+                     (pev->event_id & 0x3ff);

and here.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]