Skip to contentSkip to conversation

Loongson2: add a primary perf support (not applicable)

PATCH In review Wu Zhangjin 2 participants 4 messages Apr 28, 2010 – Apr 29, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Loongson2: add a primary perf support (not applicable)

From: Wu Zhangjin <[email protected]>

"perf - Performance analysis tools for Linux
[...]
Performance counters for Linux are a new kernel-based subsystem that provide a framework for all things performance analysis. It covers hardware level (CPU/PMU, Performance Monitoring Unit) features and software features (software counters, tracepoints) as well."
-- tools/perf/Documentation/perf.txt

Based on Deng-cheng's perf support for MIPS[1], this patch adds a primary perf support for loongson2. it is far from the full support.

To make the basic perf support work on loongson2, you need to use the kernel 2.6.34-rc from [2] and apply Deng-cheng's patches[1] at first, then apply this patch and at last compile it with CONFIG_HW_PERF_EVENTS=y (and please ensure OPROFILE=n).

And then you need to compile the user-space tools/perf with the following steps if want to local-compile it:

1. copy the {include, lib, tools/perf} directories of linux source code to the target machines and ensure it looks like this:

$ ls
include lib tools
$ ls tools
perf

2. install the basic -dev libs (use debian as an example)

$ sudo apt-get install libdw-dev libelf-dev

(If not enough, please refer to the error report when compiling, search the header files with the help of "apt-cache search ...")

3. Apply deng-cheng's another patch[3] for tools/perf

4. compile it

$ cd tools/perf
$ make

5. usage: refer to tools/perf/Documentation/examples.txt

$ ./perf list

For a non-raw event

$ ./perf stat -e cycles ls -l

For a raw event

$ ./perf stat -e r0 ls -l

Currently, seems "./perf record" and lots of software events not work, anybody have interest in playing with it can refer to {tools/perf/Documentation, arch/mips/kernel/perf_event*, arch/mips/include/asm/pmu.h, arch/x86/kernel/cpu/perf_event*, arch/arm/kernel/perf_event* ...}.

That's all! Thanks~

[1] http://patchwork.linux-mips.org/project/linux-mips/list/?=Deng-Cheng+Zhu&submitter=168&state=
[v2,4/4] MIPS: implementing hardware performance event support
[v2,3/4] MIPS: adding support for software performance events
[v2,2/4] MIPS: in non-64bit kernel, using the generic atomic64 operations for perf counter support [v2,1/4] MIPS/Oprofile: extracting PMU defines/helper functions for sharing
[2] http://dev.lemote.com/code/linux-loongson-community
[3] http://patchwork.linux-mips.org/patch/1150/

---
 arch/mips/Kconfig                       |    2 +-
 arch/mips/include/asm/pmu.h             |   19 +-
 arch/mips/kernel/perf_event.c           |    1 +
 arch/mips/kernel/perf_event_loongson2.c |  470 +++++++++++++++++++++++++++++++
 arch/mips/loongson/lemote-2f/irq.c      |    3 +-
 5 files changed, 484 insertions(+), 11 deletions(-)
 create mode 100644 arch/mips/kernel/perf_event_loongson2.c
arch/mips/Kconfig +1 -1
index 5b485a4..51bc385 100644
@@ -1859,7 +1859,7 @@ config NODES_SHIFT
 
 config HW_PERF_EVENTS
 	bool "Enable hardware performance counter support for perf events"
-	depends on PERF_EVENTS && !MIPS_MT_SMTC && OPROFILE=n && CPU_MIPS32
+	depends on PERF_EVENTS && !MIPS_MT_SMTC && OPROFILE=n
 	default y
 	help
 	  Enable hardware performance counter support for perf events. If
arch/mips/include/asm/pmu.h +10 -9
index 6da943c..df409c7 100644
@@ -19,6 +19,8 @@
 #ifndef __MIPS_PMU_H__
 #define __MIPS_PMU_H__
 
