Commit 3fd35de1 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

libperf: Add group support to perf_evsel__open()

Add support to set group_fd in perf_evsel__open() and make it follow the
group setup.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Requested-by: default avatarShunsuke Nakamura <nakamura.shun@fujitsu.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210706151704.73662-7-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c47a5599
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/string.h> #include <linux/string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <asm/bug.h>
void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
int idx) int idx)
...@@ -76,6 +77,25 @@ sys_perf_event_open(struct perf_event_attr *attr, ...@@ -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); 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, int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
struct perf_thread_map *threads) struct perf_thread_map *threads)
{ {
...@@ -111,11 +131,13 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, ...@@ -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 (cpu = 0; cpu < cpus->nr; cpu++) {
for (thread = 0; thread < threads->nr; thread++) { 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, fd = sys_perf_event_open(&evsel->attr,
threads->map[thread].pid, threads->map[thread].pid,
cpus->map[cpu], -1, 0); cpus->map[cpu], group_fd, 0);
if (fd < 0) if (fd < 0)
return -errno; return -errno;
......
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