2008-01-30 20:31:09 +08:00
|
|
|
/*
|
|
|
|
* Debug Store (DS) support
|
|
|
|
*
|
|
|
|
* This provides a low-level interface to the hardware's Debug Store
|
2008-04-08 17:01:58 +08:00
|
|
|
* feature that is used for branch trace store (BTS) and
|
2008-01-30 20:31:09 +08:00
|
|
|
* precise-event based sampling (PEBS).
|
|
|
|
*
|
2008-04-08 17:01:58 +08:00
|
|
|
* It manages:
|
|
|
|
* - per-thread and per-cpu allocation of BTS and PEBS
|
2008-11-25 16:05:27 +08:00
|
|
|
* - buffer overflow handling (to be done)
|
2008-04-08 17:01:58 +08:00
|
|
|
* - buffer access
|
2008-01-30 20:31:09 +08:00
|
|
|
*
|
2008-04-08 17:01:58 +08:00
|
|
|
* It assumes:
|
2008-11-25 16:05:27 +08:00
|
|
|
* - get_task_struct on all traced tasks
|
|
|
|
* - current is allowed to trace tasks
|
2008-01-30 20:31:09 +08:00
|
|
|
*
|
|
|
|
*
|
2008-04-08 17:01:58 +08:00
|
|
|
* Copyright (C) 2007-2008 Intel Corporation.
|
|
|
|
* Markus Metzger <markus.t.metzger@intel.com>, 2007-2008
|
2008-01-30 20:31:09 +08:00
|
|
|
*/
|
|
|
|
|
2008-10-23 13:26:29 +08:00
|
|
|
#ifndef _ASM_X86_DS_H
|
|
|
|
#define _ASM_X86_DS_H
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2008-04-08 17:01:58 +08:00
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/init.h>
|
2008-11-25 16:01:25 +08:00
|
|
|
#include <linux/err.h>
|
2008-01-30 20:31:09 +08:00
|
|
|
|
|
|
|
|
2008-11-25 15:47:19 +08:00
|
|
|
#ifdef CONFIG_X86_DS
|
|
|
|
|
2008-04-08 17:01:58 +08:00
|
|
|
struct task_struct;
|
2008-11-25 16:01:25 +08:00
|
|
|
struct ds_tracer;
|
|
|
|
struct bts_tracer;
|
|
|
|
struct pebs_tracer;
|
|
|
|
|
|
|
|
typedef void (*bts_ovfl_callback_t)(struct bts_tracer *);
|
|
|
|
typedef void (*pebs_ovfl_callback_t)(struct pebs_tracer *);
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2008-04-08 17:01:58 +08:00
|
|
|
/*
|
|
|
|
* Request BTS or PEBS
|
|
|
|
*
|
|
|
|
* Due to alignement constraints, the actual buffer may be slightly
|
|
|
|
* smaller than the requested or provided buffer.
|
2008-01-30 20:31:09 +08:00
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* Returns a pointer to a tracer structure on success, or
|
|
|
|
* ERR_PTR(errcode) on failure.
|
|
|
|
*
|
|
|
|
* The interrupt threshold is independent from the overflow callback
|
|
|
|
* to allow users to use their own overflow interrupt handling mechanism.
|
2008-04-08 17:01:58 +08:00
|
|
|
*
|
|
|
|
* task: the task to request recording for;
|
|
|
|
* NULL for per-cpu recording on the current cpu
|
|
|
|
* base: the base pointer for the (non-pageable) buffer;
|
2008-11-25 16:05:27 +08:00
|
|
|
* size: the size of the provided buffer in bytes
|
2008-04-08 17:01:58 +08:00
|
|
|
* ovfl: pointer to a function to be called on buffer overflow;
|
|
|
|
* NULL if cyclic buffer requested
|
2008-11-25 16:01:25 +08:00
|
|
|
* th: the interrupt threshold in records from the end of the buffer;
|
|
|
|
* -1 if no interrupt threshold is requested.
|
2008-01-30 20:31:09 +08:00
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern struct bts_tracer *ds_request_bts(struct task_struct *task,
|
|
|
|
void *base, size_t size,
|
|
|
|
bts_ovfl_callback_t ovfl, size_t th);
|
|
|
|
extern struct pebs_tracer *ds_request_pebs(struct task_struct *task,
|
|
|
|
void *base, size_t size,
|
|
|
|
pebs_ovfl_callback_t ovfl,
|
|
|
|
size_t th);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Release BTS or PEBS resources
|
|
|
|
*
|
|
|
|
* Returns 0 on success; -Eerrno otherwise
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_~()
|
2008-04-08 17:01:58 +08:00
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_release_bts(struct bts_tracer *tracer);
|
|
|
|
extern int ds_release_pebs(struct pebs_tracer *tracer);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
2008-11-25 16:01:25 +08:00
|
|
|
* Get the (array) index of the write pointer.
|
2008-04-08 17:01:58 +08:00
|
|
|
* (assuming an array of BTS/PEBS records)
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* Returns 0 on success; -Eerrno on error
|
2008-04-08 17:01:58 +08:00
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_~()
|
|
|
|
* pos (out): will hold the result
|
2008-04-08 17:01:58 +08:00
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_get_bts_index(struct bts_tracer *tracer, size_t *pos);
|
|
|
|
extern int ds_get_pebs_index(struct pebs_tracer *tracer, size_t *pos);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
2008-11-25 16:01:25 +08:00
|
|
|
* Get the (array) index one record beyond the end of the array.
|
2008-04-08 17:01:58 +08:00
|
|
|
* (assuming an array of BTS/PEBS records)
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* Returns 0 on success; -Eerrno on error
|
2008-04-08 17:01:58 +08:00
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_~()
|
|
|
|
* pos (out): will hold the result
|
2008-04-08 17:01:58 +08:00
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_get_bts_end(struct bts_tracer *tracer, size_t *pos);
|
|
|
|
extern int ds_get_pebs_end(struct pebs_tracer *tracer, size_t *pos);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Provide a pointer to the BTS/PEBS record at parameter index.
|
|
|
|
* (assuming an array of BTS/PEBS records)
|
|
|
|
*
|
|
|
|
* The pointer points directly into the buffer. The user is
|
|
|
|
* responsible for copying the record.
|
|
|
|
*
|
|
|
|
* Returns the size of a single record on success; -Eerrno on error
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_~()
|
2008-04-08 17:01:58 +08:00
|
|
|
* index: the index of the requested record
|
|
|
|
* record (out): pointer to the requested record
|
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_access_bts(struct bts_tracer *tracer,
|
2008-04-08 17:01:58 +08:00
|
|
|
size_t index, const void **record);
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_access_pebs(struct pebs_tracer *tracer,
|
2008-04-08 17:01:58 +08:00
|
|
|
size_t index, const void **record);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write one or more BTS/PEBS records at the write pointer index and
|
|
|
|
* advance the write pointer.
|
|
|
|
*
|
|
|
|
* If size is not a multiple of the record size, trailing bytes are
|
|
|
|
* zeroed out.
|
|
|
|
*
|
|
|
|
* May result in one or more overflow notifications.
|
|
|
|
*
|
|
|
|
* If called during overflow handling, that is, with index >=
|
|
|
|
* interrupt threshold, the write will wrap around.
|
|
|
|
*
|
|
|
|
* An overflow notification is given if and when the interrupt
|
|
|
|
* threshold is reached during or after the write.
|
|
|
|
*
|
|
|
|
* Returns the number of bytes written or -Eerrno.
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_~()
|
2008-04-08 17:01:58 +08:00
|
|
|
* buffer: the buffer to write
|
|
|
|
* size: the size of the buffer
|
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_write_bts(struct bts_tracer *tracer,
|
2008-04-08 17:01:58 +08:00
|
|
|
const void *buffer, size_t size);
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_write_pebs(struct pebs_tracer *tracer,
|
2008-04-08 17:01:58 +08:00
|
|
|
const void *buffer, size_t size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the write pointer of the BTS/PEBS buffer.
|
|
|
|
*
|
|
|
|
* Returns 0 on success; -Eerrno on error
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_~()
|
2008-04-08 17:01:58 +08:00
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_reset_bts(struct bts_tracer *tracer);
|
|
|
|
extern int ds_reset_pebs(struct pebs_tracer *tracer);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the BTS/PEBS buffer and reset the write pointer.
|
|
|
|
* The entire buffer will be zeroed out.
|
|
|
|
*
|
|
|
|
* Returns 0 on success; -Eerrno on error
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_~()
|
2008-04-08 17:01:58 +08:00
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_clear_bts(struct bts_tracer *tracer);
|
|
|
|
extern int ds_clear_pebs(struct pebs_tracer *tracer);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Provide the PEBS counter reset value.
|
|
|
|
*
|
|
|
|
* Returns 0 on success; -Eerrno on error
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_pebs()
|
2008-04-08 17:01:58 +08:00
|
|
|
* value (out): the counter reset value
|
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_get_pebs_reset(struct pebs_tracer *tracer, u64 *value);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the PEBS counter reset value.
|
|
|
|
*
|
|
|
|
* Returns 0 on success; -Eerrno on error
|
|
|
|
*
|
2008-11-25 16:01:25 +08:00
|
|
|
* tracer: the tracer handle returned from ds_request_pebs()
|
2008-04-08 17:01:58 +08:00
|
|
|
* value: the new counter reset value
|
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
extern int ds_set_pebs_reset(struct pebs_tracer *tracer, u64 value);
|
2008-04-08 17:01:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization
|
|
|
|
*/
|
|
|
|
struct cpuinfo_x86;
|
|
|
|
extern void __cpuinit ds_init_intel(struct cpuinfo_x86 *);
|
|
|
|
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2008-04-08 17:01:58 +08:00
|
|
|
/*
|
|
|
|
* The DS context - part of struct thread_struct.
|
|
|
|
*/
|
2008-11-25 16:01:25 +08:00
|
|
|
#define MAX_SIZEOF_DS (12 * 8)
|
|
|
|
|
2008-04-08 17:01:58 +08:00
|
|
|
struct ds_context {
|
|
|
|
/* pointer to the DS configuration; goes into MSR_IA32_DS_AREA */
|
2008-11-25 16:01:25 +08:00
|
|
|
unsigned char ds[MAX_SIZEOF_DS];
|
2008-04-08 17:01:58 +08:00
|
|
|
/* the owner of the BTS and PEBS configuration, respectively */
|
2008-11-25 16:01:25 +08:00
|
|
|
struct ds_tracer *owner[2];
|
2008-04-08 17:01:58 +08:00
|
|
|
/* use count */
|
|
|
|
unsigned long count;
|
|
|
|
/* a pointer to the context location inside the thread_struct
|
|
|
|
* or the per_cpu context array */
|
|
|
|
struct ds_context **this;
|
|
|
|
/* a pointer to the task owning this context, or NULL, if the
|
|
|
|
* context is owned by a cpu */
|
|
|
|
struct task_struct *task;
|
2008-01-30 20:31:09 +08:00
|
|
|
};
|
|
|
|
|
2008-04-08 17:01:58 +08:00
|
|
|
/* called by exit_thread() to free leftover contexts */
|
|
|
|
extern void ds_free(struct ds_context *context);
|
|
|
|
|
|
|
|
#else /* CONFIG_X86_DS */
|
|
|
|
|
2008-11-25 15:47:19 +08:00
|
|
|
struct cpuinfo_x86;
|
|
|
|
static inline void __cpuinit ds_init_intel(struct cpuinfo_x86 *ignored) {}
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2008-04-08 17:01:58 +08:00
|
|
|
#endif /* CONFIG_X86_DS */
|
2008-10-23 13:26:29 +08:00
|
|
|
#endif /* _ASM_X86_DS_H */
|