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

libperf: Adopt perf_mmap__mmap_len() function from tools/perf

Move perf_mmap__mmap_len() from tools/perf wto libperf, it will be used
in the following patches. And rename the existing perf's function to
mmap__mmap_len().
Signed-off-by: default avatarJiri 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-4-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e440979f
...@@ -276,7 +276,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size ...@@ -276,7 +276,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size
if (record__comp_enabled(aio->rec)) { if (record__comp_enabled(aio->rec)) {
size = zstd_compress(aio->rec->session, aio->data + aio->size, size = zstd_compress(aio->rec->session, aio->data + aio->size,
perf_mmap__mmap_len(map) - aio->size, mmap__mmap_len(map) - aio->size,
buf, size); buf, size);
} else { } else {
memcpy(aio->data + aio->size, buf, size); memcpy(aio->data + aio->size, buf, size);
...@@ -488,7 +488,7 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size) ...@@ -488,7 +488,7 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size)
struct record *rec = to; struct record *rec = to;
if (record__comp_enabled(rec)) { if (record__comp_enabled(rec)) {
size = zstd_compress(rec->session, map->data, perf_mmap__mmap_len(map), bf, size); size = zstd_compress(rec->session, map->data, mmap__mmap_len(map), bf, size);
bf = map->data; bf = map->data;
} }
......
...@@ -34,6 +34,8 @@ struct perf_mmap_param { ...@@ -34,6 +34,8 @@ struct perf_mmap_param {
int mask; int mask;
}; };
size_t perf_mmap__mmap_len(struct perf_mmap *map);
void perf_mmap__init(struct perf_mmap *map, bool overwrite); void perf_mmap__init(struct perf_mmap *map, bool overwrite);
#endif /* __LIBPERF_INTERNAL_MMAP_H */ #endif /* __LIBPERF_INTERNAL_MMAP_H */
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <internal/mmap.h> #include <internal/mmap.h>
#include <internal/lib.h>
void perf_mmap__init(struct perf_mmap *map, bool overwrite) void perf_mmap__init(struct perf_mmap *map, bool overwrite)
{ {
...@@ -7,3 +8,8 @@ void perf_mmap__init(struct perf_mmap *map, bool overwrite) ...@@ -7,3 +8,8 @@ void perf_mmap__init(struct perf_mmap *map, bool overwrite)
map->overwrite = overwrite; map->overwrite = overwrite;
refcount_set(&map->refcnt, 0); refcount_set(&map->refcnt, 0);
} }
size_t perf_mmap__mmap_len(struct perf_mmap *map)
{
return map->mask + 1 + page_size;
}
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
#include "../perf.h" #include "../perf.h"
#include <internal/lib.h> /* page_size */ #include <internal/lib.h> /* page_size */
size_t perf_mmap__mmap_len(struct mmap *map) size_t mmap__mmap_len(struct mmap *map)
{ {
return map->core.mask + 1 + page_size; return perf_mmap__mmap_len(&map->core);
} }
/* When check_messup is true, 'end' must points to a good entry */ /* When check_messup is true, 'end' must points to a good entry */
...@@ -170,7 +170,7 @@ static int perf_mmap__aio_enabled(struct mmap *map) ...@@ -170,7 +170,7 @@ static int perf_mmap__aio_enabled(struct mmap *map)
#ifdef HAVE_LIBNUMA_SUPPORT #ifdef HAVE_LIBNUMA_SUPPORT
static int perf_mmap__aio_alloc(struct mmap *map, int idx) static int perf_mmap__aio_alloc(struct mmap *map, int idx)
{ {
map->aio.data[idx] = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE, map->aio.data[idx] = mmap(NULL, mmap__mmap_len(map), PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (map->aio.data[idx] == MAP_FAILED) { if (map->aio.data[idx] == MAP_FAILED) {
map->aio.data[idx] = NULL; map->aio.data[idx] = NULL;
...@@ -183,7 +183,7 @@ static int perf_mmap__aio_alloc(struct mmap *map, int idx) ...@@ -183,7 +183,7 @@ static int perf_mmap__aio_alloc(struct mmap *map, int idx)
static void perf_mmap__aio_free(struct mmap *map, int idx) static void perf_mmap__aio_free(struct mmap *map, int idx)
{ {
if (map->aio.data[idx]) { if (map->aio.data[idx]) {
munmap(map->aio.data[idx], perf_mmap__mmap_len(map)); munmap(map->aio.data[idx], mmap__mmap_len(map));
map->aio.data[idx] = NULL; map->aio.data[idx] = NULL;
} }
} }
...@@ -196,7 +196,7 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity) ...@@ -196,7 +196,7 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity)
if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) { if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) {
data = map->aio.data[idx]; data = map->aio.data[idx];
mmap_len = perf_mmap__mmap_len(map); mmap_len = mmap__mmap_len(map);
node_mask = 1UL << cpu__get_node(cpu); node_mask = 1UL << cpu__get_node(cpu);
if (mbind(data, mmap_len, MPOL_BIND, &node_mask, 1, 0)) { if (mbind(data, mmap_len, MPOL_BIND, &node_mask, 1, 0)) {
pr_err("Failed to bind [%p-%p] AIO buffer to node %d: error %m\n", pr_err("Failed to bind [%p-%p] AIO buffer to node %d: error %m\n",
...@@ -210,7 +210,7 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity) ...@@ -210,7 +210,7 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity)
#else /* !HAVE_LIBNUMA_SUPPORT */ #else /* !HAVE_LIBNUMA_SUPPORT */
static int perf_mmap__aio_alloc(struct mmap *map, int idx) static int perf_mmap__aio_alloc(struct mmap *map, int idx)
{ {
map->aio.data[idx] = malloc(perf_mmap__mmap_len(map)); map->aio.data[idx] = malloc(mmap__mmap_len(map));
if (map->aio.data[idx] == NULL) if (map->aio.data[idx] == NULL)
return -1; return -1;
...@@ -315,11 +315,11 @@ void perf_mmap__munmap(struct mmap *map) ...@@ -315,11 +315,11 @@ void perf_mmap__munmap(struct mmap *map)
{ {
perf_mmap__aio_munmap(map); perf_mmap__aio_munmap(map);
if (map->data != NULL) { if (map->data != NULL) {
munmap(map->data, perf_mmap__mmap_len(map)); munmap(map->data, mmap__mmap_len(map));
map->data = NULL; map->data = NULL;
} }
if (map->core.base != NULL) { if (map->core.base != NULL) {
munmap(map->core.base, perf_mmap__mmap_len(map)); munmap(map->core.base, mmap__mmap_len(map));
map->core.base = NULL; map->core.base = NULL;
map->core.fd = -1; map->core.fd = -1;
refcount_set(&map->core.refcnt, 0); refcount_set(&map->core.refcnt, 0);
...@@ -371,7 +371,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) ...@@ -371,7 +371,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
refcount_set(&map->core.refcnt, 2); refcount_set(&map->core.refcnt, 2);
map->core.prev = 0; map->core.prev = 0;
map->core.mask = mp->core.mask; map->core.mask = mp->core.mask;
map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->core.prot, map->core.base = mmap(NULL, mmap__mmap_len(map), mp->core.prot,
MAP_SHARED, fd, 0); MAP_SHARED, fd, 0);
if (map->core.base == MAP_FAILED) { if (map->core.base == MAP_FAILED) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n", pr_debug2("failed to mmap perf event ring buffer, error %d\n",
...@@ -389,7 +389,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) ...@@ -389,7 +389,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
map->comp_level = mp->comp_level; map->comp_level = mp->comp_level;
if (map->comp_level && !perf_mmap__aio_enabled(map)) { if (map->comp_level && !perf_mmap__aio_enabled(map)) {
map->data = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE, map->data = mmap(NULL, mmap__mmap_len(map), PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (map->data == MAP_FAILED) { if (map->data == MAP_FAILED) {
pr_debug2("failed to mmap data buffer, error %d\n", pr_debug2("failed to mmap data buffer, error %d\n",
......
...@@ -67,7 +67,7 @@ union perf_event *perf_mmap__read_event(struct mmap *map); ...@@ -67,7 +67,7 @@ union perf_event *perf_mmap__read_event(struct mmap *map);
int perf_mmap__push(struct mmap *md, void *to, int perf_mmap__push(struct mmap *md, void *to,
int push(struct mmap *map, void *to, void *buf, size_t size)); int push(struct mmap *map, void *to, void *buf, size_t size));
size_t perf_mmap__mmap_len(struct mmap *map); size_t mmap__mmap_len(struct mmap *map);
int perf_mmap__read_init(struct mmap *md); int perf_mmap__read_init(struct mmap *md);
void perf_mmap__read_done(struct mmap *map); void perf_mmap__read_done(struct mmap *map);
......
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