Re: [PATCH v2 5/9] libperf: Add support for user space counter access

From: Rob Herring
Date: Wed Sep 02 2020 - 13:01:33 EST


On Mon, Aug 31, 2020 at 3:11 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
>
> On Fri, Aug 28, 2020 at 02:56:10PM -0600, Rob Herring wrote:
>
> SNIP
>
> >
> > +void *perf_evsel__mmap(struct perf_evsel *evsel)
> > +{
> > + int ret;
> > + struct perf_mmap *map;
> > + struct perf_mmap_param mp = {
> > + .mask = -1,
> > + .prot = PROT_READ | PROT_WRITE,
> > + };
> > +
> > + if (FD(evsel, 0, 0) < 0)
> > + return NULL;
> > +
> > + map = zalloc(sizeof(*map));
> > + if (!map)
> > + return NULL;
> > +
> > + perf_mmap__init(map, NULL, false, NULL);
> > +
> > + ret = perf_mmap__mmap(map, &mp, FD(evsel, 0, 0), 0);
> > + if (ret) {
> > + free(map);
> > + return NULL;
> > + }
> > +
> > + evsel->mmap = map;
> > + return map->base;
> > +}
>
> so this only maps first page, I think we should use different
> name and keep perf_evsel__mmap for some generic map with size
>
> perf_evsel__mmap_user
> perf_evsel__mmap_zero
> ...?
>
> not sure.. or we could add size argument

Adding a size arg is simple enough to do and saves the hard naming problem. :)

Rob