xref: /openbmc/linux/tools/perf/util/mmap.h (revision c796f021)
1 #ifndef __PERF_MMAP_H
2 #define __PERF_MMAP_H 1
3 
4 #include <internal/mmap.h>
5 #include <linux/compiler.h>
6 #include <linux/refcount.h>
7 #include <linux/types.h>
8 #include <linux/ring_buffer.h>
9 #include <linux/bitops.h>
10 #include <perf/cpumap.h>
11 #include <stdbool.h>
12 #include <pthread.h> // for cpu_set_t
13 #ifdef HAVE_AIO_SUPPORT
14 #include <aio.h>
15 #endif
16 #include "auxtrace.h"
17 #include "event.h"
18 #include "util/compress.h"
19 
20 struct aiocb;
21 
22 struct mmap_cpu_mask {
23 	unsigned long *bits;
24 	size_t nbits;
25 };
26 
27 #define MMAP_CPU_MASK_BYTES(m) \
28 	(BITS_TO_LONGS(((struct mmap_cpu_mask *)m)->nbits) * sizeof(unsigned long))
29 
30 /**
31  * struct mmap - perf's ring buffer mmap details
32  *
33  * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
34  */
35 struct mmap {
36 	struct perf_mmap	core;
37 	struct auxtrace_mmap auxtrace_mmap;
38 #ifdef HAVE_AIO_SUPPORT
39 	struct {
40 		void		 **data;
41 		struct aiocb	 *cblocks;
42 		struct aiocb	 **aiocb;
43 		int		 nr_cblocks;
44 	} aio;
45 #endif
46 	struct mmap_cpu_mask	affinity_mask;
47 	void		*data;
48 	int		comp_level;
49 	struct perf_data_file *file;
50 	struct zstd_data      zstd_data;
51 };
52 
53 struct mmap_params {
54 	struct perf_mmap_param core;
55 	int nr_cblocks, affinity, flush, comp_level;
56 	struct auxtrace_mmap_params auxtrace_mp;
57 };
58 
59 int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, struct perf_cpu cpu);
60 void mmap__munmap(struct mmap *map);
61 
62 union perf_event *perf_mmap__read_forward(struct mmap *map);
63 
64 int perf_mmap__push(struct mmap *md, void *to,
65 		    int push(struct mmap *map, void *to, void *buf, size_t size));
66 
67 size_t mmap__mmap_len(struct mmap *map);
68 
69 void mmap_cpu_mask__scnprintf(struct mmap_cpu_mask *mask, const char *tag);
70 
71 int mmap_cpu_mask__duplicate(struct mmap_cpu_mask *original,
72 				struct mmap_cpu_mask *clone);
73 
74 #endif /*__PERF_MMAP_H */
75