From: Shunsuke <nakamura.shun@fujitsu.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@redhat.com, namhyung@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Subject: [RFC PATCH 2/7] libperf: Add perf_evsel__set_close_on_exec() function
Date: Fri, 25 Feb 2022 19:31:09 +0900 [thread overview]
Message-ID: <20220225103114.144239-3-nakamura.shun@fujitsu.com> (raw)
In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com>
From: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Move evsel::open_flags to perf_evsel::open_flags and add a function to
set PERF_FLAG_FD_CLOEXEC.
Signed-off-by: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
---
tools/lib/perf/Documentation/libperf.txt | 1 +
tools/lib/perf/evsel.c | 15 ++++++++++++++-
tools/lib/perf/include/internal/evsel.h | 2 ++
tools/lib/perf/include/perf/evsel.h | 1 +
tools/lib/perf/libperf.map | 1 +
tools/perf/util/evsel.c | 16 +++++++++-------
tools/perf/util/evsel.h | 1 -
7 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
index 32c5051c24eb..96a451cd34eb 100644
--- a/tools/lib/perf/Documentation/libperf.txt
+++ b/tools/lib/perf/Documentation/libperf.txt
@@ -149,6 +149,7 @@ SYNOPSIS
struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
+ int perf_evsel__set_close_on_exec(struct perf_evsel *evsel);
--
*API to handle maps (perf ring buffers):*
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index 210ea7c06ce8..d22b1468a1ad 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -26,6 +26,7 @@ void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
evsel->attr = *attr;
evsel->idx = idx;
evsel->leader = evsel;
+ evsel->open_flags = 0;
}
struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
@@ -158,7 +159,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
fd = sys_perf_event_open(&evsel->attr,
threads->map[thread].pid,
- cpu, group_fd, 0);
+ cpu, group_fd, evsel->open_flags);
if (fd < 0)
return -errno;
@@ -454,3 +455,15 @@ void perf_counts_values__scale(struct perf_counts_values *count,
if (pscaled)
*pscaled = scaled;
}
+
+int perf_evsel__set_close_on_exec(struct perf_evsel *evsel)
+{
+ int err = 0;
+
+ if (evsel)
+ evsel->open_flags |= PERF_FLAG_FD_CLOEXEC;
+ else
+ err = -1;
+
+ return err;
+}
diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h
index cfc9ebd7968e..37a99cf261b3 100644
--- a/tools/lib/perf/include/internal/evsel.h
+++ b/tools/lib/perf/include/internal/evsel.h
@@ -51,6 +51,8 @@ struct perf_evsel {
int nr_members;
bool system_wide;
int idx;
+
+ unsigned long open_flags;
};
void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h
index 2a9516b42d15..23b0334a4c57 100644
--- a/tools/lib/perf/include/perf/evsel.h
+++ b/tools/lib/perf/include/perf/evsel.h
@@ -43,5 +43,6 @@ LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel
LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
LIBPERF_API void perf_counts_values__scale(struct perf_counts_values *count,
bool scale, __s8 *pscaled);
+LIBPERF_API int perf_evsel__set_close_on_exec(struct perf_evsel *evsel);
#endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map
index 93696affda2e..0f8d13f9009b 100644
--- a/tools/lib/perf/libperf.map
+++ b/tools/lib/perf/libperf.map
@@ -52,6 +52,7 @@ LIBPERF_0.0.1 {
perf_mmap__read_done;
perf_mmap__read_event;
perf_counts_values__scale;
+ perf_evsel__set_close_on_exec;
local:
*;
};
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 22d3267ce294..52c34552ee76 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1794,9 +1794,9 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) < 0)
return -ENOMEM;
- evsel->open_flags = PERF_FLAG_FD_CLOEXEC;
+ evsel->core.open_flags = PERF_FLAG_FD_CLOEXEC;
if (evsel->cgrp)
- evsel->open_flags |= PERF_FLAG_PID_CGROUP;
+ evsel->core.open_flags |= PERF_FLAG_PID_CGROUP;
return 0;
}
@@ -1814,7 +1814,7 @@ static void evsel__disable_missing_features(struct evsel *evsel)
evsel->core.attr.clockid = 0;
}
if (perf_missing_features.cloexec)
- evsel->open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
+ evsel->core.open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
if (perf_missing_features.mmap2)
evsel->core.attr.mmap2 = 0;
if (evsel->pmu && evsel->pmu->missing_features.exclude_guest)
@@ -1902,7 +1902,8 @@ bool evsel__detect_missing_features(struct evsel *evsel)
perf_missing_features.clockid = true;
pr_debug2_peo("switching off use_clockid\n");
return true;
- } else if (!perf_missing_features.cloexec && (evsel->open_flags & PERF_FLAG_FD_CLOEXEC)) {
+ } else if (!perf_missing_features.cloexec &&
+ (evsel->core.open_flags & PERF_FLAG_FD_CLOEXEC)) {
perf_missing_features.cloexec = true;
pr_debug2_peo("switching off cloexec flag\n");
return true;
@@ -2029,11 +2030,12 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
test_attr__ready();
pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx",
- pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd, evsel->open_flags);
+ pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd,
+ evsel->core.open_flags);
fd = sys_perf_event_open(&evsel->core.attr, pid,
perf_cpu_map__cpu(cpus, idx).cpu,
- group_fd, evsel->open_flags);
+ group_fd, evsel->core.open_flags);
FD(evsel, idx, thread) = fd;
@@ -2050,7 +2052,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
if (unlikely(test_attr__enabled)) {
test_attr__open(&evsel->core.attr, pid,
perf_cpu_map__cpu(cpus, idx),
- fd, group_fd, evsel->open_flags);
+ fd, group_fd, evsel->core.open_flags);
}
pr_debug2_peo(" = %d\n", fd);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 041b42d33bf5..8a545954eec7 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -152,7 +152,6 @@ struct evsel {
struct bperf_leader_bpf *leader_skel;
struct bperf_follower_bpf *follower_skel;
};
- unsigned long open_flags;
int precise_ip_original;
/* for missing_features */
--
2.31.1
next prev parent reply other threads:[~2022-02-25 10:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 10:31 [RFC PATCH 0/7] libperf: Add overflow detection of sampling events Shunsuke
2022-02-25 10:31 ` [RFC PATCH 1/7] libperf tests: Fix typo in the error message "evsel" -> "evlist" Shunsuke
2022-02-25 10:31 ` Shunsuke [this message]
2022-02-25 10:31 ` [RFC PATCH 3/7] libperf: Add perf_evsel__refresh()/period() functions Shunsuke
2022-02-25 10:31 ` [RFC PATCH 4/7] libperf: Add perf_evsel__set_signal() functions Shunsuke
2022-02-25 10:31 ` [RFC PATCH 5/7] libperf: Add perf_evsel__check_fd() functions Shunsuke
2022-02-25 10:31 ` [RFC PATCH 6/7] libperf test: Add test_stat_overflow() Shunsuke
2022-02-25 10:31 ` [RFC PATCH 7/7] libperf test: Add test_detect_overflow_event() Shunsuke
2022-02-26 17:23 ` [RFC PATCH 0/7] libperf: Add overflow detection of sampling events Jiri Olsa
2022-03-01 8:32 ` nakamura.shun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220225103114.144239-3-nakamura.shun@fujitsu.com \
--to=nakamura.shun@fujitsu.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®