mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Move perf_mmap__unmap() from tools/perf to libperf, to internal header internal/mmap.h. It will be used in the following patches. And rename the existing perf's function to mmap__munmap(). Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.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/20191007125344.14268-7-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
48 lines
957 B
C
48 lines
957 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <sys/mman.h>
|
|
#include <internal/mmap.h>
|
|
#include <internal/lib.h>
|
|
|
|
void perf_mmap__init(struct perf_mmap *map, bool overwrite)
|
|
{
|
|
map->fd = -1;
|
|
map->overwrite = overwrite;
|
|
refcount_set(&map->refcnt, 0);
|
|
}
|
|
|
|
size_t perf_mmap__mmap_len(struct perf_mmap *map)
|
|
{
|
|
return map->mask + 1 + page_size;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void perf_mmap__munmap(struct perf_mmap *map)
|
|
{
|
|
if (map && map->base != NULL) {
|
|
munmap(map->base, perf_mmap__mmap_len(map));
|
|
map->base = NULL;
|
|
map->fd = -1;
|
|
refcount_set(&map->refcnt, 0);
|
|
}
|
|
}
|
|
|
|
void perf_mmap__get(struct perf_mmap *map)
|
|
{
|
|
refcount_inc(&map->refcnt);
|
|
}
|