Thomas Gleixner | 9100704 | 2019-05-29 07:12:25 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011-2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> |
| 4 | * |
| 5 | * Parts came from evlist.c builtin-{top,stat,record}.c, see those files for further |
| 6 | * copyright notes. |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <sys/mman.h> |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 10 | #include <inttypes.h> |
| 11 | #include <asm/bug.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 12 | #include <linux/zalloc.h> |
Arnaldo Carvalho de Melo | f2a39fe | 2019-08-30 14:45:20 -0300 | [diff] [blame] | 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 15 | #ifdef HAVE_LIBNUMA_SUPPORT |
| 16 | #include <numaif.h> |
| 17 | #endif |
Arnaldo Carvalho de Melo | f2a39fe | 2019-08-30 14:45:20 -0300 | [diff] [blame] | 18 | #include "cpumap.h" |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 19 | #include "debug.h" |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 20 | #include "event.h" |
| 21 | #include "mmap.h" |
Arnaldo Carvalho de Melo | c1a604d | 2019-08-29 15:20:59 -0300 | [diff] [blame] | 22 | #include "../perf.h" |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 23 | #include "util.h" /* page_size */ |
| 24 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 25 | size_t perf_mmap__mmap_len(struct mmap *map) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 26 | { |
Jiri Olsa | 4fd0cef | 2019-07-27 22:27:55 +0200 | [diff] [blame] | 27 | return map->core.mask + 1 + page_size; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* When check_messup is true, 'end' must points to a good entry */ |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 31 | static union perf_event *perf_mmap__read(struct mmap *map, |
Kan Liang | b4b036b | 2018-01-18 13:26:21 -0800 | [diff] [blame] | 32 | u64 *startp, u64 end) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 33 | { |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 34 | unsigned char *data = map->core.base + page_size; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 35 | union perf_event *event = NULL; |
Kan Liang | b4b036b | 2018-01-18 13:26:21 -0800 | [diff] [blame] | 36 | int diff = end - *startp; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 37 | |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 38 | if (diff >= (int)sizeof(event->header)) { |
| 39 | size_t size; |
| 40 | |
Jiri Olsa | 4fd0cef | 2019-07-27 22:27:55 +0200 | [diff] [blame] | 41 | event = (union perf_event *)&data[*startp & map->core.mask]; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 42 | size = event->header.size; |
| 43 | |
Kan Liang | b4b036b | 2018-01-18 13:26:21 -0800 | [diff] [blame] | 44 | if (size < sizeof(event->header) || diff < (int)size) |
| 45 | return NULL; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Event straddles the mmap boundary -- header should always |
| 49 | * be inside due to u64 alignment of output. |
| 50 | */ |
Jiri Olsa | 4fd0cef | 2019-07-27 22:27:55 +0200 | [diff] [blame] | 51 | if ((*startp & map->core.mask) + size != ((*startp + size) & map->core.mask)) { |
Kan Liang | b4b036b | 2018-01-18 13:26:21 -0800 | [diff] [blame] | 52 | unsigned int offset = *startp; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 53 | unsigned int len = min(sizeof(*event), size), cpy; |
Jiri Olsa | 4443e6d | 2019-07-27 22:47:58 +0200 | [diff] [blame] | 54 | void *dst = map->core.event_copy; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 55 | |
| 56 | do { |
Jiri Olsa | 4fd0cef | 2019-07-27 22:27:55 +0200 | [diff] [blame] | 57 | cpy = min(map->core.mask + 1 - (offset & map->core.mask), len); |
| 58 | memcpy(dst, &data[offset & map->core.mask], cpy); |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 59 | offset += cpy; |
| 60 | dst += cpy; |
| 61 | len -= cpy; |
| 62 | } while (len); |
| 63 | |
Jiri Olsa | 4443e6d | 2019-07-27 22:47:58 +0200 | [diff] [blame] | 64 | event = (union perf_event *)map->core.event_copy; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 65 | } |
| 66 | |
Kan Liang | b4b036b | 2018-01-18 13:26:21 -0800 | [diff] [blame] | 67 | *startp += size; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 68 | } |
| 69 | |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 70 | return event; |
| 71 | } |
| 72 | |
Kan Liang | 3effc2f | 2018-01-18 13:26:25 -0800 | [diff] [blame] | 73 | /* |
Kan Liang | 7bb4597 | 2018-01-18 13:26:23 -0800 | [diff] [blame] | 74 | * Read event from ring buffer one by one. |
| 75 | * Return one event for each call. |
| 76 | * |
| 77 | * Usage: |
| 78 | * perf_mmap__read_init() |
| 79 | * while(event = perf_mmap__read_event()) { |
| 80 | * //process the event |
| 81 | * perf_mmap__consume() |
| 82 | * } |
| 83 | * perf_mmap__read_done() |
| 84 | */ |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 85 | union perf_event *perf_mmap__read_event(struct mmap *map) |
Kan Liang | 7bb4597 | 2018-01-18 13:26:23 -0800 | [diff] [blame] | 86 | { |
| 87 | union perf_event *event; |
| 88 | |
| 89 | /* |
| 90 | * Check if event was unmapped due to a POLLHUP/POLLERR. |
| 91 | */ |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 92 | if (!refcount_read(&map->core.refcnt)) |
Kan Liang | 7bb4597 | 2018-01-18 13:26:23 -0800 | [diff] [blame] | 93 | return NULL; |
| 94 | |
Kan Liang | 7bb4597 | 2018-01-18 13:26:23 -0800 | [diff] [blame] | 95 | /* non-overwirte doesn't pause the ringbuffer */ |
Jiri Olsa | 8df7a86 | 2019-07-27 22:42:56 +0200 | [diff] [blame] | 96 | if (!map->core.overwrite) |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 97 | map->core.end = perf_mmap__read_head(map); |
Kan Liang | 7bb4597 | 2018-01-18 13:26:23 -0800 | [diff] [blame] | 98 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 99 | event = perf_mmap__read(map, &map->core.start, map->core.end); |
Kan Liang | 7bb4597 | 2018-01-18 13:26:23 -0800 | [diff] [blame] | 100 | |
Jiri Olsa | 8df7a86 | 2019-07-27 22:42:56 +0200 | [diff] [blame] | 101 | if (!map->core.overwrite) |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 102 | map->core.prev = map->core.start; |
Kan Liang | 7bb4597 | 2018-01-18 13:26:23 -0800 | [diff] [blame] | 103 | |
| 104 | return event; |
| 105 | } |
| 106 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 107 | static bool perf_mmap__empty(struct mmap *map) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 108 | { |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 109 | return perf_mmap__read_head(map) == map->core.prev && !map->auxtrace_mmap.base; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 110 | } |
| 111 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 112 | void perf_mmap__get(struct mmap *map) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 113 | { |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 114 | refcount_inc(&map->core.refcnt); |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 115 | } |
| 116 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 117 | void perf_mmap__put(struct mmap *map) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 118 | { |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 119 | BUG_ON(map->core.base && refcount_read(&map->core.refcnt) == 0); |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 120 | |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 121 | if (refcount_dec_and_test(&map->core.refcnt)) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 122 | perf_mmap__munmap(map); |
| 123 | } |
| 124 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 125 | void perf_mmap__consume(struct mmap *map) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 126 | { |
Jiri Olsa | 8df7a86 | 2019-07-27 22:42:56 +0200 | [diff] [blame] | 127 | if (!map->core.overwrite) { |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 128 | u64 old = map->core.prev; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 129 | |
| 130 | perf_mmap__write_tail(map, old); |
| 131 | } |
| 132 | |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 133 | if (refcount_read(&map->core.refcnt) == 1 && perf_mmap__empty(map)) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 134 | perf_mmap__put(map); |
| 135 | } |
| 136 | |
| 137 | int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused, |
| 138 | struct auxtrace_mmap_params *mp __maybe_unused, |
| 139 | void *userpg __maybe_unused, |
| 140 | int fd __maybe_unused) |
| 141 | { |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | void __weak auxtrace_mmap__munmap(struct auxtrace_mmap *mm __maybe_unused) |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | void __weak auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp __maybe_unused, |
| 150 | off_t auxtrace_offset __maybe_unused, |
| 151 | unsigned int auxtrace_pages __maybe_unused, |
| 152 | bool auxtrace_overwrite __maybe_unused) |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __maybe_unused, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 157 | struct evlist *evlist __maybe_unused, |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 158 | int idx __maybe_unused, |
| 159 | bool per_cpu __maybe_unused) |
| 160 | { |
| 161 | } |
| 162 | |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 163 | #ifdef HAVE_AIO_SUPPORT |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 164 | static int perf_mmap__aio_enabled(struct mmap *map) |
Alexey Budankov | 51255a8 | 2019-03-18 20:42:19 +0300 | [diff] [blame] | 165 | { |
| 166 | return map->aio.nr_cblocks > 0; |
| 167 | } |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 168 | |
| 169 | #ifdef HAVE_LIBNUMA_SUPPORT |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 170 | static int perf_mmap__aio_alloc(struct mmap *map, int idx) |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 171 | { |
| 172 | map->aio.data[idx] = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE, |
| 173 | MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
| 174 | if (map->aio.data[idx] == MAP_FAILED) { |
| 175 | map->aio.data[idx] = NULL; |
| 176 | return -1; |
| 177 | } |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 182 | static void perf_mmap__aio_free(struct mmap *map, int idx) |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 183 | { |
| 184 | if (map->aio.data[idx]) { |
| 185 | munmap(map->aio.data[idx], perf_mmap__mmap_len(map)); |
| 186 | map->aio.data[idx] = NULL; |
| 187 | } |
| 188 | } |
| 189 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 190 | static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity) |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 191 | { |
| 192 | void *data; |
| 193 | size_t mmap_len; |
| 194 | unsigned long node_mask; |
| 195 | |
| 196 | if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) { |
| 197 | data = map->aio.data[idx]; |
| 198 | mmap_len = perf_mmap__mmap_len(map); |
| 199 | node_mask = 1UL << cpu__get_node(cpu); |
| 200 | if (mbind(data, mmap_len, MPOL_BIND, &node_mask, 1, 0)) { |
| 201 | pr_err("Failed to bind [%p-%p] AIO buffer to node %d: error %m\n", |
| 202 | data, data + mmap_len, cpu__get_node(cpu)); |
| 203 | return -1; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return 0; |
| 208 | } |
Alexey Budankov | 51255a8 | 2019-03-18 20:42:19 +0300 | [diff] [blame] | 209 | #else /* !HAVE_LIBNUMA_SUPPORT */ |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 210 | static int perf_mmap__aio_alloc(struct mmap *map, int idx) |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 211 | { |
| 212 | map->aio.data[idx] = malloc(perf_mmap__mmap_len(map)); |
| 213 | if (map->aio.data[idx] == NULL) |
| 214 | return -1; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 219 | static void perf_mmap__aio_free(struct mmap *map, int idx) |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 220 | { |
| 221 | zfree(&(map->aio.data[idx])); |
| 222 | } |
| 223 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 224 | static int perf_mmap__aio_bind(struct mmap *map __maybe_unused, int idx __maybe_unused, |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 225 | int cpu __maybe_unused, int affinity __maybe_unused) |
| 226 | { |
| 227 | return 0; |
| 228 | } |
| 229 | #endif |
| 230 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 231 | static int perf_mmap__aio_mmap(struct mmap *map, struct mmap_params *mp) |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 232 | { |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 233 | int delta_max, i, prio, ret; |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 234 | |
Alexey Budankov | d3d1af6 | 2018-11-06 12:04:58 +0300 | [diff] [blame] | 235 | map->aio.nr_cblocks = mp->nr_cblocks; |
| 236 | if (map->aio.nr_cblocks) { |
Alexey Budankov | 93f20c0 | 2018-11-06 12:07:19 +0300 | [diff] [blame] | 237 | map->aio.aiocb = calloc(map->aio.nr_cblocks, sizeof(struct aiocb *)); |
| 238 | if (!map->aio.aiocb) { |
| 239 | pr_debug2("failed to allocate aiocb for data buffer, error %m\n"); |
| 240 | return -1; |
| 241 | } |
| 242 | map->aio.cblocks = calloc(map->aio.nr_cblocks, sizeof(struct aiocb)); |
| 243 | if (!map->aio.cblocks) { |
| 244 | pr_debug2("failed to allocate cblocks for data buffer, error %m\n"); |
| 245 | return -1; |
| 246 | } |
| 247 | map->aio.data = calloc(map->aio.nr_cblocks, sizeof(void *)); |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 248 | if (!map->aio.data) { |
| 249 | pr_debug2("failed to allocate data buffer, error %m\n"); |
| 250 | return -1; |
| 251 | } |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 252 | delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX); |
Alexey Budankov | 93f20c0 | 2018-11-06 12:07:19 +0300 | [diff] [blame] | 253 | for (i = 0; i < map->aio.nr_cblocks; ++i) { |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 254 | ret = perf_mmap__aio_alloc(map, i); |
| 255 | if (ret == -1) { |
Alexey Budankov | 93f20c0 | 2018-11-06 12:07:19 +0300 | [diff] [blame] | 256 | pr_debug2("failed to allocate data buffer area, error %m"); |
| 257 | return -1; |
| 258 | } |
Jiri Olsa | 56a9470 | 2019-07-27 22:33:20 +0200 | [diff] [blame] | 259 | ret = perf_mmap__aio_bind(map, i, map->core.cpu, mp->affinity); |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 260 | if (ret == -1) |
| 261 | return -1; |
Alexey Budankov | 93f20c0 | 2018-11-06 12:07:19 +0300 | [diff] [blame] | 262 | /* |
| 263 | * Use cblock.aio_fildes value different from -1 |
| 264 | * to denote started aio write operation on the |
| 265 | * cblock so it requires explicit record__aio_sync() |
| 266 | * call prior the cblock may be reused again. |
| 267 | */ |
| 268 | map->aio.cblocks[i].aio_fildes = -1; |
| 269 | /* |
| 270 | * Allocate cblocks with priority delta to have |
| 271 | * faster aio write system calls because queued requests |
| 272 | * are kept in separate per-prio queues and adding |
| 273 | * a new request will iterate thru shorter per-prio |
| 274 | * list. Blocks with numbers higher than |
| 275 | * _SC_AIO_PRIO_DELTA_MAX go with priority 0. |
| 276 | */ |
| 277 | prio = delta_max - i; |
| 278 | map->aio.cblocks[i].aio_reqprio = prio >= 0 ? prio : 0; |
| 279 | } |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 285 | static void perf_mmap__aio_munmap(struct mmap *map) |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 286 | { |
Alexey Budankov | c8dd6ee | 2018-12-05 20:19:41 +0300 | [diff] [blame] | 287 | int i; |
| 288 | |
| 289 | for (i = 0; i < map->aio.nr_cblocks; ++i) |
Alexey Budankov | c44a8b4 | 2019-01-22 20:48:54 +0300 | [diff] [blame] | 290 | perf_mmap__aio_free(map, i); |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 291 | if (map->aio.data) |
| 292 | zfree(&map->aio.data); |
Alexey Budankov | c8dd6ee | 2018-12-05 20:19:41 +0300 | [diff] [blame] | 293 | zfree(&map->aio.cblocks); |
| 294 | zfree(&map->aio.aiocb); |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 295 | } |
Alexey Budankov | 51255a8 | 2019-03-18 20:42:19 +0300 | [diff] [blame] | 296 | #else /* !HAVE_AIO_SUPPORT */ |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 297 | static int perf_mmap__aio_enabled(struct mmap *map __maybe_unused) |
Alexey Budankov | 51255a8 | 2019-03-18 20:42:19 +0300 | [diff] [blame] | 298 | { |
| 299 | return 0; |
| 300 | } |
| 301 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 302 | static int perf_mmap__aio_mmap(struct mmap *map __maybe_unused, |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 303 | struct mmap_params *mp __maybe_unused) |
| 304 | { |
| 305 | return 0; |
| 306 | } |
| 307 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 308 | static void perf_mmap__aio_munmap(struct mmap *map __maybe_unused) |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 309 | { |
| 310 | } |
| 311 | #endif |
| 312 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 313 | void perf_mmap__munmap(struct mmap *map) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 314 | { |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 315 | perf_mmap__aio_munmap(map); |
Alexey Budankov | 51255a8 | 2019-03-18 20:42:19 +0300 | [diff] [blame] | 316 | if (map->data != NULL) { |
| 317 | munmap(map->data, perf_mmap__mmap_len(map)); |
| 318 | map->data = NULL; |
| 319 | } |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 320 | if (map->core.base != NULL) { |
| 321 | munmap(map->core.base, perf_mmap__mmap_len(map)); |
| 322 | map->core.base = NULL; |
Jiri Olsa | 2cf07b2 | 2019-07-27 22:31:17 +0200 | [diff] [blame] | 323 | map->core.fd = -1; |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 324 | refcount_set(&map->core.refcnt, 0); |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 325 | } |
| 326 | auxtrace_mmap__munmap(&map->auxtrace_mmap); |
| 327 | } |
| 328 | |
Alexey Budankov | f13de66 | 2019-01-22 20:50:57 +0300 | [diff] [blame] | 329 | static void build_node_mask(int node, cpu_set_t *mask) |
| 330 | { |
| 331 | int c, cpu, nr_cpus; |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 332 | const struct perf_cpu_map *cpu_map = NULL; |
Alexey Budankov | f13de66 | 2019-01-22 20:50:57 +0300 | [diff] [blame] | 333 | |
| 334 | cpu_map = cpu_map__online(); |
| 335 | if (!cpu_map) |
| 336 | return; |
| 337 | |
Jiri Olsa | 6549cd8 | 2019-08-22 13:11:38 +0200 | [diff] [blame] | 338 | nr_cpus = perf_cpu_map__nr(cpu_map); |
Alexey Budankov | f13de66 | 2019-01-22 20:50:57 +0300 | [diff] [blame] | 339 | for (c = 0; c < nr_cpus; c++) { |
| 340 | cpu = cpu_map->map[c]; /* map c index to online cpu index */ |
| 341 | if (cpu__get_node(cpu) == node) |
| 342 | CPU_SET(cpu, mask); |
| 343 | } |
| 344 | } |
| 345 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 346 | static void perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params *mp) |
Alexey Budankov | f13de66 | 2019-01-22 20:50:57 +0300 | [diff] [blame] | 347 | { |
| 348 | CPU_ZERO(&map->affinity_mask); |
| 349 | if (mp->affinity == PERF_AFFINITY_NODE && cpu__max_node() > 1) |
Jiri Olsa | 56a9470 | 2019-07-27 22:33:20 +0200 | [diff] [blame] | 350 | build_node_mask(cpu__get_node(map->core.cpu), &map->affinity_mask); |
Alexey Budankov | f13de66 | 2019-01-22 20:50:57 +0300 | [diff] [blame] | 351 | else if (mp->affinity == PERF_AFFINITY_CPU) |
Jiri Olsa | 56a9470 | 2019-07-27 22:33:20 +0200 | [diff] [blame] | 352 | CPU_SET(map->core.cpu, &map->affinity_mask); |
Alexey Budankov | f13de66 | 2019-01-22 20:50:57 +0300 | [diff] [blame] | 353 | } |
| 354 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 355 | int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 356 | { |
| 357 | /* |
Kan Liang | 6afad54 | 2018-03-01 18:09:11 -0500 | [diff] [blame] | 358 | * The last one will be done at perf_mmap__consume(), so that we |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 359 | * make sure we don't prevent tools from consuming every last event in |
| 360 | * the ring buffer. |
| 361 | * |
| 362 | * I.e. we can get the POLLHUP meaning that the fd doesn't exist |
| 363 | * anymore, but the last events for it are still in the ring buffer, |
| 364 | * waiting to be consumed. |
| 365 | * |
| 366 | * Tools can chose to ignore this at their own discretion, but the |
| 367 | * evlist layer can't just drop it when filtering events in |
| 368 | * perf_evlist__filter_pollfd(). |
| 369 | */ |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 370 | refcount_set(&map->core.refcnt, 2); |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 371 | map->core.prev = 0; |
Jiri Olsa | 4fd0cef | 2019-07-27 22:27:55 +0200 | [diff] [blame] | 372 | map->core.mask = mp->mask; |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 373 | map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot, |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 374 | MAP_SHARED, fd, 0); |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 375 | if (map->core.base == MAP_FAILED) { |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 376 | pr_debug2("failed to mmap perf event ring buffer, error %d\n", |
| 377 | errno); |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 378 | map->core.base = NULL; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 379 | return -1; |
| 380 | } |
Jiri Olsa | 2cf07b2 | 2019-07-27 22:31:17 +0200 | [diff] [blame] | 381 | map->core.fd = fd; |
Jiri Olsa | 56a9470 | 2019-07-27 22:33:20 +0200 | [diff] [blame] | 382 | map->core.cpu = cpu; |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 383 | |
Alexey Budankov | f13de66 | 2019-01-22 20:50:57 +0300 | [diff] [blame] | 384 | perf_mmap__setup_affinity_mask(map, mp); |
Alexey Budankov | 9d2ed64 | 2019-01-22 20:47:43 +0300 | [diff] [blame] | 385 | |
Jiri Olsa | 65aa2e6 | 2019-08-27 16:05:18 +0200 | [diff] [blame] | 386 | map->core.flush = mp->flush; |
Alexey Budankov | 470530b | 2019-03-18 20:40:26 +0300 | [diff] [blame] | 387 | |
Alexey Budankov | 51255a8 | 2019-03-18 20:42:19 +0300 | [diff] [blame] | 388 | map->comp_level = mp->comp_level; |
| 389 | |
| 390 | if (map->comp_level && !perf_mmap__aio_enabled(map)) { |
| 391 | map->data = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE, |
| 392 | MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
| 393 | if (map->data == MAP_FAILED) { |
| 394 | pr_debug2("failed to mmap data buffer, error %d\n", |
| 395 | errno); |
| 396 | map->data = NULL; |
| 397 | return -1; |
| 398 | } |
| 399 | } |
| 400 | |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 401 | if (auxtrace_mmap__mmap(&map->auxtrace_mmap, |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 402 | &mp->auxtrace_mp, map->core.base, fd)) |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 403 | return -1; |
| 404 | |
Alexey Budankov | 0b77383 | 2018-11-06 12:03:35 +0300 | [diff] [blame] | 405 | return perf_mmap__aio_mmap(map, mp); |
Arnaldo Carvalho de Melo | 1695849 | 2017-10-06 10:31:47 -0300 | [diff] [blame] | 406 | } |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 407 | |
Yisheng Xie | 699db11 | 2018-03-13 20:31:13 +0800 | [diff] [blame] | 408 | static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end) |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 409 | { |
| 410 | struct perf_event_header *pheader; |
Yisheng Xie | 699db11 | 2018-03-13 20:31:13 +0800 | [diff] [blame] | 411 | u64 evt_head = *start; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 412 | int size = mask + 1; |
| 413 | |
Yisheng Xie | 699db11 | 2018-03-13 20:31:13 +0800 | [diff] [blame] | 414 | pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start); |
| 415 | pheader = (struct perf_event_header *)(buf + (*start & mask)); |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 416 | while (true) { |
Yisheng Xie | 699db11 | 2018-03-13 20:31:13 +0800 | [diff] [blame] | 417 | if (evt_head - *start >= (unsigned int)size) { |
Wang Nan | 0b72d69 | 2017-12-04 16:51:07 +0000 | [diff] [blame] | 418 | pr_debug("Finished reading overwrite ring buffer: rewind\n"); |
Yisheng Xie | 699db11 | 2018-03-13 20:31:13 +0800 | [diff] [blame] | 419 | if (evt_head - *start > (unsigned int)size) |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 420 | evt_head -= pheader->size; |
| 421 | *end = evt_head; |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | pheader = (struct perf_event_header *)(buf + (evt_head & mask)); |
| 426 | |
| 427 | if (pheader->size == 0) { |
Wang Nan | 0b72d69 | 2017-12-04 16:51:07 +0000 | [diff] [blame] | 428 | pr_debug("Finished reading overwrite ring buffer: get start\n"); |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 429 | *end = evt_head; |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | evt_head += pheader->size; |
| 434 | pr_debug3("move evt_head: %"PRIx64"\n", evt_head); |
| 435 | } |
| 436 | WARN_ONCE(1, "Shouldn't get here\n"); |
| 437 | return -1; |
| 438 | } |
| 439 | |
Kan Liang | 8872481 | 2018-01-18 13:26:19 -0800 | [diff] [blame] | 440 | /* |
| 441 | * Report the start and end of the available data in ringbuffer |
| 442 | */ |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 443 | static int __perf_mmap__read_init(struct mmap *md) |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 444 | { |
| 445 | u64 head = perf_mmap__read_head(md); |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 446 | u64 old = md->core.prev; |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 447 | unsigned char *data = md->core.base + page_size; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 448 | unsigned long size; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 449 | |
Jiri Olsa | 8df7a86 | 2019-07-27 22:42:56 +0200 | [diff] [blame] | 450 | md->core.start = md->core.overwrite ? head : old; |
| 451 | md->core.end = md->core.overwrite ? old : head; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 452 | |
Jiri Olsa | 65aa2e6 | 2019-08-27 16:05:18 +0200 | [diff] [blame] | 453 | if ((md->core.end - md->core.start) < md->core.flush) |
Kan Liang | 189f2cc | 2018-01-18 13:26:20 -0800 | [diff] [blame] | 454 | return -EAGAIN; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 455 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 456 | size = md->core.end - md->core.start; |
Jiri Olsa | 4fd0cef | 2019-07-27 22:27:55 +0200 | [diff] [blame] | 457 | if (size > (unsigned long)(md->core.mask) + 1) { |
Jiri Olsa | 8df7a86 | 2019-07-27 22:42:56 +0200 | [diff] [blame] | 458 | if (!md->core.overwrite) { |
Wang Nan | 7fb4b40 | 2017-12-04 16:51:06 +0000 | [diff] [blame] | 459 | WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n"); |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 460 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 461 | md->core.prev = head; |
Kan Liang | d6ace3d | 2018-03-06 10:36:05 -0500 | [diff] [blame] | 462 | perf_mmap__consume(md); |
Kan Liang | 189f2cc | 2018-01-18 13:26:20 -0800 | [diff] [blame] | 463 | return -EAGAIN; |
Wang Nan | 7fb4b40 | 2017-12-04 16:51:06 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /* |
| 467 | * Backward ring buffer is full. We still have a chance to read |
| 468 | * most of data from it. |
| 469 | */ |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 470 | if (overwrite_rb_find_range(data, md->core.mask, &md->core.start, &md->core.end)) |
Kan Liang | 189f2cc | 2018-01-18 13:26:20 -0800 | [diff] [blame] | 471 | return -EINVAL; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 472 | } |
| 473 | |
Kan Liang | 189f2cc | 2018-01-18 13:26:20 -0800 | [diff] [blame] | 474 | return 0; |
Kan Liang | 8872481 | 2018-01-18 13:26:19 -0800 | [diff] [blame] | 475 | } |
| 476 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 477 | int perf_mmap__read_init(struct mmap *map) |
Arnaldo Carvalho de Melo | 895e3b0 | 2018-03-26 11:42:15 -0300 | [diff] [blame] | 478 | { |
| 479 | /* |
| 480 | * Check if event was unmapped due to a POLLHUP/POLLERR. |
| 481 | */ |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 482 | if (!refcount_read(&map->core.refcnt)) |
Arnaldo Carvalho de Melo | 895e3b0 | 2018-03-26 11:42:15 -0300 | [diff] [blame] | 483 | return -ENOENT; |
| 484 | |
| 485 | return __perf_mmap__read_init(map); |
| 486 | } |
| 487 | |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 488 | int perf_mmap__push(struct mmap *md, void *to, |
| 489 | int push(struct mmap *map, void *to, void *buf, size_t size)) |
Kan Liang | 8872481 | 2018-01-18 13:26:19 -0800 | [diff] [blame] | 490 | { |
| 491 | u64 head = perf_mmap__read_head(md); |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 492 | unsigned char *data = md->core.base + page_size; |
Kan Liang | 8872481 | 2018-01-18 13:26:19 -0800 | [diff] [blame] | 493 | unsigned long size; |
| 494 | void *buf; |
| 495 | int rc = 0; |
| 496 | |
Kan Liang | b9bae2c | 2018-03-06 10:36:07 -0500 | [diff] [blame] | 497 | rc = perf_mmap__read_init(md); |
Kan Liang | 189f2cc | 2018-01-18 13:26:20 -0800 | [diff] [blame] | 498 | if (rc < 0) |
Alexey Budankov | ef78112 | 2019-03-18 20:44:12 +0300 | [diff] [blame] | 499 | return (rc == -EAGAIN) ? 1 : -1; |
Kan Liang | 8872481 | 2018-01-18 13:26:19 -0800 | [diff] [blame] | 500 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 501 | size = md->core.end - md->core.start; |
Kan Liang | dc6c35c | 2018-01-18 13:26:17 -0800 | [diff] [blame] | 502 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 503 | if ((md->core.start & md->core.mask) + size != (md->core.end & md->core.mask)) { |
| 504 | buf = &data[md->core.start & md->core.mask]; |
| 505 | size = md->core.mask + 1 - (md->core.start & md->core.mask); |
| 506 | md->core.start += size; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 507 | |
Jiri Olsa | ded2b8f | 2018-09-13 14:54:06 +0200 | [diff] [blame] | 508 | if (push(md, to, buf, size) < 0) { |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 509 | rc = -1; |
| 510 | goto out; |
| 511 | } |
| 512 | } |
| 513 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 514 | buf = &data[md->core.start & md->core.mask]; |
| 515 | size = md->core.end - md->core.start; |
| 516 | md->core.start += size; |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 517 | |
Jiri Olsa | ded2b8f | 2018-09-13 14:54:06 +0200 | [diff] [blame] | 518 | if (push(md, to, buf, size) < 0) { |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 519 | rc = -1; |
| 520 | goto out; |
| 521 | } |
| 522 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 523 | md->core.prev = head; |
Kan Liang | d6ace3d | 2018-03-06 10:36:05 -0500 | [diff] [blame] | 524 | perf_mmap__consume(md); |
Arnaldo Carvalho de Melo | 73c17d8 | 2017-10-06 10:46:01 -0300 | [diff] [blame] | 525 | out: |
| 526 | return rc; |
| 527 | } |
Kan Liang | ee023de | 2018-01-18 13:26:22 -0800 | [diff] [blame] | 528 | |
| 529 | /* |
| 530 | * Mandatory for overwrite mode |
| 531 | * The direction of overwrite mode is backward. |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 532 | * The last perf_mmap__read() will set tail to map->core.prev. |
| 533 | * Need to correct the map->core.prev to head which is the end of next read. |
Kan Liang | ee023de | 2018-01-18 13:26:22 -0800 | [diff] [blame] | 534 | */ |
Jiri Olsa | a583053 | 2019-07-27 20:30:53 +0200 | [diff] [blame] | 535 | void perf_mmap__read_done(struct mmap *map) |
Kan Liang | ee023de | 2018-01-18 13:26:22 -0800 | [diff] [blame] | 536 | { |
Kan Liang | f58385f | 2018-03-26 09:42:09 -0400 | [diff] [blame] | 537 | /* |
| 538 | * Check if event was unmapped due to a POLLHUP/POLLERR. |
| 539 | */ |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 540 | if (!refcount_read(&map->core.refcnt)) |
Kan Liang | f58385f | 2018-03-26 09:42:09 -0400 | [diff] [blame] | 541 | return; |
| 542 | |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 543 | map->core.prev = perf_mmap__read_head(map); |
Kan Liang | ee023de | 2018-01-18 13:26:22 -0800 | [diff] [blame] | 544 | } |