+static int (*save_perf_irq)(void);
+
 #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) || \
     defined(CONFIG_CPU_R10000) || defined(CONFIG_CPU_SB1)
 
@@ -41,8 +43,6 @@
 
 #define M_COUNTER_OVERFLOW		(1UL      << 31)
 
-static int (*save_perf_irq)(void);
-
 #ifdef CONFIG_MIPS_MT_SMP
 static int cpu_has_mipsmt_pertccounters;
 #define WHAT		(M_TC_EN_VPE | \
@@ -216,15 +216,16 @@ extern unsigned int rm9000_perfcount_irq;
 
 #elif defined(CONFIG_CPU_LOONGSON2)
 
-/*
- * a patch should be sent to oprofile with the loongson-specific support.
- * otherwise, the oprofile tool will not recognize this and complain about
- * "cpu_type 'unset' is not valid".
- */
+#include <loongson.h>
+
 #define LOONGSON2_CPU_TYPE	"mips/loongson2"
 
-#define LOONGSON2_COUNTER1_EVENT(event)	((event & 0x0f) << 5)
-#define LOONGSON2_COUNTER2_EVENT(event)	((event & 0x0f) << 9)
+#define MIPS_MAX_HWEVENTS	2
+
+#define LOONGSON2_COUNTER1_EVENT(event) (((event) & 0x0f) << 5)
+#define LOONGSON2_COUNTER2_EVENT(event) (((event) & 0x0f) << 9)
+#define LOONGSON2_PERFCNT_EVENT(event, idx) \
+	(((event) & 0x0f) << ((idx) ? 9 : 5))
 
 #define LOONGSON2_PERFCNT_EXL			(1UL	<<  0)
 #define LOONGSON2_PERFCNT_KERNEL		(1UL    <<  1)
arch/mips/kernel/perf_event.c +1 -0
index a17dc64..cbcaf43 100644
@@ -459,6 +459,7 @@ const struct pmu *hw_perf_event_init(struct perf_event *event)
 }
 
 #include "perf_event_mipsxx.c"
+#include "perf_event_loongson2.c"
 
 /*
  * Callchain handling code.
arch/mips/kernel/perf_event_loongson2.c new file +470 -0

470 lines not on this page · raw message

arch/mips/loongson/lemote-2f/irq.c +2 -1
index 1d8b4d2..d5e7220 100644
@@ -79,7 +79,8 @@ void mach_irq_dispatch(unsigned int pending)
 	if (pending & CAUSEF_IP7)
 		do_IRQ(LOONGSON_TIMER_IRQ);
 	else if (pending & CAUSEF_IP6) {	/* North Bridge, Perf counter */
-#if defined(CONFIG_OPROFILE) || defined(CONFIG_OPROFILE_MODULE)
+#if defined(CONFIG_OPROFILE) || defined(CONFIG_OPROFILE_MODULE) \
+		|| defined(CONFIG_HW_PERF_EVENTS)
 		do_IRQ(LOONGSON2_PERFCNT_IRQ);
 #endif
 		bonito_irqdispatch();
Signature · 1 line
1.7.0
#1 lore raw
Quoted 2 lines

And then you need to compile the user-space tools/perf with the following steps if want to local-compile it:

And if you want to cross compile it, besides changing tools/perf/perf.h, tools/perf/Makefile also needs to have proper CFLAGS/LDFLAGS for headers and libs. Then it's OK to fire "make CROSS_COMPILE=$toolchain_prefix".

Quoted 4 lines

Currently, seems "./perf record" and lots of software events not work, anybody have interest in playing with it can refer to {tools/perf/Documentation, arch/mips/kernel/perf_event*, arch/mips/include/asm/pmu.h, arch/x86/kernel/cpu/perf_event*, arch/arm/kernel/perf_event* ...}.

