Skip to contentSkip to conversation

perf annotate: Enable cross arch annotate

PATCH Superseded Ravi Bangoria 2 participants 7 messages Jun 29, 2016 perf events

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover perf annotate: Enable cross arch annotate

Perf can currently only support code navigation (branches and calls) in annotate when run on the same architecture where perf.data was recorded. But cross arch annotate is not supported.

This patchset enables cross arch annotate. Currently I've used x86 and arm instructions which are already available and adding support for powerpc as well. Adding support for other arch will be easy.

I've created this patch on top of acme/perf/core. And tested it with x86 and powerpc only.

Example:

Record on powerpc:

  $ ./perf record -a

Report -> Annotate on x86:

  $ ./perf report -i perf.data.powerpc --vmlinux vmlinux.powerpc

Changes in v2:
- Corrected few memory leaks.
- Created Dynamic list for powerpc to optimize memory consumption

Naveen N. Rao (1):
perf annotate: add powerpc support

Ravi Bangoria (3):
perf: Utility function to fetch arch
perf annotate: Enable cross arch annotate
perf: Define macro for arch names

 tools/perf/arch/common.c           |  36 +++---
 tools/perf/arch/common.h           |  11 ++
 tools/perf/builtin-top.c           |   2 +-
 tools/perf/ui/browsers/annotate.c  |   3 +-
 tools/perf/ui/gtk/annotate.c       |   2 +-
 tools/perf/util/annotate.c         | 255 ++++++++++++++++++++++++++++++-------
 tools/perf/util/annotate.h         |   5 +-
 tools/perf/util/evsel.c            |   7 +
 tools/perf/util/evsel.h            |   2 +
 tools/perf/util/unwind-libunwind.c |   4 +-
 10 files changed, 255 insertions(+), 72 deletions(-)

--
2.5.5

#1 lore raw

PATCH v2 1/4 perf: Utility function to fetch arch

Add Utility function to fetch arch using evsel. (evsel->env->arch)

---
Changes in v2:
- No changes

 tools/perf/util/evsel.c | 7 +++++++
 tools/perf/util/evsel.h | 2 ++
 2 files changed, 9 insertions(+)
tools/perf/util/evsel.c +7 -0
index 1d8f2bb..0fea724 100644
@@ -2422,3 +2422,10 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
 			 err, strerror_r(err, sbuf, sizeof(sbuf)),
 			 perf_evsel__name(evsel));
 }
+
+char *perf_evsel__env_arch(struct perf_evsel *evsel)
+{
+	if (evsel && evsel->evlist && evsel->evlist->env)
+		return evsel->evlist->env->arch;
+	return NULL;
+}
tools/perf/util/evsel.h +2 -0
index 828ddd1..86fed7a 100644
@@ -435,4 +435,6 @@ typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *);
 int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
 			     attr__fprintf_f attr__fprintf, void *priv);
 
+char *perf_evsel__env_arch(struct perf_evsel *evsel);
+
 #endif /* __PERF_EVSEL_H */
Signature · 1 line
2.5.5
#2 lore raw

PATCH v2 2/4 perf annotate: Enable cross arch annotate

In reply to Ravi Bangoria

Change current data structures and function to enable cross arch annotate.

Current implementation does not contain logic of record on one arch and annotating on other. This remote annotate is partially possible with current implementation for x86 (or may be arm as well) only. But, to make remote annotation work properly, all architecture instruction tables need to be included in the perf binary. And while annotating, look for instruction table where perf.data was recorded.

For arm, few instructions were defined under #if __arm__ which I've used as a table for arm. But I'm not sure whether instruction defined outside of that also contains arm instructions. Apart from that, 'call__parse()' and 'move__parse()' contains #ifdef __arm__ directive. I've changed it to if (!strcmp(norm_arch, "arm")). But I've not tested this as well.

---
Changes in v2:
- No changes

 tools/perf/builtin-top.c          |   2 +-
 tools/perf/ui/browsers/annotate.c |   3 +-
 tools/perf/ui/gtk/annotate.c      |   2 +-
 tools/perf/util/annotate.c        | 136 ++++++++++++++++++++++++--------------
 tools/perf/util/annotate.h        |   5 +-
 5 files changed, 95 insertions(+), 53 deletions(-)
