aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-05-23 22:28:59 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-05-30 11:41:44 -0400
commitc45628b0a3f90c4ffeca5f72f227008ceedc21c5 (patch)
treeda39888cd2388ca752f09e48909520d0bc9e524a
parent792d48b4cf9c248ab2bf66c140a27c48e116bed7 (diff)
perf record: Robustify perf_event__synth_time_conv()
It is possible that all events in an evlist are overwritable. perf_event__synth_time_conv() should not crash in this case. record__pick_pc() is used to check avaliability. Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1464056944-166978-3-git-send-email-wangnan0@huawei.com Signed-off-by: He Kuang <hekuang@huawei.com> [ Split from a larger patch ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/arch/x86/util/tsc.c2
-rw-r--r--tools/perf/builtin-record.c9
2 files changed, 10 insertions, 1 deletions
diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index 357f1b13b5ae..2e5567c94e09 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -62,6 +62,8 @@ int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
62 struct perf_tsc_conversion tc; 62 struct perf_tsc_conversion tc;
63 int err; 63 int err;
64 64
65 if (!pc)
66 return 0;
65 err = perf_read_tsc_conversion(pc, &tc); 67 err = perf_read_tsc_conversion(pc, &tc);
66 if (err == -EOPNOTSUPP) 68 if (err == -EOPNOTSUPP)
67 return 0; 69 return 0;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index dc3fcb597e4c..d4cf1b0c88f9 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -655,6 +655,13 @@ perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused
655 return 0; 655 return 0;
656} 656}
657 657
658static const struct perf_event_mmap_page *record__pick_pc(struct record *rec)
659{
660 if (rec->evlist && rec->evlist->mmap && rec->evlist->mmap[0].base)
661 return rec->evlist->mmap[0].base;
662 return NULL;
663}
664
658static int record__synthesize(struct record *rec) 665static int record__synthesize(struct record *rec)
659{ 666{
660 struct perf_session *session = rec->session; 667 struct perf_session *session = rec->session;
@@ -692,7 +699,7 @@ static int record__synthesize(struct record *rec)
692 } 699 }
693 } 700 }
694 701
695 err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool, 702 err = perf_event__synth_time_conv(record__pick_pc(rec), tool,
696 process_synthesized_event, machine); 703 process_synthesized_event, machine);
697 if (err) 704 if (err)
698 goto out; 705 goto out;