1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef OPROFILE_H
14#define OPROFILE_H
15
16#include <linux/types.h>
17#include <linux/spinlock.h>
18#include <linux/init.h>
19#include <linux/errno.h>
20#include <linux/printk.h>
21#include <linux/atomic.h>
22
23
24
25
26
27
28
29#define ESCAPE_CODE ~0UL
30#define CTX_SWITCH_CODE 1
31#define CPU_SWITCH_CODE 2
32#define COOKIE_SWITCH_CODE 3
33#define KERNEL_ENTER_SWITCH_CODE 4
34#define KERNEL_EXIT_SWITCH_CODE 5
35#define MODULE_LOADED_CODE 6
36#define CTX_TGID_CODE 7
37#define TRACE_BEGIN_CODE 8
38#define TRACE_END_CODE 9
39#define XEN_ENTER_SWITCH_CODE 10
40#define SPU_PROFILING_CODE 11
41#define SPU_CTX_SWITCH_CODE 12
42#define IBS_FETCH_CODE 13
43#define IBS_OP_CODE 14
44
45struct dentry;
46struct file_operations;
47struct pt_regs;
48
49
50struct oprofile_operations {
51
52
53 int (*create_files)(struct dentry * root);
54
55 int (*setup)(void);
56
57 void (*shutdown)(void);
58
59 int (*start)(void);
60
61 void (*stop)(void);
62
63
64
65
66
67 int (*sync_start)(void);
68 int (*sync_stop)(void);
69
70
71 void (*backtrace)(struct pt_regs * const regs, unsigned int depth);
72
73
74 int (*switch_events)(void);
75
76 char * cpu_type;
77};
78
79
80
81
82
83
84
85
86int oprofile_arch_init(struct oprofile_operations * ops);
87
88
89
90
91void oprofile_arch_exit(void);
92
93
94
95
96void oprofile_add_sample(struct pt_regs * const regs, unsigned long event);
97
98
99
100
101
102
103
104
105void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
106 unsigned long event, int is_kernel);
107
108
109
110
111void oprofile_add_ext_hw_sample(unsigned long pc, struct pt_regs * const regs,
112 unsigned long event, int is_kernel,
113 struct task_struct *task);
114
115
116
117void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event);
118
119
120void oprofile_add_trace(unsigned long eip);
121
122
123
124
125
126
127int oprofilefs_create_file(struct dentry * root,
128 char const * name, const struct file_operations * fops);
129
130int oprofilefs_create_file_perm(struct dentry * root,
131 char const * name, const struct file_operations * fops, int perm);
132
133
134int oprofilefs_create_ulong(struct dentry * root,
135 char const * name, ulong * val);
136
137
138int oprofilefs_create_ro_ulong(struct dentry * root,
139 char const * name, ulong * val);
140
141
142int oprofilefs_create_ro_atomic(struct dentry * root,
143 char const * name, atomic_t * val);
144
145
146struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
147
148
149
150
151
152ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset);
153
154
155
156
157
158ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset);
159
160
161
162
163
164int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
165
166
167extern raw_spinlock_t oprofilefs_lock;
168
169
170
171
172void oprofile_put_buff(unsigned long *buf, unsigned int start,
173 unsigned int stop, unsigned int max);
174
175unsigned long oprofile_get_cpu_buffer_size(void);
176void oprofile_cpu_buffer_inc_smpl_lost(void);
177
178
179
180struct op_sample;
181
182struct op_entry {
183 struct ring_buffer_event *event;
184 struct op_sample *sample;
185 unsigned long size;
186 unsigned long *data;
187};
188
189void oprofile_write_reserve(struct op_entry *entry,
190 struct pt_regs * const regs,
191 unsigned long pc, int code, int size);
192int oprofile_add_data(struct op_entry *entry, unsigned long val);
193int oprofile_add_data64(struct op_entry *entry, u64 val);
194int oprofile_write_commit(struct op_entry *entry);
195
196#ifdef CONFIG_HW_PERF_EVENTS
197int __init oprofile_perf_init(struct oprofile_operations *ops);
198void oprofile_perf_exit(void);
199char *op_name_from_perf_id(void);
200#else
201static inline int __init oprofile_perf_init(struct oprofile_operations *ops)
202{
203 pr_info("oprofile: hardware counters not available\n");
204 return -ENODEV;
205}
206static inline void oprofile_perf_exit(void) { }
207#endif
208
209#endif
210