at v2.6.28 168 lines 5.2 kB view raw
1/** 2 * @file oprofile.h 3 * 4 * API for machine-specific interrupts to interface 5 * to oprofile. 6 * 7 * @remark Copyright 2002 OProfile authors 8 * @remark Read the file COPYING 9 * 10 * @author John Levon <levon@movementarian.org> 11 */ 12 13#ifndef OPROFILE_H 14#define OPROFILE_H 15 16#include <linux/types.h> 17#include <linux/spinlock.h> 18#include <asm/atomic.h> 19 20/* Each escaped entry is prefixed by ESCAPE_CODE 21 * then one of the following codes, then the 22 * relevant data. 23 * These #defines live in this file so that arch-specific 24 * buffer sync'ing code can access them. 25 */ 26#define ESCAPE_CODE ~0UL 27#define CTX_SWITCH_CODE 1 28#define CPU_SWITCH_CODE 2 29#define COOKIE_SWITCH_CODE 3 30#define KERNEL_ENTER_SWITCH_CODE 4 31#define KERNEL_EXIT_SWITCH_CODE 5 32#define MODULE_LOADED_CODE 6 33#define CTX_TGID_CODE 7 34#define TRACE_BEGIN_CODE 8 35#define TRACE_END_CODE 9 36#define XEN_ENTER_SWITCH_CODE 10 37#define SPU_PROFILING_CODE 11 38#define SPU_CTX_SWITCH_CODE 12 39#define IBS_FETCH_CODE 13 40#define IBS_OP_CODE 14 41 42struct super_block; 43struct dentry; 44struct file_operations; 45struct pt_regs; 46 47/* Operations structure to be filled in */ 48struct oprofile_operations { 49 /* create any necessary configuration files in the oprofile fs. 50 * Optional. */ 51 int (*create_files)(struct super_block * sb, struct dentry * root); 52 /* Do any necessary interrupt setup. Optional. */ 53 int (*setup)(void); 54 /* Do any necessary interrupt shutdown. Optional. */ 55 void (*shutdown)(void); 56 /* Start delivering interrupts. */ 57 int (*start)(void); 58 /* Stop delivering interrupts. */ 59 void (*stop)(void); 60 /* Arch-specific buffer sync functions. 61 * Return value = 0: Success 62 * Return value = -1: Failure 63 * Return value = 1: Run generic sync function 64 */ 65 int (*sync_start)(void); 66 int (*sync_stop)(void); 67 68 /* Initiate a stack backtrace. Optional. */ 69 void (*backtrace)(struct pt_regs * const regs, unsigned int depth); 70 /* CPU identification string. */ 71 char * cpu_type; 72}; 73 74/** 75 * One-time initialisation. *ops must be set to a filled-in 76 * operations structure. This is called even in timer interrupt 77 * mode so an arch can set a backtrace callback. 78 * 79 * If an error occurs, the fields should be left untouched. 80 */ 81int oprofile_arch_init(struct oprofile_operations * ops); 82 83/** 84 * One-time exit/cleanup for the arch. 85 */ 86void oprofile_arch_exit(void); 87 88/** 89 * Add a sample. This may be called from any context. Pass 90 * smp_processor_id() as cpu. 91 */ 92void oprofile_add_sample(struct pt_regs * const regs, unsigned long event); 93 94/** 95 * Add an extended sample. Use this when the PC is not from the regs, and 96 * we cannot determine if we're in kernel mode from the regs. 97 * 98 * This function does perform a backtrace. 99 * 100 */ 101void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs, 102 unsigned long event, int is_kernel); 103 104/* Use this instead when the PC value is not from the regs. Doesn't 105 * backtrace. */ 106void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event); 107 108/* add a backtrace entry, to be called from the ->backtrace callback */ 109void oprofile_add_trace(unsigned long eip); 110 111 112/** 113 * Create a file of the given name as a child of the given root, with 114 * the specified file operations. 115 */ 116int oprofilefs_create_file(struct super_block * sb, struct dentry * root, 117 char const * name, const struct file_operations * fops); 118 119int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root, 120 char const * name, const struct file_operations * fops, int perm); 121 122/** Create a file for read/write access to an unsigned long. */ 123int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root, 124 char const * name, ulong * val); 125 126/** Create a file for read-only access to an unsigned long. */ 127int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root, 128 char const * name, ulong * val); 129 130/** Create a file for read-only access to an atomic_t. */ 131int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root, 132 char const * name, atomic_t * val); 133 134/** create a directory */ 135struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root, 136 char const * name); 137 138/** 139 * Write the given asciz string to the given user buffer @buf, updating *offset 140 * appropriately. Returns bytes written or -EFAULT. 141 */ 142ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset); 143 144/** 145 * Convert an unsigned long value into ASCII and copy it to the user buffer @buf, 146 * updating *offset appropriately. Returns bytes written or -EFAULT. 147 */ 148ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset); 149 150/** 151 * Read an ASCII string for a number from a userspace buffer and fill *val on success. 152 * Returns 0 on success, < 0 on error. 153 */ 154int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count); 155 156/** lock for read/write safety */ 157extern spinlock_t oprofilefs_lock; 158 159/** 160 * Add the contents of a circular buffer to the event buffer. 161 */ 162void oprofile_put_buff(unsigned long *buf, unsigned int start, 163 unsigned int stop, unsigned int max); 164 165unsigned long oprofile_get_cpu_buffer_size(void); 166void oprofile_cpu_buffer_inc_smpl_lost(void); 167 168#endif /* OPROFILE_H */