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 <asm/barrier.h>
8#include <stdbool.h>
9#include "auxtrace.h"
10#include "event.h"
11
12
13
14
15
16
17struct perf_mmap {
18 void *base;
19 int mask;
20 int fd;
21 refcount_t refcnt;
22 u64 prev;
23 struct auxtrace_mmap auxtrace_mmap;
24 char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
25};
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48enum bkw_mmap_state {
49 BKW_MMAP_NOTREADY,
50 BKW_MMAP_RUNNING,
51 BKW_MMAP_DATA_PENDING,
52 BKW_MMAP_EMPTY,
53};
54
55struct mmap_params {
56 int prot, mask;
57 struct auxtrace_mmap_params auxtrace_mp;
58};
59
60int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd);
61void perf_mmap__munmap(struct perf_mmap *map);
62
63void perf_mmap__get(struct perf_mmap *map);
64void perf_mmap__put(struct perf_mmap *map);
65
66void perf_mmap__consume(struct perf_mmap *map, bool overwrite);
67
68static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
69{
70 struct perf_event_mmap_page *pc = mm->base;
71 u64 head = READ_ONCE(pc->data_head);
72 rmb();
73 return head;
74}
75
76static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
77{
78 struct perf_event_mmap_page *pc = md->base;
79
80
81
82
83 mb();
84 pc->data_tail = tail;
85}
86
87union perf_event *perf_mmap__read_forward(struct perf_mmap *map);
88
89union perf_event *perf_mmap__read_event(struct perf_mmap *map,
90 bool overwrite,
91 u64 *startp, u64 end);
92
93int perf_mmap__push(struct perf_mmap *md, bool backward,
94 void *to, int push(void *to, void *buf, size_t size));
95
96size_t perf_mmap__mmap_len(struct perf_mmap *map);
97
98int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
99 u64 *startp, u64 *endp);
100void perf_mmap__read_done(struct perf_mmap *map);
101#endif
102