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>
This commit is contained in:
Родитель
ce90e3856b
Коммит
594ac61ad3
|
@ -234,25 +234,6 @@ static int perf_record__open(struct perf_record *rec)
|
||||||
|
|
||||||
list_for_each_entry(pos, &evlist->entries, node) {
|
list_for_each_entry(pos, &evlist->entries, node) {
|
||||||
struct perf_event_attr *attr = &pos->attr;
|
struct perf_event_attr *attr = &pos->attr;
|
||||||
/*
|
|
||||||
* Check if parse_single_tracepoint_event has already asked for
|
|
||||||
* PERF_SAMPLE_TIME.
|
|
||||||
*
|
|
||||||
* XXX this is kludgy but short term fix for problems introduced by
|
|
||||||
* eac23d1c that broke 'perf script' by having different sample_types
|
|
||||||
* when using multiple tracepoint events when we use a perf binary
|
|
||||||
* that tries to use sample_id_all on an older kernel.
|
|
||||||
*
|
|
||||||
* We need to move counter creation to perf_session, support
|
|
||||||
* different sample_types, etc.
|
|
||||||
*/
|
|
||||||
bool time_needed = attr->sample_type & PERF_SAMPLE_TIME;
|
|
||||||
|
|
||||||
fallback_missing_features:
|
|
||||||
if (opts->exclude_guest_missing)
|
|
||||||
attr->exclude_guest = attr->exclude_host = 0;
|
|
||||||
retry_sample_id:
|
|
||||||
attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
|
|
||||||
try_again:
|
try_again:
|
||||||
if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) {
|
if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) {
|
||||||
int err = errno;
|
int err = errno;
|
||||||
|
@ -266,23 +247,6 @@ try_again:
|
||||||
" an out-of-range profile CPU?\n");
|
" an out-of-range profile CPU?\n");
|
||||||
rc = -err;
|
rc = -err;
|
||||||
goto out;
|
goto out;
|
||||||
} else if (err == EINVAL) {
|
|
||||||
if (!opts->exclude_guest_missing &&
|
|
||||||
(attr->exclude_guest || attr->exclude_host)) {
|
|
||||||
pr_debug("Old kernel, cannot exclude "
|
|
||||||
"guest or host samples.\n");
|
|
||||||
opts->exclude_guest_missing = true;
|
|
||||||
goto fallback_missing_features;
|
|
||||||
} else if (!opts->sample_id_all_missing) {
|
|
||||||
/*
|
|
||||||
* Old kernel, no attr->sample_id_type_all field
|
|
||||||
*/
|
|
||||||
opts->sample_id_all_missing = true;
|
|
||||||
if (!opts->sample_time && !opts->raw_samples && !time_needed)
|
|
||||||
perf_evsel__reset_sample_bit(pos, TIME);
|
|
||||||
|
|
||||||
goto retry_sample_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -132,8 +132,6 @@ static struct stats walltime_nsecs_stats;
|
||||||
static int create_perf_stat_counter(struct perf_evsel *evsel)
|
static int create_perf_stat_counter(struct perf_evsel *evsel)
|
||||||
{
|
{
|
||||||
struct perf_event_attr *attr = &evsel->attr;
|
struct perf_event_attr *attr = &evsel->attr;
|
||||||
bool exclude_guest_missing = false;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (scale)
|
if (scale)
|
||||||
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
|
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
|
||||||
|
@ -141,16 +139,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
|
||||||
|
|
||||||
attr->inherit = !no_inherit;
|
attr->inherit = !no_inherit;
|
||||||
|
|
||||||
retry:
|
if (perf_target__has_cpu(&target))
|
||||||
if (exclude_guest_missing)
|
return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
|
||||||
evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
|
|
||||||
|
|
||||||
if (perf_target__has_cpu(&target)) {
|
|
||||||
ret = perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
|
|
||||||
if (ret)
|
|
||||||
goto check_ret;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!perf_target__has_task(&target) &&
|
if (!perf_target__has_task(&target) &&
|
||||||
perf_evsel__is_group_leader(evsel)) {
|
perf_evsel__is_group_leader(evsel)) {
|
||||||
|
@ -158,21 +148,7 @@ retry:
|
||||||
attr->enable_on_exec = 1;
|
attr->enable_on_exec = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = perf_evsel__open_per_thread(evsel, evsel_list->threads);
|
return perf_evsel__open_per_thread(evsel, evsel_list->threads);
|
||||||
if (!ret)
|
|
||||||
return 0;
|
|
||||||
/* fall through */
|
|
||||||
check_ret:
|
|
||||||
if (ret && errno == EINVAL) {
|
|
||||||
if (!exclude_guest_missing &&
|
|
||||||
(evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
|
|
||||||
pr_debug("Old kernel, cannot exclude "
|
|
||||||
"guest or host samples.\n");
|
|
||||||
exclude_guest_missing = true;
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -900,12 +900,6 @@ static void perf_top__start_counters(struct perf_top *top)
|
||||||
|
|
||||||
list_for_each_entry(counter, &evlist->entries, node) {
|
list_for_each_entry(counter, &evlist->entries, node) {
|
||||||
struct perf_event_attr *attr = &counter->attr;
|
struct perf_event_attr *attr = &counter->attr;
|
||||||
|
|
||||||
fallback_missing_features:
|
|
||||||
if (top->exclude_guest_missing)
|
|
||||||
attr->exclude_guest = attr->exclude_host = 0;
|
|
||||||
retry_sample_id:
|
|
||||||
attr->sample_id_all = top->sample_id_all_missing ? 0 : 1;
|
|
||||||
try_again:
|
try_again:
|
||||||
if (perf_evsel__open(counter, top->evlist->cpus,
|
if (perf_evsel__open(counter, top->evlist->cpus,
|
||||||
top->evlist->threads) < 0) {
|
top->evlist->threads) < 0) {
|
||||||
|
@ -914,20 +908,6 @@ try_again:
|
||||||
if (err == EPERM || err == EACCES) {
|
if (err == EPERM || err == EACCES) {
|
||||||
ui__error_paranoid();
|
ui__error_paranoid();
|
||||||
goto out_err;
|
goto out_err;
|
||||||
} else if (err == EINVAL) {
|
|
||||||
if (!top->exclude_guest_missing &&
|
|
||||||
(attr->exclude_guest || attr->exclude_host)) {
|
|
||||||
pr_debug("Old kernel, cannot exclude "
|
|
||||||
"guest or host samples.\n");
|
|
||||||
top->exclude_guest_missing = true;
|
|
||||||
goto fallback_missing_features;
|
|
||||||
} else if (!top->sample_id_all_missing) {
|
|
||||||
/*
|
|
||||||
* Old kernel, no attr->sample_id_type_all field
|
|
||||||
*/
|
|
||||||
top->sample_id_all_missing = true;
|
|
||||||
goto retry_sample_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* If it's cycles then fall back to hrtimer
|
* If it's cycles then fall back to hrtimer
|
||||||
|
|
|
@ -237,8 +237,6 @@ struct perf_record_opts {
|
||||||
bool raw_samples;
|
bool raw_samples;
|
||||||
bool sample_address;
|
bool sample_address;
|
||||||
bool sample_time;
|
bool sample_time;
|
||||||
bool sample_id_all_missing;
|
|
||||||
bool exclude_guest_missing;
|
|
||||||
bool period;
|
bool period;
|
||||||
unsigned int freq;
|
unsigned int freq;
|
||||||
unsigned int mmap_pages;
|
unsigned int mmap_pages;
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
#include <linux/perf_event.h>
|
#include <linux/perf_event.h>
|
||||||
#include "perf_regs.h"
|
#include "perf_regs.h"
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
bool sample_id_all;
|
||||||
|
bool exclude_guest;
|
||||||
|
} perf_missing_features;
|
||||||
|
|
||||||
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
|
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
|
||||||
|
|
||||||
static int __perf_evsel__sample_size(u64 sample_type)
|
static int __perf_evsel__sample_size(u64 sample_type)
|
||||||
|
@ -463,7 +468,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
|
||||||
struct perf_event_attr *attr = &evsel->attr;
|
struct perf_event_attr *attr = &evsel->attr;
|
||||||
int track = !evsel->idx; /* only the first counter needs these */
|
int track = !evsel->idx; /* only the first counter needs these */
|
||||||
|
|
||||||
attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
|
attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
|
||||||
attr->inherit = !opts->no_inherit;
|
attr->inherit = !opts->no_inherit;
|
||||||
|
|
||||||
perf_evsel__set_sample_bit(evsel, IP);
|
perf_evsel__set_sample_bit(evsel, IP);
|
||||||
|
@ -513,7 +518,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
|
||||||
if (opts->period)
|
if (opts->period)
|
||||||
perf_evsel__set_sample_bit(evsel, PERIOD);
|
perf_evsel__set_sample_bit(evsel, PERIOD);
|
||||||
|
|
||||||
if (!opts->sample_id_all_missing &&
|
if (!perf_missing_features.sample_id_all &&
|
||||||
(opts->sample_time || !opts->no_inherit ||
|
(opts->sample_time || !opts->no_inherit ||
|
||||||
perf_target__has_cpu(&opts->target)))
|
perf_target__has_cpu(&opts->target)))
|
||||||
perf_evsel__set_sample_bit(evsel, TIME);
|
perf_evsel__set_sample_bit(evsel, TIME);
|
||||||
|
@ -761,6 +766,13 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
|
||||||
pid = evsel->cgrp->fd;
|
pid = evsel->cgrp->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fallback_missing_features:
|
||||||
|
if (perf_missing_features.exclude_guest)
|
||||||
|
evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
|
||||||
|
retry_sample_id:
|
||||||
|
if (perf_missing_features.sample_id_all)
|
||||||
|
evsel->attr.sample_id_all = 0;
|
||||||
|
|
||||||
for (cpu = 0; cpu < cpus->nr; cpu++) {
|
for (cpu = 0; cpu < cpus->nr; cpu++) {
|
||||||
|
|
||||||
for (thread = 0; thread < threads->nr; thread++) {
|
for (thread = 0; thread < threads->nr; thread++) {
|
||||||
|
@ -777,13 +789,26 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
|
||||||
group_fd, flags);
|
group_fd, flags);
|
||||||
if (FD(evsel, cpu, thread) < 0) {
|
if (FD(evsel, cpu, thread) < 0) {
|
||||||
err = -errno;
|
err = -errno;
|
||||||
goto out_close;
|
goto try_fallback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
try_fallback:
|
||||||
|
if (err != -EINVAL || cpu > 0 || thread > 0)
|
||||||
|
goto out_close;
|
||||||
|
|
||||||
|
if (!perf_missing_features.exclude_guest &&
|
||||||
|
(evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
|
||||||
|
perf_missing_features.exclude_guest = true;
|
||||||
|
goto fallback_missing_features;
|
||||||
|
} else if (!perf_missing_features.sample_id_all) {
|
||||||
|
perf_missing_features.sample_id_all = true;
|
||||||
|
goto retry_sample_id;
|
||||||
|
}
|
||||||
|
|
||||||
out_close:
|
out_close:
|
||||||
do {
|
do {
|
||||||
while (--thread >= 0) {
|
while (--thread >= 0) {
|
||||||
|
|
|
@ -29,8 +29,6 @@ struct perf_top {
|
||||||
bool sort_has_symbols;
|
bool sort_has_symbols;
|
||||||
bool kptr_restrict_warned;
|
bool kptr_restrict_warned;
|
||||||
bool vmlinux_warned;
|
bool vmlinux_warned;
|
||||||
bool sample_id_all_missing;
|
|
||||||
bool exclude_guest_missing;
|
|
||||||
bool dump_symtab;
|
bool dump_symtab;
|
||||||
struct hist_entry *sym_filter_entry;
|
struct hist_entry *sym_filter_entry;
|
||||||
struct perf_evsel *sym_evsel;
|
struct perf_evsel *sym_evsel;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче