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