lkml.org 
[lkml]   [2021]   [Jan]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 4/9] libperf: Add evsel mmap support
On Wed, Jan 13, 2021 at 08:06:00PM -0600, Rob Herring wrote:
> In order to support usersapce access, an event must be mmapped. While
> there's already mmap support for evlist, the usecase is a bit different
> than the self monitoring with userspace access. So let's add a new
> perf_evsel__mmap() function to mmap an evsel. This allows implementing
> userspace access as a fastpath for perf_evsel__read().
>
> The mmapped address is returned by perf_evsel__mmap_base() which
> primarily for users/tests to check if userspace access is enabled.
>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> v5:
> - Create an mmap for every underlying event opened. Due to this, we
> need a different way to get the mmap ptr, so perf_evsel__mmap_base()
> is introduced.
> v4:
> - Change perf_evsel__mmap size to pages instead of bytes
> v3:
> - New patch split out from user access patch
> ---
> tools/lib/perf/Documentation/libperf.txt | 2 +
> tools/lib/perf/evsel.c | 47 +++++++++++++++++++++++-
> tools/lib/perf/include/internal/evsel.h | 2 +
> tools/lib/perf/include/perf/evsel.h | 2 +
> tools/lib/perf/libperf.map | 2 +
> 5 files changed, 53 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
> index 0c74c30ed23a..a2c73df191ca 100644
> --- a/tools/lib/perf/Documentation/libperf.txt
> +++ b/tools/lib/perf/Documentation/libperf.txt
> @@ -136,6 +136,8 @@ SYNOPSIS
> struct perf_thread_map *threads);
> void perf_evsel__close(struct perf_evsel *evsel);
> void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu);
> + int perf_evsel__mmap(struct perf_evsel *evsel, int pages);
> + void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu, int thread);
> int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
> struct perf_counts_values *count);
> int perf_evsel__enable(struct perf_evsel *evsel);
> diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
> index 4dc06289f4c7..0b5bdf4badae 100644
> --- a/tools/lib/perf/evsel.c
> +++ b/tools/lib/perf/evsel.c
> @@ -11,10 +11,12 @@
> #include <stdlib.h>
> #include <internal/xyarray.h>
> #include <internal/cpumap.h>
> +#include <internal/mmap.h>
> #include <internal/threadmap.h>
> #include <internal/lib.h>
> #include <linux/string.h>
> #include <sys/ioctl.h>
> +#include <sys/mman.h>
>
> void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
> {
> @@ -37,11 +39,17 @@ void perf_evsel__delete(struct perf_evsel *evsel)
> free(evsel);
> }
>
> -#define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
> +struct evsel_fd {
> + int fd;
> + struct perf_mmap mmap;
> +};

nice shortcut ;-) but 'struct perf_mmap' is too big for that

I think it's better to add new 'evsel::mmap' xyarray to hold it,
add perf_evsel__alloc_mmap to allocate it and call it from
perf_evsel__mmap the same way as we callperf_evsel__alloc_fd
from perf_evsel__open

thanks,
jirka

\
 
 \ /
  Last update: 2021-01-23 23:45    [W:0.147 / U:1.732 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site