x86, bts: turn macro into static inline function
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / include / asm / ds.h
bloba95008457ea430ffbe7fdde3fc6a5fd57778ce79
1 /*
2 * Debug Store (DS) support
4 * This provides a low-level interface to the hardware's Debug Store
5 * feature that is used for branch trace store (BTS) and
6 * precise-event based sampling (PEBS).
8 * It manages:
9 * - per-thread and per-cpu allocation of BTS and PEBS
10 * - buffer memory allocation (optional)
11 * - buffer overflow handling
12 * - buffer access
14 * It assumes:
15 * - get_task_struct on all parameter tasks
16 * - current is allowed to trace parameter tasks
19 * Copyright (C) 2007-2008 Intel Corporation.
20 * Markus Metzger <markus.t.metzger@intel.com>, 2007-2008
23 #ifndef _ASM_X86_DS_H
24 #define _ASM_X86_DS_H
27 #include <linux/types.h>
28 #include <linux/init.h>
31 #ifdef CONFIG_X86_DS
33 struct task_struct;
36 * Request BTS or PEBS
38 * Due to alignement constraints, the actual buffer may be slightly
39 * smaller than the requested or provided buffer.
41 * Returns 0 on success; -Eerrno otherwise
43 * task: the task to request recording for;
44 * NULL for per-cpu recording on the current cpu
45 * base: the base pointer for the (non-pageable) buffer;
46 * NULL if buffer allocation requested
47 * size: the size of the requested or provided buffer
48 * ovfl: pointer to a function to be called on buffer overflow;
49 * NULL if cyclic buffer requested
51 typedef void (*ds_ovfl_callback_t)(struct task_struct *);
52 extern int ds_request_bts(struct task_struct *task, void *base, size_t size,
53 ds_ovfl_callback_t ovfl);
54 extern int ds_request_pebs(struct task_struct *task, void *base, size_t size,
55 ds_ovfl_callback_t ovfl);
58 * Release BTS or PEBS resources
60 * Frees buffers allocated on ds_request.
62 * Returns 0 on success; -Eerrno otherwise
64 * task: the task to release resources for;
65 * NULL to release resources for the current cpu
67 extern int ds_release_bts(struct task_struct *task);
68 extern int ds_release_pebs(struct task_struct *task);
71 * Return the (array) index of the write pointer.
72 * (assuming an array of BTS/PEBS records)
74 * Returns -Eerrno on error
76 * task: the task to access;
77 * NULL to access the current cpu
78 * pos (out): if not NULL, will hold the result
80 extern int ds_get_bts_index(struct task_struct *task, size_t *pos);
81 extern int ds_get_pebs_index(struct task_struct *task, size_t *pos);
84 * Return the (array) index one record beyond the end of the array.
85 * (assuming an array of BTS/PEBS records)
87 * Returns -Eerrno on error
89 * task: the task to access;
90 * NULL to access the current cpu
91 * pos (out): if not NULL, will hold the result
93 extern int ds_get_bts_end(struct task_struct *task, size_t *pos);
94 extern int ds_get_pebs_end(struct task_struct *task, size_t *pos);
97 * Provide a pointer to the BTS/PEBS record at parameter index.
98 * (assuming an array of BTS/PEBS records)
100 * The pointer points directly into the buffer. The user is
101 * responsible for copying the record.
103 * Returns the size of a single record on success; -Eerrno on error
105 * task: the task to access;
106 * NULL to access the current cpu
107 * index: the index of the requested record
108 * record (out): pointer to the requested record
110 extern int ds_access_bts(struct task_struct *task,
111 size_t index, const void **record);
112 extern int ds_access_pebs(struct task_struct *task,
113 size_t index, const void **record);
116 * Write one or more BTS/PEBS records at the write pointer index and
117 * advance the write pointer.
119 * If size is not a multiple of the record size, trailing bytes are
120 * zeroed out.
122 * May result in one or more overflow notifications.
124 * If called during overflow handling, that is, with index >=
125 * interrupt threshold, the write will wrap around.
127 * An overflow notification is given if and when the interrupt
128 * threshold is reached during or after the write.
130 * Returns the number of bytes written or -Eerrno.
132 * task: the task to access;
133 * NULL to access the current cpu
134 * buffer: the buffer to write
135 * size: the size of the buffer
137 extern int ds_write_bts(struct task_struct *task,
138 const void *buffer, size_t size);
139 extern int ds_write_pebs(struct task_struct *task,
140 const void *buffer, size_t size);
143 * Same as ds_write_bts/pebs, but omit ownership checks.
145 * This is needed to have some other task than the owner of the
146 * BTS/PEBS buffer or the parameter task itself write into the
147 * respective buffer.
149 extern int ds_unchecked_write_bts(struct task_struct *task,
150 const void *buffer, size_t size);
151 extern int ds_unchecked_write_pebs(struct task_struct *task,
152 const void *buffer, size_t size);
155 * Reset the write pointer of the BTS/PEBS buffer.
157 * Returns 0 on success; -Eerrno on error
159 * task: the task to access;
160 * NULL to access the current cpu
162 extern int ds_reset_bts(struct task_struct *task);
163 extern int ds_reset_pebs(struct task_struct *task);
166 * Clear the BTS/PEBS buffer and reset the write pointer.
167 * The entire buffer will be zeroed out.
169 * Returns 0 on success; -Eerrno on error
171 * task: the task to access;
172 * NULL to access the current cpu
174 extern int ds_clear_bts(struct task_struct *task);
175 extern int ds_clear_pebs(struct task_struct *task);
178 * Provide the PEBS counter reset value.
180 * Returns 0 on success; -Eerrno on error
182 * task: the task to access;
183 * NULL to access the current cpu
184 * value (out): the counter reset value
186 extern int ds_get_pebs_reset(struct task_struct *task, u64 *value);
189 * Set the PEBS counter reset value.
191 * Returns 0 on success; -Eerrno on error
193 * task: the task to access;
194 * NULL to access the current cpu
195 * value: the new counter reset value
197 extern int ds_set_pebs_reset(struct task_struct *task, u64 value);
200 * Initialization
202 struct cpuinfo_x86;
203 extern void __cpuinit ds_init_intel(struct cpuinfo_x86 *);
208 * The DS context - part of struct thread_struct.
210 struct ds_context {
211 /* pointer to the DS configuration; goes into MSR_IA32_DS_AREA */
212 unsigned char *ds;
213 /* the owner of the BTS and PEBS configuration, respectively */
214 struct task_struct *owner[2];
215 /* buffer overflow notification function for BTS and PEBS */
216 ds_ovfl_callback_t callback[2];
217 /* the original buffer address */
218 void *buffer[2];
219 /* the number of allocated pages for on-request allocated buffers */
220 unsigned int pages[2];
221 /* use count */
222 unsigned long count;
223 /* a pointer to the context location inside the thread_struct
224 * or the per_cpu context array */
225 struct ds_context **this;
226 /* a pointer to the task owning this context, or NULL, if the
227 * context is owned by a cpu */
228 struct task_struct *task;
231 /* called by exit_thread() to free leftover contexts */
232 extern void ds_free(struct ds_context *context);
234 #else /* CONFIG_X86_DS */
236 struct cpuinfo_x86;
237 static inline void __cpuinit ds_init_intel(struct cpuinfo_x86 *ignored) {}
239 #endif /* CONFIG_X86_DS */
240 #endif /* _ASM_X86_DS_H */