Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1430614

[RFC 2/6] perf annotate: Define macro for arch names

From Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Newsgroups linux.kernel
Subject [RFC 2/6] perf annotate: Define macro for arch names
Date 2016-06-24 14:00 +0200
Message-ID <rNxWa-7AL-27@gated-at.bofh.it> (permalink)
References <rNxWa-7AL-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Define macro for each arch name and use them instead of using arch
name as string.

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
---
 tools/perf/arch/common.c           | 36 ++++++++++++++++++------------------
 tools/perf/arch/common.h           | 10 ++++++++++
 tools/perf/util/unwind-libunwind.c |  5 +++--
 3 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index fa090a9..7da6ac7 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -105,25 +105,25 @@ static int lookup_triplets(const char *const *triplets, const char *name)
 const char *normalize_arch(char *arch)
 {
 	if (!strcmp(arch, "x86_64"))
-		return "x86";
+		return PERF_ARCH_X86;
 	if (arch[0] == 'i' && arch[2] == '8' && arch[3] == '6')
-		return "x86";
+		return PERF_ARCH_X86;
 	if (!strcmp(arch, "sun4u") || !strncmp(arch, "sparc", 5))
-		return "sparc";
+		return PERF_ARCH_SPARC;
 	if (!strcmp(arch, "aarch64") || !strcmp(arch, "arm64"))
-		return "arm64";
+		return PERF_ARCH_ARM64;
 	if (!strncmp(arch, "arm", 3) || !strcmp(arch, "sa110"))
-		return "arm";
+		return PERF_ARCH_ARM;
 	if (!strncmp(arch, "s390", 4))
-		return "s390";
+		return PERF_ARCH_S390;
 	if (!strncmp(arch, "parisc", 6))
-		return "parisc";
+		return PERF_ARCH_PARISC;
 	if (!strncmp(arch, "powerpc", 7) || !strncmp(arch, "ppc", 3))
-		return "powerpc";
+		return PERF_ARCH_POWERPC;
 	if (!strncmp(arch, "mips", 4))
-		return "mips";
+		return PERF_ARCH_MIPS;
 	if (!strncmp(arch, "sh", 2) && isdigit(arch[2]))
-		return "sh";
+		return PERF_ARCH_SH;
 
 	return arch;
 }
@@ -163,21 +163,21 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
 		zfree(&buf);
 	}
 
-	if (!strcmp(arch, "arm"))
+	if (!strcmp(arch, PERF_ARCH_ARM))
 		path_list = arm_triplets;
-	else if (!strcmp(arch, "arm64"))
+	else if (!strcmp(arch, PERF_ARCH_ARM64))
 		path_list = arm64_triplets;
-	else if (!strcmp(arch, "powerpc"))
+	else if (!strcmp(arch, PERF_ARCH_POWERPC))
 		path_list = powerpc_triplets;
-	else if (!strcmp(arch, "sh"))
+	else if (!strcmp(arch, PERF_ARCH_SH))
 		path_list = sh_triplets;
-	else if (!strcmp(arch, "s390"))
+	else if (!strcmp(arch, PERF_ARCH_S390))
 		path_list = s390_triplets;
-	else if (!strcmp(arch, "sparc"))
+	else if (!strcmp(arch, PERF_ARCH_SPARC))
 		path_list = sparc_triplets;
-	else if (!strcmp(arch, "x86"))
+	else if (!strcmp(arch, PERF_ARCH_X86))
 		path_list = x86_triplets;
-	else if (!strcmp(arch, "mips"))
+	else if (!strcmp(arch, PERF_ARCH_MIPS))
 		path_list = mips_triplets;
 	else {
 		ui__error("binutils for %s not supported.\n", arch);
diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h
index 6b01c73..bbb6960 100644
--- a/tools/perf/arch/common.h
+++ b/tools/perf/arch/common.h
@@ -5,6 +5,16 @@
 
 extern const char *objdump_path;
 
+#define PERF_ARCH_X86		"x86"
+#define PERF_ARCH_SPARC		"sparc"
+#define PERF_ARCH_ARM64		"arm64"
+#define PERF_ARCH_ARM		"arm"
+#define PERF_ARCH_S390		"s390"
+#define PERF_ARCH_PARISC	"parisc"
+#define PERF_ARCH_POWERPC	"powerpc"
+#define PERF_ARCH_MIPS		"mips"
+#define PERF_ARCH_SH		"sh"
+
 int perf_env__lookup_objdump(struct perf_env *env);
 const char *normalize_arch(char *arch);
 
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 8547119..ccebe5e 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -36,10 +36,11 @@ int unwind__prepare_access(struct thread *thread, struct map *map)
 
 	arch = normalize_arch(thread->mg->machine->env->arch);
 
-	if (!strcmp(arch, "x86")) {
+	if (!strcmp(arch, PERF_ARCH_X86)) {
 		if (dso_type != DSO__TYPE_64BIT)
 			ops = x86_32_unwind_libunwind_ops;
-	} else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
+	} else if (!strcmp(arch, PERF_ARCH_ARM64) ||
+		   !strcmp(arch, PERF_ARCH_ARM)) {
 		if (dso_type == DSO__TYPE_64BIT)
 			ops = arm64_unwind_libunwind_ops;
 	}
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC 0/6] perf annotate: Enable cross arch annotate Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-24 14:00 +0200
  [RFC 4/6] perf annotate: generalize handling of ret instructions Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-24 14:00 +0200
    Re: [RFC 4/6] perf annotate: generalize handling of ret instructions Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 19:40 +0200
    [tip:perf/core] perf annotate: Generalize handling of 'ret'  instructions "tip-bot for Naveen N. Rao" <tipbot@zytor.com> - 2016-06-29 11:50 +0200
  [RFC 5/6] perf annotate: add powerpc support Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-24 14:00 +0200
  [RFC 2/6] perf annotate: Define macro for arch names Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-24 14:00 +0200
  [RFC 1/6] perf: Remove unused hist_entry__annotate function Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-24 14:00 +0200
    Re: [RFC 1/6] perf: Remove unused hist_entry__annotate function Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 19:40 +0200
    [tip:perf/core] perf annotate: Remove unused hist_entry__annotate  function tip-bot for Ravi Bangoria <tipbot@zytor.com> - 2016-06-29 11:50 +0200
  [RFC 3/6] perf annotate: Enable cross arch annotate Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-24 14:00 +0200
    Re: [RFC 3/6] perf annotate: Enable cross arch annotate Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 19:20 +0200
      Re: [RFC 3/6] perf annotate: Enable cross arch annotate Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-28 13:50 +0200

csiph-web