aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/evsel.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-12-13 11:13:07 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 14:40:08 -0500
commit594ac61ad3be9c80c738a9fe3bb95c05d8d1bae1 (patch)
tree3fb2c1395bafd1799e34443d58adef6c4b65c7fe /tools/perf/util/evsel.c
parentce90e3856ba55af4d3d9c9c1168cc624607f6c7c (diff)
perf evsel: Do missing feature fallbacks in just one place
Instead of doing it in stat, top, record or any other tool that opens event descriptors. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-vr8hzph83d5t2mdlkf565h84@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r--tools/perf/util/evsel.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 7a2a3dc3ff03..ee6ee3f45c2a 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -22,6 +22,11 @@
22#include <linux/perf_event.h> 22#include <linux/perf_event.h>
23#include "perf_regs.h" 23#include "perf_regs.h"
24 24
25static struct {
26 bool sample_id_all;
27 bool exclude_guest;
28} perf_missing_features;
29
25#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) 30#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
26 31
27static int __perf_evsel__sample_size(u64 sample_type) 32static int __perf_evsel__sample_size(u64 sample_type)
@@ -463,7 +468,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
463 struct perf_event_attr *attr = &evsel->attr; 468 struct perf_event_attr *attr = &evsel->attr;
464 int track = !evsel->idx; /* only the first counter needs these */ 469 int track = !evsel->idx; /* only the first counter needs these */
465 470
466 attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1; 471 attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
467 attr->inherit = !opts->no_inherit; 472 attr->inherit = !opts->no_inherit;
468 473
469 perf_evsel__set_sample_bit(evsel, IP); 474 perf_evsel__set_sample_bit(evsel, IP);
@@ -513,7 +518,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
513 if (opts->period) 518 if (opts->period)
514 perf_evsel__set_sample_bit(evsel, PERIOD); 519 perf_evsel__set_sample_bit(evsel, PERIOD);
515 520
516 if (!opts->sample_id_all_missing && 521 if (!perf_missing_features.sample_id_all &&
517 (opts->sample_time || !opts->no_inherit || 522 (opts->sample_time || !opts->no_inherit ||
518 perf_target__has_cpu(&opts->target))) 523 perf_target__has_cpu(&opts->target)))
519 perf_evsel__set_sample_bit(evsel, TIME); 524 perf_evsel__set_sample_bit(evsel, TIME);
@@ -761,6 +766,13 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
761 pid = evsel->cgrp->fd; 766 pid = evsel->cgrp->fd;
762 } 767 }
763 768
769fallback_missing_features:
770 if (perf_missing_features.exclude_guest)
771 evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
772retry_sample_id:
773 if (perf_missing_features.sample_id_all)
774 evsel->attr.sample_id_all = 0;
775
764 for (cpu = 0; cpu < cpus->nr; cpu++) { 776 for (cpu = 0; cpu < cpus->nr; cpu++) {
765 777
766 for (thread = 0; thread < threads->nr; thread++) { 778 for (thread = 0; thread < threads->nr; thread++) {
@@ -777,13 +789,26 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
777 group_fd, flags); 789 group_fd, flags);
778 if (FD(evsel, cpu, thread) < 0) { 790 if (FD(evsel, cpu, thread) < 0) {
779 err = -errno; 791 err = -errno;
780 goto out_close; 792 goto try_fallback;
781 } 793 }
782 } 794 }
783 } 795 }
784 796
785 return 0; 797 return 0;
786 798
799try_fallback:
800 if (err != -EINVAL || cpu > 0 || thread > 0)
801 goto out_close;
802
803 if (!perf_missing_features.exclude_guest &&
804 (evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
805 perf_missing_features.exclude_guest = true;
806 goto fallback_missing_features;
807 } else if (!perf_missing_features.sample_id_all) {
808 perf_missing_features.sample_id_all = true;
809 goto retry_sample_id;
810 }
811
787out_close: 812out_close:
788 do { 813 do {
789 while (--thread >= 0) { 814 while (--thread >= 0) {