mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-27 06:04:23 +08:00
Merge branches 'tracing/fastboot', 'tracing/ftrace', 'tracing/function-graph-tracer' and 'tracing/hw-branch-tracing' into tracing/core
This commit is contained in:
commit
9dfc3bc7d2
@ -6,13 +6,13 @@
|
||||
* precise-event based sampling (PEBS).
|
||||
*
|
||||
* It manages:
|
||||
* - per-thread and per-cpu allocation of BTS and PEBS
|
||||
* - DS and BTS hardware configuration
|
||||
* - buffer overflow handling (to be done)
|
||||
* - buffer access
|
||||
*
|
||||
* It assumes:
|
||||
* - get_task_struct on all traced tasks
|
||||
* - current is allowed to trace tasks
|
||||
* It does not do:
|
||||
* - security checking (is the caller allowed to trace the task)
|
||||
* - buffer allocation (memory accounting)
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2007-2008 Intel Corporation.
|
||||
@ -31,6 +31,7 @@
|
||||
#ifdef CONFIG_X86_DS
|
||||
|
||||
struct task_struct;
|
||||
struct ds_context;
|
||||
struct ds_tracer;
|
||||
struct bts_tracer;
|
||||
struct pebs_tracer;
|
||||
@ -38,6 +39,38 @@ struct pebs_tracer;
|
||||
typedef void (*bts_ovfl_callback_t)(struct bts_tracer *);
|
||||
typedef void (*pebs_ovfl_callback_t)(struct pebs_tracer *);
|
||||
|
||||
|
||||
/*
|
||||
* A list of features plus corresponding macros to talk about them in
|
||||
* the ds_request function's flags parameter.
|
||||
*
|
||||
* We use the enum to index an array of corresponding control bits;
|
||||
* we use the macro to index a flags bit-vector.
|
||||
*/
|
||||
enum ds_feature {
|
||||
dsf_bts = 0,
|
||||
dsf_bts_kernel,
|
||||
#define BTS_KERNEL (1 << dsf_bts_kernel)
|
||||
/* trace kernel-mode branches */
|
||||
|
||||
dsf_bts_user,
|
||||
#define BTS_USER (1 << dsf_bts_user)
|
||||
/* trace user-mode branches */
|
||||
|
||||
dsf_bts_overflow,
|
||||
dsf_bts_max,
|
||||
dsf_pebs = dsf_bts_max,
|
||||
|
||||
dsf_pebs_max,
|
||||
dsf_ctl_max = dsf_pebs_max,
|
||||
dsf_bts_timestamps = dsf_ctl_max,
|
||||
#define BTS_TIMESTAMPS (1 << dsf_bts_timestamps)
|
||||
/* add timestamps into BTS trace */
|
||||
|
||||
#define BTS_USER_FLAGS (BTS_KERNEL | BTS_USER | BTS_TIMESTAMPS)
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Request BTS or PEBS
|
||||
*
|
||||
@ -58,92 +91,135 @@ typedef void (*pebs_ovfl_callback_t)(struct pebs_tracer *);
|
||||
* NULL if cyclic buffer requested
|
||||
* th: the interrupt threshold in records from the end of the buffer;
|
||||
* -1 if no interrupt threshold is requested.
|
||||
* flags: a bit-mask of the above flags
|
||||
*/
|
||||
extern struct bts_tracer *ds_request_bts(struct task_struct *task,
|
||||
void *base, size_t size,
|
||||
bts_ovfl_callback_t ovfl, size_t th);
|
||||
bts_ovfl_callback_t ovfl,
|
||||
size_t th, unsigned int flags);
|
||||
extern struct pebs_tracer *ds_request_pebs(struct task_struct *task,
|
||||
void *base, size_t size,
|
||||
pebs_ovfl_callback_t ovfl,
|
||||
size_t th);
|
||||
size_t th, unsigned int flags);
|
||||
|
||||
/*
|
||||
* Release BTS or PEBS resources
|
||||
*
|
||||
* Returns 0 on success; -Eerrno otherwise
|
||||
* Suspend and resume BTS or PEBS tracing
|
||||
*
|
||||
* tracer: the tracer handle returned from ds_request_~()
|
||||
*/
|
||||
extern int ds_release_bts(struct bts_tracer *tracer);
|
||||
extern int ds_release_pebs(struct pebs_tracer *tracer);
|
||||
extern void ds_release_bts(struct bts_tracer *tracer);
|
||||
extern void ds_suspend_bts(struct bts_tracer *tracer);
|
||||
extern void ds_resume_bts(struct bts_tracer *tracer);
|
||||
extern void ds_release_pebs(struct pebs_tracer *tracer);
|
||||
extern void ds_suspend_pebs(struct pebs_tracer *tracer);
|
||||
extern void ds_resume_pebs(struct pebs_tracer *tracer);
|
||||
|
||||
|
||||
/*
|
||||
* Get the (array) index of the write pointer.
|
||||
* (assuming an array of BTS/PEBS records)
|
||||
* The raw DS buffer state as it is used for BTS and PEBS recording.
|
||||
*
|
||||
* Returns 0 on success; -Eerrno on error
|
||||
*
|
||||
* tracer: the tracer handle returned from ds_request_~()
|
||||
* pos (out): will hold the result
|
||||
* This is the low-level, arch-dependent interface for working
|
||||
* directly on the raw trace data.
|
||||
*/
|
||||
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);
|
||||
struct ds_trace {
|
||||
/* the number of bts/pebs records */
|
||||
size_t n;
|
||||
/* the size of a bts/pebs record in bytes */
|
||||
size_t size;
|
||||
/* pointers into the raw buffer:
|
||||
- to the first entry */
|
||||
void *begin;
|
||||
/* - one beyond the last entry */
|
||||
void *end;
|
||||
/* - one beyond the newest entry */
|
||||
void *top;
|
||||
/* - the interrupt threshold */
|
||||
void *ith;
|
||||
/* flags given on ds_request() */
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
/*
|
||||
* Get the (array) index one record beyond the end of the array.
|
||||
* (assuming an array of BTS/PEBS records)
|
||||
*
|
||||
* Returns 0 on success; -Eerrno on error
|
||||
*
|
||||
* tracer: the tracer handle returned from ds_request_~()
|
||||
* pos (out): will hold the result
|
||||
* An arch-independent view on branch trace data.
|
||||
*/
|
||||
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);
|
||||
enum bts_qualifier {
|
||||
bts_invalid,
|
||||
#define BTS_INVALID bts_invalid
|
||||
|
||||
bts_branch,
|
||||
#define BTS_BRANCH bts_branch
|
||||
|
||||
bts_task_arrives,
|
||||
#define BTS_TASK_ARRIVES bts_task_arrives
|
||||
|
||||
bts_task_departs,
|
||||
#define BTS_TASK_DEPARTS bts_task_departs
|
||||
|
||||
bts_qual_bit_size = 4,
|
||||
bts_qual_max = (1 << bts_qual_bit_size),
|
||||
};
|
||||
|
||||
struct bts_struct {
|
||||
__u64 qualifier;
|
||||
union {
|
||||
/* BTS_BRANCH */
|
||||
struct {
|
||||
__u64 from;
|
||||
__u64 to;
|
||||
} lbr;
|
||||
/* BTS_TASK_ARRIVES or BTS_TASK_DEPARTS */
|
||||
struct {
|
||||
__u64 jiffies;
|
||||
pid_t pid;
|
||||
} timestamp;
|
||||
} variant;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Provide a pointer to the BTS/PEBS record at parameter index.
|
||||
* (assuming an array of BTS/PEBS records)
|
||||
* The BTS state.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* tracer: the tracer handle returned from ds_request_~()
|
||||
* index: the index of the requested record
|
||||
* record (out): pointer to the requested record
|
||||
* This gives access to the raw DS state and adds functions to provide
|
||||
* an arch-independent view of the BTS data.
|
||||
*/
|
||||
extern int ds_access_bts(struct bts_tracer *tracer,
|
||||
size_t index, const void **record);
|
||||
extern int ds_access_pebs(struct pebs_tracer *tracer,
|
||||
size_t index, const void **record);
|
||||
struct bts_trace {
|
||||
struct ds_trace ds;
|
||||
|
||||
int (*read)(struct bts_tracer *tracer, const void *at,
|
||||
struct bts_struct *out);
|
||||
int (*write)(struct bts_tracer *tracer, const struct bts_struct *in);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Write one or more BTS/PEBS records at the write pointer index and
|
||||
* advance the write pointer.
|
||||
* The PEBS state.
|
||||
*
|
||||
* If size is not a multiple of the record size, trailing bytes are
|
||||
* zeroed out.
|
||||
* This gives access to the raw DS state and the PEBS-specific counter
|
||||
* reset value.
|
||||
*/
|
||||
struct pebs_trace {
|
||||
struct ds_trace ds;
|
||||
|
||||
/* the PEBS reset value */
|
||||
unsigned long long reset_value;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Read the BTS or PEBS trace.
|
||||
*
|
||||
* May result in one or more overflow notifications.
|
||||
* Returns a view on the trace collected for the parameter tracer.
|
||||
*
|
||||
* 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.
|
||||
* The view remains valid as long as the traced task is not running or
|
||||
* the tracer is suspended.
|
||||
* Writes into the trace buffer are not reflected.
|
||||
*
|
||||
* tracer: the tracer handle returned from ds_request_~()
|
||||
* buffer: the buffer to write
|
||||
* size: the size of the buffer
|
||||
*/
|
||||
extern int ds_write_bts(struct bts_tracer *tracer,
|
||||
const void *buffer, size_t size);
|
||||
extern int ds_write_pebs(struct pebs_tracer *tracer,
|
||||
const void *buffer, size_t size);
|
||||
extern const struct bts_trace *ds_read_bts(struct bts_tracer *tracer);
|
||||
extern const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer);
|
||||
|
||||
|
||||
/*
|
||||
* Reset the write pointer of the BTS/PEBS buffer.
|
||||
@ -155,27 +231,6 @@ extern int ds_write_pebs(struct pebs_tracer *tracer,
|
||||
extern int ds_reset_bts(struct bts_tracer *tracer);
|
||||
extern int ds_reset_pebs(struct pebs_tracer *tracer);
|
||||
|
||||
/*
|
||||
* Clear the BTS/PEBS buffer and reset the write pointer.
|
||||
* The entire buffer will be zeroed out.
|
||||
*
|
||||
* Returns 0 on success; -Eerrno on error
|
||||
*
|
||||
* tracer: the tracer handle returned from ds_request_~()
|
||||
*/
|
||||
extern int ds_clear_bts(struct bts_tracer *tracer);
|
||||
extern int ds_clear_pebs(struct pebs_tracer *tracer);
|
||||
|
||||
/*
|
||||
* Provide the PEBS counter reset value.
|
||||
*
|
||||
* Returns 0 on success; -Eerrno on error
|
||||
*
|
||||
* tracer: the tracer handle returned from ds_request_pebs()
|
||||
* value (out): the counter reset value
|
||||
*/
|
||||
extern int ds_get_pebs_reset(struct pebs_tracer *tracer, u64 *value);
|
||||
|
||||
/*
|
||||
* Set the PEBS counter reset value.
|
||||
*
|
||||
@ -192,35 +247,17 @@ extern int ds_set_pebs_reset(struct pebs_tracer *tracer, u64 value);
|
||||
struct cpuinfo_x86;
|
||||
extern void __cpuinit ds_init_intel(struct cpuinfo_x86 *);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* The DS context - part of struct thread_struct.
|
||||
* Context switch work
|
||||
*/
|
||||
#define MAX_SIZEOF_DS (12 * 8)
|
||||
|
||||
struct ds_context {
|
||||
/* pointer to the DS configuration; goes into MSR_IA32_DS_AREA */
|
||||
unsigned char ds[MAX_SIZEOF_DS];
|
||||
/* the owner of the BTS and PEBS configuration, respectively */
|
||||
struct ds_tracer *owner[2];
|
||||
/* 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;
|
||||
};
|
||||
|
||||
/* called by exit_thread() to free leftover contexts */
|
||||
extern void ds_free(struct ds_context *context);
|
||||
extern void ds_switch_to(struct task_struct *prev, struct task_struct *next);
|
||||
|
||||
#else /* CONFIG_X86_DS */
|
||||
|
||||
struct cpuinfo_x86;
|
||||
static inline void __cpuinit ds_init_intel(struct cpuinfo_x86 *ignored) {}
|
||||
static inline void ds_switch_to(struct task_struct *prev,
|
||||
struct task_struct *next) {}
|
||||
|
||||
#endif /* CONFIG_X86_DS */
|
||||
#endif /* _ASM_X86_DS_H */
|
||||
|
@ -752,6 +752,19 @@ extern void switch_to_new_gdt(void);
|
||||
extern void cpu_init(void);
|
||||
extern void init_gdt(int cpu);
|
||||
|
||||
static inline unsigned long get_debugctlmsr(void)
|
||||
{
|
||||
unsigned long debugctlmsr = 0;
|
||||
|
||||
#ifndef CONFIG_X86_DEBUGCTLMSR
|
||||
if (boot_cpu_data.x86 < 6)
|
||||
return 0;
|
||||
#endif
|
||||
rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
|
||||
|
||||
return debugctlmsr;
|
||||
}
|
||||
|
||||
static inline void update_debugctlmsr(unsigned long debugctlmsr)
|
||||
{
|
||||
#ifndef CONFIG_X86_DEBUGCTLMSR
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <asm/processor-flags.h>
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <asm/ds.h> /* the DS BTS struct is used for ptrace too */
|
||||
#include <asm/segment.h>
|
||||
#endif
|
||||
|
||||
@ -128,34 +127,6 @@ struct pt_regs {
|
||||
#endif /* !__i386__ */
|
||||
|
||||
|
||||
#ifdef CONFIG_X86_PTRACE_BTS
|
||||
/* a branch trace record entry
|
||||
*
|
||||
* In order to unify the interface between various processor versions,
|
||||
* we use the below data structure for all processors.
|
||||
*/
|
||||
enum bts_qualifier {
|
||||
BTS_INVALID = 0,
|
||||
BTS_BRANCH,
|
||||
BTS_TASK_ARRIVES,
|
||||
BTS_TASK_DEPARTS
|
||||
};
|
||||
|
||||
struct bts_struct {
|
||||
__u64 qualifier;
|
||||
union {
|
||||
/* BTS_BRANCH */
|
||||
struct {
|
||||
__u64 from_ip;
|
||||
__u64 to_ip;
|
||||
} lbr;
|
||||
/* BTS_TASK_ARRIVES or
|
||||
BTS_TASK_DEPARTS */
|
||||
__u64 jiffies;
|
||||
} variant;
|
||||
};
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#include <linux/init.h>
|
||||
@ -163,13 +134,6 @@ struct bts_struct {
|
||||
struct cpuinfo_x86;
|
||||
struct task_struct;
|
||||
|
||||
#ifdef CONFIG_X86_PTRACE_BTS
|
||||
extern void __cpuinit ptrace_bts_init_intel(struct cpuinfo_x86 *);
|
||||
extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);
|
||||
#else
|
||||
#define ptrace_bts_init_intel(config) do {} while (0)
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
|
||||
extern unsigned long profile_pc(struct pt_regs *regs);
|
||||
|
||||
extern unsigned long
|
||||
|
@ -93,7 +93,6 @@ struct thread_info {
|
||||
#define TIF_FORCED_TF 24 /* true if TF in eflags artificially */
|
||||
#define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */
|
||||
#define TIF_DS_AREA_MSR 26 /* uses thread_struct.ds_area_msr */
|
||||
#define TIF_BTS_TRACE_TS 27 /* record scheduling event timestamps */
|
||||
|
||||
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
|
||||
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
|
||||
@ -115,7 +114,6 @@ struct thread_info {
|
||||
#define _TIF_FORCED_TF (1 << TIF_FORCED_TF)
|
||||
#define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR)
|
||||
#define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR)
|
||||
#define _TIF_BTS_TRACE_TS (1 << TIF_BTS_TRACE_TS)
|
||||
|
||||
/* work to do in syscall_trace_enter() */
|
||||
#define _TIF_WORK_SYSCALL_ENTRY \
|
||||
@ -141,8 +139,7 @@ struct thread_info {
|
||||
|
||||
/* flags to check in __switch_to() */
|
||||
#define _TIF_WORK_CTXSW \
|
||||
(_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_BTS_TRACE_TS| \
|
||||
_TIF_NOTSC)
|
||||
(_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_NOTSC)
|
||||
|
||||
#define _TIF_WORK_CTXSW_PREV _TIF_WORK_CTXSW
|
||||
#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG)
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/dmi.h>
|
||||
#include <linux/dmar.h>
|
||||
#include <linux/ftrace.h>
|
||||
|
||||
#include <asm/atomic.h>
|
||||
#include <asm/smp.h>
|
||||
@ -800,7 +801,7 @@ static void local_apic_timer_interrupt(void)
|
||||
* [ if a single-CPU system runs an SMP kernel then we call the local
|
||||
* interrupt as well. Thus we cannot inline the local irq ... ]
|
||||
*/
|
||||
void smp_apic_timer_interrupt(struct pt_regs *regs)
|
||||
void __irq_entry smp_apic_timer_interrupt(struct pt_regs *regs)
|
||||
{
|
||||
struct pt_regs *old_regs = set_irq_regs(regs);
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/msr.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/ptrace.h>
|
||||
#include <asm/ds.h>
|
||||
#include <asm/bugs.h>
|
||||
|
||||
@ -309,9 +308,6 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c)
|
||||
set_cpu_cap(c, X86_FEATURE_P3);
|
||||
#endif
|
||||
|
||||
if (cpu_has_bts)
|
||||
ptrace_bts_init_intel(c);
|
||||
|
||||
detect_extended_topology(c);
|
||||
if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
|
||||
/*
|
||||
|
1037
arch/x86/kernel/ds.c
1037
arch/x86/kernel/ds.c
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,7 @@
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ftrace.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/io_apic.h>
|
||||
#include <asm/idle.h>
|
||||
@ -47,7 +48,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
|
||||
* SMP cross-CPU interrupts have their own specific
|
||||
* handlers).
|
||||
*/
|
||||
asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
|
||||
asmlinkage unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
|
||||
{
|
||||
struct pt_regs *old_regs = set_irq_regs(regs);
|
||||
struct irq_desc *desc;
|
||||
|
@ -252,11 +252,14 @@ void exit_thread(void)
|
||||
put_cpu();
|
||||
}
|
||||
#ifdef CONFIG_X86_DS
|
||||
/* Free any DS contexts that have not been properly released. */
|
||||
if (unlikely(current->thread.ds_ctx)) {
|
||||
/* we clear debugctl to make sure DS is not used. */
|
||||
update_debugctlmsr(0);
|
||||
ds_free(current->thread.ds_ctx);
|
||||
/* Free any BTS tracers that have not been properly released. */
|
||||
if (unlikely(current->bts)) {
|
||||
ds_release_bts(current->bts);
|
||||
current->bts = NULL;
|
||||
|
||||
kfree(current->bts_buffer);
|
||||
current->bts_buffer = NULL;
|
||||
current->bts_size = 0;
|
||||
}
|
||||
#endif /* CONFIG_X86_DS */
|
||||
}
|
||||
@ -420,48 +423,19 @@ int set_tsc_mode(unsigned int val)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_X86_DS
|
||||
static int update_debugctl(struct thread_struct *prev,
|
||||
struct thread_struct *next, unsigned long debugctl)
|
||||
{
|
||||
unsigned long ds_prev = 0;
|
||||
unsigned long ds_next = 0;
|
||||
|
||||
if (prev->ds_ctx)
|
||||
ds_prev = (unsigned long)prev->ds_ctx->ds;
|
||||
if (next->ds_ctx)
|
||||
ds_next = (unsigned long)next->ds_ctx->ds;
|
||||
|
||||
if (ds_next != ds_prev) {
|
||||
/* we clear debugctl to make sure DS
|
||||
* is not in use when we change it */
|
||||
debugctl = 0;
|
||||
update_debugctlmsr(0);
|
||||
wrmsr(MSR_IA32_DS_AREA, ds_next, 0);
|
||||
}
|
||||
return debugctl;
|
||||
}
|
||||
#else
|
||||
static int update_debugctl(struct thread_struct *prev,
|
||||
struct thread_struct *next, unsigned long debugctl)
|
||||
{
|
||||
return debugctl;
|
||||
}
|
||||
#endif /* CONFIG_X86_DS */
|
||||
|
||||
static noinline void
|
||||
__switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
|
||||
struct tss_struct *tss)
|
||||
{
|
||||
struct thread_struct *prev, *next;
|
||||
unsigned long debugctl;
|
||||
|
||||
prev = &prev_p->thread;
|
||||
next = &next_p->thread;
|
||||
|
||||
debugctl = update_debugctl(prev, next, prev->debugctlmsr);
|
||||
|
||||
if (next->debugctlmsr != debugctl)
|
||||
if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) ||
|
||||
test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR))
|
||||
ds_switch_to(prev_p, next_p);
|
||||
else if (next->debugctlmsr != prev->debugctlmsr)
|
||||
update_debugctlmsr(next->debugctlmsr);
|
||||
|
||||
if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
|
||||
@ -483,15 +457,6 @@ __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
|
||||
hard_enable_TSC();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_X86_PTRACE_BTS
|
||||
if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS))
|
||||
ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS);
|
||||
|
||||
if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS))
|
||||
ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES);
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
|
||||
|
||||
if (!test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) {
|
||||
/*
|
||||
* Disable the bitmap via an invalid offset. We still cache
|
||||
|
@ -237,11 +237,14 @@ void exit_thread(void)
|
||||
put_cpu();
|
||||
}
|
||||
#ifdef CONFIG_X86_DS
|
||||
/* Free any DS contexts that have not been properly released. */
|
||||
if (unlikely(t->ds_ctx)) {
|
||||
/* we clear debugctl to make sure DS is not used. */
|
||||
update_debugctlmsr(0);
|
||||
ds_free(t->ds_ctx);
|
||||
/* Free any BTS tracers that have not been properly released. */
|
||||
if (unlikely(current->bts)) {
|
||||
ds_release_bts(current->bts);
|
||||
current->bts = NULL;
|
||||
|
||||
kfree(current->bts_buffer);
|
||||
current->bts_buffer = NULL;
|
||||
current->bts_size = 0;
|
||||
}
|
||||
#endif /* CONFIG_X86_DS */
|
||||
}
|
||||
@ -471,35 +474,14 @@ static inline void __switch_to_xtra(struct task_struct *prev_p,
|
||||
struct tss_struct *tss)
|
||||
{
|
||||
struct thread_struct *prev, *next;
|
||||
unsigned long debugctl;
|
||||
|
||||
prev = &prev_p->thread,
|
||||
next = &next_p->thread;
|
||||
|
||||
debugctl = prev->debugctlmsr;
|
||||
|
||||
#ifdef CONFIG_X86_DS
|
||||
{
|
||||
unsigned long ds_prev = 0, ds_next = 0;
|
||||
|
||||
if (prev->ds_ctx)
|
||||
ds_prev = (unsigned long)prev->ds_ctx->ds;
|
||||
if (next->ds_ctx)
|
||||
ds_next = (unsigned long)next->ds_ctx->ds;
|
||||
|
||||
if (ds_next != ds_prev) {
|
||||
/*
|
||||
* We clear debugctl to make sure DS
|
||||
* is not in use when we change it:
|
||||
*/
|
||||
debugctl = 0;
|
||||
update_debugctlmsr(0);
|
||||
wrmsrl(MSR_IA32_DS_AREA, ds_next);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_X86_DS */
|
||||
|
||||
if (next->debugctlmsr != debugctl)
|
||||
if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) ||
|
||||
test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR))
|
||||
ds_switch_to(prev_p, next_p);
|
||||
else if (next->debugctlmsr != prev->debugctlmsr)
|
||||
update_debugctlmsr(next->debugctlmsr);
|
||||
|
||||
if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
|
||||
@ -534,14 +516,6 @@ static inline void __switch_to_xtra(struct task_struct *prev_p,
|
||||
*/
|
||||
memset(tss->io_bitmap, 0xff, prev->io_bitmap_max);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_X86_PTRACE_BTS
|
||||
if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS))
|
||||
ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS);
|
||||
|
||||
if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS))
|
||||
ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES);
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -581,153 +581,73 @@ static int ioperm_get(struct task_struct *target,
|
||||
}
|
||||
|
||||
#ifdef CONFIG_X86_PTRACE_BTS
|
||||
/*
|
||||
* The configuration for a particular BTS hardware implementation.
|
||||
*/
|
||||
struct bts_configuration {
|
||||
/* the size of a BTS record in bytes; at most BTS_MAX_RECORD_SIZE */
|
||||
unsigned char sizeof_bts;
|
||||
/* the size of a field in the BTS record in bytes */
|
||||
unsigned char sizeof_field;
|
||||
/* a bitmask to enable/disable BTS in DEBUGCTL MSR */
|
||||
unsigned long debugctl_mask;
|
||||
};
|
||||
static struct bts_configuration bts_cfg;
|
||||
|
||||
#define BTS_MAX_RECORD_SIZE (8 * 3)
|
||||
|
||||
|
||||
/*
|
||||
* Branch Trace Store (BTS) uses the following format. Different
|
||||
* architectures vary in the size of those fields.
|
||||
* - source linear address
|
||||
* - destination linear address
|
||||
* - flags
|
||||
*
|
||||
* Later architectures use 64bit pointers throughout, whereas earlier
|
||||
* architectures use 32bit pointers in 32bit mode.
|
||||
*
|
||||
* We compute the base address for the first 8 fields based on:
|
||||
* - the field size stored in the DS configuration
|
||||
* - the relative field position
|
||||
*
|
||||
* In order to store additional information in the BTS buffer, we use
|
||||
* a special source address to indicate that the record requires
|
||||
* special interpretation.
|
||||
*
|
||||
* Netburst indicated via a bit in the flags field whether the branch
|
||||
* was predicted; this is ignored.
|
||||
*/
|
||||
|
||||
enum bts_field {
|
||||
bts_from = 0,
|
||||
bts_to,
|
||||
bts_flags,
|
||||
|
||||
bts_escape = (unsigned long)-1,
|
||||
bts_qual = bts_to,
|
||||
bts_jiffies = bts_flags
|
||||
};
|
||||
|
||||
static inline unsigned long bts_get(const char *base, enum bts_field field)
|
||||
{
|
||||
base += (bts_cfg.sizeof_field * field);
|
||||
return *(unsigned long *)base;
|
||||
}
|
||||
|
||||
static inline void bts_set(char *base, enum bts_field field, unsigned long val)
|
||||
{
|
||||
base += (bts_cfg.sizeof_field * field);;
|
||||
(*(unsigned long *)base) = val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate a BTS record from the raw format into the bts_struct format
|
||||
*
|
||||
* out (out): bts_struct interpretation
|
||||
* raw: raw BTS record
|
||||
*/
|
||||
static void ptrace_bts_translate_record(struct bts_struct *out, const void *raw)
|
||||
{
|
||||
memset(out, 0, sizeof(*out));
|
||||
if (bts_get(raw, bts_from) == bts_escape) {
|
||||
out->qualifier = bts_get(raw, bts_qual);
|
||||
out->variant.jiffies = bts_get(raw, bts_jiffies);
|
||||
} else {
|
||||
out->qualifier = BTS_BRANCH;
|
||||
out->variant.lbr.from_ip = bts_get(raw, bts_from);
|
||||
out->variant.lbr.to_ip = bts_get(raw, bts_to);
|
||||
}
|
||||
}
|
||||
|
||||
static int ptrace_bts_read_record(struct task_struct *child, size_t index,
|
||||
struct bts_struct __user *out)
|
||||
{
|
||||
struct bts_struct ret;
|
||||
const void *bts_record;
|
||||
size_t bts_index, bts_end;
|
||||
const struct bts_trace *trace;
|
||||
struct bts_struct bts;
|
||||
const unsigned char *at;
|
||||
int error;
|
||||
|
||||
error = ds_get_bts_end(child->bts, &bts_end);
|
||||
trace = ds_read_bts(child->bts);
|
||||
if (!trace)
|
||||
return -EPERM;
|
||||
|
||||
at = trace->ds.top - ((index + 1) * trace->ds.size);
|
||||
if ((void *)at < trace->ds.begin)
|
||||
at += (trace->ds.n * trace->ds.size);
|
||||
|
||||
if (!trace->read)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
error = trace->read(child->bts, at, &bts);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
if (bts_end <= index)
|
||||
return -EINVAL;
|
||||
|
||||
error = ds_get_bts_index(child->bts, &bts_index);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
/* translate the ptrace bts index into the ds bts index */
|
||||
bts_index += bts_end - (index + 1);
|
||||
if (bts_end <= bts_index)
|
||||
bts_index -= bts_end;
|
||||
|
||||
error = ds_access_bts(child->bts, bts_index, &bts_record);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
ptrace_bts_translate_record(&ret, bts_record);
|
||||
|
||||
if (copy_to_user(out, &ret, sizeof(ret)))
|
||||
if (copy_to_user(out, &bts, sizeof(bts)))
|
||||
return -EFAULT;
|
||||
|
||||
return sizeof(ret);
|
||||
return sizeof(bts);
|
||||
}
|
||||
|
||||
static int ptrace_bts_drain(struct task_struct *child,
|
||||
long size,
|
||||
struct bts_struct __user *out)
|
||||
{
|
||||
struct bts_struct ret;
|
||||
const unsigned char *raw;
|
||||
size_t end, i;
|
||||
int error;
|
||||
const struct bts_trace *trace;
|
||||
const unsigned char *at;
|
||||
int error, drained = 0;
|
||||
|
||||
error = ds_get_bts_index(child->bts, &end);
|
||||
if (error < 0)
|
||||
return error;
|
||||
trace = ds_read_bts(child->bts);
|
||||
if (!trace)
|
||||
return -EPERM;
|
||||
|
||||
if (size < (end * sizeof(struct bts_struct)))
|
||||
if (!trace->read)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (size < (trace->ds.top - trace->ds.begin))
|
||||
return -EIO;
|
||||
|
||||
error = ds_access_bts(child->bts, 0, (const void **)&raw);
|
||||
if (error < 0)
|
||||
return error;
|
||||
for (at = trace->ds.begin; (void *)at < trace->ds.top;
|
||||
out++, drained++, at += trace->ds.size) {
|
||||
struct bts_struct bts;
|
||||
int error;
|
||||
|
||||
for (i = 0; i < end; i++, out++, raw += bts_cfg.sizeof_bts) {
|
||||
ptrace_bts_translate_record(&ret, raw);
|
||||
error = trace->read(child->bts, at, &bts);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
if (copy_to_user(out, &ret, sizeof(ret)))
|
||||
if (copy_to_user(out, &bts, sizeof(bts)))
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
error = ds_clear_bts(child->bts);
|
||||
memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size);
|
||||
|
||||
error = ds_reset_bts(child->bts);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
return end;
|
||||
return drained;
|
||||
}
|
||||
|
||||
static int ptrace_bts_config(struct task_struct *child,
|
||||
@ -735,136 +655,89 @@ static int ptrace_bts_config(struct task_struct *child,
|
||||
const struct ptrace_bts_config __user *ucfg)
|
||||
{
|
||||
struct ptrace_bts_config cfg;
|
||||
int error = 0;
|
||||
unsigned int flags = 0;
|
||||
|
||||
error = -EOPNOTSUPP;
|
||||
if (!bts_cfg.sizeof_bts)
|
||||
goto errout;
|
||||
|
||||
error = -EIO;
|
||||
if (cfg_size < sizeof(cfg))
|
||||
goto errout;
|
||||
return -EIO;
|
||||
|
||||
error = -EFAULT;
|
||||
if (copy_from_user(&cfg, ucfg, sizeof(cfg)))
|
||||
goto errout;
|
||||
return -EFAULT;
|
||||
|
||||
error = -EINVAL;
|
||||
if ((cfg.flags & PTRACE_BTS_O_SIGNAL) &&
|
||||
!(cfg.flags & PTRACE_BTS_O_ALLOC))
|
||||
goto errout;
|
||||
|
||||
if (cfg.flags & PTRACE_BTS_O_ALLOC) {
|
||||
bts_ovfl_callback_t ovfl = NULL;
|
||||
unsigned int sig = 0;
|
||||
|
||||
error = -EINVAL;
|
||||
if (cfg.size < (10 * bts_cfg.sizeof_bts))
|
||||
goto errout;
|
||||
|
||||
if (cfg.flags & PTRACE_BTS_O_SIGNAL) {
|
||||
if (!cfg.signal)
|
||||
goto errout;
|
||||
|
||||
error = -EOPNOTSUPP;
|
||||
goto errout;
|
||||
|
||||
sig = cfg.signal;
|
||||
}
|
||||
|
||||
if (child->bts) {
|
||||
(void)ds_release_bts(child->bts);
|
||||
kfree(child->bts_buffer);
|
||||
|
||||
child->bts = NULL;
|
||||
child->bts_buffer = NULL;
|
||||
}
|
||||
|
||||
error = -ENOMEM;
|
||||
child->bts_buffer = kzalloc(cfg.size, GFP_KERNEL);
|
||||
if (!child->bts_buffer)
|
||||
goto errout;
|
||||
|
||||
child->bts = ds_request_bts(child, child->bts_buffer, cfg.size,
|
||||
ovfl, /* th = */ (size_t)-1);
|
||||
if (IS_ERR(child->bts)) {
|
||||
error = PTR_ERR(child->bts);
|
||||
kfree(child->bts_buffer);
|
||||
child->bts = NULL;
|
||||
child->bts_buffer = NULL;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
child->thread.bts_ovfl_signal = sig;
|
||||
if (child->bts) {
|
||||
ds_release_bts(child->bts);
|
||||
child->bts = NULL;
|
||||
}
|
||||
|
||||
error = -EINVAL;
|
||||
if (!child->thread.ds_ctx && cfg.flags)
|
||||
goto errout;
|
||||
if (cfg.flags & PTRACE_BTS_O_SIGNAL) {
|
||||
if (!cfg.signal)
|
||||
return -EINVAL;
|
||||
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
child->thread.bts_ovfl_signal = cfg.signal;
|
||||
}
|
||||
|
||||
if ((cfg.flags & PTRACE_BTS_O_ALLOC) &&
|
||||
(cfg.size != child->bts_size)) {
|
||||
kfree(child->bts_buffer);
|
||||
|
||||
child->bts_size = cfg.size;
|
||||
child->bts_buffer = kzalloc(cfg.size, GFP_KERNEL);
|
||||
if (!child->bts_buffer) {
|
||||
child->bts_size = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg.flags & PTRACE_BTS_O_TRACE)
|
||||
child->thread.debugctlmsr |= bts_cfg.debugctl_mask;
|
||||
else
|
||||
child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask;
|
||||
flags |= BTS_USER;
|
||||
|
||||
if (cfg.flags & PTRACE_BTS_O_SCHED)
|
||||
set_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
|
||||
else
|
||||
clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
|
||||
flags |= BTS_TIMESTAMPS;
|
||||
|
||||
error = sizeof(cfg);
|
||||
child->bts = ds_request_bts(child, child->bts_buffer, child->bts_size,
|
||||
/* ovfl = */ NULL, /* th = */ (size_t)-1,
|
||||
flags);
|
||||
if (IS_ERR(child->bts)) {
|
||||
int error = PTR_ERR(child->bts);
|
||||
|
||||
out:
|
||||
if (child->thread.debugctlmsr)
|
||||
set_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
|
||||
else
|
||||
clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
|
||||
kfree(child->bts_buffer);
|
||||
child->bts = NULL;
|
||||
child->bts_buffer = NULL;
|
||||
child->bts_size = 0;
|
||||
|
||||
return error;
|
||||
return error;
|
||||
}
|
||||
|
||||
errout:
|
||||
child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask;
|
||||
clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
|
||||
goto out;
|
||||
return sizeof(cfg);
|
||||
}
|
||||
|
||||
static int ptrace_bts_status(struct task_struct *child,
|
||||
long cfg_size,
|
||||
struct ptrace_bts_config __user *ucfg)
|
||||
{
|
||||
const struct bts_trace *trace;
|
||||
struct ptrace_bts_config cfg;
|
||||
size_t end;
|
||||
const void *base, *max;
|
||||
int error;
|
||||
|
||||
if (cfg_size < sizeof(cfg))
|
||||
return -EIO;
|
||||
|
||||
error = ds_get_bts_end(child->bts, &end);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
error = ds_access_bts(child->bts, /* index = */ 0, &base);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
error = ds_access_bts(child->bts, /* index = */ end, &max);
|
||||
if (error < 0)
|
||||
return error;
|
||||
trace = ds_read_bts(child->bts);
|
||||
if (!trace)
|
||||
return -EPERM;
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.size = (max - base);
|
||||
cfg.size = trace->ds.end - trace->ds.begin;
|
||||
cfg.signal = child->thread.bts_ovfl_signal;
|
||||
cfg.bts_size = sizeof(struct bts_struct);
|
||||
|
||||
if (cfg.signal)
|
||||
cfg.flags |= PTRACE_BTS_O_SIGNAL;
|
||||
|
||||
if (test_tsk_thread_flag(child, TIF_DEBUGCTLMSR) &&
|
||||
child->thread.debugctlmsr & bts_cfg.debugctl_mask)
|
||||
if (trace->ds.flags & BTS_USER)
|
||||
cfg.flags |= PTRACE_BTS_O_TRACE;
|
||||
|
||||
if (test_tsk_thread_flag(child, TIF_BTS_TRACE_TS))
|
||||
if (trace->ds.flags & BTS_TIMESTAMPS)
|
||||
cfg.flags |= PTRACE_BTS_O_SCHED;
|
||||
|
||||
if (copy_to_user(ucfg, &cfg, sizeof(cfg)))
|
||||
@ -873,104 +746,28 @@ static int ptrace_bts_status(struct task_struct *child,
|
||||
return sizeof(cfg);
|
||||
}
|
||||
|
||||
static int ptrace_bts_write_record(struct task_struct *child,
|
||||
const struct bts_struct *in)
|
||||
static int ptrace_bts_clear(struct task_struct *child)
|
||||
{
|
||||
unsigned char bts_record[BTS_MAX_RECORD_SIZE];
|
||||
const struct bts_trace *trace;
|
||||
|
||||
BUG_ON(BTS_MAX_RECORD_SIZE < bts_cfg.sizeof_bts);
|
||||
trace = ds_read_bts(child->bts);
|
||||
if (!trace)
|
||||
return -EPERM;
|
||||
|
||||
memset(bts_record, 0, bts_cfg.sizeof_bts);
|
||||
switch (in->qualifier) {
|
||||
case BTS_INVALID:
|
||||
break;
|
||||
memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size);
|
||||
|
||||
case BTS_BRANCH:
|
||||
bts_set(bts_record, bts_from, in->variant.lbr.from_ip);
|
||||
bts_set(bts_record, bts_to, in->variant.lbr.to_ip);
|
||||
break;
|
||||
|
||||
case BTS_TASK_ARRIVES:
|
||||
case BTS_TASK_DEPARTS:
|
||||
bts_set(bts_record, bts_from, bts_escape);
|
||||
bts_set(bts_record, bts_qual, in->qualifier);
|
||||
bts_set(bts_record, bts_jiffies, in->variant.jiffies);
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return ds_write_bts(child->bts, bts_record, bts_cfg.sizeof_bts);
|
||||
return ds_reset_bts(child->bts);
|
||||
}
|
||||
|
||||
void ptrace_bts_take_timestamp(struct task_struct *tsk,
|
||||
enum bts_qualifier qualifier)
|
||||
static int ptrace_bts_size(struct task_struct *child)
|
||||
{
|
||||
struct bts_struct rec = {
|
||||
.qualifier = qualifier,
|
||||
.variant.jiffies = jiffies_64
|
||||
};
|
||||
const struct bts_trace *trace;
|
||||
|
||||
ptrace_bts_write_record(tsk, &rec);
|
||||
}
|
||||
trace = ds_read_bts(child->bts);
|
||||
if (!trace)
|
||||
return -EPERM;
|
||||
|
||||
static const struct bts_configuration bts_cfg_netburst = {
|
||||
.sizeof_bts = sizeof(long) * 3,
|
||||
.sizeof_field = sizeof(long),
|
||||
.debugctl_mask = (1<<2)|(1<<3)|(1<<5)
|
||||
};
|
||||
|
||||
static const struct bts_configuration bts_cfg_pentium_m = {
|
||||
.sizeof_bts = sizeof(long) * 3,
|
||||
.sizeof_field = sizeof(long),
|
||||
.debugctl_mask = (1<<6)|(1<<7)
|
||||
};
|
||||
|
||||
static const struct bts_configuration bts_cfg_core2 = {
|
||||
.sizeof_bts = 8 * 3,
|
||||
.sizeof_field = 8,
|
||||
.debugctl_mask = (1<<6)|(1<<7)|(1<<9)
|
||||
};
|
||||
|
||||
static inline void bts_configure(const struct bts_configuration *cfg)
|
||||
{
|
||||
bts_cfg = *cfg;
|
||||
}
|
||||
|
||||
void __cpuinit ptrace_bts_init_intel(struct cpuinfo_x86 *c)
|
||||
{
|
||||
switch (c->x86) {
|
||||
case 0x6:
|
||||
switch (c->x86_model) {
|
||||
case 0 ... 0xC:
|
||||
/* sorry, don't know about them */
|
||||
break;
|
||||
case 0xD:
|
||||
case 0xE: /* Pentium M */
|
||||
bts_configure(&bts_cfg_pentium_m);
|
||||
break;
|
||||
default: /* Core2, Atom, ... */
|
||||
bts_configure(&bts_cfg_core2);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0xF:
|
||||
switch (c->x86_model) {
|
||||
case 0x0:
|
||||
case 0x1:
|
||||
case 0x2: /* Netburst */
|
||||
bts_configure(&bts_cfg_netburst);
|
||||
break;
|
||||
default:
|
||||
/* sorry, don't know about them */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* sorry, don't know about them */
|
||||
break;
|
||||
}
|
||||
return (trace->ds.top - trace->ds.begin) / trace->ds.size;
|
||||
}
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
|
||||
@ -987,15 +784,12 @@ void ptrace_disable(struct task_struct *child)
|
||||
#endif
|
||||
#ifdef CONFIG_X86_PTRACE_BTS
|
||||
if (child->bts) {
|
||||
(void)ds_release_bts(child->bts);
|
||||
ds_release_bts(child->bts);
|
||||
child->bts = NULL;
|
||||
|
||||
kfree(child->bts_buffer);
|
||||
child->bts_buffer = NULL;
|
||||
|
||||
child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask;
|
||||
if (!child->thread.debugctlmsr)
|
||||
clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
|
||||
|
||||
clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
|
||||
child->bts_size = 0;
|
||||
}
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
}
|
||||
@ -1128,16 +922,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
|
||||
(child, data, (struct ptrace_bts_config __user *)addr);
|
||||
break;
|
||||
|
||||
case PTRACE_BTS_SIZE: {
|
||||
size_t size;
|
||||
|
||||
ret = ds_get_bts_index(child->bts, &size);
|
||||
if (ret == 0) {
|
||||
BUG_ON(size != (int) size);
|
||||
ret = (int) size;
|
||||
}
|
||||
case PTRACE_BTS_SIZE:
|
||||
ret = ptrace_bts_size(child);
|
||||
break;
|
||||
}
|
||||
|
||||
case PTRACE_BTS_GET:
|
||||
ret = ptrace_bts_read_record
|
||||
@ -1145,7 +932,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
|
||||
break;
|
||||
|
||||
case PTRACE_BTS_CLEAR:
|
||||
ret = ds_clear_bts(child->bts);
|
||||
ret = ptrace_bts_clear(child);
|
||||
break;
|
||||
|
||||
case PTRACE_BTS_DRAIN:
|
||||
@ -1408,6 +1195,14 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
|
||||
|
||||
case PTRACE_GET_THREAD_AREA:
|
||||
case PTRACE_SET_THREAD_AREA:
|
||||
#ifdef CONFIG_X86_PTRACE_BTS
|
||||
case PTRACE_BTS_CONFIG:
|
||||
case PTRACE_BTS_STATUS:
|
||||
case PTRACE_BTS_SIZE:
|
||||
case PTRACE_BTS_GET:
|
||||
case PTRACE_BTS_CLEAR:
|
||||
case PTRACE_BTS_DRAIN:
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
return arch_ptrace(child, request, addr, data);
|
||||
|
||||
default:
|
||||
|
@ -44,6 +44,7 @@ SECTIONS
|
||||
SCHED_TEXT
|
||||
LOCK_TEXT
|
||||
KPROBES_TEXT
|
||||
IRQENTRY_TEXT
|
||||
*(.fixup)
|
||||
*(.gnu.warning)
|
||||
_etext = .; /* End of text section */
|
||||
|
@ -35,6 +35,7 @@ SECTIONS
|
||||
SCHED_TEXT
|
||||
LOCK_TEXT
|
||||
KPROBES_TEXT
|
||||
IRQENTRY_TEXT
|
||||
*(.fixup)
|
||||
*(.gnu.warning)
|
||||
_etext = .; /* End of text section */
|
||||
|
@ -288,6 +288,16 @@
|
||||
*(.kprobes.text) \
|
||||
VMLINUX_SYMBOL(__kprobes_text_end) = .;
|
||||
|
||||
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
||||
#define IRQENTRY_TEXT \
|
||||
ALIGN_FUNCTION(); \
|
||||
VMLINUX_SYMBOL(__irqentry_text_start) = .; \
|
||||
*(.irqentry.text) \
|
||||
VMLINUX_SYMBOL(__irqentry_text_end) = .;
|
||||
#else
|
||||
#define IRQENTRY_TEXT
|
||||
#endif
|
||||
|
||||
/* Section used for early init (in .S files) */
|
||||
#define HEAD_TEXT *(.head.text)
|
||||
|
||||
|
@ -377,6 +377,16 @@ struct ftrace_graph_ret {
|
||||
*/
|
||||
#define __notrace_funcgraph notrace
|
||||
|
||||
/*
|
||||
* We want to which function is an entrypoint of a hardirq.
|
||||
* That will help us to put a signal on output.
|
||||
*/
|
||||
#define __irq_entry __attribute__((__section__(".irqentry.text")))
|
||||
|
||||
/* Limits of hardirq entrypoints */
|
||||
extern char __irqentry_text_start[];
|
||||
extern char __irqentry_text_end[];
|
||||
|
||||
#define FTRACE_RETFUNC_DEPTH 50
|
||||
#define FTRACE_RETSTACK_ALLOC_SIZE 32
|
||||
/* Type of the callback handlers for tracing function graph*/
|
||||
@ -414,6 +424,7 @@ static inline void unpause_graph_tracing(void)
|
||||
#else
|
||||
|
||||
#define __notrace_funcgraph
|
||||
#define __irq_entry
|
||||
|
||||
static inline void ftrace_graph_init_task(struct task_struct *t) { }
|
||||
static inline void ftrace_graph_exit_task(struct task_struct *t) { }
|
||||
|
@ -1176,6 +1176,7 @@ struct task_struct {
|
||||
* The buffer to hold the BTS data.
|
||||
*/
|
||||
void *bts_buffer;
|
||||
size_t bts_size;
|
||||
#endif /* CONFIG_X86_PTRACE_BTS */
|
||||
|
||||
/* PID/PID hash table linkage. */
|
||||
|
@ -30,8 +30,8 @@ DECLARE_TRACE(sched_switch,
|
||||
TPARGS(rq, prev, next));
|
||||
|
||||
DECLARE_TRACE(sched_migrate_task,
|
||||
TPPROTO(struct rq *rq, struct task_struct *p, int dest_cpu),
|
||||
TPARGS(rq, p, dest_cpu));
|
||||
TPPROTO(struct task_struct *p, int orig_cpu, int dest_cpu),
|
||||
TPARGS(p, orig_cpu, dest_cpu));
|
||||
|
||||
DECLARE_TRACE(sched_process_free,
|
||||
TPPROTO(struct task_struct *p),
|
||||
|
@ -1851,6 +1851,8 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
|
||||
|
||||
clock_offset = old_rq->clock - new_rq->clock;
|
||||
|
||||
trace_sched_migrate_task(p, task_cpu(p), new_cpu);
|
||||
|
||||
#ifdef CONFIG_SCHEDSTATS
|
||||
if (p->se.wait_start)
|
||||
p->se.wait_start -= clock_offset;
|
||||
@ -2868,7 +2870,6 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu)
|
||||
|| unlikely(!cpu_active(dest_cpu)))
|
||||
goto out;
|
||||
|
||||
trace_sched_migrate_task(rq, p, dest_cpu);
|
||||
/* force the process onto the specified CPU */
|
||||
if (migrate_task(p, dest_cpu, &req)) {
|
||||
/* Need to wait for migration thread (might exit: take ref). */
|
||||
|
@ -251,9 +251,9 @@ config STACK_TRACER
|
||||
|
||||
Say N if unsure.
|
||||
|
||||
config BTS_TRACER
|
||||
config HW_BRANCH_TRACER
|
||||
depends on HAVE_HW_BRANCH_TRACER
|
||||
bool "Trace branches"
|
||||
bool "Trace hw branches"
|
||||
select TRACING
|
||||
help
|
||||
This tracer records all branches on the system in a circular
|
||||
|
@ -31,7 +31,7 @@ obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
|
||||
obj-$(CONFIG_BOOT_TRACER) += trace_boot.o
|
||||
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o
|
||||
obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o
|
||||
obj-$(CONFIG_BTS_TRACER) += trace_bts.o
|
||||
obj-$(CONFIG_HW_BRANCH_TRACER) += trace_hw_branches.o
|
||||
obj-$(CONFIG_POWER_TRACER) += trace_power.o
|
||||
|
||||
libftrace-y := ftrace.o
|
||||
|
@ -2425,7 +2425,7 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
|
||||
|
||||
/* Notify the tracer early; before we stop tracing. */
|
||||
if (iter->trace && iter->trace->open)
|
||||
iter->trace->open(iter);
|
||||
iter->trace->open(iter);
|
||||
|
||||
/* Annotate start of buffers if we had overruns */
|
||||
if (ring_buffer_overruns(iter->tr->buffer))
|
||||
|
@ -28,7 +28,7 @@ enum trace_type {
|
||||
TRACE_GRAPH_RET,
|
||||
TRACE_GRAPH_ENT,
|
||||
TRACE_USER_STACK,
|
||||
TRACE_BTS,
|
||||
TRACE_HW_BRANCHES,
|
||||
TRACE_POWER,
|
||||
|
||||
__TRACE_LAST_TYPE
|
||||
@ -159,10 +159,10 @@ struct trace_branch {
|
||||
char correct;
|
||||
};
|
||||
|
||||
struct bts_entry {
|
||||
struct hw_branch_entry {
|
||||
struct trace_entry ent;
|
||||
unsigned long from;
|
||||
unsigned long to;
|
||||
u64 from;
|
||||
u64 to;
|
||||
};
|
||||
|
||||
struct trace_power {
|
||||
@ -278,7 +278,7 @@ extern void __ftrace_bad_type(void);
|
||||
TRACE_GRAPH_ENT); \
|
||||
IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
|
||||
TRACE_GRAPH_RET); \
|
||||
IF_ASSIGN(var, ent, struct bts_entry, TRACE_BTS);\
|
||||
IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
|
||||
IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
|
||||
__ftrace_bad_type(); \
|
||||
} while (0)
|
||||
@ -414,9 +414,7 @@ void trace_function(struct trace_array *tr,
|
||||
|
||||
void trace_graph_return(struct ftrace_graph_ret *trace);
|
||||
int trace_graph_entry(struct ftrace_graph_ent *trace);
|
||||
void trace_bts(struct trace_array *tr,
|
||||
unsigned long from,
|
||||
unsigned long to);
|
||||
void trace_hw_branch(struct trace_array *tr, u64 from, u64 to);
|
||||
|
||||
void tracing_start_cmdline_record(void);
|
||||
void tracing_stop_cmdline_record(void);
|
||||
|
@ -231,6 +231,49 @@ trace_branch_is_leaf(struct trace_iterator *iter,
|
||||
return true;
|
||||
}
|
||||
|
||||
static enum print_line_t
|
||||
print_graph_irq(struct trace_seq *s, unsigned long addr,
|
||||
enum trace_type type, int cpu, pid_t pid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (addr < (unsigned long)__irqentry_text_start ||
|
||||
addr >= (unsigned long)__irqentry_text_end)
|
||||
return TRACE_TYPE_UNHANDLED;
|
||||
|
||||
if (type == TRACE_GRAPH_ENT) {
|
||||
ret = trace_seq_printf(s, "==========> | ");
|
||||
} else {
|
||||
/* Cpu */
|
||||
if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
|
||||
ret = print_graph_cpu(s, cpu);
|
||||
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
}
|
||||
/* Proc */
|
||||
if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) {
|
||||
ret = print_graph_proc(s, pid);
|
||||
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
|
||||
ret = trace_seq_printf(s, " | ");
|
||||
if (!ret)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
}
|
||||
|
||||
/* No overhead */
|
||||
if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERHEAD) {
|
||||
ret = trace_seq_printf(s, " ");
|
||||
if (!ret)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
}
|
||||
|
||||
ret = trace_seq_printf(s, "<========== |\n");
|
||||
}
|
||||
if (!ret)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
return TRACE_TYPE_HANDLED;
|
||||
}
|
||||
|
||||
static enum print_line_t
|
||||
print_graph_duration(unsigned long long duration, struct trace_seq *s)
|
||||
@ -344,7 +387,7 @@ print_graph_entry_leaf(struct trace_iterator *iter,
|
||||
|
||||
static enum print_line_t
|
||||
print_graph_entry_nested(struct ftrace_graph_ent_entry *entry,
|
||||
struct trace_seq *s)
|
||||
struct trace_seq *s, pid_t pid, int cpu)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
@ -357,8 +400,18 @@ print_graph_entry_nested(struct ftrace_graph_ent_entry *entry,
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
}
|
||||
|
||||
/* No time */
|
||||
ret = trace_seq_printf(s, " | ");
|
||||
/* Interrupt */
|
||||
ret = print_graph_irq(s, call->func, TRACE_GRAPH_ENT, cpu, pid);
|
||||
if (ret == TRACE_TYPE_UNHANDLED) {
|
||||
/* No time */
|
||||
ret = trace_seq_printf(s, " | ");
|
||||
if (!ret)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
} else {
|
||||
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
}
|
||||
|
||||
|
||||
/* Function */
|
||||
for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) {
|
||||
@ -410,7 +463,7 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
|
||||
if (trace_branch_is_leaf(iter, field))
|
||||
return print_graph_entry_leaf(iter, field, s);
|
||||
else
|
||||
return print_graph_entry_nested(field, s);
|
||||
return print_graph_entry_nested(field, s, iter->ent->pid, cpu);
|
||||
|
||||
}
|
||||
|
||||
@ -474,6 +527,11 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
|
||||
if (!ret)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
}
|
||||
|
||||
ret = print_graph_irq(s, trace->func, TRACE_GRAPH_RET, cpu, ent->pid);
|
||||
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
|
||||
return TRACE_TYPE_HANDLED;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* BTS tracer
|
||||
* h/w branch tracer for x86 based on bts
|
||||
*
|
||||
* Copyright (C) 2008 Markus Metzger <markus.t.metzger@gmail.com>
|
||||
*
|
||||
@ -25,68 +25,6 @@ static DEFINE_PER_CPU(unsigned char[SIZEOF_BTS], buffer);
|
||||
#define this_buffer per_cpu(buffer, smp_processor_id())
|
||||
|
||||
|
||||
/*
|
||||
* Information to interpret a BTS record.
|
||||
* This will go into an in-kernel BTS interface.
|
||||
*/
|
||||
static unsigned char sizeof_field;
|
||||
static unsigned long debugctl_mask;
|
||||
|
||||
#define sizeof_bts (3 * sizeof_field)
|
||||
|
||||
static void bts_trace_cpuinit(struct cpuinfo_x86 *c)
|
||||
{
|
||||
switch (c->x86) {
|
||||
case 0x6:
|
||||
switch (c->x86_model) {
|
||||
case 0x0 ... 0xC:
|
||||
break;
|
||||
case 0xD:
|
||||
case 0xE: /* Pentium M */
|
||||
sizeof_field = sizeof(long);
|
||||
debugctl_mask = (1<<6)|(1<<7);
|
||||
break;
|
||||
default:
|
||||
sizeof_field = 8;
|
||||
debugctl_mask = (1<<6)|(1<<7);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0xF:
|
||||
switch (c->x86_model) {
|
||||
case 0x0:
|
||||
case 0x1:
|
||||
case 0x2: /* Netburst */
|
||||
sizeof_field = sizeof(long);
|
||||
debugctl_mask = (1<<2)|(1<<3);
|
||||
break;
|
||||
default:
|
||||
/* sorry, don't know about them */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* sorry, don't know about them */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void bts_enable(void)
|
||||
{
|
||||
unsigned long debugctl;
|
||||
|
||||
rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
|
||||
wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl | debugctl_mask);
|
||||
}
|
||||
|
||||
static inline void bts_disable(void)
|
||||
{
|
||||
unsigned long debugctl;
|
||||
|
||||
rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
|
||||
wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl & ~debugctl_mask);
|
||||
}
|
||||
|
||||
static void bts_trace_reset(struct trace_array *tr)
|
||||
{
|
||||
int cpu;
|
||||
@ -99,15 +37,17 @@ static void bts_trace_reset(struct trace_array *tr)
|
||||
|
||||
static void bts_trace_start_cpu(void *arg)
|
||||
{
|
||||
if (this_tracer)
|
||||
ds_release_bts(this_tracer);
|
||||
|
||||
this_tracer =
|
||||
ds_request_bts(/* task = */ NULL, this_buffer, SIZEOF_BTS,
|
||||
/* ovfl = */ NULL, /* th = */ (size_t)-1);
|
||||
/* ovfl = */ NULL, /* th = */ (size_t)-1,
|
||||
BTS_KERNEL);
|
||||
if (IS_ERR(this_tracer)) {
|
||||
this_tracer = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
bts_enable();
|
||||
}
|
||||
|
||||
static void bts_trace_start(struct trace_array *tr)
|
||||
@ -123,8 +63,6 @@ static void bts_trace_start(struct trace_array *tr)
|
||||
static void bts_trace_stop_cpu(void *arg)
|
||||
{
|
||||
if (this_tracer) {
|
||||
bts_disable();
|
||||
|
||||
ds_release_bts(this_tracer);
|
||||
this_tracer = NULL;
|
||||
}
|
||||
@ -140,7 +78,6 @@ static void bts_trace_stop(struct trace_array *tr)
|
||||
|
||||
static int bts_trace_init(struct trace_array *tr)
|
||||
{
|
||||
bts_trace_cpuinit(&boot_cpu_data);
|
||||
bts_trace_reset(tr);
|
||||
bts_trace_start(tr);
|
||||
|
||||
@ -149,47 +86,37 @@ static int bts_trace_init(struct trace_array *tr)
|
||||
|
||||
static void bts_trace_print_header(struct seq_file *m)
|
||||
{
|
||||
#ifdef __i386__
|
||||
seq_puts(m, "# CPU# FROM TO FUNCTION\n");
|
||||
seq_puts(m, "# | | | |\n");
|
||||
#else
|
||||
seq_puts(m,
|
||||
"# CPU# FROM TO FUNCTION\n");
|
||||
seq_puts(m,
|
||||
"# | | | |\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static enum print_line_t bts_trace_print_line(struct trace_iterator *iter)
|
||||
{
|
||||
struct trace_entry *entry = iter->ent;
|
||||
struct trace_seq *seq = &iter->seq;
|
||||
struct bts_entry *it;
|
||||
struct hw_branch_entry *it;
|
||||
|
||||
trace_assign_type(it, entry);
|
||||
|
||||
if (entry->type == TRACE_BTS) {
|
||||
int ret;
|
||||
#ifdef CONFIG_KALLSYMS
|
||||
char function[KSYM_SYMBOL_LEN];
|
||||
sprint_symbol(function, it->from);
|
||||
#else
|
||||
char *function = "<unknown>";
|
||||
#endif
|
||||
|
||||
ret = trace_seq_printf(seq, "%4d 0x%lx -> 0x%lx [%s]\n",
|
||||
entry->cpu, it->from, it->to, function);
|
||||
if (!ret)
|
||||
return TRACE_TYPE_PARTIAL_LINE;;
|
||||
return TRACE_TYPE_HANDLED;
|
||||
if (entry->type == TRACE_HW_BRANCHES) {
|
||||
if (trace_seq_printf(seq, "%4d ", entry->cpu) &&
|
||||
trace_seq_printf(seq, "0x%016llx -> 0x%016llx ",
|
||||
it->from, it->to) &&
|
||||
(!it->from ||
|
||||
seq_print_ip_sym(seq, it->from, /* sym_flags = */ 0)) &&
|
||||
trace_seq_printf(seq, "\n"))
|
||||
return TRACE_TYPE_HANDLED;
|
||||
return TRACE_TYPE_PARTIAL_LINE;;
|
||||
}
|
||||
return TRACE_TYPE_UNHANDLED;
|
||||
}
|
||||
|
||||
void trace_bts(struct trace_array *tr, unsigned long from, unsigned long to)
|
||||
void trace_hw_branch(struct trace_array *tr, u64 from, u64 to)
|
||||
{
|
||||
struct ring_buffer_event *event;
|
||||
struct bts_entry *entry;
|
||||
struct hw_branch_entry *entry;
|
||||
unsigned long irq;
|
||||
|
||||
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), &irq);
|
||||
@ -197,56 +124,58 @@ void trace_bts(struct trace_array *tr, unsigned long from, unsigned long to)
|
||||
return;
|
||||
entry = ring_buffer_event_data(event);
|
||||
tracing_generic_entry_update(&entry->ent, 0, from);
|
||||
entry->ent.type = TRACE_BTS;
|
||||
entry->ent.type = TRACE_HW_BRANCHES;
|
||||
entry->ent.cpu = smp_processor_id();
|
||||
entry->from = from;
|
||||
entry->to = to;
|
||||
ring_buffer_unlock_commit(tr->buffer, event, irq);
|
||||
}
|
||||
|
||||
static void trace_bts_at(struct trace_array *tr, size_t index)
|
||||
static void trace_bts_at(struct trace_array *tr,
|
||||
const struct bts_trace *trace, void *at)
|
||||
{
|
||||
const void *raw = NULL;
|
||||
unsigned long from, to;
|
||||
int err;
|
||||
struct bts_struct bts;
|
||||
int err = 0;
|
||||
|
||||
err = ds_access_bts(this_tracer, index, &raw);
|
||||
WARN_ON_ONCE(!trace->read);
|
||||
if (!trace->read)
|
||||
return;
|
||||
|
||||
err = trace->read(this_tracer, at, &bts);
|
||||
if (err < 0)
|
||||
return;
|
||||
|
||||
from = *(const unsigned long *)raw;
|
||||
to = *(const unsigned long *)((const char *)raw + sizeof_field);
|
||||
|
||||
trace_bts(tr, from, to);
|
||||
switch (bts.qualifier) {
|
||||
case BTS_BRANCH:
|
||||
trace_hw_branch(tr, bts.variant.lbr.from, bts.variant.lbr.to);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void trace_bts_cpu(void *arg)
|
||||
{
|
||||
struct trace_array *tr = (struct trace_array *) arg;
|
||||
size_t index = 0, end = 0, i;
|
||||
int err;
|
||||
const struct bts_trace *trace;
|
||||
unsigned char *at;
|
||||
|
||||
if (!this_tracer)
|
||||
return;
|
||||
|
||||
bts_disable();
|
||||
|
||||
err = ds_get_bts_index(this_tracer, &index);
|
||||
if (err < 0)
|
||||
ds_suspend_bts(this_tracer);
|
||||
trace = ds_read_bts(this_tracer);
|
||||
if (!trace)
|
||||
goto out;
|
||||
|
||||
err = ds_get_bts_end(this_tracer, &end);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
for (at = trace->ds.top; (void *)at < trace->ds.end;
|
||||
at += trace->ds.size)
|
||||
trace_bts_at(tr, trace, at);
|
||||
|
||||
for (i = index; i < end; i++)
|
||||
trace_bts_at(tr, i);
|
||||
|
||||
for (i = 0; i < index; i++)
|
||||
trace_bts_at(tr, i);
|
||||
for (at = trace->ds.begin; (void *)at < trace->ds.top;
|
||||
at += trace->ds.size)
|
||||
trace_bts_at(tr, trace, at);
|
||||
|
||||
out:
|
||||
bts_enable();
|
||||
ds_resume_bts(this_tracer);
|
||||
}
|
||||
|
||||
static void trace_bts_prepare(struct trace_iterator *iter)
|
||||
@ -259,7 +188,7 @@ static void trace_bts_prepare(struct trace_iterator *iter)
|
||||
|
||||
struct tracer bts_tracer __read_mostly =
|
||||
{
|
||||
.name = "bts",
|
||||
.name = "hw-branch-tracer",
|
||||
.init = bts_trace_init,
|
||||
.reset = bts_trace_stop,
|
||||
.print_header = bts_trace_print_header,
|
@ -114,6 +114,7 @@ my %text_sections = (
|
||||
".text" => 1,
|
||||
".sched.text" => 1,
|
||||
".spinlock.text" => 1,
|
||||
".irqentry.text" => 1,
|
||||
);
|
||||
|
||||
$objdump = "objdump" if ((length $objdump) == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user