Commit 0b773831 authored by Alexey Budankov's avatar Alexey Budankov Committed by Arnaldo Carvalho de Melo

perf mmap: Map data buffer for preserving collected data

The map->data buffer is used to preserve map->base profiling data for
writing to disk. AIO map->cblock is used to queue corresponding
map->data buffer for asynchronous writing.
Signed-off-by: default avatarAlexey Budankov <alexey.budankov@linux.intel.com>
Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/5fcda10c-6c63-68df-383a-c6d9e5d1f918@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2a07d814
...@@ -1028,7 +1028,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages, ...@@ -1028,7 +1028,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
* Its value is decided by evsel's write_backward. * Its value is decided by evsel's write_backward.
* So &mp should not be passed through const pointer. * So &mp should not be passed through const pointer.
*/ */
struct mmap_params mp; struct mmap_params mp = { .nr_cblocks = 0 };
if (!evlist->mmap) if (!evlist->mmap)
evlist->mmap = perf_evlist__alloc_mmap(evlist, false); evlist->mmap = perf_evlist__alloc_mmap(evlist, false);
......
...@@ -153,8 +153,55 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb ...@@ -153,8 +153,55 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb
{ {
} }
#ifdef HAVE_AIO_SUPPORT
static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
{
int delta_max;
if (mp->nr_cblocks) {
map->aio.data = malloc(perf_mmap__mmap_len(map));
if (!map->aio.data) {
pr_debug2("failed to allocate data buffer, error %m\n");
return -1;
}
/*
* Use cblock.aio_fildes value different from -1
* to denote started aio write operation on the
* cblock so it requires explicit record__aio_sync()
* call prior the cblock may be reused again.
*/
map->aio.cblock.aio_fildes = -1;
/*
* Allocate cblock with max priority delta to
* have faster aio write system calls.
*/
delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX);
map->aio.cblock.aio_reqprio = delta_max;
}
return 0;
}
static void perf_mmap__aio_munmap(struct perf_mmap *map)
{
if (map->aio.data)
zfree(&map->aio.data);
}
#else
static int perf_mmap__aio_mmap(struct perf_mmap *map __maybe_unused,
struct mmap_params *mp __maybe_unused)
{
return 0;
}
static void perf_mmap__aio_munmap(struct perf_mmap *map __maybe_unused)
{
}
#endif
void perf_mmap__munmap(struct perf_mmap *map) void perf_mmap__munmap(struct perf_mmap *map)
{ {
perf_mmap__aio_munmap(map);
if (map->base != NULL) { if (map->base != NULL) {
munmap(map->base, perf_mmap__mmap_len(map)); munmap(map->base, perf_mmap__mmap_len(map));
map->base = NULL; map->base = NULL;
...@@ -197,7 +244,7 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int c ...@@ -197,7 +244,7 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int c
&mp->auxtrace_mp, map->base, fd)) &mp->auxtrace_mp, map->base, fd))
return -1; return -1;
return 0; return perf_mmap__aio_mmap(map, mp);
} }
static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end) static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/ring_buffer.h> #include <linux/ring_buffer.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef HAVE_AIO_SUPPORT
#include <aio.h>
#endif
#include "auxtrace.h" #include "auxtrace.h"
#include "event.h" #include "event.h"
...@@ -26,6 +29,12 @@ struct perf_mmap { ...@@ -26,6 +29,12 @@ struct perf_mmap {
bool overwrite; bool overwrite;
struct auxtrace_mmap auxtrace_mmap; struct auxtrace_mmap auxtrace_mmap;
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
#ifdef HAVE_AIO_SUPPORT
struct {
void *data;
struct aiocb cblock;
} aio;
#endif
}; };
/* /*
...@@ -57,7 +66,7 @@ enum bkw_mmap_state { ...@@ -57,7 +66,7 @@ enum bkw_mmap_state {
}; };
struct mmap_params { struct mmap_params {
int prot, mask; int prot, mask, nr_cblocks;
struct auxtrace_mmap_params auxtrace_mp; struct auxtrace_mmap_params auxtrace_mp;
}; };
......
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