lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Message-ID: <1464056944-166978-3-git-send-email-wangnan0@huawei.com> Date: Tue, 24 May 2016 02:28:59 +0000 From: Wang Nan <wangnan0@...wei.com> To: <acme@...nel.org> CC: <pi3orama@....com>, <linux-kernel@...r.kernel.org>, Wang Nan <wangnan0@...wei.com>, He Kuang <hekuang@...wei.com>, "Arnaldo Carvalho de Melo" <acme@...hat.com>, Jiri Olsa <jolsa@...nel.org>, Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>, Namhyung Kim <namhyung@...nel.org>, "Zefan Li" <lizefan@...wei.com> Subject: [PATCH v4 2/7] perf tools: Don't poll and mmap overwritable events There's no need to receive events from overwritable ring buffer. Instead, perf should make them run background until something happen. This patch makes normal events from overwrite events ignored. Overwritable events must be mapped readonly and backward, so if evlist and evsel is not match (evsel->overwrite is true but either evlist is read/write or evlist is not backward, and vice versa), skip mapping it. 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. Further commits will expand it when we introduce auxiliary evlists and have multiple mmaps. Signed-off-by: Wang Nan <wangnan0@...wei.com> Signed-off-by: He Kuang <hekuang@...wei.com> Cc: Arnaldo Carvalho de Melo <acme@...hat.com> Cc: Jiri Olsa <jolsa@...nel.org> Cc: Masami Hiramatsu <masami.hiramatsu.pt@...achi.com> Cc: Namhyung Kim <namhyung@...nel.org> Cc: Zefan Li <lizefan@...wei.com> Cc: pi3orama@....com --- tools/perf/arch/x86/util/tsc.c | 2 ++ tools/perf/builtin-record.c | 9 ++++++++- tools/perf/util/evlist.c | 23 +++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c index 357f1b1..2e5567c 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, struct perf_tsc_conversion tc; int err; + if (!pc) + return 0; err = perf_read_tsc_conversion(pc, &tc); if (err == -EOPNOTSUPP) return 0; diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index dc3fcb5..d4cf1b0 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 return 0; } +static const struct perf_event_mmap_page *record__pick_pc(struct record *rec) +{ + if (rec->evlist && rec->evlist->mmap && rec->evlist->mmap[0].base) + return rec->evlist->mmap[0].base; + return NULL; +} + static int record__synthesize(struct record *rec) { struct perf_session *session = rec->session; @@ -692,7 +699,7 @@ static int record__synthesize(struct record *rec) } } - err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool, + err = perf_event__synth_time_conv(record__pick_pc(rec), tool, process_synthesized_event, machine); if (err) goto out; diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 55cea69..fbd0d47 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -463,9 +463,9 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) return 0; } -static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx) +static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent) { - int pos = fdarray__add(&evlist->pollfd, fd, POLLIN | POLLERR | POLLHUP); + int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP); /* * Save the idx so that when we filter out fds POLLHUP'ed we can * close the associated evlist->mmap[] entry. @@ -481,7 +481,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) { - return __perf_evlist__add_pollfd(evlist, fd, -1); + return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN); } static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd) @@ -984,15 +984,28 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx, return 0; } +static bool +perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused, + struct perf_evsel *evsel) +{ + if (evsel->overwrite) + return false; + return true; +} + static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, struct mmap_params *mp, int cpu, int thread, int *output) { struct perf_evsel *evsel; + int revent; evlist__for_each(evlist->parent, evsel) { int fd; + if (evsel->overwrite != (evlist->overwrite && evlist->backward)) + continue; + if (evsel->system_wide && thread) continue; @@ -1009,6 +1022,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, perf_evlist__mmap_get(evlist, idx); } + revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0; + /* * The system_wide flag causes a selected event to be opened * always without a pid. Consequently it will never get a @@ -1017,7 +1032,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, * Therefore don't add it for polling. */ if (!evsel->system_wide && - __perf_evlist__add_pollfd(evlist->parent, fd, idx) < 0) { + __perf_evlist__add_pollfd(evlist->parent, fd, idx, revent) < 0) { perf_evlist__mmap_put(evlist, idx); return -1; } -- 1.8.3.4
Powered by blists - more mailing lists