* [PATCH] perf annotate: fix parsing aarch64 branch instructions after objdump update @ 2018-08-24 0:10 Kim Phillips 2018-08-24 7:59 ` Thomas-Mich Richter 2018-08-27 12:50 ` Arnaldo Carvalho de Melo 0 siblings, 2 replies; 7+ messages in thread From: Kim Phillips @ 2018-08-24 0:10 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Ravi Bangoria, Anton Blanchard, Robin Murphy, Alexander Shishkin, Christian Borntraeger, Mark Rutland, Peter Zijlstra, Taeung Song, Ingo Molnar, Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-kernel, linux-arm-kernel, perf group Starting with binutils 2.28, aarch64 objdump adds comments to the disassembly output to show the alternative names of a condition code [1]. It is assumed that commas in objdump comments could occur in other arches now or in the future, so this fix is arch-independent. The fix could have been done with arm64 specific jump__parse and jump__scnprintf functions, but the jump__scnprintf instruction would have to have its comment character be a literal, since the scnprintf functions cannot receive a struct arch easily. This inconvenience also applies to the generic jump__scnprintf, which is why we add a raw_comment pointer to struct ins_operands, so the __parse function assigns it to be re-used by its corresponding __scnprintf function. Example differences in 'perf annotate --stdio2' output on an aarch64 perf.data file: BEFORE: → b.cs ffff200008133d1c <unwind_frame+0x18c> // b.hs, dffff7ecc47b AFTER : ↓ b.cs 18c BEFORE: → b.cc ffff200008d8d9cc <get_alloc_profile+0x31c> // b.lo, b.ul, dffff727295b AFTER : ↓ b.cc 31c The branch target labels 18c and 31c also now appear in the output: BEFORE: add x26, x29, #0x80 AFTER : 18c: add x26, x29, #0x80 BEFORE: add x21, x21, #0x8 AFTER : 31c: add x21, x21, #0x8 The Fixes: tag below is added so stable branches will get the update; it doesn't necessarily mean that commit was broken at the time, rather it didn't withstand the aarch64 objdump update. Tested no difference in output for sample x86_64, power arch perf.data files. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bb7eff5206e4795ac79c177a80fe9f4630aaf730 Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> Cc: Anton Blanchard <anton@samba.org> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Taeung Song <treeze.taeung@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Fixes: b13bbeee5ee6 ("perf annotate: Fix branch instruction with multiple operands") Signed-off-by: Kim Phillips <kim.phillips@arm.com> --- tools/perf/util/annotate.c | 17 ++++++++++++++++- tools/perf/util/annotate.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e32ead4744bd..b83897dafbb0 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -282,7 +282,8 @@ bool ins__is_call(const struct ins *ins) return ins->ops == &call_ops || ins->ops == &s390_call_ops; } -static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms) +static int jump__parse(struct arch *arch, struct ins_operands *ops, + struct map_symbol *ms) { struct map *map = ms->map; struct symbol *sym = ms->sym; @@ -291,6 +292,15 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op }; const char *c = strchr(ops->raw, ','); u64 start, end; + + /* + * Prevent from matching commas in the comment section, e.g.: + * ffff200008446e70: b.cs ffff2000084470f4 <generic_exec_single+0x314> // b.hs, b.nlast + */ + ops->raw_comment = strchr(ops->raw, arch->objdump.comment_char); + if (c && ops->raw_comment && c > ops->raw_comment) + c = NULL; + /* * Examples of lines to parse for the _cpp_lex_token@@Base * function: @@ -367,6 +377,11 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size, return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name); c = strchr(ops->raw, ','); + + /* Prevent from matching commas in the comment section */ + if (ops->raw_comment && c && c > ops->raw_comment) + c = NULL; + if (c != NULL) { const char *c2 = strchr(c + 1, ','); diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 005a5fe8a8c6..5399ba2321bb 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -22,6 +22,7 @@ struct ins { struct ins_operands { char *raw; + char *raw_comment; struct { char *raw; char *name; -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] perf annotate: fix parsing aarch64 branch instructions after objdump update 2018-08-24 0:10 [PATCH] perf annotate: fix parsing aarch64 branch instructions after objdump update Kim Phillips @ 2018-08-24 7:59 ` Thomas-Mich Richter 2018-08-24 21:45 ` Kim Phillips 2018-08-27 12:50 ` Arnaldo Carvalho de Melo 1 sibling, 1 reply; 7+ messages in thread From: Thomas-Mich Richter @ 2018-08-24 7:59 UTC (permalink / raw) To: Kim Phillips, Arnaldo Carvalho de Melo Cc: Ravi Bangoria, Anton Blanchard, Robin Murphy, Alexander Shishkin, Christian Borntraeger, Mark Rutland, Peter Zijlstra, Taeung Song, Ingo Molnar, Jiri Olsa, Namhyung Kim, linux-kernel, linux-arm-kernel, perf group On 08/24/2018 02:10 AM, Kim Phillips wrote: > Starting with binutils 2.28, aarch64 objdump adds comments to the > disassembly output to show the alternative names of a condition code [1]. > > It is assumed that commas in objdump comments could occur in other arches > now or in the future, so this fix is arch-independent. > > The fix could have been done with arm64 specific jump__parse and > jump__scnprintf functions, but the jump__scnprintf instruction would > have to have its comment character be a literal, since the scnprintf > functions cannot receive a struct arch easily. > > This inconvenience also applies to the generic jump__scnprintf, which > is why we add a raw_comment pointer to struct ins_operands, so the > __parse function assigns it to be re-used by its corresponding __scnprintf > function. > > Example differences in 'perf annotate --stdio2' output on an > aarch64 perf.data file: > > BEFORE: → b.cs ffff200008133d1c <unwind_frame+0x18c> // b.hs, dffff7ecc47b > AFTER : ↓ b.cs 18c > > BEFORE: → b.cc ffff200008d8d9cc <get_alloc_profile+0x31c> // b.lo, b.ul, dffff727295b > AFTER : ↓ b.cc 31c > > The branch target labels 18c and 31c also now appear in the output: > > BEFORE: add x26, x29, #0x80 > AFTER : 18c: add x26, x29, #0x80 > > BEFORE: add x21, x21, #0x8 > AFTER : 31c: add x21, x21, #0x8 > > The Fixes: tag below is added so stable branches will get the update; it > doesn't necessarily mean that commit was broken at the time, rather it > didn't withstand the aarch64 objdump update. > > Tested no difference in output for sample x86_64, power arch perf.data files. Tested, no difference in output on s390. Just to let you know. -- Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany -- Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] perf annotate: fix parsing aarch64 branch instructions after objdump update 2018-08-24 7:59 ` Thomas-Mich Richter @ 2018-08-24 21:45 ` Kim Phillips 0 siblings, 0 replies; 7+ messages in thread From: Kim Phillips @ 2018-08-24 21:45 UTC (permalink / raw) To: Thomas-Mich Richter Cc: Arnaldo Carvalho de Melo, Ravi Bangoria, Anton Blanchard, Robin Murphy, Alexander Shishkin, Christian Borntraeger, Mark Rutland, Peter Zijlstra, Taeung Song, Ingo Molnar, Jiri Olsa, Namhyung Kim, linux-kernel, linux-arm-kernel, perf group On Fri, 24 Aug 2018 09:59:22 +0200 Thomas-Mich Richter <tmricht@linux.ibm.com> wrote: > On 08/24/2018 02:10 AM, Kim Phillips wrote: > > Tested no difference in output for sample x86_64, power arch perf.data files. > > Tested, no difference in output on s390. Just to let you know. Thanks! An official Tested-by: tag would help keep acme from guessing whether he should convert these less-officially sounding types of emails in the future. I doubt your official Tested-by implies you necessarily have had to claim you fully tested it on e.g., x86-64, esp. if your Tested-by is in such context as provided above. BTW, if you want to send me an s390 perf.data file and the file resulting from 'perf archive', and a matching vmlinux in an off-list email, I can add it to my perf-archives arsenal for future testing. Again, thanks for testing! Kim ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] perf annotate: fix parsing aarch64 branch instructions after objdump update 2018-08-24 0:10 [PATCH] perf annotate: fix parsing aarch64 branch instructions after objdump update Kim Phillips 2018-08-24 7:59 ` Thomas-Mich Richter @ 2018-08-27 12:50 ` Arnaldo Carvalho de Melo 2018-08-27 17:53 ` [PATCH v2] " Kim Phillips 1 sibling, 1 reply; 7+ messages in thread From: Arnaldo Carvalho de Melo @ 2018-08-27 12:50 UTC (permalink / raw) To: Kim Phillips Cc: Ravi Bangoria, Anton Blanchard, Robin Murphy, Alexander Shishkin, Christian Borntraeger, Mark Rutland, Peter Zijlstra, Taeung Song, Ingo Molnar, Jiri Olsa, Namhyung Kim, linux-kernel, linux-arm-kernel, perf group Em Thu, Aug 23, 2018 at 07:10:47PM -0500, Kim Phillips escreveu: > Starting with binutils 2.28, aarch64 objdump adds comments to the > disassembly output to show the alternative names of a condition code [1]. > > It is assumed that commas in objdump comments could occur in other arches > now or in the future, so this fix is arch-independent. > > The fix could have been done with arm64 specific jump__parse and > jump__scnprintf functions, but the jump__scnprintf instruction would > have to have its comment character be a literal, since the scnprintf > functions cannot receive a struct arch easily. > > This inconvenience also applies to the generic jump__scnprintf, which > is why we add a raw_comment pointer to struct ins_operands, so the > __parse function assigns it to be re-used by its corresponding __scnprintf > function. > > Example differences in 'perf annotate --stdio2' output on an > aarch64 perf.data file: > > BEFORE: → b.cs ffff200008133d1c <unwind_frame+0x18c> // b.hs, dffff7ecc47b > AFTER : ↓ b.cs 18c > > BEFORE: → b.cc ffff200008d8d9cc <get_alloc_profile+0x31c> // b.lo, b.ul, dffff727295b > AFTER : ↓ b.cc 31c > > The branch target labels 18c and 31c also now appear in the output: > > BEFORE: add x26, x29, #0x80 > AFTER : 18c: add x26, x29, #0x80 > > BEFORE: add x21, x21, #0x8 > AFTER : 31c: add x21, x21, #0x8 > > The Fixes: tag below is added so stable branches will get the update; it > doesn't necessarily mean that commit was broken at the time, rather it > didn't withstand the aarch64 objdump update. > > Tested no difference in output for sample x86_64, power arch perf.data files. > > [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bb7eff5206e4795ac79c177a80fe9f4630aaf730 > > Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> > Cc: Anton Blanchard <anton@samba.org> > Cc: Robin Murphy <robin.murphy@arm.com> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> > Cc: Christian Borntraeger <borntraeger@de.ibm.com> > Cc: Mark Rutland <mark.rutland@arm.com> > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: Taeung Song <treeze.taeung@gmail.com> > Cc: Ingo Molnar <mingo@redhat.com> > Cc: Arnaldo Carvalho de Melo <acme@kernel.org> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> > Cc: Jiri Olsa <jolsa@redhat.com> > Cc: Namhyung Kim <namhyung@kernel.org> > Fixes: b13bbeee5ee6 ("perf annotate: Fix branch instruction with multiple operands") > Signed-off-by: Kim Phillips <kim.phillips@arm.com> > --- > tools/perf/util/annotate.c | 17 ++++++++++++++++- > tools/perf/util/annotate.h | 1 + > 2 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c > index e32ead4744bd..b83897dafbb0 100644 > --- a/tools/perf/util/annotate.c > +++ b/tools/perf/util/annotate.c > @@ -282,7 +282,8 @@ bool ins__is_call(const struct ins *ins) > return ins->ops == &call_ops || ins->ops == &s390_call_ops; > } > > -static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms) > +static int jump__parse(struct arch *arch, struct ins_operands *ops, > + struct map_symbol *ms) Try to refrain from reflowing, what you need to do here is just to remove that __maybe_unused. > { > struct map *map = ms->map; > struct symbol *sym = ms->sym; > @@ -291,6 +292,15 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op > }; > const char *c = strchr(ops->raw, ','); > u64 start, end; > + > + /* > + * Prevent from matching commas in the comment section, e.g.: > + * ffff200008446e70: b.cs ffff2000084470f4 <generic_exec_single+0x314> // b.hs, b.nlast > + */ > + ops->raw_comment = strchr(ops->raw, arch->objdump.comment_char); > + if (c && ops->raw_comment && c > ops->raw_comment) > + c = NULL; > + > /* > * Examples of lines to parse for the _cpp_lex_token@@Base > * function: > @@ -367,6 +377,11 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size, > return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name); > > c = strchr(ops->raw, ','); > + > + /* Prevent from matching commas in the comment section */ > + if (ops->raw_comment && c && c > ops->raw_comment) > + c = NULL; This is equivalent to the previous test, but why do it differently? Since both are open coded equivalents, why not do something like: c = validate_comma(c, ops); That would translate to: static inline const char *validate_comma(const char *c, ops) { return c > ops->raw_comment ? NULL : c; } Which should be a third equivalent form to check if c, having been found, is after ops->raw_comment, if there is a raw_comment? - Arnaldo > + > if (c != NULL) { > const char *c2 = strchr(c + 1, ','); > > diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h > index 005a5fe8a8c6..5399ba2321bb 100644 > --- a/tools/perf/util/annotate.h > +++ b/tools/perf/util/annotate.h > @@ -22,6 +22,7 @@ struct ins { > > struct ins_operands { > char *raw; > + char *raw_comment; > struct { > char *raw; > char *name; > -- > 2.17.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] perf annotate: fix parsing aarch64 branch instructions after objdump update 2018-08-27 12:50 ` Arnaldo Carvalho de Melo @ 2018-08-27 17:53 ` Kim Phillips 2018-08-30 18:47 ` Arnaldo Carvalho de Melo 2018-09-06 13:07 ` [tip:perf/core] perf annotate: Fix " tip-bot for Kim Phillips 0 siblings, 2 replies; 7+ messages in thread From: Kim Phillips @ 2018-08-27 17:53 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Ravi Bangoria, Anton Blanchard, Robin Murphy, Alexander Shishkin, Christian Borntraeger, Mark Rutland, Peter Zijlstra, Taeung Song, Ingo Molnar, Jiri Olsa, Namhyung Kim, linux-kernel, linux-arm-kernel, perf group Starting with binutils 2.28, aarch64 objdump adds comments to the disassembly output to show the alternative names of a condition code [1]. It is assumed that commas in objdump comments could occur in other arches now or in the future, so this fix is arch-independent. The fix could have been done with arm64 specific jump__parse and jump__scnprintf functions, but the jump__scnprintf instruction would have to have its comment character be a literal, since the scnprintf functions cannot receive a struct arch easily. This inconvenience also applies to the generic jump__scnprintf, which is why we add a raw_comment pointer to struct ins_operands, so the __parse function assigns it to be re-used by its corresponding __scnprintf function. Example differences in 'perf annotate --stdio2' output on an aarch64 perf.data file: BEFORE: → b.cs ffff200008133d1c <unwind_frame+0x18c> // b.hs, dffff7ecc47b AFTER : ↓ b.cs 18c BEFORE: → b.cc ffff200008d8d9cc <get_alloc_profile+0x31c> // b.lo, b.ul, dffff727295b AFTER : ↓ b.cc 31c The branch target labels 18c and 31c also now appear in the output: BEFORE: add x26, x29, #0x80 AFTER : 18c: add x26, x29, #0x80 BEFORE: add x21, x21, #0x8 AFTER : 31c: add x21, x21, #0x8 The Fixes: tag below is added so stable branches will get the update; it doesn't necessarily mean that commit was broken at the time, rather it didn't withstand the aarch64 objdump update. Tested no difference in output for sample x86_64, power arch perf.data files. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bb7eff5206e4795ac79c177a80fe9f4630aaf730 Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> Cc: Anton Blanchard <anton@samba.org> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Taeung Song <treeze.taeung@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Fixes: b13bbeee5ee6 ("perf annotate: Fix branch instruction with multiple operands") Signed-off-by: Kim Phillips <kim.phillips@arm.com> --- v2: address acme's comments: - consolidate into a validate_comma() - call from an additional couple of places necessary - don't listen to checkpatch wrt reflowing jump__parse definition line to less than 80 characters, just rm the __maybe_unused - re-tested no diff on x86_64 and power arch, arm64 conditional branches fixed. tools/perf/util/annotate.c | 22 +++++++++++++++++++++- tools/perf/util/annotate.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e4268b948e0e..4a2525524e52 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -276,7 +276,19 @@ bool ins__is_call(const struct ins *ins) return ins->ops == &call_ops || ins->ops == &s390_call_ops; } -static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms) +/* + * Prevents from matching commas in the comment section, e.g.: + * ffff200008446e70: b.cs ffff2000084470f4 <generic_exec_single+0x314> // b.hs, b.nlast + */ +static inline const char *validate_comma(const char *c, struct ins_operands *ops) +{ + if (ops->raw_comment && c > ops->raw_comment) + return NULL; + + return c; +} + +static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms) { struct map *map = ms->map; struct symbol *sym = ms->sym; @@ -285,6 +297,10 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op }; const char *c = strchr(ops->raw, ','); u64 start, end; + + ops->raw_comment = strchr(ops->raw, arch->objdump.comment_char); + c = validate_comma(c, ops); + /* * Examples of lines to parse for the _cpp_lex_token@@Base * function: @@ -304,6 +320,7 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op ops->target.addr = strtoull(c, NULL, 16); if (!ops->target.addr) { c = strchr(c, ','); + c = validate_comma(c, ops); if (c++ != NULL) ops->target.addr = strtoull(c, NULL, 16); } @@ -361,9 +378,12 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size, return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name); c = strchr(ops->raw, ','); + c = validate_comma(c, ops); + if (c != NULL) { const char *c2 = strchr(c + 1, ','); + c2 = validate_comma(c2, ops); /* check for 3-op insn */ if (c2 != NULL) c = c2; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 005a5fe8a8c6..5399ba2321bb 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -22,6 +22,7 @@ struct ins { struct ins_operands { char *raw; + char *raw_comment; struct { char *raw; char *name; -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] perf annotate: fix parsing aarch64 branch instructions after objdump update 2018-08-27 17:53 ` [PATCH v2] " Kim Phillips @ 2018-08-30 18:47 ` Arnaldo Carvalho de Melo 2018-09-06 13:07 ` [tip:perf/core] perf annotate: Fix " tip-bot for Kim Phillips 1 sibling, 0 replies; 7+ messages in thread From: Arnaldo Carvalho de Melo @ 2018-08-30 18:47 UTC (permalink / raw) To: Kim Phillips Cc: Ravi Bangoria, Anton Blanchard, Robin Murphy, Alexander Shishkin, Christian Borntraeger, Mark Rutland, Peter Zijlstra, Taeung Song, Ingo Molnar, Jiri Olsa, Namhyung Kim, linux-kernel, linux-arm-kernel, perf group Em Mon, Aug 27, 2018 at 12:53:40PM -0500, Kim Phillips escreveu: > v2: address acme's comments: > - consolidate into a validate_comma() > - call from an additional couple of places necessary > - don't listen to checkpatch wrt reflowing jump__parse definition > line to less than 80 characters, just rm the __maybe_unused > - re-tested no diff on x86_64 and power arch, arm64 conditional > branches fixed. Thanks for taking into account my comments, applied. - Arnaldo ^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip:perf/core] perf annotate: Fix parsing aarch64 branch instructions after objdump update 2018-08-27 17:53 ` [PATCH v2] " Kim Phillips 2018-08-30 18:47 ` Arnaldo Carvalho de Melo @ 2018-09-06 13:07 ` tip-bot for Kim Phillips 1 sibling, 0 replies; 7+ messages in thread From: tip-bot for Kim Phillips @ 2018-09-06 13:07 UTC (permalink / raw) To: linux-tip-commits Cc: mingo, mark.rutland, treeze.taeung, namhyung, anton, robin.murphy, acme, jolsa, tglx, peterz, borntraeger, linux-kernel, kim.phillips, alexander.shishkin, hpa, ravi.bangoria Commit-ID: 4e67b2a5df5d3f341776d12ee575e00ca3ef92de Gitweb: https://git.kernel.org/tip/4e67b2a5df5d3f341776d12ee575e00ca3ef92de Author: Kim Phillips <kim.phillips@arm.com> AuthorDate: Mon, 27 Aug 2018 12:53:40 -0500 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Thu, 30 Aug 2018 15:51:54 -0300 perf annotate: Fix parsing aarch64 branch instructions after objdump update Starting with binutils 2.28, aarch64 objdump adds comments to the disassembly output to show the alternative names of a condition code [1]. It is assumed that commas in objdump comments could occur in other arches now or in the future, so this fix is arch-independent. The fix could have been done with arm64 specific jump__parse and jump__scnprintf functions, but the jump__scnprintf instruction would have to have its comment character be a literal, since the scnprintf functions cannot receive a struct arch easily. This inconvenience also applies to the generic jump__scnprintf, which is why we add a raw_comment pointer to struct ins_operands, so the __parse function assigns it to be re-used by its corresponding __scnprintf function. Example differences in 'perf annotate --stdio2' output on an aarch64 perf.data file: BEFORE: → b.cs ffff200008133d1c <unwind_frame+0x18c> // b.hs, dffff7ecc47b AFTER : ↓ b.cs 18c BEFORE: → b.cc ffff200008d8d9cc <get_alloc_profile+0x31c> // b.lo, b.ul, dffff727295b AFTER : ↓ b.cc 31c The branch target labels 18c and 31c also now appear in the output: BEFORE: add x26, x29, #0x80 AFTER : 18c: add x26, x29, #0x80 BEFORE: add x21, x21, #0x8 AFTER : 31c: add x21, x21, #0x8 The Fixes: tag below is added so stable branches will get the update; it doesn't necessarily mean that commit was broken at the time, rather it didn't withstand the aarch64 objdump update. Tested no difference in output for sample x86_64, power arch perf.data files. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bb7eff5206e4795ac79c177a80fe9f4630aaf730 Signed-off-by: Kim Phillips <kim.phillips@arm.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Anton Blanchard <anton@samba.org> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Taeung Song <treeze.taeung@gmail.com> Cc: linux-arm-kernel@lists.infradead.org Fixes: b13bbeee5ee6 ("perf annotate: Fix branch instruction with multiple operands") Link: http://lkml.kernel.org/r/20180827125340.a2f7e291901d17cea05daba4@arm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/util/annotate.c | 22 +++++++++++++++++++++- tools/perf/util/annotate.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e62b69ea87cd..28cd6a17491b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -282,7 +282,19 @@ bool ins__is_call(const struct ins *ins) return ins->ops == &call_ops || ins->ops == &s390_call_ops; } -static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms) +/* + * Prevents from matching commas in the comment section, e.g.: + * ffff200008446e70: b.cs ffff2000084470f4 <generic_exec_single+0x314> // b.hs, b.nlast + */ +static inline const char *validate_comma(const char *c, struct ins_operands *ops) +{ + if (ops->raw_comment && c > ops->raw_comment) + return NULL; + + return c; +} + +static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms) { struct map *map = ms->map; struct symbol *sym = ms->sym; @@ -291,6 +303,10 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op }; const char *c = strchr(ops->raw, ','); u64 start, end; + + ops->raw_comment = strchr(ops->raw, arch->objdump.comment_char); + c = validate_comma(c, ops); + /* * Examples of lines to parse for the _cpp_lex_token@@Base * function: @@ -310,6 +326,7 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op ops->target.addr = strtoull(c, NULL, 16); if (!ops->target.addr) { c = strchr(c, ','); + c = validate_comma(c, ops); if (c++ != NULL) ops->target.addr = strtoull(c, NULL, 16); } @@ -367,9 +384,12 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size, return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name); c = strchr(ops->raw, ','); + c = validate_comma(c, ops); + if (c != NULL) { const char *c2 = strchr(c + 1, ','); + c2 = validate_comma(c2, ops); /* check for 3-op insn */ if (c2 != NULL) c = c2; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 005a5fe8a8c6..5399ba2321bb 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -22,6 +22,7 @@ struct ins { struct ins_operands { char *raw; + char *raw_comment; struct { char *raw; char *name; ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-09-06 13:07 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-08-24 0:10 [PATCH] perf annotate: fix parsing aarch64 branch instructions after objdump update Kim Phillips 2018-08-24 7:59 ` Thomas-Mich Richter 2018-08-24 21:45 ` Kim Phillips 2018-08-27 12:50 ` Arnaldo Carvalho de Melo 2018-08-27 17:53 ` [PATCH v2] " Kim Phillips 2018-08-30 18:47 ` Arnaldo Carvalho de Melo 2018-09-06 13:07 ` [tip:perf/core] perf annotate: Fix " tip-bot for Kim Phillips
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).