perf: Add API for PMUs to write to the AUX area
[deliverable/linux.git] / kernel / events / internal.h
1 #ifndef _KERNEL_EVENTS_INTERNAL_H
2 #define _KERNEL_EVENTS_INTERNAL_H
3
4 #include <linux/hardirq.h>
5 #include <linux/uaccess.h>
6
7 /* Buffer handling */
8
9 #define RING_BUFFER_WRITABLE 0x01
10
11 struct ring_buffer {
12 atomic_t refcount;
13 struct rcu_head rcu_head;
14 #ifdef CONFIG_PERF_USE_VMALLOC
15 struct work_struct work;
16 int page_order; /* allocation order */
17 #endif
18 int nr_pages; /* nr of data pages */
19 int overwrite; /* can overwrite itself */
20
21 atomic_t poll; /* POLL_ for wakeups */
22
23 local_t head; /* write position */
24 local_t nest; /* nested writers */
25 local_t events; /* event limit */
26 local_t wakeup; /* wakeup stamp */
27 local_t lost; /* nr records lost */
28
29 long watermark; /* wakeup watermark */
30 /* poll crap */
31 spinlock_t event_lock;
32 struct list_head event_list;
33
34 atomic_t mmap_count;
35 unsigned long mmap_locked;
36 struct user_struct *mmap_user;
37
38 /* AUX area */
39 local_t aux_head;
40 local_t aux_nest;
41 unsigned long aux_pgoff;
42 int aux_nr_pages;
43 atomic_t aux_mmap_count;
44 unsigned long aux_mmap_locked;
45 void (*free_aux)(void *);
46 atomic_t aux_refcount;
47 void **aux_pages;
48 void *aux_priv;
49
50 struct perf_event_mmap_page *user_page;
51 void *data_pages[0];
52 };
53
54 extern void rb_free(struct ring_buffer *rb);
55 extern struct ring_buffer *
56 rb_alloc(int nr_pages, long watermark, int cpu, int flags);
57 extern void perf_event_wakeup(struct perf_event *event);
58 extern int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,
59 pgoff_t pgoff, int nr_pages, int flags);
60 extern void rb_free_aux(struct ring_buffer *rb);
61 extern struct ring_buffer *ring_buffer_get(struct perf_event *event);
62 extern void ring_buffer_put(struct ring_buffer *rb);
63
64 static inline bool rb_has_aux(struct ring_buffer *rb)
65 {
66 return !!rb->aux_nr_pages;
67 }
68
69 void perf_event_aux_event(struct perf_event *event, unsigned long head,
70 unsigned long size, u64 flags);
71
72 extern void
73 perf_event_header__init_id(struct perf_event_header *header,
74 struct perf_sample_data *data,
75 struct perf_event *event);
76 extern void
77 perf_event__output_id_sample(struct perf_event *event,
78 struct perf_output_handle *handle,
79 struct perf_sample_data *sample);
80
81 extern struct page *
82 perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff);
83
84 #ifdef CONFIG_PERF_USE_VMALLOC
85 /*
86 * Back perf_mmap() with vmalloc memory.
87 *
88 * Required for architectures that have d-cache aliasing issues.
89 */
90
91 static inline int page_order(struct ring_buffer *rb)
92 {
93 return rb->page_order;
94 }
95
96 #else
97
98 static inline int page_order(struct ring_buffer *rb)
99 {
100 return 0;
101 }
102 #endif
103
104 static inline unsigned long perf_data_size(struct ring_buffer *rb)
105 {
106 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
107 }
108
109 static inline unsigned long perf_aux_size(struct ring_buffer *rb)
110 {
111 return rb->aux_nr_pages << PAGE_SHIFT;
112 }
113
114 #define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
115 static inline unsigned long \
116 func_name(struct perf_output_handle *handle, \
117 const void *buf, unsigned long len) \
118 { \
119 unsigned long size, written; \
120 \
121 do { \
122 size = min(handle->size, len); \
123 written = memcpy_func(handle->addr, buf, size); \
124 written = size - written; \
125 \
126 len -= written; \
127 handle->addr += written; \
128 buf += written; \
129 handle->size -= written; \
130 if (!handle->size) { \
131 struct ring_buffer *rb = handle->rb; \
132 \
133 handle->page++; \
134 handle->page &= rb->nr_pages - 1; \
135 handle->addr = rb->data_pages[handle->page]; \
136 handle->size = PAGE_SIZE << page_order(rb); \
137 } \
138 } while (len && written == size); \
139 \
140 return len; \
141 }
142
143 static inline unsigned long
144 memcpy_common(void *dst, const void *src, unsigned long n)
145 {
146 memcpy(dst, src, n);
147 return 0;
148 }
149
150 DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
151
152 static inline unsigned long
153 memcpy_skip(void *dst, const void *src, unsigned long n)
154 {
155 return 0;
156 }
157
158 DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
159
160 #ifndef arch_perf_out_copy_user
161 #define arch_perf_out_copy_user arch_perf_out_copy_user
162
163 static inline unsigned long
164 arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
165 {
166 unsigned long ret;
167
168 pagefault_disable();
169 ret = __copy_from_user_inatomic(dst, src, n);
170 pagefault_enable();
171
172 return ret;
173 }
174 #endif
175
176 DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
177
178 /* Callchain handling */
179 extern struct perf_callchain_entry *
180 perf_callchain(struct perf_event *event, struct pt_regs *regs);
181 extern int get_callchain_buffers(void);
182 extern void put_callchain_buffers(void);
183
184 static inline int get_recursion_context(int *recursion)
185 {
186 int rctx;
187
188 if (in_nmi())
189 rctx = 3;
190 else if (in_irq())
191 rctx = 2;
192 else if (in_softirq())
193 rctx = 1;
194 else
195 rctx = 0;
196
197 if (recursion[rctx])
198 return -1;
199
200 recursion[rctx]++;
201 barrier();
202
203 return rctx;
204 }
205
206 static inline void put_recursion_context(int *recursion, int rctx)
207 {
208 barrier();
209 recursion[rctx]--;
210 }
211
212 #ifdef CONFIG_HAVE_PERF_USER_STACK_DUMP
213 static inline bool arch_perf_have_user_stack_dump(void)
214 {
215 return true;
216 }
217
218 #define perf_user_stack_pointer(regs) user_stack_pointer(regs)
219 #else
220 static inline bool arch_perf_have_user_stack_dump(void)
221 {
222 return false;
223 }
224
225 #define perf_user_stack_pointer(regs) 0
226 #endif /* CONFIG_HAVE_PERF_USER_STACK_DUMP */
227
228 #endif /* _KERNEL_EVENTS_INTERNAL_H */
This page took 0.041494 seconds and 5 git commands to generate.