perf evsel: Mark a evsel as disabled when asking the kernel do disable it
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: b7e8452b860c299f342a012922bdd9ab8f2bb722 Gitweb: https://git.kernel.org/tip/b7e8452b860c299f342a012922bdd9ab8f2bb722 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Sat, 20 Oct 2018 09:04:41 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 22 Oct 2018 12:37:45 -0300
perf evsel: Mark a evsel as disabled when asking the kernel do disable it
Because there may be more such events in the ring buffer that should be discarded when an app decides to stop considering them.
At some point we'll do this with eBPF, this way we stop them at origin, before they are placed in the ring buffer.
Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 23 +++++++++++++++++------ tools/perf/util/evsel.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-)
tools/perf/util/evlist.c +1 -1
@@ -358,7 +358,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)struct perf_evsel *pos;evlist__for_each_entry (evlist, pos) { -if (!perf_evsel__is_group_leader (pos) || !pos->fd) +if (pos->disabled || !perf_evsel__is_group_leader (pos) || !pos->fd)continue ;perf_evsel__disable (pos); }
tools/perf/util/evsel.c +17 -6
@@ -1207,16 +1207,27 @@ int perf_evsel__append_addr_filter(struct perf_evsel *evsel, const char *filter)int perf_evsel__enable (struct perf_evsel *evsel) { -return perf_evsel__run_ioctl (evsel, -PERF_EVENT_IOC_ENABLE , -0 ); +int err =perf_evsel__run_ioctl (evsel,PERF_EVENT_IOC_ENABLE ,0 ); + +if (!err) + evsel->disabled = false; + +return err; }int perf_evsel__disable (struct perf_evsel *evsel) { -return perf_evsel__run_ioctl (evsel, -PERF_EVENT_IOC_DISABLE , -0 ); +int err =perf_evsel__run_ioctl (evsel,PERF_EVENT_IOC_DISABLE ,0 ); +/* +* We mark it disabled here so that tools that disable a event can +* ignore events after they disable it. I.e. the ring buffer may have +* already a few more events queued up before the kernel got the stop +* request. +*/ +if (!err) + evsel->disabled = true; + +return err; }int perf_evsel__alloc_id (struct perf_evsel *evsel,int ncpus,int nthreads)
tools/perf/util/evsel.h +1 -0
@@ -122,6 +122,7 @@ struct perf_evsel {bool snapshot;bool supported;bool needs_swap; +bool disabled;bool no_aux_samples;bool immediate;bool system_wide;