2019-10-07 19:53:09 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2019-10-07 19:53:12 +07:00
|
|
|
#include <sys/mman.h>
|
2019-10-07 19:53:09 +07:00
|
|
|
#include <internal/mmap.h>
|
2019-10-07 19:53:11 +07:00
|
|
|
#include <internal/lib.h>
|
2019-10-07 19:53:09 +07:00
|
|
|
|
|
|
|
void perf_mmap__init(struct perf_mmap *map, bool overwrite)
|
|
|
|
{
|
|
|
|
map->fd = -1;
|
|
|
|
map->overwrite = overwrite;
|
|
|
|
refcount_set(&map->refcnt, 0);
|
|
|
|
}
|
2019-10-07 19:53:11 +07:00
|
|
|
|
|
|
|
size_t perf_mmap__mmap_len(struct perf_mmap *map)
|
|
|
|
{
|
|
|
|
return map->mask + 1 + page_size;
|
|
|
|
}
|
2019-10-07 19:53:12 +07:00
|
|
|
|
|
|
|
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
|
|
|
|
int fd, int cpu)
|
|
|
|
{
|
|
|
|
map->prev = 0;
|
|
|
|
map->mask = mp->mask;
|
|
|
|
map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
|
|
|
|
MAP_SHARED, fd, 0);
|
|
|
|
if (map->base == MAP_FAILED) {
|
|
|
|
map->base = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
map->fd = fd;
|
|
|
|
map->cpu = cpu;
|
|
|
|
return 0;
|
|
|
|
}
|
2019-10-07 19:53:13 +07:00
|
|
|
|
|
|
|
void perf_mmap__get(struct perf_mmap *map)
|
|
|
|
{
|
|
|
|
refcount_inc(&map->refcnt);
|
|
|
|
}
|