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: Alexey Budankov <alexey.budan...@linux.intel.com>
---
 Changes in v7:
  - implemented handling record.aio setting from perfconfig file
 Changes in v6:
  - adjusted setting of priorities for cblocks;
 Changes in v5:
  - reshaped layout of data structures;
  - implemented --aio option;
 Changes in v4:
  - converted mmap()/munmap() to malloc()/free() for mmap->data buffer 
management 
 Changes in v2:
  - converted zalloc() to calloc() for allocation of mmap_aio array,
  - cleared typo and adjusted fallback branch code;
---
 tools/perf/util/mmap.c | 25 +++++++++++++++++++++++++
 tools/perf/util/mmap.h |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index fc832676a798..e53038d76445 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -155,6 +155,8 @@ void __weak auxtrace_mmap_params__set_idx(struct 
auxtrace_mmap_params *mp __mayb
 
 void perf_mmap__munmap(struct perf_mmap *map)
 {
+       if (map->data)
+               zfree(&map->data);
        if (map->base != NULL) {
                munmap(map->base, perf_mmap__mmap_len(map));
                map->base = NULL;
@@ -166,6 +168,7 @@ void perf_mmap__munmap(struct perf_mmap *map)
 
 int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
 {
+       int delta_max;
        /*
         * The last one will be done at perf_mmap__consume(), so that we
         * make sure we don't prevent tools from consuming every last event in
@@ -190,6 +193,28 @@ int perf_mmap__mmap(struct perf_mmap *map, struct 
mmap_params *mp, int fd)
                map->base = NULL;
                return -1;
        }
+       delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX);
+       map->data = malloc(perf_mmap__mmap_len(map));
+       if (!map->data) {
+               pr_debug2("failed to allocate data buffer, error %d\n",
+                               errno);
+               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->cblock.aio_fildes = -1;
+       /*
+        * Allocate cblock with max priority delta to
+        * have faster aio_write() calls because queued
+        * requests are kept in separate per-prio queues
+        * and adding a new request iterates thru shorter
+        * per-prio list.
+        */
+       map->cblock.aio_reqprio = delta_max;
        map->fd = fd;
 
        if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index d82294db1295..1974e621e36b 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -6,6 +6,7 @@
 #include <linux/types.h>
 #include <asm/barrier.h>
 #include <stdbool.h>
+#include <aio.h>
 #include "auxtrace.h"
 #include "event.h"
 
@@ -25,6 +26,8 @@ struct perf_mmap {
        bool             overwrite;
        struct auxtrace_mmap auxtrace_mmap;
        char             event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
+       void             *data;
+       struct aiocb     cblock;
 };
 
 /*

Reply via email to