aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorStephane Eranian <eranian@google.com>2012-04-27 08:45:38 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-05-01 13:20:00 -0400
commit5622c07b4741e0afd7607bce6e850b76eeb23210 (patch)
treebbd2aa4459baf10ef88aef17fc5b55abaf451ce0 /tools
parentafda0f94483f46a4caddb529b8f95e0aaf015de6 (diff)
perf stat: Fix case where guest/host monitoring is not supported by kernel
By default, perf stat sets exclude_guest = 1. But when you run perf on a kernel which does not support host/guest filtering, then you get an error saying the event in unsupported. This comes from the fact that when the perf_event_attr struct passed by the user is larger than the one known to the kernel there is safety check which ensures that all unknown bits are zero. But here, exclude_guest is 1 (part of the unknown bits) and thus the perf_event_open() syscall return EINVAL. To my surprise, running perf record on the same kernel did not exhibit the problem. The reason is that perf record handles the problem by catching the error and retrying with guest/host excludes set to zero. For some reason, this was not done with perf stat. This patch fixes this problem. Signed-off-by: Stephane Eranian <eranian@google.com> Cc: Gleb Natapov <gleb@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Joerg Roedel <joro@8bytes.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Robert Richter <robert.richter@amd.com> Link: http://lkml.kernel.org/r/20120427124538.GA7230@quad Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-stat.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c941bb640f49..4532a789fbe3 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -283,6 +283,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
283{ 283{
284 struct perf_event_attr *attr = &evsel->attr; 284 struct perf_event_attr *attr = &evsel->attr;
285 struct xyarray *group_fd = NULL; 285 struct xyarray *group_fd = NULL;
286 bool exclude_guest_missing = false;
287 int ret;
286 288
287 if (group && evsel != first) 289 if (group && evsel != first)
288 group_fd = first->fd; 290 group_fd = first->fd;
@@ -293,16 +295,39 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
293 295
294 attr->inherit = !no_inherit; 296 attr->inherit = !no_inherit;
295 297
296 if (system_wide) 298retry:
297 return perf_evsel__open_per_cpu(evsel, evsel_list->cpus, 299 if (exclude_guest_missing)
300 evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
301
302 if (system_wide) {
303 ret = perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
298 group, group_fd); 304 group, group_fd);
305 if (ret)
306 goto check_ret;
307 return 0;
308 }
309
299 if (!target_pid && !target_tid && (!group || evsel == first)) { 310 if (!target_pid && !target_tid && (!group || evsel == first)) {
300 attr->disabled = 1; 311 attr->disabled = 1;
301 attr->enable_on_exec = 1; 312 attr->enable_on_exec = 1;
302 } 313 }
303 314
304 return perf_evsel__open_per_thread(evsel, evsel_list->threads, 315 ret = perf_evsel__open_per_thread(evsel, evsel_list->threads,
305 group, group_fd); 316 group, group_fd);
317 if (!ret)
318 return 0;
319 /* fall through */
320check_ret:
321 if (ret && errno == EINVAL) {
322 if (!exclude_guest_missing &&
323 (evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
324 pr_debug("Old kernel, cannot exclude "
325 "guest or host samples.\n");
326 exclude_guest_missing = true;
327 goto retry;
328 }
329 }
330 return ret;
306} 331}
307 332
308/* 333/*