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 /* Each escaped entry is prefixed by ESCAPE_CODE
17 * then one of the following codes, then the
19 * These #defines live in this file so that arch-specific
20 * buffer sync'ing code can access them.
22 #define ESCAPE_CODE ~0UL
23 #define CTX_SWITCH_CODE 1
24 #define CPU_SWITCH_CODE 2
25 #define COOKIE_SWITCH_CODE 3
26 #define KERNEL_ENTER_SWITCH_CODE 4
27 #define KERNEL_EXIT_SWITCH_CODE 5
28 #define MODULE_LOADED_CODE 6
29 #define CTX_TGID_CODE 7
30 #define TRACE_BEGIN_CODE 8
31 #define TRACE_END_CODE 9
32 #define XEN_ENTER_SWITCH_CODE 10
33 #define SPU_PROFILING_CODE 11
34 #define SPU_CTX_SWITCH_CODE 12
35 #define IBS_FETCH_CODE 13
36 #define IBS_OP_CODE 14
39 /* Operations structure to be filled in */
40 struct oprofile_operations {
41 /* create any necessary configuration files in the oprofile fs.
43 int (*create_files)(void* sb, void *root);
44 /* Do any necessary interrupt setup. Optional. */
46 /* Do any necessary interrupt shutdown. Optional. */
47 void (*shutdown)(void);
48 /* Start delivering interrupts. */
50 /* Stop delivering interrupts. */
52 /* Arch-specific buffer sync functions.
53 * Return value = 0: Success
54 * Return value = -1: Failure
55 * Return value = 1: Run generic sync function
57 int (*sync_start)(void);
58 int (*sync_stop)(void);
60 /* Initiate a stack backtrace. Optional. */
61 void (*backtrace)(void * const regs, unsigned int depth);
63 /* Multiplex between different events. Optional. */
64 int (*switch_events)(void);
65 /* CPU identification string. */
70 * One-time initialisation. *ops must be set to a filled-in
71 * operations structure. This is called even in timer interrupt
72 * mode so an arch can set a backtrace callback.
74 * If an error occurs, the fields should be left untouched.
76 int oprofile_arch_init(struct oprofile_operations * ops);
79 * One-time exit/cleanup for the arch.
81 void oprofile_arch_exit(void);
84 * Add a sample. This may be called from any context.
86 void oprofile_add_sample(void* const regs, unsigned long event);
89 * Add an extended sample. Use this when the PC is not from the regs, and
90 * we cannot determine if we're in kernel mode from the regs.
92 * This function does perform a backtrace.
95 void oprofile_add_ext_sample(unsigned long pc, void * const regs,
96 unsigned long event, int is_kernel);
98 /* circular include stuff... */
101 * Add an hardware sample.
103 void oprofile_add_ext_hw_sample(unsigned long pc, /*struct pt_regs*/void * const regs,
104 unsigned long event, int is_kernel,
107 /* Use this instead when the PC value is not from the regs. Doesn't
109 void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event);
111 void oprofile_add_backtrace(uintptr_t pc, uintptr_t fp);
112 void oprofile_add_userpc(uintptr_t pc);
114 /* add a backtrace entry, to be called from the ->backtrace callback */
115 void oprofile_add_trace(unsigned long eip);
119 * Add the contents of a circular buffer to the event buffer.
121 void oprofile_put_buff(unsigned long *buf, unsigned int start,
122 unsigned int stop, unsigned int max);
124 unsigned long oprofile_get_cpu_buffer_size(void);
125 void oprofile_cpu_buffer_inc_smpl_lost(void);
127 /* cpu buffer functions */
133 struct op_sample *sample;
138 void oprofile_write_reserve(struct op_entry *entry,
139 void */*struct pt_regs **/ const regs,
140 unsigned long pc, int code, int size);
141 int oprofile_add_data(struct op_entry *entry, unsigned long val);
142 int oprofile_add_data64(struct op_entry *entry, uint64_t val);
143 int oprofile_write_commit(struct op_entry *entry);
145 int oprofile_perf_init(struct oprofile_operations *ops);
146 void oprofile_perf_exit(void);
147 char *op_name_from_perf_id(void);
149 struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu);
150 unsigned long op_cpu_buffer_entries(int cpu);
151 void oprofile_cpubuf_flushone(int core, int newbuf);
152 void oprofile_cpubuf_flushall(int alloc);
153 void oprofile_control_trace(int onoff);
154 int oprofread(void *,int);
158 make these weak funcitons.
159 static inline int __init oprofile_perf_init(struct oprofile_operations *ops)
161 pr_info("oprofile: hardware counters not available\n");
164 static inline void oprofile_perf_exit(void) { }
167 #endif /* OPROFILE_H */