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