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 super_block;
46struct dentry;
47struct file_operations;
48struct pt_regs;
49
50
51struct oprofile_operations {
52
53
54 int (*create_files)(struct super_block * sb, struct dentry * root);
55
56 int (*setup)(void);
57
58 void (*shutdown)(void);
59
60 int (*start)(void);
61
62 void (*stop)(void);
63
64
65
66
67
68 int (*sync_start)(void);
69 int (*sync_stop)(void);
70
71
72 void (*backtrace)(struct pt_regs * const regs, unsigned int depth);
73
74
75 int (*switch_events)(void);
76
77 char * cpu_type;
78};
79
80
81
82
83
84
85
86
87int oprofile_arch_init(struct oprofile_operations * ops);
88
89
90
91
92void oprofile_arch_exit(void);
93
94
95
96
97void oprofile_add_sample(struct pt_regs * const regs, unsigned long event);
98
99
100
101
102
103
104
105
106void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
107 unsigned long event, int is_kernel);
108
109
110
111
112void oprofile_add_ext_hw_sample(unsigned long pc, struct pt_regs * const regs,
113 unsigned long event, int is_kernel,
114 struct task_struct *task);
115
116
117
118void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event);
119
120
121void oprofile_add_trace(unsigned long eip);
122
123
124
125
126
127
128int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
129 char const * name, const struct file_operations * fops);
130
131int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
132 char const * name, const struct file_operations * fops, int perm);
133
134
135int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
136 char const * name, ulong * val);
137
138
139int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
140 char const * name, ulong * val);
141
142
143int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
144 char const * name, atomic_t * val);
145
146
147struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
148 char const * name);
149
150
151
152
153
154ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset);
155
156
157
158
159
160ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset);
161
162
163
164
165
166int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
167
168
169extern raw_spinlock_t oprofilefs_lock;
170
171
172
173
174void oprofile_put_buff(unsigned long *buf, unsigned int start,
175 unsigned int stop, unsigned int max);
176
177unsigned long oprofile_get_cpu_buffer_size(void);
178void oprofile_cpu_buffer_inc_smpl_lost(void);
179
180
181
182struct op_sample;
183
184struct op_entry {
185 struct ring_buffer_event *event;
186 struct op_sample *sample;
187 unsigned long size;
188 unsigned long *data;
189};
190
191void oprofile_write_reserve(struct op_entry *entry,
192 struct pt_regs * const regs,
193 unsigned long pc, int code, int size);
194int oprofile_add_data(struct op_entry *entry, unsigned long val);
195int oprofile_add_data64(struct op_entry *entry, u64 val);
196int oprofile_write_commit(struct op_entry *entry);
197
198#ifdef CONFIG_HW_PERF_EVENTS
199int __init oprofile_perf_init(struct oprofile_operations *ops);
200void oprofile_perf_exit(void);
201char *op_name_from_perf_id(void);
202#else
203static inline int __init oprofile_perf_init(struct oprofile_operations *ops)
204{
205 pr_info("oprofile: hardware counters not available\n");
206 return -ENODEV;
207}
208static inline void oprofile_perf_exit(void) { }
209#endif
210
211#endif
212