linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] MIPS: perf: Initial annotation support
@ 2020-01-15 21:54 Dengcheng Zhu
  0 siblings, 0 replies; only message in thread
From: Dengcheng Zhu @ 2020-01-15 21:54 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, paulburton
  Cc: linux-kernel, linux-mips, Dengcheng Zhu

Add support for perf annotate on MIPS.

Example of `ls /bin` annotation:

 Percent |      Source code & Disassembly of libc-2.24.so for cycles (46 samples, percent: local period)
--------------------------------------------------------------------------------------------------------
         :
         :
         :
         :           Disassembly of section .text:
         :
         :           00000000000a53a0 <strlen@@GLIBC_2.0>:
    4.22 :   a53a0:  andi    v0,a0,0x7
    0.00 :   a53a4:  beqzc   v0,a54c4 <strlen@@GLIBC_2.0+0x124>
    0.00 :   a53a8:  lb      v0,0(a0)
    0.00 :   a53ac:  beqzc   v0,a54cc <strlen@@GLIBC_2.0+0x12c>
    0.00 :   a53b0:  move    v0,a0
    0.00 :   a53b4:  bc      a53c0 <strlen@@GLIBC_2.0+0x20>
    2.16 :   a53b8:  lb      v1,0(v0)
    9.07 :   a53bc:  beqzc   v1,a5468 <strlen@@GLIBC_2.0+0xc8>
    0.00 :   a53c0:  daddiu  v0,v0,1
...

Reviewed-by: Paul Burton <paulburton@kernel.org>
Signed-off-by: Dengcheng Zhu <dzhu@wavecomp.com>
---
Changes:

v2 - v1:
 * Adding compact version and branch-likely version instructions.
 * Adding jalx and jr.hb instructions.

 tools/perf/arch/mips/Build                   |  2 +-
 tools/perf/arch/mips/annotate/instructions.c | 41 ++++++++++++++++++++
 tools/perf/util/annotate.c                   |  8 ++++
 3 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/arch/mips/annotate/instructions.c

diff --git a/tools/perf/arch/mips/Build b/tools/perf/arch/mips/Build
index 1bb8bf6d7fd4..e4e5f33c84d8 100644
--- a/tools/perf/arch/mips/Build
+++ b/tools/perf/arch/mips/Build
@@ -1 +1 @@
-# empty
+perf-y += util/
diff --git a/tools/perf/arch/mips/annotate/instructions.c b/tools/perf/arch/mips/annotate/instructions.c
new file mode 100644
index 000000000000..c479b458dc10
--- /dev/null
+++ b/tools/perf/arch/mips/annotate/instructions.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+
+static struct ins_ops *mips__associate_instruction_ops(struct arch *arch, const char *name)
+{
+	struct ins_ops *ops;
+
+	/*
+	 * Including compact version (beqzalc) and branch-likely
+	 * (e.g. bgezall) versions
+	 */
+	if (!strncmp(name, "bal", 3) ||
+	    !strncmp(name, "bgezal", 6) ||
+	    !strncmp(name, "bltzal", 6) ||
+	    !strncmp(name, "bgtzal", 6) ||
+	    !strncmp(name, "blezal", 6) ||
+	    !strncmp(name, "beqzal", 6) ||
+	    !strncmp(name, "bnezal", 6) ||
+	    !strncmp(name, "jal", 3) || /* jal[rx]? */
+	    !strcmp(name, "jialc"))
+		ops = &call_ops;
+	else if (!strncmp(name, "jr", 2)) /* jr(\.hb)? */
+		ops = &ret_ops;
+	else if (name[0] == 'j' || name[0] == 'b')
+		ops = &jump_ops;
+	else
+		return NULL;
+
+	arch__associate_ins_ops(arch, name, ops);
+
+	return ops;
+}
+
+static int mips__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
+{
+	if (!arch->initialized) {
+		arch->associate_instruction_ops = mips__associate_instruction_ops;
+		arch->initialized = true;
+	}
+
+	return 0;
+}
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index f5e77ed237e8..aeae04a3ff0d 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -153,6 +153,7 @@ static int arch__associate_ins_ops(struct arch* arch, const char *name, struct i
 #include "arch/arm/annotate/instructions.c"
 #include "arch/arm64/annotate/instructions.c"
 #include "arch/csky/annotate/instructions.c"
+#include "arch/mips/annotate/instructions.c"
 #include "arch/x86/annotate/instructions.c"
 #include "arch/powerpc/annotate/instructions.c"
 #include "arch/s390/annotate/instructions.c"
@@ -175,6 +176,13 @@ static struct arch architectures[] = {
 		.name = "csky",
 		.init = csky__annotate_init,
 	},
+	{
+		.name = "mips",
+		.init = mips__annotate_init,
+		.objdump = {
+			.comment_char = '#',
+		},
+	},
 	{
 		.name = "x86",
 		.init = x86__annotate_init,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-15 21:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 21:54 [PATCH v2] MIPS: perf: Initial annotation support Dengcheng Zhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).