Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef __LIBPERF_INTERNAL_MMAP_H |
| 3 | #define __LIBPERF_INTERNAL_MMAP_H |
| 4 | |
Jiri Olsa | 4443e6d | 2019-07-27 22:47:58 +0200 | [diff] [blame] | 5 | #include <linux/compiler.h> |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 6 | #include <linux/refcount.h> |
Jiri Olsa | ebe4d72 | 2019-07-27 22:39:53 +0200 | [diff] [blame] | 7 | #include <linux/types.h> |
Jiri Olsa | 8df7a86 | 2019-07-27 22:42:56 +0200 | [diff] [blame] | 8 | #include <stdbool.h> |
Ian Rogers | 6d18804 | 2022-01-04 22:13:51 -0800 | [diff] [blame] | 9 | #include <internal/cpumap.h> |
Jiri Olsa | e03edfe | 2019-07-27 22:35:35 +0200 | [diff] [blame] | 10 | |
Jiri Olsa | 4443e6d | 2019-07-27 22:47:58 +0200 | [diff] [blame] | 11 | /* perf sample has 16 bits size limit */ |
| 12 | #define PERF_SAMPLE_MAX_SIZE (1 << 16) |
| 13 | |
Jiri Olsa | 80e53d1 | 2019-10-07 14:53:15 +0200 | [diff] [blame] | 14 | struct perf_mmap; |
Rob Herring | 47d01e7 | 2021-04-14 11:07:39 -0500 | [diff] [blame] | 15 | struct perf_counts_values; |
Jiri Olsa | 80e53d1 | 2019-10-07 14:53:15 +0200 | [diff] [blame] | 16 | |
| 17 | typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map); |
| 18 | |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 19 | /** |
| 20 | * struct perf_mmap - perf's ring buffer mmap details |
| 21 | * |
| 22 | * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this |
| 23 | */ |
| 24 | struct perf_mmap { |
Jiri Olsa | 80e53d1 | 2019-10-07 14:53:15 +0200 | [diff] [blame] | 25 | void *base; |
| 26 | int mask; |
| 27 | int fd; |
Ian Rogers | 6d18804 | 2022-01-04 22:13:51 -0800 | [diff] [blame] | 28 | struct perf_cpu cpu; |
Jiri Olsa | 80e53d1 | 2019-10-07 14:53:15 +0200 | [diff] [blame] | 29 | refcount_t refcnt; |
| 30 | u64 prev; |
| 31 | u64 start; |
| 32 | u64 end; |
| 33 | bool overwrite; |
| 34 | u64 flush; |
| 35 | libperf_unmap_cb_t unmap_cb; |
| 36 | char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); |
Jiri Olsa | 6eb65f7 | 2019-10-17 12:59:09 +0200 | [diff] [blame] | 37 | struct perf_mmap *next; |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 38 | }; |
| 39 | |
Jiri Olsa | e440979 | 2019-10-07 14:53:10 +0200 | [diff] [blame] | 40 | struct perf_mmap_param { |
| 41 | int prot; |
| 42 | int mask; |
| 43 | }; |
| 44 | |
Jiri Olsa | bf59b30 | 2019-10-07 14:53:11 +0200 | [diff] [blame] | 45 | size_t perf_mmap__mmap_len(struct perf_mmap *map); |
| 46 | |
Jiri Olsa | 6eb65f7 | 2019-10-17 12:59:09 +0200 | [diff] [blame] | 47 | void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev, |
| 48 | bool overwrite, libperf_unmap_cb_t unmap_cb); |
Jiri Olsa | 32c261c | 2019-10-07 14:53:12 +0200 | [diff] [blame] | 49 | int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, |
Ian Rogers | 6d18804 | 2022-01-04 22:13:51 -0800 | [diff] [blame] | 50 | int fd, struct perf_cpu cpu); |
Jiri Olsa | 59d7ea62 | 2019-10-07 14:53:14 +0200 | [diff] [blame] | 51 | void perf_mmap__munmap(struct perf_mmap *map); |
Jiri Olsa | e75710f | 2019-10-07 14:53:13 +0200 | [diff] [blame] | 52 | void perf_mmap__get(struct perf_mmap *map); |
Jiri Olsa | 80e53d1 | 2019-10-07 14:53:15 +0200 | [diff] [blame] | 53 | void perf_mmap__put(struct perf_mmap *map); |
Jiri Olsa | 353120b | 2019-10-07 14:53:09 +0200 | [diff] [blame] | 54 | |
Jiri Olsa | 7728fa0 | 2019-10-07 14:53:17 +0200 | [diff] [blame] | 55 | u64 perf_mmap__read_head(struct perf_mmap *map); |
| 56 | |
Rob Herring | 47d01e7 | 2021-04-14 11:07:39 -0500 | [diff] [blame] | 57 | int perf_mmap__read_self(struct perf_mmap *map, struct perf_counts_values *count); |
| 58 | |
Jiri Olsa | 547740f | 2019-07-27 22:07:44 +0200 | [diff] [blame] | 59 | #endif /* __LIBPERF_INTERNAL_MMAP_H */ |