Linux Audio

Check our new training course

Loading...
v3.15
  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
 11struct 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	struct perf_event_mmap_page	*user_page;
 39	void				*data_pages[0];
 40};
 41
 42extern void rb_free(struct ring_buffer *rb);
 43extern struct ring_buffer *
 44rb_alloc(int nr_pages, long watermark, int cpu, int flags);
 45extern void perf_event_wakeup(struct perf_event *event);
 46
 47extern void
 48perf_event_header__init_id(struct perf_event_header *header,
 49			   struct perf_sample_data *data,
 50			   struct perf_event *event);
 51extern void
 52perf_event__output_id_sample(struct perf_event *event,
 53			     struct perf_output_handle *handle,
 54			     struct perf_sample_data *sample);
 55
 56extern struct page *
 57perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff);
 58
 59#ifdef CONFIG_PERF_USE_VMALLOC
 60/*
 61 * Back perf_mmap() with vmalloc memory.
 62 *
 63 * Required for architectures that have d-cache aliasing issues.
 64 */
 65
 66static inline int page_order(struct ring_buffer *rb)
 67{
 68	return rb->page_order;
 69}
 70
 71#else
 72
 73static inline int page_order(struct ring_buffer *rb)
 74{
 75	return 0;
 76}
 77#endif
 78
 79static inline unsigned long perf_data_size(struct ring_buffer *rb)
 80{
 81	return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
 82}
 83
 84#define DEFINE_OUTPUT_COPY(func_name, memcpy_func)			\
 85static inline unsigned long						\
 86func_name(struct perf_output_handle *handle,				\
 87	  const void *buf, unsigned long len)				\
 88{									\
 89	unsigned long size, written;					\
 90									\
 91	do {								\
 92		size    = min(handle->size, len);			\
 93		written = memcpy_func(handle->addr, buf, size);		\
 94		written = size - written;				\
 95									\
 96		len -= written;						\
 97		handle->addr += written;				\
 98		buf += written;						\
 99		handle->size -= written;				\
100		if (!handle->size) {					\
101			struct ring_buffer *rb = handle->rb;		\
102									\
103			handle->page++;					\
104			handle->page &= rb->nr_pages - 1;		\
105			handle->addr = rb->data_pages[handle->page];	\
106			handle->size = PAGE_SIZE << page_order(rb);	\
107		}							\
108	} while (len && written == size);				\
109									\
110	return len;							\
111}
112
113static inline unsigned long
114memcpy_common(void *dst, const void *src, unsigned long n)
115{
116	memcpy(dst, src, n);
117	return 0;
118}
119
120DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
121
122static inline unsigned long
123memcpy_skip(void *dst, const void *src, unsigned long n)
124{
125	return 0;
126}
127
128DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
129
130#ifndef arch_perf_out_copy_user
131#define arch_perf_out_copy_user arch_perf_out_copy_user
132
133static inline unsigned long
134arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
135{
136	unsigned long ret;
137
138	pagefault_disable();
139	ret = __copy_from_user_inatomic(dst, src, n);
140	pagefault_enable();
141
142	return ret;
143}
144#endif
145
146DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
147
148/* Callchain handling */
149extern struct perf_callchain_entry *
150perf_callchain(struct perf_event *event, struct pt_regs *regs);
151extern int get_callchain_buffers(void);
152extern void put_callchain_buffers(void);
153
154static inline int get_recursion_context(int *recursion)
155{
156	int rctx;
157
158	if (in_nmi())
159		rctx = 3;
160	else if (in_irq())
161		rctx = 2;
162	else if (in_softirq())
163		rctx = 1;
164	else
165		rctx = 0;
166
167	if (recursion[rctx])
168		return -1;
169
170	recursion[rctx]++;
171	barrier();
172
173	return rctx;
174}
175
176static inline void put_recursion_context(int *recursion, int rctx)
177{
178	barrier();
179	recursion[rctx]--;
180}
181
182#ifdef CONFIG_HAVE_PERF_USER_STACK_DUMP
183static inline bool arch_perf_have_user_stack_dump(void)
184{
185	return true;
186}
187
188#define perf_user_stack_pointer(regs) user_stack_pointer(regs)
189#else
190static inline bool arch_perf_have_user_stack_dump(void)
191{
192	return false;
193}
194
195#define perf_user_stack_pointer(regs) 0
196#endif /* CONFIG_HAVE_PERF_USER_STACK_DUMP */
197
198#endif /* _KERNEL_EVENTS_INTERNAL_H */
v3.1
 1#ifndef _KERNEL_EVENTS_INTERNAL_H
 2#define _KERNEL_EVENTS_INTERNAL_H
 3
 
 
 
 
 
 4#define RING_BUFFER_WRITABLE		0x01
 5
 6struct ring_buffer {
 7	atomic_t			refcount;
 8	struct rcu_head			rcu_head;
 9#ifdef CONFIG_PERF_USE_VMALLOC
10	struct work_struct		work;
11	int				page_order;	/* allocation order  */
12#endif
13	int				nr_pages;	/* nr of data pages  */
14	int				writable;	/* are we writable   */
15
16	atomic_t			poll;		/* POLL_ for wakeups */
17
18	local_t				head;		/* write position    */
19	local_t				nest;		/* nested writers    */
20	local_t				events;		/* event limit       */
21	local_t				wakeup;		/* wakeup stamp      */
22	local_t				lost;		/* nr records lost   */
23
24	long				watermark;	/* wakeup watermark  */
 
 
 
 
 
 
 
25
26	struct perf_event_mmap_page	*user_page;
27	void				*data_pages[0];
28};
29
30extern void rb_free(struct ring_buffer *rb);
31extern struct ring_buffer *
32rb_alloc(int nr_pages, long watermark, int cpu, int flags);
33extern void perf_event_wakeup(struct perf_event *event);
34
35extern void
36perf_event_header__init_id(struct perf_event_header *header,
37			   struct perf_sample_data *data,
38			   struct perf_event *event);
39extern void
40perf_event__output_id_sample(struct perf_event *event,
41			     struct perf_output_handle *handle,
42			     struct perf_sample_data *sample);
43
44extern struct page *
45perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff);
46
47#ifdef CONFIG_PERF_USE_VMALLOC
48/*
49 * Back perf_mmap() with vmalloc memory.
50 *
51 * Required for architectures that have d-cache aliasing issues.
52 */
53
54static inline int page_order(struct ring_buffer *rb)
55{
56	return rb->page_order;
57}
58
59#else
60
61static inline int page_order(struct ring_buffer *rb)
62{
63	return 0;
64}
65#endif
66
67static unsigned long perf_data_size(struct ring_buffer *rb)
68{
69	return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
70}
71
72static inline void
73__output_copy(struct perf_output_handle *handle,
74		   const void *buf, unsigned int len)
75{
76	do {
77		unsigned long size = min_t(unsigned long, handle->size, len);
78
79		memcpy(handle->addr, buf, size);
80
81		len -= size;
82		handle->addr += size;
83		buf += size;
84		handle->size -= size;
85		if (!handle->size) {
86			struct ring_buffer *rb = handle->rb;
87
88			handle->page++;
89			handle->page &= rb->nr_pages - 1;
90			handle->addr = rb->data_pages[handle->page];
91			handle->size = PAGE_SIZE << page_order(rb);
92		}
93	} while (len);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96#endif /* _KERNEL_EVENTS_INTERNAL_H */