[PATCH v3 2/4] perf annotate: Enable cross arch annotate
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. Signed-off-by: Ravi Bangoria--- Changes in v3: - 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(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 07fc792..d4fd947 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -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; diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 29dc6d2..3a652a6f 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -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; } diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c index 9c7ff8d..d7150b3 100644 --- a/tools/perf/ui/gtk/annotate.c +++ b/tools/perf/ui/gtk/annotate.c @@ -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; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index c385fec..36a5825 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -20,12 +20,14 @@ #include #include #include +#include +#include "../arch/common.h" const char *disassembler_style; const char *objdump_path; static regex_t file_lineno; -static struct ins *ins__find(const char *name); +static struct ins *ins__find(const char *name, const char *norm_arch); static int disasm_line__parse(char *line, char **namep, char **rawp); static void ins__delete(struct ins_operands *ops) @@ -53,7 +55,8 @@ int ins__scnprintf(struct ins *ins, char *bf, size_t size, return ins__raw_scnprintf(ins, bf, size, ops); } -static int call__parse(struct ins_operands *ops) +static int call__parse(struct ins_operands *ops, + __maybe_unused const char *norm_arch) { char *endptr, *tok, *name; @@ -65,10 +68,8 @@ static int call__parse(struct ins_operands *ops) name++; -#ifdef __arm__ - if (strchr(name, '+')) + if (!strcmp(norm_arch, "arm") && strchr(name, '+')) return -1; -#endif tok = strchr(name, '>'); if (tok == NULL) @@ -117,7 +118,8 @@ bool ins__is_call(const struct ins *ins) return ins->ops == _ops; } -static int jump__parse(struct ins_operands *ops) +static int jump__parse(struct ins_operands *ops, + __maybe_unused const char *norm_arch) { const char *s = strchr(ops->raw, '+'); @@ -172,7 +174,7 @@ static int comment__symbol(char *raw, char *comment, u64 *addrp, char **namep) return 0; } -static int lock__parse(struct ins_operands *ops) +static int lock__parse(struct ins_operands *ops, const char *norm_arch) { char *name; @@ -183,7 +185,7 @@ static int lock__parse(struct ins_operands *ops) if (disasm_line__parse(ops->raw, , >locked.ops->raw) < 0) goto out_free_ops; - ops->locked.ins = ins__find(name); + ops->locked.ins = ins__find(name, norm_arch); free(name); if
[PATCH v3 2/4] perf annotate: Enable cross arch annotate
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. Signed-off-by: Ravi Bangoria --- Changes in v3: - 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(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 07fc792..d4fd947 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -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; diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 29dc6d2..3a652a6f 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -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; } diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c index 9c7ff8d..d7150b3 100644 --- a/tools/perf/ui/gtk/annotate.c +++ b/tools/perf/ui/gtk/annotate.c @@ -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; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index c385fec..36a5825 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -20,12 +20,14 @@ #include #include #include +#include +#include "../arch/common.h" const char *disassembler_style; const char *objdump_path; static regex_t file_lineno; -static struct ins *ins__find(const char *name); +static struct ins *ins__find(const char *name, const char *norm_arch); static int disasm_line__parse(char *line, char **namep, char **rawp); static void ins__delete(struct ins_operands *ops) @@ -53,7 +55,8 @@ int ins__scnprintf(struct ins *ins, char *bf, size_t size, return ins__raw_scnprintf(ins, bf, size, ops); } -static int call__parse(struct ins_operands *ops) +static int call__parse(struct ins_operands *ops, + __maybe_unused const char *norm_arch) { char *endptr, *tok, *name; @@ -65,10 +68,8 @@ static int call__parse(struct ins_operands *ops) name++; -#ifdef __arm__ - if (strchr(name, '+')) + if (!strcmp(norm_arch, "arm") && strchr(name, '+')) return -1; -#endif tok = strchr(name, '>'); if (tok == NULL) @@ -117,7 +118,8 @@ bool ins__is_call(const struct ins *ins) return ins->ops == _ops; } -static int jump__parse(struct ins_operands *ops) +static int jump__parse(struct ins_operands *ops, + __maybe_unused const char *norm_arch) { const char *s = strchr(ops->raw, '+'); @@ -172,7 +174,7 @@ static int comment__symbol(char *raw, char *comment, u64 *addrp, char **namep) return 0; } -static int lock__parse(struct ins_operands *ops) +static int lock__parse(struct ins_operands *ops, const char *norm_arch) { char *name; @@ -183,7 +185,7 @@ static int lock__parse(struct ins_operands *ops) if (disasm_line__parse(ops->raw, , >locked.ops->raw) < 0) goto out_free_ops; - ops->locked.ins = ins__find(name); + ops->locked.ins = ins__find(name, norm_arch); free(name); if (ops->locked.ins == NULL) @@ -193,7