"perf record" works fine on 24K/34K/74K cores. In addition, If you are seeing the message "Couldn't record kernel reference relocation symbol", and your kernel symbols only have _stext (without _text), then search "_text" in builtin-record.c and replace with "_stext". Here is the link: http://lkml.org/lkml/2010/1/18/177

For software events, it should be able to work without specific changes for loongson, I suppose. Because changes have been done to common MIPS code to support software events.

Quoted 7 lines

 config HW_PERF_EVENTS
       bool "Enable hardware performance counter support for perf events"
-       depends on PERF_EVENTS && !MIPS_MT_SMTC && OPROFILE=n && CPU_MIPS32
+       depends on PERF_EVENTS && !MIPS_MT_SMTC && OPROFILE=n default y
       help
         Enable hardware performance counter support for perf events. If

How about adding CPU_LOONGSON2* instead of deleting CPU_MIPS32? Because we want the perf functionality to be available when we are able to choose it..

#2 lore raw
Quoted 13 lines · Deng-Cheng Zhu
Quoted 2 lines

And then you need to compile the user-space tools/perf with the following steps if want to local-compile it:

And if you want to cross compile it, besides changing tools/perf/perf.h, tools/perf/Makefile also needs to have proper CFLAGS/LDFLAGS for headers and libs. Then it's OK to fire "make CROSS_COMPILE=$toolchain_prefix".

Quoted 4 lines

Currently, seems "./perf record" and lots of software events not work, anybody have interest in playing with it can refer to {tools/perf/Documentation, arch/mips/kernel/perf_event*, arch/mips/include/asm/pmu.h, arch/x86/kernel/cpu/perf_event*, arch/arm/kernel/perf_event* ...}.

Quoted 5 lines

"perf record" works fine on 24K/34K/74K cores. In addition, If you are seeing the message "Couldn't record kernel reference relocation symbol", and your kernel symbols only have _stext (without _text), then search "_text" in builtin-record.c and replace with "_stext". Here is the link: http://lkml.org/lkml/2010/1/18/177

Yeah, I have seen the message but have not looked into it, thanks!

Quoted 5 lines

For software events, it should be able to work without specific changes for loongson, I suppose. Because changes have been done to common MIPS code to support software events.

Perhaps need to enable some related kernel options for the "kmem:..." is not in the result of "./perf list", I will check it later.

Quoted 11 lines

arch/mips/Kconfig config NODES_SHIFT · line 1865

Quoted 7 lines

config HW_PERF_EVENTS
bool "Enable hardware performance counter support for perf events"

arch/mips/Kconfig +1 -1
-       depends on PERF_EVENTS && !MIPS_MT_SMTC && OPROFILE=n && CPU_MIPS32
+       depends on PERF_EVENTS && !MIPS_MT_SMTC && OPROFILE=n
       default y
       help
         Enable hardware performance counter support for perf events. If

How about adding CPU_LOONGSON2* instead of deleting CPU_MIPS32? Because we want the perf functionality to be available when we are able to choose it..

Okay, will apply it in the next revision.

BTW: After comparing this patch and your arch/mips/kernel/perf_event_mipsxx.c, perhaps we can share more common functions, such as hw_perf_event_destroy(), hw_perf_enable(), hw_perf_disable() and handle_associated_event()...

Thanks & Regards,
Wu Zhangjin

#3 lore raw
Quoted 4 lines

BTW: After comparing this patch and your arch/mips/kernel/perf_event_mipsxx.c, perhaps we can share more common functions, such as hw_perf_event_destroy(), hw_perf_enable(), hw_perf_disable() and handle_associated_event()...

hw_perf_event_destroy(): OK, if reset_counters() will be also implemented in non-mipsxx. hw_perf_enable()/hw_perf_disable(): OK. Initially I thought there could be different implementations for these 2 functions in non-mipsxx depending on the very different perf control regs and the use of saved_ctrl. But you are right, we can, and had better to move these up.
handle_associated_event(): OK.

Thanks! I'll apply these in v3.