diff options
-rw-r--r-- | tools/perf/util/evlist.c | 2 | ||||
-rw-r--r-- | tools/perf/util/mmap.c | 49 | ||||
-rw-r--r-- | tools/perf/util/mmap.h | 11 |
3 files changed, 59 insertions, 3 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 36526d229315..6f010b9f0a81 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -1028,7 +1028,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages, | |||
1028 | * Its value is decided by evsel's write_backward. | 1028 | * Its value is decided by evsel's write_backward. |
1029 | * So &mp should not be passed through const pointer. | 1029 | * So &mp should not be passed through const pointer. |
1030 | */ | 1030 | */ |
1031 | struct mmap_params mp; | 1031 | struct mmap_params mp = { .nr_cblocks = 0 }; |
1032 | 1032 | ||
1033 | if (!evlist->mmap) | 1033 | if (!evlist->mmap) |
1034 | evlist->mmap = perf_evlist__alloc_mmap(evlist, false); | 1034 | evlist->mmap = perf_evlist__alloc_mmap(evlist, false); |
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index cdb95b3a1213..47cdc3ad6546 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c | |||
@@ -153,8 +153,55 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb | |||
153 | { | 153 | { |
154 | } | 154 | } |
155 | 155 | ||
156 | #ifdef HAVE_AIO_SUPPORT | ||
157 | static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp) | ||
158 | { | ||
159 | int delta_max; | ||
160 | |||
161 | if (mp->nr_cblocks) { | ||
162 | map->aio.data = malloc(perf_mmap__mmap_len(map)); | ||
163 | if (!map->aio.data) { | ||
164 | pr_debug2("failed to allocate data buffer, error %m\n"); | ||
165 | return -1; | ||
166 | } | ||
167 | /* | ||
168 | * Use cblock.aio_fildes value different from -1 | ||
169 | * to denote started aio write operation on the | ||
170 | * cblock so it requires explicit record__aio_sync() | ||
171 | * call prior the cblock may be reused again. | ||
172 | */ | ||
173 | map->aio.cblock.aio_fildes = -1; | ||
174 | /* | ||
175 | * Allocate cblock with max priority delta to | ||
176 | * have faster aio write system calls. | ||
177 | */ | ||
178 | delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX); | ||
179 | map->aio.cblock.aio_reqprio = delta_max; | ||
180 | } | ||
181 | |||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static void perf_mmap__aio_munmap(struct perf_mmap *map) | ||
186 | { | ||
187 | if (map->aio.data) | ||
188 | zfree(&map->aio.data); | ||
189 | } | ||
190 | #else | ||
191 | static int perf_mmap__aio_mmap(struct perf_mmap *map __maybe_unused, | ||
192 | struct mmap_params *mp __maybe_unused) | ||
193 | { | ||
194 | return 0; | ||
195 | } | ||
196 | |||
197 | static void perf_mmap__aio_munmap(struct perf_mmap *map __maybe_unused) | ||
198 | { | ||
199 | } | ||
200 | #endif | ||
201 | |||
156 | void perf_mmap__munmap(struct perf_mmap *map) | 202 | void perf_mmap__munmap(struct perf_mmap *map) |
157 | { | 203 | { |
204 | perf_mmap__aio_munmap(map); | ||
158 | if (map->base != NULL) { | 205 | if (map->base != NULL) { |
159 | munmap(map->base, perf_mmap__mmap_len(map)); | 206 | munmap(map->base, perf_mmap__mmap_len(map)); |
160 | map->base = NULL; | 207 | map->base = NULL; |
@@ -197,7 +244,7 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int c | |||
197 | &mp->auxtrace_mp, map->base, fd)) | 244 | &mp->auxtrace_mp, map->base, fd)) |
198 | return -1; | 245 | return -1; |
199 | 246 | ||
200 | return 0; | 247 | return perf_mmap__aio_mmap(map, mp); |
201 | } | 248 | } |
202 | 249 | ||
203 | static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end) | 250 | static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end) |
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index cc5e2d6d17a9..3f10ad030c5e 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h | |||
@@ -6,6 +6,9 @@ | |||
6 | #include <linux/types.h> | 6 | #include <linux/types.h> |
7 | #include <linux/ring_buffer.h> | 7 | #include <linux/ring_buffer.h> |
8 | #include <stdbool.h> | 8 | #include <stdbool.h> |
9 | #ifdef HAVE_AIO_SUPPORT | ||
10 | #include <aio.h> | ||
11 | #endif | ||
9 | #include "auxtrace.h" | 12 | #include "auxtrace.h" |
10 | #include "event.h" | 13 | #include "event.h" |
11 | 14 | ||
@@ -26,6 +29,12 @@ struct perf_mmap { | |||
26 | bool overwrite; | 29 | bool overwrite; |
27 | struct auxtrace_mmap auxtrace_mmap; | 30 | struct auxtrace_mmap auxtrace_mmap; |
28 | char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); | 31 | char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); |
32 | #ifdef HAVE_AIO_SUPPORT | ||
33 | struct { | ||
34 | void *data; | ||
35 | struct aiocb cblock; | ||
36 | } aio; | ||
37 | #endif | ||
29 | }; | 38 | }; |
30 | 39 | ||
31 | /* | 40 | /* |
@@ -57,7 +66,7 @@ enum bkw_mmap_state { | |||
57 | }; | 66 | }; |
58 | 67 | ||
59 | struct mmap_params { | 68 | struct mmap_params { |
60 | int prot, mask; | 69 | int prot, mask, nr_cblocks; |
61 | struct auxtrace_mmap_params auxtrace_mp; | 70 | struct auxtrace_mmap_params auxtrace_mp; |
62 | }; | 71 | }; |
63 | 72 | ||