4 * API for machine-specific interrupts to interface
7 * @remark Copyright 2002 OProfile authors
8 * @remark Read the file COPYING
10 * @author John Levon <levon@movementarian.org>
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>
23 #include <xen/interface/xenoprof.h>
26 /* Each escaped entry is prefixed by ESCAPE_CODE
27 * then one of the following codes, then the
29 * These #defines live in this file so that arch-specific
30 * buffer sync'ing code can access them.
32 #define ESCAPE_CODE ~0UL
33 #define CTX_SWITCH_CODE 1
34 #define CPU_SWITCH_CODE 2
35 #define COOKIE_SWITCH_CODE 3
36 #define KERNEL_ENTER_SWITCH_CODE 4
37 #define USER_ENTER_SWITCH_CODE 5
38 #define MODULE_LOADED_CODE 6
39 #define CTX_TGID_CODE 7
40 #define TRACE_BEGIN_CODE 8
41 #define TRACE_END_CODE 9
42 #define XEN_ENTER_SWITCH_CODE 10
44 #define SPU_PROFILING_CODE 11
45 #define SPU_CTX_SWITCH_CODE 12
47 #define DOMAIN_SWITCH_CODE 11
49 #define IBS_FETCH_CODE 13
50 #define IBS_OP_CODE 14
54 struct file_operations;
57 /* Operations structure to be filled in */
58 struct oprofile_operations {
59 /* create any necessary configuration files in the oprofile fs.
61 int (*create_files)(struct super_block * sb, struct dentry * root);
63 /* setup active domains with Xen */
64 int (*set_active)(int *active_domains, unsigned int adomains);
65 /* setup passive domains with Xen */
66 int (*set_passive)(int *passive_domains, unsigned int pdomains);
68 /* Do any necessary interrupt setup. Optional. */
70 /* Do any necessary interrupt shutdown. Optional. */
71 void (*shutdown)(void);
72 /* Start delivering interrupts. */
74 /* Stop delivering interrupts. */
76 /* Arch-specific buffer sync functions.
77 * Return value = 0: Success
78 * Return value = -1: Failure
79 * Return value = 1: Run generic sync function
81 int (*sync_start)(void);
82 int (*sync_stop)(void);
84 /* Initiate a stack backtrace. Optional. */
85 void (*backtrace)(struct pt_regs * const regs, unsigned int depth);
87 /* Multiplex between different events. Optional. */
88 int (*switch_events)(void);
89 /* CPU identification string. */
94 * One-time initialisation. *ops must be set to a filled-in
95 * operations structure. This is called even in timer interrupt
96 * mode so an arch can set a backtrace callback.
98 * If an error occurs, the fields should be left untouched.
100 int oprofile_arch_init(struct oprofile_operations * ops);
103 * One-time exit/cleanup for the arch.
105 void oprofile_arch_exit(void);
108 * Add a sample. This may be called from any context.
110 void oprofile_add_sample(struct pt_regs * const regs, unsigned long event);
113 * Add an extended sample. Use this when the PC is not from the regs, and
114 * we cannot determine if we're in kernel mode from the regs.
116 * This function does perform a backtrace.
119 void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
120 unsigned long event, int is_kernel);
123 * Add an hardware sample.
125 void oprofile_add_ext_hw_sample(unsigned long pc, struct pt_regs * const regs,
126 unsigned long event, int is_kernel,
127 struct task_struct *task);
129 /* Use this instead when the PC value is not from the regs. Doesn't
131 void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event);
133 void oprofile_add_mode(int cpu_mode);
135 /* add a backtrace entry, to be called from the ->backtrace callback */
136 void oprofile_add_trace(unsigned long eip);
138 /* add a domain switch entry */
139 int oprofile_add_domain_switch(int32_t domain_id);
143 * Create a file of the given name as a child of the given root, with
144 * the specified file operations.
146 int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
147 char const * name, const struct file_operations * fops);
149 int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
150 char const * name, const struct file_operations * fops, int perm);
152 /** Create a file for read/write access to an unsigned long. */
153 int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
154 char const * name, ulong * val);
156 /** Create a file for read-only access to an unsigned long. */
157 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
158 char const * name, ulong * val);
160 /** Create a file for read-only access to an atomic_t. */
161 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
162 char const * name, atomic_t * val);
164 /** create a directory */
165 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
169 * Write the given asciz string to the given user buffer @buf, updating *offset
170 * appropriately. Returns bytes written or -EFAULT.
172 ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset);
175 * Convert an unsigned long value into ASCII and copy it to the user buffer @buf,
176 * updating *offset appropriately. Returns bytes written or -EFAULT.
178 ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset);
181 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
182 * Returns 0 on success, < 0 on error.
184 int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
186 /** lock for read/write safety */
187 extern raw_spinlock_t oprofilefs_lock;
190 * Add the contents of a circular buffer to the event buffer.
192 void oprofile_put_buff(unsigned long *buf, unsigned int start,
193 unsigned int stop, unsigned int max);
195 unsigned long oprofile_get_cpu_buffer_size(void);
196 void oprofile_cpu_buffer_inc_smpl_lost(void);
198 /* cpu buffer functions */
203 struct ring_buffer_event *event;
204 struct op_sample *sample;
209 void oprofile_write_reserve(struct op_entry *entry,
210 struct pt_regs * const regs,
211 unsigned long pc, int code, int size);
212 int oprofile_add_data(struct op_entry *entry, unsigned long val);
213 int oprofile_add_data64(struct op_entry *entry, u64 val);
214 int oprofile_write_commit(struct op_entry *entry);
216 #ifdef CONFIG_HW_PERF_EVENTS
217 int __init oprofile_perf_init(struct oprofile_operations *ops);
218 void oprofile_perf_exit(void);
219 char *op_name_from_perf_id(void);
221 static inline int __init oprofile_perf_init(struct oprofile_operations *ops)
223 pr_info("oprofile: hardware counters not available\n");
226 static inline void oprofile_perf_exit(void) { }
227 #endif /* CONFIG_HW_PERF_EVENTS */
229 #endif /* OPROFILE_H */