perf script brstackinsn: Fix recovery from LBR/binary mismatch
PATCH 2/3 perf jevents: Fix period for Intel fixed counters
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
The Intel fixed counters use a special table to override the JSON information. During this override the period information from the JSON file got dropped, which results in inst_retired.any and similar running with frequency mode instead of a period. Just specify the expected period in the table.
--- tools/perf/pmu-events/jevents.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/pmu-events/jevents.c +6 -6
@@ -449,12 +449,12 @@ static struct fixed {const char *name;const char *event; } fixed[] = { - { "inst_retired.any", "event=0xc0" }, - { "inst_retired.any_p", "event=0xc0" }, - { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03" }, - { "cpu_clk_unhalted.thread", "event=0x3c" }, - { "cpu_clk_unhalted.core", "event=0x3c" }, - { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1" }, + { "inst_retired.any", "event=0xc0,period=2000003" }, + { "inst_retired.any_p", "event=0xc0,period=2000003" }, + { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03,period=2000003" }, + { "cpu_clk_unhalted.thread", "event=0x3c,period=2000003" }, + { "cpu_clk_unhalted.core", "event=0x3c,period=2000003" }, + { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1,period=2000003" }, { NULL, NULL}, };
Signature · 1 line
2.21.0
PATCH 3/3 perf annotate: Improve handling of corrupted ~/.debug
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Sometimes ~/.debug can get corrupted and contain files that still have symbol tables, but which objdump cannot handle. Add a fallback to read the "original" file in such a case. This might be wrong too if it's different, but in many cases when profiling on the same host it will work.
--- tools/perf/util/annotate.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
tools/perf/util/annotate.c +23 -4
@@ -1638,19 +1638,22 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *return 0 ; } -static int dso__disassemble_filename (struct dso *dso,char *filename,size_t filename_size) +static int dso__disassemble_filename (struct dso *dso,char *filename,size_t filename_size, +bool *build_id) {char linkname[PATH_MAX ];char *build_id_filename;char *build_id_path =NULL ;char *pos; + *build_id = false;if (dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso))return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX ; build_id_filename =dso__build_id_filename (dso,NULL ,0 , false);if (build_id_filename) { + *build_id = true;__symbol__join_symfs (filename, filename_size, build_id_filename);free (build_id_filename); }else {
@@ -1854,11 +1857,14 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)int lineno =0 ;int nline;pid_t pid; -int err =dso__disassemble_filename (dso, symfs_filename,sizeof (symfs_filename)); +bool build_id; +int err =dso__disassemble_filename (dso, symfs_filename,sizeof (symfs_filename), + &build_id);if (err)return err; +again:pr_debug ("%s: filename=%s, sym=%s, start=%#" PRIx64", end=%#" PRIx64"\n" , __func__, symfs_filename, sym->name, map->unmap_ip (map, sym->start), map->unmap_ip (map, sym->end));
@@ -1955,8 +1961,21 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) nline++; } -if (nline ==0 ) -pr_err ("No output from %s\n" , command); +if (nline ==0 ) { +pr_err ("No objdump output for %s. Corrupted file?\n" , symfs_filename); +if (build_id) { +/* +* It could be that the buildid file is corrupted. +* Try again with the "true" file. This might be wrong +* too, but it's better than nothing. +* We could move the build id file here? +*/ +__symbol__join_symfs (symfs_filename,sizeof (symfs_filename), + dso->long_name); + build_id = false; + goto again; + } + }/* * kallsyms does not have symbol sizes so there may a nop at the end.
Signature · 1 line
2.21.0
PATCH 1/3 perf script brstackinsn: Fix recovery from LBR/binary mismatch
From: Andi Kleen <[email protected]>
When the LBR data and the instructions in a binary do not match the loop printing instructions could get confused and print a long stream of bogus <bad> instructions.
The problem was that if the instruction decoder cannot decode an instruction it ilen wasn't initialized, so the loop going through the basic block would continue with the previous value.
Harden the code to avoid such problems:
- Make sure ilen is always freshly initialized and is 0 for bad instructions.
- Do not overrun the code buffer while printing instructions
- Print a warning message if the final jump is not on an instruction boundary.
--- tools/perf/builtin-script.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +5 -1
@@ -1061,7 +1061,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,continue ; insn =0 ; -for (off =0 ;; off += ilen) { +for (off =0 ; off < (unsigned )len; off += ilen) {uint64_t ip = start + off; printed +=ip__fprintf_sym (ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
@@ -1072,6 +1072,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, printed +=print_srccode (thread, x.cpumode, ip);break ; }else { + ilen =0 ; printed +=fprintf (fp,"\t%016" PRIx64"\t%s\n" , ip,dump_insn (&x, ip, buffer + off, len - off, &ilen));if (ilen ==0 )
@@ -1081,6 +1082,8 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, insn++; } } +if (off != (unsigned )len) + printed +=fprintf (fp,"\tmismatch of LBR data and executable\n" ); }/*
@@ -1121,6 +1124,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, goto out; }for (off =0 ; off <= end - start; off += ilen) { + ilen =0 ; printed +=fprintf (fp,"\t%016" PRIx64"\t%s\n" , start + off,dump_insn (&x, start + off, buffer + off, len - off, &ilen));if (ilen ==0 )
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
AppliedEm Fri, Sep 27, 2019 at 04:35:44PM -0700, Andi Kleen escreveu:
Quoted 10 lines
From: Andi Kleen <[email protected]>
When the LBR data and the instructions in a binary do not match the loop printing instructions could get confused and print a long stream of bogus <bad> instructions.
The problem was that if the instruction decoder cannot decode an instruction it ilen wasn't initialized, so the loop going through the basic block would continue with the previous value.
Quoted 6 lines
Harden the code to avoid such problems:
- Make sure ilen is always freshly initialized and is 0 for bad instructions.
- Do not overrun the code buffer while printing instructions
- Print a warning message if the final jump is not on an instruction boundary.
Thanks, applied.
- Arnaldo
Quoted 45 lines
Signed-off-by Andi Kleen <[email protected]>--- tools/perf/builtin-script.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)tools/perf/builtin-script.c +5
-1@@ -1061,7 +1061,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,continue ; insn =0 ; -for (off =0 ;; off += ilen) { +for (off =0 ; off < (unsigned )len; off += ilen) {uint64_t ip = start + off; printed +=ip__fprintf_sym (ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);@@ -1072,6 +1072,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, printed +=print_srccode (thread, x.cpumode, ip);break ; }else { + ilen =0 ; printed +=fprintf (fp,"\t%016" PRIx64"\t%s\n" , ip,dump_insn (&x, ip, buffer + off, len - off, &ilen));if (ilen ==0 )@@ -1081,6 +1082,8 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, insn++; } } +if (off != (unsigned )len) + printed +=fprintf (fp,"\tmismatch of LBR data and executable\n" ); }/* @@ -1121,6 +1124,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, goto out; }for (off =0 ; off <= end - start; off += ilen) { + ilen =0 ; printed +=fprintf (fp,"\t%016" PRIx64"\t%s\n" , start + off,dump_insn (&x, start + off, buffer + off, len - off, &ilen));if (ilen ==0 )Signature · 1 line
2.21.0
Signature · 1 line
- Arnaldo
Arnaldo Carvalho de Melo
AppliedRe: [PATCH 2/3] perf jevents: Fix period for Intel fixed counters
In reply to Andi KleenEm Fri, Sep 27, 2019 at 04:35:45PM -0700, Andi Kleen escreveu:
Quoted 7 lines
From: Andi Kleen <[email protected]>
The Intel fixed counters use a special table to override the JSON information. During this override the period information from the JSON file got dropped, which results in inst_retired.any and similar running with frequency mode instead of a period. Just specify the expected period in the table.
Thanks, applied.
- Arnaldo
Quoted 30 lines
Signed-off-by Andi Kleen <[email protected]>--- tools/perf/pmu-events/jevents.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)tools/perf/pmu-events/jevents.c +6
-6@@ -449,12 +449,12 @@ static struct fixed {const char *name;const char *event; } fixed[] = { - { "inst_retired.any", "event=0xc0" }, - { "inst_retired.any_p", "event=0xc0" }, - { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03" }, - { "cpu_clk_unhalted.thread", "event=0x3c" }, - { "cpu_clk_unhalted.core", "event=0x3c" }, - { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1" }, + { "inst_retired.any", "event=0xc0,period=2000003" }, + { "inst_retired.any_p", "event=0xc0,period=2000003" }, + { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03,period=2000003" }, + { "cpu_clk_unhalted.thread", "event=0x3c,period=2000003" }, + { "cpu_clk_unhalted.core", "event=0x3c,period=2000003" }, + { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1,period=2000003" }, { NULL, NULL}, };Signature · 1 line
2.21.0
Signature · 1 line
- Arnaldo
[tip: perf/urgent] perf jevents: Fix period for Intel fixed counters
In reply to Andi KleenThe following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 6bdfd9f118bd59cf0f85d3bf4b72b586adea17c1 Gitweb: https://git.kernel.org/tip/6bdfd9f118bd59cf0f85d3bf4b72b586adea17c1 Author: Andi Kleen <[email protected]> AuthorDate: Fri, 27 Sep 2019 16:35:45 -07:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Mon, 30 Sep 2019 17:29:53 -03:00
perf jevents: Fix period for Intel fixed counters
The Intel fixed counters use a special table to override the JSON information.
During this override the period information from the JSON file got dropped, which results in inst_retired.any and similar running with frequency mode instead of a period.
Just specify the expected period in the table.
--- tools/perf/pmu-events/jevents.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/pmu-events/jevents.c +6 -6
@@ -450,12 +450,12 @@ static struct fixed {const char *name;const char *event; } fixed[] = { - { "inst_retired.any", "event=0xc0" }, - { "inst_retired.any_p", "event=0xc0" }, - { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03" }, - { "cpu_clk_unhalted.thread", "event=0x3c" }, - { "cpu_clk_unhalted.core", "event=0x3c" }, - { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1" }, + { "inst_retired.any", "event=0xc0,period=2000003" }, + { "inst_retired.any_p", "event=0xc0,period=2000003" }, + { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03,period=2000003" }, + { "cpu_clk_unhalted.thread", "event=0x3c,period=2000003" }, + { "cpu_clk_unhalted.core", "event=0x3c,period=2000003" }, + { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1,period=2000003" }, { NULL, NULL}, };
The following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: e98df280bc2a499fd41d7f9e2d6733884de69902 Gitweb: https://git.kernel.org/tip/e98df280bc2a499fd41d7f9e2d6733884de69902 Author: Andi Kleen <[email protected]> AuthorDate: Fri, 27 Sep 2019 16:35:44 -07:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Mon, 30 Sep 2019 17:29:52 -03:00
perf script brstackinsn: Fix recovery from LBR/binary mismatch
When the LBR data and the instructions in a binary do not match the loop printing instructions could get confused and print a long stream of bogus <bad> instructions.
The problem was that if the instruction decoder cannot decode an instruction it ilen wasn't initialized, so the loop going through the basic block would continue with the previous value.
Harden the code to avoid such problems:
- Make sure ilen is always freshly initialized and is 0 for bad instructions.
- Do not overrun the code buffer while printing instructions
- Print a warning message if the final jump is not on an instruction boundary.
--- tools/perf/builtin-script.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +5 -1
@@ -1063,7 +1063,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,continue ; insn =0 ; -for (off =0 ;; off += ilen) { +for (off =0 ; off < (unsigned )len; off += ilen) {uint64_t ip = start + off; printed +=ip__fprintf_sym (ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
@@ -1074,6 +1074,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, printed +=print_srccode (thread, x.cpumode, ip);break ; }else { + ilen =0 ; printed +=fprintf (fp,"\t%016" PRIx64"\t%s\n" , ip,dump_insn (&x, ip, buffer + off, len - off, &ilen));if (ilen ==0 )
@@ -1083,6 +1084,8 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, insn++; } } +if (off != (unsigned )len) + printed +=fprintf (fp,"\tmismatch of LBR data and executable\n" ); }/*
@@ -1123,6 +1126,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, goto out; }for (off =0 ; off <= end - start; off += ilen) { + ilen =0 ; printed +=fprintf (fp,"\t%016" PRIx64"\t%s\n" , start + off,dump_insn (&x, start + off, buffer + off, len - off, &ilen));if (ilen ==0 )