1 #ifndef _KERNEL_EVENTS_INTERNAL_H
2 #define _KERNEL_EVENTS_INTERNAL_H
4 #include <linux/hardirq.h>
5 #include <linux/uaccess.h>
9 #define RING_BUFFER_WRITABLE 0x01
13 struct rcu_head rcu_head
;
14 #ifdef CONFIG_PERF_USE_VMALLOC
15 struct work_struct work
;
16 int page_order
; /* allocation order */
18 int nr_pages
; /* nr of data pages */
19 int overwrite
; /* can overwrite itself */
20 int paused
; /* can write into ring buffer */
22 atomic_t poll
; /* POLL_ for wakeups */
24 local_t head
; /* write position */
25 local_t nest
; /* nested writers */
26 local_t events
; /* event limit */
27 local_t wakeup
; /* wakeup stamp */
28 local_t lost
; /* nr records lost */
30 long watermark
; /* wakeup watermark */
33 spinlock_t event_lock
;
34 struct list_head event_list
;
37 unsigned long mmap_locked
;
38 struct user_struct
*mmap_user
;
44 unsigned long aux_pgoff
;
47 atomic_t aux_mmap_count
;
48 unsigned long aux_mmap_locked
;
49 void (*free_aux
)(void *);
50 atomic_t aux_refcount
;
54 struct perf_event_mmap_page
*user_page
;
58 extern void rb_free(struct ring_buffer
*rb
);
60 static inline void rb_free_rcu(struct rcu_head
*rcu_head
)
62 struct ring_buffer
*rb
;
64 rb
= container_of(rcu_head
, struct ring_buffer
, rcu_head
);
68 static inline void rb_toggle_paused(struct ring_buffer
*rb
, bool pause
)
70 if (!pause
&& rb
->nr_pages
)
76 extern struct ring_buffer
*
77 rb_alloc(int nr_pages
, long watermark
, int cpu
, int flags
);
78 extern void perf_event_wakeup(struct perf_event
*event
);
79 extern int rb_alloc_aux(struct ring_buffer
*rb
, struct perf_event
*event
,
80 pgoff_t pgoff
, int nr_pages
, long watermark
, int flags
);
81 extern void rb_free_aux(struct ring_buffer
*rb
);
82 extern struct ring_buffer
*ring_buffer_get(struct perf_event
*event
);
83 extern void ring_buffer_put(struct ring_buffer
*rb
);
85 static inline bool rb_has_aux(struct ring_buffer
*rb
)
87 return !!rb
->aux_nr_pages
;
90 void perf_event_aux_event(struct perf_event
*event
, unsigned long head
,
91 unsigned long size
, u64 flags
);
94 perf_mmap_to_page(struct ring_buffer
*rb
, unsigned long pgoff
);
96 #ifdef CONFIG_PERF_USE_VMALLOC
98 * Back perf_mmap() with vmalloc memory.
100 * Required for architectures that have d-cache aliasing issues.
103 static inline int page_order(struct ring_buffer
*rb
)
105 return rb
->page_order
;
110 static inline int page_order(struct ring_buffer
*rb
)
116 static inline unsigned long perf_data_size(struct ring_buffer
*rb
)
118 return rb
->nr_pages
<< (PAGE_SHIFT
+ page_order(rb
));
121 static inline unsigned long perf_aux_size(struct ring_buffer
*rb
)
123 return rb
->aux_nr_pages
<< PAGE_SHIFT
;
126 #define __DEFINE_OUTPUT_COPY_BODY(memcpy_func) \
128 unsigned long size, written; \
131 size = min(handle->size, len); \
132 written = memcpy_func(handle->addr, buf, size); \
133 written = size - written; \
136 handle->addr += written; \
138 handle->size -= written; \
139 if (!handle->size) { \
140 struct ring_buffer *rb = handle->rb; \
143 handle->page &= rb->nr_pages - 1; \
144 handle->addr = rb->data_pages[handle->page]; \
145 handle->size = PAGE_SIZE << page_order(rb); \
147 } while (len && written == size); \
152 #define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
153 static inline unsigned long \
154 func_name(struct perf_output_handle *handle, \
155 const void *buf, unsigned long len) \
156 __DEFINE_OUTPUT_COPY_BODY(memcpy_func)
158 static inline unsigned long
159 __output_custom(struct perf_output_handle
*handle
, perf_copy_f copy_func
,
160 const void *buf
, unsigned long len
)
161 __DEFINE_OUTPUT_COPY_BODY(copy_func
)
163 static inline unsigned long
164 memcpy_common(void *dst
, const void *src
, unsigned long n
)
170 DEFINE_OUTPUT_COPY(__output_copy
, memcpy_common
)
172 static inline unsigned long
173 memcpy_skip(void *dst
, const void *src
, unsigned long n
)
178 DEFINE_OUTPUT_COPY(__output_skip
, memcpy_skip
)
180 #ifndef arch_perf_out_copy_user
181 #define arch_perf_out_copy_user arch_perf_out_copy_user
183 static inline unsigned long
184 arch_perf_out_copy_user(void *dst
, const void *src
, unsigned long n
)
189 ret
= __copy_from_user_inatomic(dst
, src
, n
);
196 DEFINE_OUTPUT_COPY(__output_copy_user
, arch_perf_out_copy_user
)
198 /* Callchain handling */
199 extern struct perf_callchain_entry
*
200 perf_callchain(struct perf_event
*event
, struct pt_regs
*regs
);
202 static inline int get_recursion_context(int *recursion
)
210 else if (in_softirq())
224 static inline void put_recursion_context(int *recursion
, int rctx
)
230 #ifdef CONFIG_HAVE_PERF_USER_STACK_DUMP
231 static inline bool arch_perf_have_user_stack_dump(void)
236 #define perf_user_stack_pointer(regs) user_stack_pointer(regs)
238 static inline bool arch_perf_have_user_stack_dump(void)
243 #define perf_user_stack_pointer(regs) 0
244 #endif /* CONFIG_HAVE_PERF_USER_STACK_DUMP */
246 #endif /* _KERNEL_EVENTS_INTERNAL_H */