hw_breakpoint.h 3.81 KB
Newer Older
1 2
#ifndef _LINUX_HW_BREAKPOINT_H
#define _LINUX_HW_BREAKPOINT_H
3

4
#include <linux/perf_event.h>
5
#include <uapi/linux/hw_breakpoint.h>
6

7 8
#ifdef CONFIG_HAVE_HW_BREAKPOINT

9 10
extern int __init init_hw_breakpoint(void);

11 12
static inline void hw_breakpoint_init(struct perf_event_attr *attr)
{
13 14
	memset(attr, 0, sizeof(*attr));

15 16
	attr->type = PERF_TYPE_BREAKPOINT;
	attr->size = sizeof(*attr);
17 18 19 20
	/*
	 * As it's for in-kernel or ptrace use, we want it to be pinned
	 * and to call its callback every hits.
	 */
21
	attr->pinned = 1;
22
	attr->sample_period = 1;
23 24 25 26 27 28
}

static inline void ptrace_breakpoint_init(struct perf_event_attr *attr)
{
	hw_breakpoint_init(attr);
	attr->exclude_kernel = 1;
29 30
}

31 32 33 34 35 36 37 38 39 40
static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
{
	return bp->attr.bp_addr;
}

static inline int hw_breakpoint_type(struct perf_event *bp)
{
	return bp->attr.bp_type;
}

41
static inline unsigned long hw_breakpoint_len(struct perf_event *bp)
42 43 44 45 46
{
	return bp->attr.bp_len;
}

extern struct perf_event *
47
register_user_hw_breakpoint(struct perf_event_attr *attr,
48
			    perf_overflow_handler_t triggered,
49
			    void *context,
50
			    struct task_struct *tsk);
51 52

/* FIXME: only change from the attr, and don't unregister */
53
extern int
54
modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
55 56 57 58

/*
 * Kernel breakpoints are not associated with any particular thread.
 */
59
extern struct perf_event *
60
register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
61
				perf_overflow_handler_t	triggered,
62
				void *context,
63
				int cpu);
64

65
extern struct perf_event * __percpu *
66
register_wide_hw_breakpoint(struct perf_event_attr *attr,
67 68
			    perf_overflow_handler_t triggered,
			    void *context);
69 70 71 72

extern int register_perf_hw_breakpoint(struct perf_event *bp);
extern int __register_perf_hw_breakpoint(struct perf_event *bp);
extern void unregister_hw_breakpoint(struct perf_event *bp);
73
extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
74

75 76
extern int dbg_reserve_bp_slot(struct perf_event *bp);
extern int dbg_release_bp_slot(struct perf_event *bp);
77 78 79 80 81
extern int reserve_bp_slot(struct perf_event *bp);
extern void release_bp_slot(struct perf_event *bp);

extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);

82 83 84 85 86
static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
{
	return &bp->hw.info;
}

87 88
#else /* !CONFIG_HAVE_HW_BREAKPOINT */

89 90
static inline int __init init_hw_breakpoint(void) { return 0; }

91
static inline struct perf_event *
92
register_user_hw_breakpoint(struct perf_event_attr *attr,
93
			    perf_overflow_handler_t triggered,
94
			    void *context,
95
			    struct task_struct *tsk)	{ return NULL; }
96
static inline int
97
modify_user_hw_breakpoint(struct perf_event *bp,
98
			  struct perf_event_attr *attr)	{ return -ENOSYS; }
99
static inline struct perf_event *
100
register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
101
				perf_overflow_handler_t	 triggered,
102
				void *context,
103
				int cpu)		{ return NULL; }
104
static inline struct perf_event * __percpu *
105
register_wide_hw_breakpoint(struct perf_event_attr *attr,
106 107
			    perf_overflow_handler_t triggered,
			    void *context)		{ return NULL; }
108 109 110 111 112 113
static inline int
register_perf_hw_breakpoint(struct perf_event *bp)	{ return -ENOSYS; }
static inline int
__register_perf_hw_breakpoint(struct perf_event *bp) 	{ return -ENOSYS; }
static inline void unregister_hw_breakpoint(struct perf_event *bp)	{ }
static inline void
114
unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events)	{ }
115 116 117 118 119
static inline int
reserve_bp_slot(struct perf_event *bp)			{return -ENOSYS; }
static inline void release_bp_slot(struct perf_event *bp) 		{ }

static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk)	{ }
120

121 122 123 124 125
static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
{
	return NULL;
}

126 127
#endif /* CONFIG_HAVE_HW_BREAKPOINT */
#endif /* _LINUX_HW_BREAKPOINT_H */