perf intel-pt: Add lookahead callback
[linux/fpc-iii.git] / tools / perf / util / mmap.h
blob274ce389cd84891f0c97bf3184460e72a108912b
1 #ifndef __PERF_MMAP_H
2 #define __PERF_MMAP_H 1
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"
15 struct aiocb;
16 /**
17 * struct perf_mmap - perf's ring buffer mmap details
19 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
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 void *data;
44 int comp_level;
48 * State machine of bkw_mmap_state:
50 * .________________(forbid)_____________.
51 * | V
52 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
53 * ^ ^ | ^ |
54 * | |__(forbid)____/ |___(forbid)___/|
55 * | |
56 * \_________________(3)_______________/
58 * NOTREADY : Backward ring buffers are not ready
59 * RUNNING : Backward ring buffers are recording
60 * DATA_PENDING : We are required to collect data from backward ring buffers
61 * EMPTY : We have collected data from backward ring buffers.
63 * (0): Setup backward ring buffer
64 * (1): Pause ring buffers for reading
65 * (2): Read from ring buffers
66 * (3): Resume ring buffers for recording
68 enum bkw_mmap_state {
69 BKW_MMAP_NOTREADY,
70 BKW_MMAP_RUNNING,
71 BKW_MMAP_DATA_PENDING,
72 BKW_MMAP_EMPTY,
75 struct mmap_params {
76 int prot, mask, nr_cblocks, affinity, flush, comp_level;
77 struct auxtrace_mmap_params auxtrace_mp;
80 int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu);
81 void perf_mmap__munmap(struct perf_mmap *map);
83 void perf_mmap__get(struct perf_mmap *map);
84 void perf_mmap__put(struct perf_mmap *map);
86 void perf_mmap__consume(struct perf_mmap *map);
88 static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
90 return ring_buffer_read_head(mm->base);
93 static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
95 ring_buffer_write_tail(md->base, tail);
98 union perf_event *perf_mmap__read_forward(struct perf_mmap *map);
100 union perf_event *perf_mmap__read_event(struct perf_mmap *map);
102 int perf_mmap__push(struct perf_mmap *md, void *to,
103 int push(struct perf_mmap *map, void *to, void *buf, size_t size));
105 size_t perf_mmap__mmap_len(struct perf_mmap *map);
107 int perf_mmap__read_init(struct perf_mmap *md);
108 void perf_mmap__read_done(struct perf_mmap *map);
109 #endif /*__PERF_MMAP_H */