Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Wang Nan and committed by
Arnaldo Carvalho de Melo
c45628b0 792d48b4

+10 -1
+2
tools/perf/arch/x86/util/tsc.c
··· 62 62 struct perf_tsc_conversion tc; 63 63 int err; 64 64 65 + if (!pc) 66 + return 0; 65 67 err = perf_read_tsc_conversion(pc, &tc); 66 68 if (err == -EOPNOTSUPP) 67 69 return 0;
+8 -1
tools/perf/builtin-record.c
··· 655 655 return 0; 656 656 } 657 657 658 + static 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 + 658 665 static int record__synthesize(struct record *rec) 659 666 { 660 667 struct perf_session *session = rec->session; ··· 699 692 } 700 693 } 701 694 702 - err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool, 695 + err = perf_event__synth_time_conv(record__pick_pc(rec), tool, 703 696 process_synthesized_event, machine); 704 697 if (err) 705 698 goto out;