Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | struct super_block; |
| 21 | struct dentry; |
| 22 | struct file_operations; |
| 23 | struct pt_regs; |
| 24 | |
| 25 | /* Operations structure to be filled in */ |
| 26 | struct oprofile_operations { |
| 27 | /* create any necessary configuration files in the oprofile fs. |
| 28 | * Optional. */ |
| 29 | int (*create_files)(struct super_block * sb, struct dentry * root); |
| 30 | /* Do any necessary interrupt setup. Optional. */ |
| 31 | int (*setup)(void); |
| 32 | /* Do any necessary interrupt shutdown. Optional. */ |
| 33 | void (*shutdown)(void); |
| 34 | /* Start delivering interrupts. */ |
| 35 | int (*start)(void); |
| 36 | /* Stop delivering interrupts. */ |
| 37 | void (*stop)(void); |
| 38 | /* Initiate a stack backtrace. Optional. */ |
| 39 | void (*backtrace)(struct pt_regs * const regs, unsigned int depth); |
| 40 | /* CPU identification string. */ |
| 41 | char * cpu_type; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * One-time initialisation. *ops must be set to a filled-in |
| 46 | * operations structure. This is called even in timer interrupt |
| 47 | * mode so an arch can set a backtrace callback. |
| 48 | * |
| 49 | * If an error occurs, the fields should be left untouched. |
| 50 | */ |
| 51 | int oprofile_arch_init(struct oprofile_operations * ops); |
| 52 | |
| 53 | /** |
| 54 | * One-time exit/cleanup for the arch. |
| 55 | */ |
| 56 | void oprofile_arch_exit(void); |
| 57 | |
| 58 | /** |
| 59 | * Add a sample. This may be called from any context. Pass |
| 60 | * smp_processor_id() as cpu. |
| 61 | */ |
| 62 | void oprofile_add_sample(struct pt_regs * const regs, unsigned long event); |
| 63 | |
Brian Rogan | 2735771 | 2006-03-28 01:56:20 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Add an extended sample. Use this when the PC is not from the regs, and |
| 66 | * we cannot determine if we're in kernel mode from the regs. |
| 67 | * |
| 68 | * This function does perform a backtrace. |
| 69 | * |
| 70 | */ |
| 71 | void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs, |
| 72 | unsigned long event, int is_kernel); |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* Use this instead when the PC value is not from the regs. Doesn't |
| 75 | * backtrace. */ |
| 76 | void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event); |
| 77 | |
| 78 | /* add a backtrace entry, to be called from the ->backtrace callback */ |
| 79 | void oprofile_add_trace(unsigned long eip); |
| 80 | |
| 81 | |
| 82 | /** |
| 83 | * Create a file of the given name as a child of the given root, with |
| 84 | * the specified file operations. |
| 85 | */ |
| 86 | int oprofilefs_create_file(struct super_block * sb, struct dentry * root, |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 87 | char const * name, const struct file_operations * fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root, |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 90 | char const * name, const struct file_operations * fops, int perm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /** Create a file for read/write access to an unsigned long. */ |
| 93 | int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root, |
| 94 | char const * name, ulong * val); |
| 95 | |
| 96 | /** Create a file for read-only access to an unsigned long. */ |
| 97 | int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root, |
| 98 | char const * name, ulong * val); |
| 99 | |
| 100 | /** Create a file for read-only access to an atomic_t. */ |
| 101 | int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root, |
| 102 | char const * name, atomic_t * val); |
| 103 | |
| 104 | /** create a directory */ |
| 105 | struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root, |
| 106 | char const * name); |
| 107 | |
| 108 | /** |
| 109 | * Write the given asciz string to the given user buffer @buf, updating *offset |
| 110 | * appropriately. Returns bytes written or -EFAULT. |
| 111 | */ |
| 112 | ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset); |
| 113 | |
| 114 | /** |
| 115 | * Convert an unsigned long value into ASCII and copy it to the user buffer @buf, |
| 116 | * updating *offset appropriately. Returns bytes written or -EFAULT. |
| 117 | */ |
| 118 | ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset); |
| 119 | |
| 120 | /** |
| 121 | * Read an ASCII string for a number from a userspace buffer and fill *val on success. |
| 122 | * Returns 0 on success, < 0 on error. |
| 123 | */ |
| 124 | int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count); |
| 125 | |
| 126 | /** lock for read/write safety */ |
| 127 | extern spinlock_t oprofilefs_lock; |
| 128 | |
| 129 | #endif /* OPROFILE_H */ |