Linux 4.1.18
[linux/fpc-iii.git] / kernel / events / internal.h
bloba6adc36a3732f537884367b108ce33af88bac57f
1 #ifndef _KERNEL_EVENTS_INTERNAL_H
2 #define _KERNEL_EVENTS_INTERNAL_H
4 #include <linux/hardirq.h>
5 #include <linux/uaccess.h>
7 /* Buffer handling */
9 #define RING_BUFFER_WRITABLE 0x01
11 struct ring_buffer {
12 atomic_t refcount;
13 struct rcu_head rcu_head;
14 struct irq_work irq_work;
15 #ifdef CONFIG_PERF_USE_VMALLOC
16 struct work_struct work;
17 int page_order; /* allocation order */
18 #endif
19 int nr_pages; /* nr of data pages */
20 int overwrite; /* can overwrite itself */
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 */
31 long aux_watermark;
32 /* poll crap */
33 spinlock_t event_lock;
34 struct list_head event_list;
36 atomic_t mmap_count;
37 unsigned long mmap_locked;
38 struct user_struct *mmap_user;
40 /* AUX area */
41 local_t aux_head;
42 local_t aux_nest;
43 local_t aux_wakeup;
44 unsigned long aux_pgoff;
45 int aux_nr_pages;
46 int aux_overwrite;
47 atomic_t aux_mmap_count;
48 unsigned long aux_mmap_locked;
49 void (*free_aux)(void *);
50 atomic_t aux_refcount;
51 void **aux_pages;
52 void *aux_priv;
54 struct perf_event_mmap_page *user_page;
55 void *data_pages[0];
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);
65 rb_free(rb);
68 extern struct ring_buffer *
69 rb_alloc(int nr_pages, long watermark, int cpu, int flags);
70 extern void perf_event_wakeup(struct perf_event *event);
71 extern int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,
72 pgoff_t pgoff, int nr_pages, long watermark, int flags);
73 extern void rb_free_aux(struct ring_buffer *rb);
74 extern struct ring_buffer *ring_buffer_get(struct perf_event *event);
75 extern void ring_buffer_put(struct ring_buffer *rb);
77 static inline bool rb_has_aux(struct ring_buffer *rb)
79 return !!rb->aux_nr_pages;
82 void perf_event_aux_event(struct perf_event *event, unsigned long head,
83 unsigned long size, u64 flags);
85 extern void
86 perf_event_header__init_id(struct perf_event_header *header,
87 struct perf_sample_data *data,
88 struct perf_event *event);
89 extern void
90 perf_event__output_id_sample(struct perf_event *event,
91 struct perf_output_handle *handle,
92 struct perf_sample_data *sample);
94 extern struct page *
95 perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff);
97 #ifdef CONFIG_PERF_USE_VMALLOC
99 * Back perf_mmap() with vmalloc memory.
101 * Required for architectures that have d-cache aliasing issues.
104 static inline int page_order(struct ring_buffer *rb)
106 return rb->page_order;
109 #else
111 static inline int page_order(struct ring_buffer *rb)
113 return 0;
115 #endif
117 static inline unsigned long perf_data_size(struct ring_buffer *rb)
119 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
122 static inline unsigned long perf_aux_size(struct ring_buffer *rb)
124 return rb->aux_nr_pages << PAGE_SHIFT;
127 #define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
128 static inline unsigned long \
129 func_name(struct perf_output_handle *handle, \
130 const void *buf, unsigned long len) \
132 unsigned long size, written; \
134 do { \
135 size = min(handle->size, len); \
136 written = memcpy_func(handle->addr, buf, size); \
137 written = size - written; \
139 len -= written; \
140 handle->addr += written; \
141 buf += written; \
142 handle->size -= written; \
143 if (!handle->size) { \
144 struct ring_buffer *rb = handle->rb; \
146 handle->page++; \
147 handle->page &= rb->nr_pages - 1; \
148 handle->addr = rb->data_pages[handle->page]; \
149 handle->size = PAGE_SIZE << page_order(rb); \
151 } while (len && written == size); \
153 return len; \
156 static inline unsigned long
157 memcpy_common(void *dst, const void *src, unsigned long n)
159 memcpy(dst, src, n);
160 return 0;
163 DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
165 static inline unsigned long
166 memcpy_skip(void *dst, const void *src, unsigned long n)
168 return 0;
171 DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
173 #ifndef arch_perf_out_copy_user
174 #define arch_perf_out_copy_user arch_perf_out_copy_user
176 static inline unsigned long
177 arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
179 unsigned long ret;
181 pagefault_disable();
182 ret = __copy_from_user_inatomic(dst, src, n);
183 pagefault_enable();
185 return ret;
187 #endif
189 DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
191 /* Callchain handling */
192 extern struct perf_callchain_entry *
193 perf_callchain(struct perf_event *event, struct pt_regs *regs);
194 extern int get_callchain_buffers(void);
195 extern void put_callchain_buffers(void);
197 static inline int get_recursion_context(int *recursion)
199 int rctx;
201 if (in_nmi())
202 rctx = 3;
203 else if (in_irq())
204 rctx = 2;
205 else if (in_softirq())
206 rctx = 1;
207 else
208 rctx = 0;
210 if (recursion[rctx])
211 return -1;
213 recursion[rctx]++;
214 barrier();
216 return rctx;
219 static inline void put_recursion_context(int *recursion, int rctx)
221 barrier();
222 recursion[rctx]--;
225 #ifdef CONFIG_HAVE_PERF_USER_STACK_DUMP
226 static inline bool arch_perf_have_user_stack_dump(void)
228 return true;
231 #define perf_user_stack_pointer(regs) user_stack_pointer(regs)
232 #else
233 static inline bool arch_perf_have_user_stack_dump(void)
235 return false;
238 #define perf_user_stack_pointer(regs) 0
239 #endif /* CONFIG_HAVE_PERF_USER_STACK_DUMP */
241 #endif /* _KERNEL_EVENTS_INTERNAL_H */