tools/perf/builtin-top.c +1 -1
index 07fc792..d4fd947 100644
@@ -128,7 +128,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
 		return err;
 	}
 
-	err = symbol__annotate(sym, map, 0);
+	err = symbol__annotate(sym, map, 0, NULL);
 	if (err == 0) {
 out_assign:
 		top->sym_filter_entry = he;
tools/perf/ui/browsers/annotate.c +2 -1
index 29dc6d2..3a652a6f 100644
@@ -1050,7 +1050,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
 		  (nr_pcnt - 1);
 	}
 
-	if (symbol__annotate(sym, map, sizeof_bdl) < 0) {
+	if (symbol__annotate(sym, map, sizeof_bdl,
+			     perf_evsel__env_arch(evsel)) < 0) {
 		ui__error("%s", ui_helpline__last_msg);
 		goto out_free_offsets;
 	}
tools/perf/ui/gtk/annotate.c +1 -1
index 9c7ff8d..d7150b3 100644
@@ -166,7 +166,7 @@ static int symbol__gtk_annotate(struct symbol *sym, struct map *map,
 	if (map->dso->annotate_warned)
 		return -1;
 
-	if (symbol__annotate(sym, map, 0) < 0) {
+	if (symbol__annotate(sym, map, 0, perf_evsel__env_arch(evsel)) < 0) {
 		ui__error("%s", ui_helpline__current);
 		return -1;
 	}
tools/perf/util/annotate.c +88 -48

291 lines not on this page · raw message

tools/perf/util/annotate.h +3 -2
index a23084f..4902138 100644
@@ -36,7 +36,7 @@ struct ins_operands {
 
 struct ins_ops {
 	void (*free)(struct ins_operands *ops);
-	int (*parse)(struct ins_operands *ops);
+	int (*parse)(struct ins_operands *ops, const char *norm_arch);
 	int (*scnprintf)(struct ins *ins, char *bf, size_t size,
 			 struct ins_operands *ops);
 };
@@ -155,7 +155,8 @@ int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 addr);
 int symbol__alloc_hist(struct symbol *sym);
 void symbol__annotate_zero_histograms(struct symbol *sym);
 
-int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
+int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize,
+		     char *arch);
 
 int symbol__annotate_init(struct map *map, struct symbol *sym);
 int symbol__annotate_printf(struct symbol *sym, struct map *map,
Signature · 1 line
2.5.5
#3 lore raw

PATCH v2 3/4 perf annotate: add powerpc support

In reply to Ravi Bangoria

From: Naveen N. Rao <[email protected]>

Powerpc has long list of branch instructions and hardcoding them in table appears to be error-prone. So, add new function to find instruction instead of creating table. This function dynamically create table(list of 'struct ins'), and instead of creating object every time, first check if list already contain object for that nemonics.

---
Changes in v2:
- Corrected few memory leaks.
- Created Dynamic list for powerpc to optimize memory consumption

 tools/perf/util/annotate.c | 121 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
tools/perf/util/annotate.c +121 -0
index 36a5825..812bfad 100644
@@ -461,6 +461,11 @@ static struct ins instructions_arm[] = {
 	{ .name = "bne",   .ops  = &jump_ops, },
 };
 
+struct instructions_powerpc {
+	struct ins *ins;
+	struct list_head list;
+};
+
 static int ins__key_cmp(const void *name, const void *insp)
 {
 	const struct ins *ins = insp;
@@ -476,6 +481,120 @@ static int ins__cmp(const void *a, const void *b)
 	return strcmp(ia->name, ib->name);
 }
 
+static int list_add__ins_powerpc(struct instructions_powerpc *head,
+				 struct ins *ins)
+{
+	struct instructions_powerpc *ins_powerpc;
+
+	ins_powerpc = zalloc(sizeof(struct instructions_powerpc));
+	if (!ins_powerpc)
+		return -1;
+
+	ins_powerpc->ins = ins;
+	list_add_tail(&(ins_powerpc->list), &(head->list));
+
+	return 0;
+}
+
+static struct ins *list_search__ins_powerpc(struct instructions_powerpc *head,
+					    const char *name)
+{
+	struct instructions_powerpc *pos;
+
+	list_for_each_entry(pos, &head->list, list) {
+		if (!strcmp(pos->ins->name, name))
+			return pos->ins;
+	}
+	return NULL;
+}
+
+static struct ins *ins__find_powerpc(const char *name)
+{
+	int i;
+	struct ins *ins;
+	static struct instructions_powerpc head;
+	static bool list_initialized;
+
+	if (!list_initialized) {
+		INIT_LIST_HEAD(&head.list);
+		list_initialized = true;
+	}
+
+	/*
+	 * Search if we already created object of 'struct ins'
+	 * for this instruction
+	 */
+	ins = list_search__ins_powerpc(&head, name);
+	if (ins)
+		return ins;
+
+	ins = zalloc(sizeof(struct ins));
+	if (!ins)
+		return NULL;
+
+	ins->name = strdup(name);
+	if (!ins->name)
+		goto err;
+
+	if (name[0] == 'b') {
+		/* branch instructions */
+		ins->ops = &jump_ops;
+
+		/*
+		 * - Few start with 'b', but aren't branch instructions.
+		 * - Let's also ignore instructions involving 'ctr' and
+		 *   'tar' since target branch addresses for those can't
+		 *   be determined statically.
+		 */
+		if (!strncmp(name, "bcd", 3)   ||
+		    !strncmp(name, "brinc", 5) ||
+		    !strncmp(name, "bper", 4)  ||
+		    strstr(name, "ctr")        ||
+		    strstr(name, "tar"))
+			goto err;
+
+		i = strlen(name) - 1;
+		if (i < 0)
+			goto err;
+
+		/* ignore optional hints at the end of the instructions */
+		if (name[i] == '+' || name[i] == '-')
+			i--;
+
+		if (name[i] == 'l' || (name[i] == 'a' && name[i-1] == 'l')) {
+			/*
+			 * if the instruction ends up with 'l' or 'la', then
+			 * those are considered 'calls' since they update LR.
+			 * ... except for 'bnl' which is branch if not less than
+			 * and the absolute form of the same.
+			 */
+			if (strcmp(name, "bnl") && strcmp(name, "bnl+") &&
+			    strcmp(name, "bnl-") && strcmp(name, "bnla") &&
+			    strcmp(name, "bnla+") && strcmp(name, "bnla-"))
+				ins->ops = &call_ops;
+		}
+		if (name[i] == 'r' && name[i-1] == 'l')
+			/*
+			 * instructions ending with 'lr' are considered to be
+			 * return instructions
+			 */
+			ins->ops = &ret_ops;
+
+		/*
+		 * Add instruction to list so next time no need to
+		 * allocate memory for it.
+		 */
+		if (list_add__ins_powerpc(&head, ins) < 0)
+			goto err;
+
+		return ins;
+	}
+
+err:
+	zfree(&ins);
+	return NULL;
+}
+
 static void ins__sort(struct ins *instructions, int nmemb)
 {
 	qsort(instructions, nmemb, sizeof(struct ins), ins__cmp);
@@ -511,6 +630,8 @@ static struct ins *ins__find(const char *name, const char *norm_arch)
 	} else if (!strcmp(norm_arch, "arm")) {
 		instructions = instructions_arm;
 		nmemb = ARRAY_SIZE(instructions_arm);
+	} else if (!strcmp(norm_arch, "powerpc")) {
+		return ins__find_powerpc(name);
 	} else {
 		pr_err("perf annotate not supported by %s arch\n", norm_arch);
 		return NULL;
Signature · 1 line
2.5.5
#4 lore raw

Re: [PATCH v2 3/4] perf annotate: add powerpc support

Quoted 83 lines · Ravi Bangoria

From: Naveen N. Rao <[email protected]>

Powerpc has long list of branch instructions and hardcoding them in table appears to be error-prone. So, add new function to find instruction instead of creating table. This function dynamically create table(list of 'struct ins'), and instead of creating object every time, first check if list already contain object for that nemonics.

---
Changes in v2:
- Corrected few memory leaks.
- Created Dynamic list for powerpc to optimize memory consumption

 tools/perf/util/annotate.c | 121 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
tools/perf/util/annotate.c +49 -0
index 36a5825..812bfad 100644
@@ -461,6 +461,11 @@ static struct ins instructions_arm[] = {
 	{ .name = "bne",   .ops  = &jump_ops, },
 };
 
+struct instructions_powerpc {
+	struct ins *ins;
+	struct list_head list;
+};
+
 static int ins__key_cmp(const void *name, const void *insp)
 {
 	const struct ins *ins = insp;
@@ -476,6 +481,120 @@ static int ins__cmp(const void *a, const void *b)
 	return strcmp(ia->name, ib->name);
 }
 
+static int list_add__ins_powerpc(struct instructions_powerpc *head,
+				 struct ins *ins)
+{
+	struct instructions_powerpc *ins_powerpc;
+
+	ins_powerpc = zalloc(sizeof(struct instructions_powerpc));
+	if (!ins_powerpc)
+		return -1;
+
+	ins_powerpc->ins = ins;
+	list_add_tail(&(ins_powerpc->list), &(head->list));
+
+	return 0;
+}
+
+static struct ins *list_search__ins_powerpc(struct instructions_powerpc *head,
+					    const char *name)
+{
+	struct instructions_powerpc *pos;
+
+	list_for_each_entry(pos, &head->list, list) {
+		if (!strcmp(pos->ins->name, name))
+			return pos->ins;
+	}
+	return NULL;
+}
+
+static struct ins *ins__find_powerpc(const char *name)
+{
+	int i;
+	struct ins *ins;
+	static struct instructions_powerpc head;
+	static bool list_initialized;
+
+	if (!list_initialized) {
+		INIT_LIST_HEAD(&head.list);
+		list_initialized = true;
+	}
+
+	/*
+	 * Search if we already created object of 'struct ins'
+	 * for this instruction
+	 */
+	ins = list_search__ins_powerpc(&head, name);

tools/perf/util/annotate.c static int ins__cmp(const void *a, const void *b) · line 537

Quoted 10 lines
tools/perf/util/annotate.c +10 -0
+	if (ins)
+		return ins;
+
+	ins = zalloc(sizeof(struct ins));
+	if (!ins)
+		return NULL;
+
+	ins->name = strdup(name);
+	if (!ins->name)
+		goto err;

You can move the above two inside the below if condition, so that you only allocate memory if needed.

Or, what would be better would be to pass 'name' and the appropriate ops pointer to the helper above (list_add__ins_powerpc) and have that allocate 'struct ins' and insert into the list.

Quoted 7 lines
tools/perf/util/annotate.c +7 -0
+
+	if (name[0] == 'b') {
+		/* branch instructions */
+		ins->ops = &jump_ops;
+
+		/*
+		 * - Few start with 'b', but aren't branch instructions.

tools/perf/util/annotate.c static int ins__cmp(const void *a, const void *b) · line 554

Quoted 10 lines
tools/perf/util/annotate.c +10 -0
+		 * - Let's also ignore instructions involving 'ctr' and
+		 *   'tar' since target branch addresses for those can't
+		 *   be determined statically.
+		 */
+		if (!strncmp(name, "bcd", 3)   ||
+		    !strncmp(name, "brinc", 5) ||
+		    !strncmp(name, "bper", 4)  ||
+		    strstr(name, "ctr")        ||
+		    strstr(name, "tar"))
+			goto err;

You are still leaking ins->name here.

- Naveen

Quoted 59 lines
tools/perf/util/annotate.c +43 -0
+
+		i = strlen(name) - 1;
+		if (i < 0)
+			goto err;
+
+		/* ignore optional hints at the end of the instructions */
+		if (name[i] == '+' || name[i] == '-')
+			i--;
+
+		if (name[i] == 'l' || (name[i] == 'a' && name[i-1] == 
 'l')) {
+			/*
+			 * if the instruction ends up with 'l' or 'la', then
+			 * those are considered 'calls' since they update LR.
+			 * ... except for 'bnl' which is branch if not less than
+			 * and the absolute form of the same.
+			 */
+			if (strcmp(name, "bnl") && strcmp(name, "bnl+") &&
+			    strcmp(name, "bnl-") && strcmp(name, "bnla") &&
+			    strcmp(name, "bnla+") && strcmp(name, "bnla-"))
+				ins->ops = &call_ops;
+		}
+		if (name[i] == 'r' && name[i-1] == 'l')
+			/*
+			 * instructions ending with 'lr' are considered to be
+			 * return instructions
+			 */
+			ins->ops = &ret_ops;
+
+		/*
+		 * Add instruction to list so next time no need to
+		 * allocate memory for it.
+		 */
+		if (list_add__ins_powerpc(&head, ins) < 0)
+			goto err;
+
+		return ins;
+	}
+
+err:
+	zfree(&ins);
+	return NULL;
+}
+
 static void ins__sort(struct ins *instructions, int nmemb)
 {
tools/perf/util/annotate.c +2 -0
 	qsort(instructions, nmemb, sizeof(struct ins), ins__cmp);
@@ -511,6 +630,8 @@ static struct ins *ins__find(const char *name, const char *norm_arch)
 	} else if (!strcmp(norm_arch, "arm")) {
 		instructions = instructions_arm;
 		nmemb = ARRAY_SIZE(instructions_arm);
+	} else if (!strcmp(norm_arch, "powerpc")) {
+		return ins__find_powerpc(name);
 	} else {
 		pr_err("perf annotate not supported by %s arch\n", norm_arch);
 		return NULL;
Signature · 1 line
2.5.5
#5 lore raw

Re: [PATCH v2 3/4] perf annotate: add powerpc support

Thanks Naveen,

Quoted 97 lines · Naveen N. Rao
Quoted 83 lines · Ravi Bangoria

From: Naveen N. Rao <[email protected]>

Powerpc has long list of branch instructions and hardcoding them in table appears to be error-prone. So, add new function to find instruction instead of creating table. This function dynamically create table(list of 'struct ins'), and instead of creating object every time, first check if list already contain object for that nemonics.

---
Changes in v2:
- Corrected few memory leaks.
- Created Dynamic list for powerpc to optimize memory consumption

  tools/perf/util/annotate.c | 121 +++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 121 insertions(+)
tools/perf/util/annotate.c +49 -0
index 36a5825..812bfad 100644
@@ -461,6 +461,11 @@ static struct ins instructions_arm[] = {
  	{ .name = "bne",   .ops  = &jump_ops, },
  };
 
+struct instructions_powerpc {
+	struct ins *ins;
+	struct list_head list;
+};
+
  static int ins__key_cmp(const void *name, const void *insp)
  {
  	const struct ins *ins = insp;
@@ -476,6 +481,120 @@ static int ins__cmp(const void *a, const void *b)
  	return strcmp(ia->name, ib->name);
  }
 
+static int list_add__ins_powerpc(struct instructions_powerpc *head,
+				 struct ins *ins)
+{
+	struct instructions_powerpc *ins_powerpc;
+
+	ins_powerpc = zalloc(sizeof(struct instructions_powerpc));
+	if (!ins_powerpc)
+		return -1;
+
+	ins_powerpc->ins = ins;
+	list_add_tail(&(ins_powerpc->list), &(head->list));
+
+	return 0;
+}
+
+static struct ins *list_search__ins_powerpc(struct instructions_powerpc *head,
+					    const char *name)
+{
+	struct instructions_powerpc *pos;
+
+	list_for_each_entry(pos, &head->list, list) {
+		if (!strcmp(pos->ins->name, name))
+			return pos->ins;
+	}
+	return NULL;
+}
+
+static struct ins *ins__find_powerpc(const char *name)
+{
+	int i;
+	struct ins *ins;
+	static struct instructions_powerpc head;
+	static bool list_initialized;
+
+	if (!list_initialized) {
+		INIT_LIST_HEAD(&head.list);
+		list_initialized = true;
+	}
+
+	/*
+	 * Search if we already created object of 'struct ins'
+	 * for this instruction
+	 */
+	ins = list_search__ins_powerpc(&head, name);

tools/perf/util/annotate.c static int ins__cmp(const void *a, const void *b) · line 537

Quoted 10 lines
tools/perf/util/annotate.c +10 -0
+	if (ins)
+		return ins;
+
+	ins = zalloc(sizeof(struct ins));
+	if (!ins)
+		return NULL;
+
+	ins->name = strdup(name);
+	if (!ins->name)
+		goto err;

You can move the above two inside the below if condition, so that you only allocate memory if needed.

Quoted 3 lines

Or, what would be better would be to pass 'name' and the appropriate ops pointer to the helper above (list_add__ins_powerpc) and have that allocate 'struct ins' and insert into the list.

Yes I will think about this.

Quoted 10 lines
Quoted 10 lines
tools/perf/util/annotate.c +10 -0
+
+	if (name[0] == 'b') {
+		/* branch instructions */
+		ins->ops = &jump_ops;
+
+		/*
+		 * - Few start with 'b', but aren't branch instructions.
+		 * - Let's also ignore instructions involving 'ctr' and
+		 *   'tar' since target branch addresses for those can't
+		 *   be determined statically.
Quoted 8 lines

tools/perf/util/annotate.c static int ins__cmp(const void *a, const void *b) · line 554

Quoted 7 lines
tools/perf/util/annotate.c +7 -0
+		 */
+		if (!strncmp(name, "bcd", 3)   ||
+		    !strncmp(name, "brinc", 5) ||
+		    !strncmp(name, "bper", 4)  ||
+		    strstr(name, "ctr")        ||
+		    strstr(name, "tar"))
+			goto err;

You are still leaking ins->name here.

Ah!! Sorry. I missed that we are using strdup here. Will correct it.

-Ravi

#6 lore raw

PATCH v2 4/4 perf annotate: Define macro for arch names

In reply to Ravi Bangoria

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

---
Changes in v2:
- No changes

 tools/perf/arch/common.c           | 36 ++++++++++++++++++------------------
 tools/perf/arch/common.h           | 11 +++++++++++
 tools/perf/util/annotate.c         | 10 +++++-----
 tools/perf/util/unwind-libunwind.c |  4 ++--
 4 files changed, 36 insertions(+), 25 deletions(-)
tools/perf/arch/common.c +18 -18
index ee69668..feb2113 100644
@@ -122,25 +122,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 NORM_X86;
 	if (arch[0] == 'i' && arch[2] == '8' && arch[3] == '6')
-		return "x86";
+		return NORM_X86;
 	if (!strcmp(arch, "sun4u") || !strncmp(arch, "sparc", 5))
-		return "sparc";
+		return NORM_SPARC;
 	if (!strcmp(arch, "aarch64") || !strcmp(arch, "arm64"))
-		return "arm64";
+		return NORM_ARM64;
 	if (!strncmp(arch, "arm", 3) || !strcmp(arch, "sa110"))
-		return "arm";
+		return NORM_ARM;
 	if (!strncmp(arch, "s390", 4))
-		return "s390";
+		return NORM_S390;
 	if (!strncmp(arch, "parisc", 6))
-		return "parisc";
+		return NORM_PARISC;
 	if (!strncmp(arch, "powerpc", 7) || !strncmp(arch, "ppc", 3))
-		return "powerpc";
+		return NORM_POWERPC;
 	if (!strncmp(arch, "mips", 4))
-		return "mips";
+		return NORM_MIPS;
 	if (!strncmp(arch, "sh", 2) && isdigit(arch[2]))
-		return "sh";
+		return NORM_SH;
 
 	return arch;
 }
@@ -180,21 +180,21 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
 		zfree(&buf);
 	}
 
-	if (!strcmp(arch, "arm"))
+	if (!strcmp(arch, NORM_ARM))
 		path_list = arm_triplets;
-	else if (!strcmp(arch, "arm64"))
+	else if (!strcmp(arch, NORM_ARM64))
 		path_list = arm64_triplets;
-	else if (!strcmp(arch, "powerpc"))
+	else if (!strcmp(arch, NORM_POWERPC))
 		path_list = powerpc_triplets;
-	else if (!strcmp(arch, "sh"))
+	else if (!strcmp(arch, NORM_SH))
 		path_list = sh_triplets;
-	else if (!strcmp(arch, "s390"))
+	else if (!strcmp(arch, NORM_S390))
 		path_list = s390_triplets;
-	else if (!strcmp(arch, "sparc"))
+	else if (!strcmp(arch, NORM_SPARC))
 		path_list = sparc_triplets;
-	else if (!strcmp(arch, "x86"))
+	else if (!strcmp(arch, NORM_X86))
 		path_list = x86_triplets;
-	else if (!strcmp(arch, "mips"))
+	else if (!strcmp(arch, NORM_MIPS))
 		path_list = mips_triplets;
 	else {
 		ui__error("binutils for %s not supported.\n", arch);
tools/perf/arch/common.h +11 -0
index 6b01c73..14ca8ca 100644
@@ -5,6 +5,17 @@
 
 extern const char *objdump_path;
 
+/* Macro for normalized arch names */
+#define NORM_X86	"x86"
+#define NORM_SPARC	"sparc"
+#define NORM_ARM64	"arm64"
+#define NORM_ARM	"arm"
+#define NORM_S390	"s390"
+#define NORM_PARISC	"parisc"
+#define NORM_POWERPC	"powerpc"
+#define NORM_MIPS	"mips"
+#define NORM_SH		"sh"
+
 int perf_env__lookup_objdump(struct perf_env *env);
 const char *normalize_arch(char *arch);
 
tools/perf/util/annotate.c +5 -5
index 812bfad..8c27486 100644
@@ -68,7 +68,7 @@ static int call__parse(struct ins_operands *ops,
 
 	name++;
 
-	if (!strcmp(norm_arch, "arm") && strchr(name, '+'))
+	if (!strcmp(norm_arch, NORM_ARM) && strchr(name, '+'))
 		return -1;
 
 	tok = strchr(name, '>');
@@ -255,7 +255,7 @@ static int mov__parse(struct ins_operands *ops,
 
 	target = ++s;
 
-	if (!strcmp(norm_arch, "arm"))
+	if (!strcmp(norm_arch, NORM_ARM))
 		comment = strchr(s, ';');
 	else
 		comment = strchr(s, '#');
@@ -624,13 +624,13 @@ static struct ins *ins__find(const char *name, const char *norm_arch)
 		sorted = true;
 	}
 
-	if (!strcmp(norm_arch, "x86")) {
+	if (!strcmp(norm_arch, NORM_X86)) {
 		instructions = instructions_x86;
 		nmemb = ARRAY_SIZE(instructions_x86);
-	} else if (!strcmp(norm_arch, "arm")) {
+	} else if (!strcmp(norm_arch, NORM_ARM)) {
 		instructions = instructions_arm;
 		nmemb = ARRAY_SIZE(instructions_arm);
-	} else if (!strcmp(norm_arch, "powerpc")) {
+	} else if (!strcmp(norm_arch, NORM_POWERPC)) {
 		return ins__find_powerpc(name);
 	} else {
 		pr_err("perf annotate not supported by %s arch\n", norm_arch);
tools/perf/util/unwind-libunwind.c +2 -2
index 8547119..8d4a53f 100644
@@ -36,10 +36,10 @@ 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, NORM_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, NORM_ARM64) || !strcmp(arch, NORM_ARM)) {
 		if (dso_type == DSO__TYPE_64BIT)
 			ops = arm64_unwind_libunwind_ops;
 	}
Signature · 1 line
2.5.5