Merge branch 'nvme-5.2-rc2' of git://git.infradead.org/nvme into for-linus
[linux-2.6-microblaze.git] / tools / perf / util / mmap.h
1 #ifndef __PERF_MMAP_H
2 #define __PERF_MMAP_H 1
3
4 #include <linux/compiler.h>
5 #include <linux/refcount.h>
6 #include <linux/types.h>
7 #include <linux/ring_buffer.h>
8 #include <stdbool.h>
9 #ifdef HAVE_AIO_SUPPORT
10 #include <aio.h>
11 #endif
12 #include "auxtrace.h"
13 #include "event.h"
14
15 struct aiocb;
16 /**
17  * struct perf_mmap - perf's ring buffer mmap details
18  *
19  * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
20  */
21 struct perf_mmap {
22         void             *base;
23         int              mask;
24         int              fd;
25         int              cpu;
26         refcount_t       refcnt;
27         u64              prev;
28         u64              start;
29         u64              end;
30         bool             overwrite;
31         struct auxtrace_mmap auxtrace_mmap;
32         char             event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
33 #ifdef HAVE_AIO_SUPPORT
34         struct {
35                 void             **data;
36                 struct aiocb     *cblocks;
37                 struct aiocb     **aiocb;
38                 int              nr_cblocks;
39         } aio;
40 #endif
41         cpu_set_t       affinity_mask;
42         u64             flush;
43 };
44
45 /*
46  * State machine of bkw_mmap_state:
47  *
48  *                     .________________(forbid)_____________.
49  *                     |                                     V
50  * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
51  *                     ^  ^              |   ^               |
52  *                     |  |__(forbid)____/   |___(forbid)___/|
53  *                     |                                     |
54  *                      \_________________(3)_______________/
55  *
56  * NOTREADY     : Backward ring buffers are not ready
57  * RUNNING      : Backward ring buffers are recording
58  * DATA_PENDING : We are required to collect data from backward ring buffers
59  * EMPTY        : We have collected data from backward ring buffers.
60  *
61  * (0): Setup backward ring buffer
62  * (1): Pause ring buffers for reading
63  * (2): Read from ring buffers
64  * (3): Resume ring buffers for recording
65  */
66 enum bkw_mmap_state {
67         BKW_MMAP_NOTREADY,
68         BKW_MMAP_RUNNING,
69         BKW_MMAP_DATA_PENDING,
70         BKW_MMAP_EMPTY,
71 };
72
73 struct mmap_params {
74         int                         prot, mask, nr_cblocks, affinity, flush;
75         struct auxtrace_mmap_params auxtrace_mp;
76 };
77
78 int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu);
79 void perf_mmap__munmap(struct perf_mmap *map);
80
81 void perf_mmap__get(struct perf_mmap *map);
82 void perf_mmap__put(struct perf_mmap *map);
83
84 void perf_mmap__consume(struct perf_mmap *map);
85
86 static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
87 {
88         return ring_buffer_read_head(mm->base);
89 }
90
91 static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
92 {
93         ring_buffer_write_tail(md->base, tail);
94 }
95
96 union perf_event *perf_mmap__read_forward(struct perf_mmap *map);
97
98 union perf_event *perf_mmap__read_event(struct perf_mmap *map);
99
100 int perf_mmap__push(struct perf_mmap *md, void *to,
101                     int push(struct perf_mmap *map, void *to, void *buf, size_t size));
102 #ifdef HAVE_AIO_SUPPORT
103 int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx,
104                         int push(void *to, struct aiocb *cblock, void *buf, size_t size, off_t off),
105                         off_t *off);
106 #else
107 static inline int perf_mmap__aio_push(struct perf_mmap *md __maybe_unused, void *to __maybe_unused, int idx __maybe_unused,
108         int push(void *to, struct aiocb *cblock, void *buf, size_t size, off_t off) __maybe_unused,
109         off_t *off __maybe_unused)
110 {
111         return 0;
112 }
113 #endif
114
115 size_t perf_mmap__mmap_len(struct perf_mmap *map);
116
117 int perf_mmap__read_init(struct perf_mmap *md);
118 void perf_mmap__read_done(struct perf_mmap *map);
119 #endif /*__PERF_MMAP_H */