Commit 46ec69ad authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

perf tools: Fix probing the kernel API with cpu-wide events

Fall back to probing with the current pid if cpu-wide probing fails.
This primarily affects the setting of comm_exec flag when the user is
un-privileged and /proc/sys/kernel/perf_event_paranoid > 0.

The change to comm_exec can be observed by using -vv with perf record
and a kernel that supports comm_exec.
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
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/r/1407855871-15024-4-git-send-email-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c6fa3565
...@@ -14,6 +14,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str) ...@@ -14,6 +14,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
struct perf_evsel *evsel; struct perf_evsel *evsel;
unsigned long flags = perf_event_open_cloexec_flag(); unsigned long flags = perf_event_open_cloexec_flag();
int err = -EAGAIN, fd; int err = -EAGAIN, fd;
static pid_t pid = -1;
evlist = perf_evlist__new(); evlist = perf_evlist__new();
if (!evlist) if (!evlist)
...@@ -24,14 +25,22 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str) ...@@ -24,14 +25,22 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
evsel = perf_evlist__first(evlist); evsel = perf_evlist__first(evlist);
fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, flags); while (1) {
if (fd < 0) fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1, flags);
goto out_delete; if (fd < 0) {
if (pid == -1 && errno == EACCES) {
pid = 0;
continue;
}
goto out_delete;
}
break;
}
close(fd); close(fd);
fn(evsel); fn(evsel);
fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, flags); fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1, flags);
if (fd < 0) { if (fd < 0) {
if (errno == EINVAL) if (errno == EINVAL)
err = -EINVAL; err = -EINVAL;
...@@ -201,6 +210,7 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str) ...@@ -201,6 +210,7 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)
struct perf_evsel *evsel; struct perf_evsel *evsel;
int err, fd, cpu; int err, fd, cpu;
bool ret = false; bool ret = false;
pid_t pid = -1;
temp_evlist = perf_evlist__new(); temp_evlist = perf_evlist__new();
if (!temp_evlist) if (!temp_evlist)
...@@ -221,12 +231,20 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str) ...@@ -221,12 +231,20 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)
cpu = evlist->cpus->map[0]; cpu = evlist->cpus->map[0];
} }
fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, while (1) {
perf_event_open_cloexec_flag()); fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1,
if (fd >= 0) { perf_event_open_cloexec_flag());
close(fd); if (fd < 0) {
ret = true; if (pid == -1 && errno == EACCES) {
pid = 0;
continue;
}
goto out_delete;
}
break;
} }
close(fd);
ret = true;
out_delete: out_delete:
perf_evlist__delete(temp_evlist); perf_evlist__delete(temp_evlist);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment