]>
Commit | Line | Data |
---|---|---|
718c602d AH |
1 | /* |
2 | * auxtrace.h: AUX area trace support | |
3 | * Copyright (c) 2013-2015, Intel Corporation. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms and conditions of the GNU General Public License, | |
7 | * version 2, as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | */ | |
15 | ||
16 | #ifndef __PERF_AUXTRACE_H | |
17 | #define __PERF_AUXTRACE_H | |
18 | ||
19 | #include <sys/types.h> | |
20 | #include <stdbool.h> | |
9e0cc4fe | 21 | #include <stddef.h> |
718c602d AH |
22 | #include <linux/perf_event.h> |
23 | #include <linux/types.h> | |
24 | ||
25 | #include "../perf.h" | |
c446870d | 26 | #include "session.h" |
718c602d | 27 | |
9e0cc4fe AH |
28 | union perf_event; |
29 | struct perf_session; | |
718c602d | 30 | struct perf_evlist; |
9e0cc4fe AH |
31 | struct perf_tool; |
32 | struct record_opts; | |
33 | struct auxtrace_info_event; | |
718c602d | 34 | |
c446870d AH |
35 | /** |
36 | * struct auxtrace - session callbacks to allow AUX area data decoding. | |
37 | * @process_event: lets the decoder see all session events | |
38 | * @flush_events: process any remaining data | |
39 | * @free_events: free resources associated with event processing | |
40 | * @free: free resources associated with the session | |
41 | */ | |
42 | struct auxtrace { | |
43 | int (*process_event)(struct perf_session *session, | |
44 | union perf_event *event, | |
45 | struct perf_sample *sample, | |
46 | struct perf_tool *tool); | |
47 | int (*flush_events)(struct perf_session *session, | |
48 | struct perf_tool *tool); | |
49 | void (*free_events)(struct perf_session *session); | |
50 | void (*free)(struct perf_session *session); | |
51 | }; | |
52 | ||
718c602d AH |
53 | /** |
54 | * struct auxtrace_mmap - records an mmap of the auxtrace buffer. | |
55 | * @base: address of mapped area | |
56 | * @userpg: pointer to buffer's perf_event_mmap_page | |
57 | * @mask: %0 if @len is not a power of two, otherwise (@len - %1) | |
58 | * @len: size of mapped area | |
59 | * @prev: previous aux_head | |
60 | * @idx: index of this mmap | |
61 | * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu | |
62 | * mmap) otherwise %0 | |
63 | * @cpu: cpu number for a per-cpu mmap otherwise %-1 | |
64 | */ | |
65 | struct auxtrace_mmap { | |
66 | void *base; | |
67 | void *userpg; | |
68 | size_t mask; | |
69 | size_t len; | |
70 | u64 prev; | |
71 | int idx; | |
72 | pid_t tid; | |
73 | int cpu; | |
74 | }; | |
75 | ||
76 | /** | |
77 | * struct auxtrace_mmap_params - parameters to set up struct auxtrace_mmap. | |
78 | * @mask: %0 if @len is not a power of two, otherwise (@len - %1) | |
79 | * @offset: file offset of mapped area | |
80 | * @len: size of mapped area | |
81 | * @prot: mmap memory protection | |
82 | * @idx: index of this mmap | |
83 | * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu | |
84 | * mmap) otherwise %0 | |
85 | * @cpu: cpu number for a per-cpu mmap otherwise %-1 | |
86 | */ | |
87 | struct auxtrace_mmap_params { | |
88 | size_t mask; | |
89 | off_t offset; | |
90 | size_t len; | |
91 | int prot; | |
92 | int idx; | |
93 | pid_t tid; | |
94 | int cpu; | |
95 | }; | |
96 | ||
9e0cc4fe AH |
97 | /** |
98 | * struct auxtrace_record - callbacks for recording AUX area data. | |
99 | * @recording_options: validate and process recording options | |
100 | * @info_priv_size: return the size of the private data in auxtrace_info_event | |
101 | * @info_fill: fill-in the private data in auxtrace_info_event | |
102 | * @free: free this auxtrace record structure | |
103 | * @reference: provide a 64-bit reference number for auxtrace_event | |
104 | * @read_finish: called after reading from an auxtrace mmap | |
105 | */ | |
106 | struct auxtrace_record { | |
107 | int (*recording_options)(struct auxtrace_record *itr, | |
108 | struct perf_evlist *evlist, | |
109 | struct record_opts *opts); | |
110 | size_t (*info_priv_size)(struct auxtrace_record *itr); | |
111 | int (*info_fill)(struct auxtrace_record *itr, | |
112 | struct perf_session *session, | |
113 | struct auxtrace_info_event *auxtrace_info, | |
114 | size_t priv_size); | |
115 | void (*free)(struct auxtrace_record *itr); | |
116 | u64 (*reference)(struct auxtrace_record *itr); | |
117 | int (*read_finish)(struct auxtrace_record *itr, int idx); | |
118 | }; | |
119 | ||
718c602d AH |
120 | static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm) |
121 | { | |
122 | struct perf_event_mmap_page *pc = mm->userpg; | |
123 | #if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) | |
124 | u64 head = ACCESS_ONCE(pc->aux_head); | |
125 | #else | |
126 | u64 head = __sync_val_compare_and_swap(&pc->aux_head, 0, 0); | |
127 | #endif | |
128 | ||
129 | /* Ensure all reads are done after we read the head */ | |
130 | rmb(); | |
131 | return head; | |
132 | } | |
133 | ||
134 | static inline void auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) | |
135 | { | |
136 | struct perf_event_mmap_page *pc = mm->userpg; | |
137 | #if BITS_PER_LONG != 64 && defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) | |
138 | u64 old_tail; | |
139 | #endif | |
140 | ||
141 | /* Ensure all reads are done before we write the tail out */ | |
142 | mb(); | |
143 | #if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) | |
144 | pc->aux_tail = tail; | |
145 | #else | |
146 | do { | |
147 | old_tail = __sync_val_compare_and_swap(&pc->aux_tail, 0, 0); | |
148 | } while (!__sync_bool_compare_and_swap(&pc->aux_tail, old_tail, tail)); | |
149 | #endif | |
150 | } | |
151 | ||
152 | int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, | |
153 | struct auxtrace_mmap_params *mp, | |
154 | void *userpg, int fd); | |
155 | void auxtrace_mmap__munmap(struct auxtrace_mmap *mm); | |
156 | void auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp, | |
157 | off_t auxtrace_offset, | |
158 | unsigned int auxtrace_pages, | |
159 | bool auxtrace_overwrite); | |
160 | void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, | |
161 | struct perf_evlist *evlist, int idx, | |
162 | bool per_cpu); | |
163 | ||
9e0cc4fe AH |
164 | typedef int (*process_auxtrace_t)(struct perf_tool *tool, |
165 | union perf_event *event, void *data1, | |
166 | size_t len1, void *data2, size_t len2); | |
167 | ||
168 | int auxtrace_mmap__read(struct auxtrace_mmap *mm, struct auxtrace_record *itr, | |
169 | struct perf_tool *tool, process_auxtrace_t fn); | |
170 | ||
171 | struct auxtrace_record *auxtrace_record__init(struct perf_evlist *evlist, | |
172 | int *err); | |
173 | ||
174 | int auxtrace_record__options(struct auxtrace_record *itr, | |
175 | struct perf_evlist *evlist, | |
176 | struct record_opts *opts); | |
177 | size_t auxtrace_record__info_priv_size(struct auxtrace_record *itr); | |
178 | int auxtrace_record__info_fill(struct auxtrace_record *itr, | |
179 | struct perf_session *session, | |
180 | struct auxtrace_info_event *auxtrace_info, | |
181 | size_t priv_size); | |
182 | void auxtrace_record__free(struct auxtrace_record *itr); | |
183 | u64 auxtrace_record__reference(struct auxtrace_record *itr); | |
184 | ||
185 | int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr, | |
186 | struct perf_tool *tool, | |
187 | struct perf_session *session, | |
188 | perf_event__handler_t process); | |
189 | ||
c446870d AH |
190 | static inline int auxtrace__process_event(struct perf_session *session, |
191 | union perf_event *event, | |
192 | struct perf_sample *sample, | |
193 | struct perf_tool *tool) | |
194 | { | |
195 | if (!session->auxtrace) | |
196 | return 0; | |
197 | ||
198 | return session->auxtrace->process_event(session, event, sample, tool); | |
199 | } | |
200 | ||
201 | static inline int auxtrace__flush_events(struct perf_session *session, | |
202 | struct perf_tool *tool) | |
203 | { | |
204 | if (!session->auxtrace) | |
205 | return 0; | |
206 | ||
207 | return session->auxtrace->flush_events(session, tool); | |
208 | } | |
209 | ||
210 | static inline void auxtrace__free_events(struct perf_session *session) | |
211 | { | |
212 | if (!session->auxtrace) | |
213 | return; | |
214 | ||
215 | return session->auxtrace->free_events(session); | |
216 | } | |
217 | ||
218 | static inline void auxtrace__free(struct perf_session *session) | |
219 | { | |
220 | if (!session->auxtrace) | |
221 | return; | |
222 | ||
223 | return session->auxtrace->free(session); | |
224 | } | |
225 | ||
718c602d | 226 | #endif |