summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRiccardo Mancini <rickyman7@gmail.com>2021-08-21 11:19:22 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2021-08-31 16:29:12 -0300
commit46def08f5db0d84275bd0a3ba4a279a2197aa3a6 (patch)
tree3042bbe4bb3d0ff5c4e41e49d0c9ca4c69a138b0 /tools
parentd45ce03434fd0f9177a0d3a7237fce4263eed24b (diff)
perf evsel: Save open flags in evsel in prepare_open()
This patch caches the flags used in perf_event_open() inside evsel, so that they can be set in __evsel__prepare_open() (this will be useful in patches in the workqueue series, when the fallback mechanisms will be handled outside the open itself). This also optimizes the code, by not having to recompute them everytime. Since flags are now saved in evsel, the flags argument in perf_event_open() is removed. Signed-off-by: Riccardo Mancini <rickyman7@gmail.com> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/d9f63159098e56fa518eecf25171d72e6f74df37.1629490974.git.rickyman7@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/evsel.c24
-rw-r--r--tools/perf/util/evsel.h1
2 files changed, 13 insertions, 12 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ddf324e2e17a..509a2970a94b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1710,17 +1710,16 @@ static void display_attr(struct perf_event_attr *attr)
}
static int perf_event_open(struct evsel *evsel,
- pid_t pid, int cpu, int group_fd,
- unsigned long flags)
+ pid_t pid, int cpu, int group_fd)
{
int precise_ip = evsel->core.attr.precise_ip;
int fd;
while (1) {
pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx",
- pid, cpu, group_fd, flags);
+ pid, cpu, group_fd, evsel->open_flags);
- fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, group_fd, flags);
+ fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, group_fd, evsel->open_flags);
if (fd >= 0)
break;
@@ -1788,6 +1787,10 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
perf_evsel__alloc_fd(&evsel->core, cpus->nr, nthreads) < 0)
return -ENOMEM;
+ evsel->open_flags = PERF_FLAG_FD_CLOEXEC;
+ if (evsel->cgrp)
+ evsel->open_flags |= PERF_FLAG_PID_CGROUP;
+
return 0;
}
@@ -1796,7 +1799,6 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
int start_cpu, int end_cpu)
{
int cpu, thread, nthreads;
- unsigned long flags = PERF_FLAG_FD_CLOEXEC;
int pid = -1, err, old_errno;
enum { NO_CHANGE, SET_TO_MAX, INCREASED_MAX } set_rlimit = NO_CHANGE;
@@ -1815,10 +1817,8 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
else
nthreads = threads->nr;
- if (evsel->cgrp) {
- flags |= PERF_FLAG_PID_CGROUP;
+ if (evsel->cgrp)
pid = evsel->cgrp->fd;
- }
fallback_missing_features:
if (perf_missing_features.weight_struct) {
@@ -1832,7 +1832,7 @@ fallback_missing_features:
evsel->core.attr.clockid = 0;
}
if (perf_missing_features.cloexec)
- flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
+ evsel->open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
if (perf_missing_features.mmap2)
evsel->core.attr.mmap2 = 0;
if (perf_missing_features.exclude_guest)
@@ -1866,7 +1866,7 @@ retry_open:
test_attr__ready();
fd = perf_event_open(evsel, pid, cpus->map[cpu],
- group_fd, flags);
+ group_fd);
FD(evsel, cpu, thread) = fd;
@@ -1874,7 +1874,7 @@ retry_open:
if (unlikely(test_attr__enabled)) {
test_attr__open(&evsel->core.attr, pid, cpus->map[cpu],
- fd, group_fd, flags);
+ fd, group_fd, evsel->open_flags);
}
if (fd < 0) {
@@ -2012,7 +2012,7 @@ try_fallback:
perf_missing_features.clockid = true;
pr_debug2_peo("switching off use_clockid\n");
goto fallback_missing_features;
- } else if (!perf_missing_features.cloexec && (flags & PERF_FLAG_FD_CLOEXEC)) {
+ } else if (!perf_missing_features.cloexec && (evsel->open_flags & PERF_FLAG_FD_CLOEXEC)) {
perf_missing_features.cloexec = true;
pr_debug2_peo("switching off cloexec flag\n");
goto fallback_missing_features;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 80383096d51c..76efcfa3e14d 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -150,6 +150,7 @@ struct evsel {
struct bperf_leader_bpf *leader_skel;
struct bperf_follower_bpf *follower_skel;
};
+ unsigned long open_flags;
};
struct perf_missing_features {