From: Jiri Olsa <jolsa@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Michael Petlan <mpetlan@redhat.com>,
Ian Rogers <irogers@google.com>,
nakamura.shun@fujitsu.com, linux-perf-users@vger.kernel.org
Subject: [PATCH 6/7] libperF: Add group support to perf_evsel__open
Date: Tue, 6 Jul 2021 17:17:03 +0200 [thread overview]
Message-ID: <20210706151704.73662-7-jolsa@kernel.org> (raw)
In-Reply-To: <20210706151704.73662-1-jolsa@kernel.org>
Adding support to set group_fd in perf_evsel__open
call and make it to follow the group setup.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/lib/perf/evsel.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index 3e6638d27c45..9ebf7122d476 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -17,6 +17,7 @@
#include <linux/string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
+#include <asm/bug.h>
void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
int idx)
@@ -76,6 +77,25 @@ sys_perf_event_open(struct perf_event_attr *attr,
return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
}
+static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
+{
+ struct perf_evsel *leader = evsel->leader;
+ int fd;
+
+ if (evsel == leader)
+ return -1;
+
+ /*
+ * Leader must be already processed/open,
+ * if not it's a bug.
+ */
+ BUG_ON(!leader->fd);
+
+ fd = FD(leader, cpu, thread);
+ BUG_ON(fd == -1);
+ return fd;
+}
+
int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
struct perf_thread_map *threads)
{
@@ -111,11 +131,13 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
for (cpu = 0; cpu < cpus->nr; cpu++) {
for (thread = 0; thread < threads->nr; thread++) {
- int fd;
+ int fd, group_fd;
+
+ group_fd = get_group_fd(evsel, cpu, thread);
fd = sys_perf_event_open(&evsel->attr,
threads->map[thread].pid,
- cpus->map[cpu], -1, 0);
+ cpus->map[cpu], group_fd, 0);
if (fd < 0)
return -errno;
--
2.31.1
next prev parent reply other threads:[~2021-07-06 15:18 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-06 15:16 [RFCv2 0/7] libperf: Add leader/group info to perf_evsel Jiri Olsa
2021-07-06 15:16 ` [PATCH 1/7] libperf: Change tests to single static and shared binaries Jiri Olsa
2021-07-06 15:16 ` [PATCH 2/7] libperf: Move idx to perf_evsel::idx Jiri Olsa
2021-07-07 14:45 ` Arnaldo Carvalho de Melo
2021-07-07 18:17 ` Jiri Olsa
2021-07-07 18:36 ` Arnaldo Carvalho de Melo
2021-07-07 14:49 ` Arnaldo Carvalho de Melo
2021-07-07 17:48 ` Arnaldo Carvalho de Melo
2021-07-07 18:18 ` Jiri Olsa
2021-07-07 18:17 ` Jiri Olsa
2021-07-06 15:17 ` [PATCH 3/7] libperf: Move leader to perf_evsel::leader Jiri Olsa
2021-07-07 14:53 ` Arnaldo Carvalho de Melo
2021-07-07 18:14 ` Jiri Olsa
2021-07-07 18:34 ` Arnaldo Carvalho de Melo
2021-07-06 15:17 ` [PATCH 4/7] libperf: Move nr_groups to evlist::nr_groups Jiri Olsa
2021-07-06 15:17 ` [PATCH 5/7] libperf: Add perf_evlist__set_leader function Jiri Olsa
2021-07-06 15:17 ` Jiri Olsa [this message]
2021-07-07 17:43 ` [PATCH 6/7] libperF: Add group support to perf_evsel__open Arnaldo Carvalho de Melo
2021-07-07 18:15 ` Jiri Olsa
2021-07-09 17:57 ` [PATCH] libperf: Remove BUG_ON() from library code in get_group_fd(). was " Arnaldo Carvalho de Melo
2021-07-06 15:17 ` [PATCH 7/7] libperf: Add tests for perf_evlist__set_leader function Jiri Olsa
2021-07-09 17:59 ` Arnaldo Carvalho de Melo
2021-07-07 14:47 ` [RFCv2 0/7] libperf: Add leader/group info to perf_evsel Arnaldo Carvalho de Melo
2021-07-07 18:20 ` Jiri Olsa
2021-07-07 18:37 ` Arnaldo Carvalho de Melo
2021-07-09 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=20210706151704.73662-7-jolsa@kernel.org \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=mpetlan@redhat.com \
--cc=nakamura.shun@fujitsu.com \
--cc=namhyung@kernel.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;
as well as URLs for NNTP newsgroup(s).