Linux Perf
mmap.h
Go to the documentation of this file.
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 
17 struct perf_mmap {
18  void *base;
19  int mask;
20  int fd;
21  refcount_t refcnt;
22  u64 prev;
23  u64 start;
24  u64 end;
25  bool overwrite;
27  char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
28 };
29 
30 /*
31  * State machine of bkw_mmap_state:
32  *
33  * .________________(forbid)_____________.
34  * | V
35  * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
36  * ^ ^ | ^ |
37  * | |__(forbid)____/ |___(forbid)___/|
38  * | |
39  * \_________________(3)_______________/
40  *
41  * NOTREADY : Backward ring buffers are not ready
42  * RUNNING : Backward ring buffers are recording
43  * DATA_PENDING : We are required to collect data from backward ring buffers
44  * EMPTY : We have collected data from backward ring buffers.
45  *
46  * (0): Setup backward ring buffer
47  * (1): Pause ring buffers for reading
48  * (2): Read from ring buffers
49  * (3): Resume ring buffers for recording
50  */
56 };
57 
58 struct mmap_params {
59  int prot, mask;
60  struct auxtrace_mmap_params auxtrace_mp;
61 };
62 
63 int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd);
64 void perf_mmap__munmap(struct perf_mmap *map);
65 
66 void perf_mmap__get(struct perf_mmap *map);
67 void perf_mmap__put(struct perf_mmap *map);
68 
69 void perf_mmap__consume(struct perf_mmap *map);
70 
71 static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
72 {
73  struct perf_event_mmap_page *pc = mm->base;
74  u64 head = READ_ONCE(pc->data_head);
75  rmb();
76  return head;
77 }
78 
79 static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
80 {
81  struct perf_event_mmap_page *pc = md->base;
82 
83  /*
84  * ensure all reads are done before we write the tail out.
85  */
86  mb();
87  pc->data_tail = tail;
88 }
89 
91 
92 union perf_event *perf_mmap__read_event(struct perf_mmap *map);
93 
94 int perf_mmap__push(struct perf_mmap *md, void *to,
95  int push(void *to, void *buf, size_t size));
96 
97 size_t perf_mmap__mmap_len(struct perf_mmap *map);
98 
99 int perf_mmap__read_init(struct perf_mmap *md);
100 void perf_mmap__read_done(struct perf_mmap *map);
101 #endif /*__PERF_MMAP_H */
char event_copy [PERF_SAMPLE_MAX_SIZE] __aligned(8)
refcount_t refcnt
Definition: mmap.h:21
size_t size
Definition: evsel.c:60
void perf_mmap__read_done(struct perf_mmap *map)
Definition: mmap.c:329
union perf_event * perf_mmap__read_event(struct perf_mmap *map)
Definition: mmap.c:78
int mask
Definition: mmap.h:19
bool overwrite
Definition: mmap.h:25
int fd
Definition: mmap.h:20
size_t perf_mmap__mmap_len(struct perf_mmap *map)
Definition: mmap.c:18
Definition: mmap.h:17
static void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
Definition: mmap.h:79
int prot
Definition: mmap.h:59
bkw_mmap_state
Definition: mmap.h:51
void perf_mmap__consume(struct perf_mmap *map)
Definition: mmap.c:118
void perf_mmap__munmap(struct perf_mmap *map)
Definition: mmap.c:156
void perf_mmap__put(struct perf_mmap *map)
Definition: mmap.c:110
u64 start
Definition: mmap.h:23
int perf_mmap__read_init(struct perf_mmap *md)
Definition: mmap.c:271
u64 prev
Definition: mmap.h:22
Definition: jevents.c:228
int perf_mmap__push(struct perf_mmap *md, void *to, int push(void *to, void *buf, size_t size))
Definition: mmap.c:282
#define PERF_SAMPLE_MAX_SIZE
Definition: event.h:95
int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
Definition: mmap.c:167
void perf_mmap__get(struct perf_mmap *map)
Definition: mmap.c:105
static u64 perf_mmap__read_head(struct perf_mmap *mm)
Definition: mmap.h:71
void * base
Definition: mmap.h:18
u64 end
Definition: mmap.h:24
union perf_event * perf_mmap__read_forward(struct perf_mmap *map)