Frederic Weisbecker | 2da3e16 | 2009-11-05 23:06:50 +0100 | [diff] [blame] | 1 | #ifndef _LINUX_HW_BREAKPOINT_H |
| 2 | #define _LINUX_HW_BREAKPOINT_H |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 3 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 4 | enum { |
| 5 | HW_BREAKPOINT_LEN_1 = 1, |
| 6 | HW_BREAKPOINT_LEN_2 = 2, |
| 7 | HW_BREAKPOINT_LEN_4 = 4, |
| 8 | HW_BREAKPOINT_LEN_8 = 8, |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 9 | }; |
| 10 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 11 | enum { |
| 12 | HW_BREAKPOINT_R = 1, |
| 13 | HW_BREAKPOINT_W = 2, |
| 14 | HW_BREAKPOINT_X = 4, |
| 15 | }; |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 16 | |
Frederic Weisbecker | 5093eba | 2009-11-22 05:21:35 +0100 | [diff] [blame] | 17 | #ifdef __KERNEL__ |
Ingo Molnar | 688bcaf | 2009-11-14 01:12:47 +0100 | [diff] [blame] | 18 | |
Frederic Weisbecker | e6db487 | 2009-11-23 15:42:32 +0100 | [diff] [blame] | 19 | #include <linux/perf_event.h> |
| 20 | |
Frederic Weisbecker | fa7c27e | 2009-11-23 22:30:12 +0100 | [diff] [blame] | 21 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 22 | |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 23 | static inline void hw_breakpoint_init(struct perf_event_attr *attr) |
| 24 | { |
Frederic Weisbecker | ed872d0 | 2009-12-07 03:14:17 +0100 | [diff] [blame] | 25 | memset(attr, 0, sizeof(*attr)); |
| 26 | |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 27 | attr->type = PERF_TYPE_BREAKPOINT; |
| 28 | attr->size = sizeof(*attr); |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 29 | /* |
| 30 | * As it's for in-kernel or ptrace use, we want it to be pinned |
| 31 | * and to call its callback every hits. |
| 32 | */ |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 33 | attr->pinned = 1; |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 34 | attr->sample_period = 1; |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 37 | static inline unsigned long hw_breakpoint_addr(struct perf_event *bp) |
| 38 | { |
| 39 | return bp->attr.bp_addr; |
| 40 | } |
| 41 | |
| 42 | static inline int hw_breakpoint_type(struct perf_event *bp) |
| 43 | { |
| 44 | return bp->attr.bp_type; |
| 45 | } |
| 46 | |
| 47 | static inline int hw_breakpoint_len(struct perf_event *bp) |
| 48 | { |
| 49 | return bp->attr.bp_len; |
| 50 | } |
| 51 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 52 | extern struct perf_event * |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 53 | register_user_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 54 | perf_overflow_handler_t triggered, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 55 | struct task_struct *tsk); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 56 | |
| 57 | /* FIXME: only change from the attr, and don't unregister */ |
Frederic Weisbecker | 44234ad | 2009-12-09 09:25:48 +0100 | [diff] [blame] | 58 | extern int |
Frederic Weisbecker | 2f0993e | 2009-12-05 07:06:10 +0100 | [diff] [blame] | 59 | modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 60 | |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 61 | /* |
| 62 | * Kernel breakpoints are not associated with any particular thread. |
| 63 | */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 64 | extern struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 65 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 66 | perf_overflow_handler_t triggered, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 67 | int cpu); |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 68 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 69 | extern struct perf_event ** |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 70 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 71 | perf_overflow_handler_t triggered); |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 72 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 73 | extern int register_perf_hw_breakpoint(struct perf_event *bp); |
| 74 | extern int __register_perf_hw_breakpoint(struct perf_event *bp); |
| 75 | extern void unregister_hw_breakpoint(struct perf_event *bp); |
| 76 | extern void unregister_wide_hw_breakpoint(struct perf_event **cpu_events); |
| 77 | |
| 78 | extern int reserve_bp_slot(struct perf_event *bp); |
| 79 | extern void release_bp_slot(struct perf_event *bp); |
| 80 | |
| 81 | extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk); |
| 82 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 83 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 84 | { |
| 85 | return &bp->hw.info; |
| 86 | } |
| 87 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 88 | #else /* !CONFIG_HAVE_HW_BREAKPOINT */ |
| 89 | |
| 90 | static inline struct perf_event * |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 91 | register_user_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 92 | perf_overflow_handler_t triggered, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 93 | struct task_struct *tsk) { return NULL; } |
Frederic Weisbecker | 44234ad | 2009-12-09 09:25:48 +0100 | [diff] [blame] | 94 | static inline int |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 95 | modify_user_hw_breakpoint(struct perf_event *bp, |
Frederic Weisbecker | 99ac64c | 2009-12-11 11:58:42 +0100 | [diff] [blame] | 96 | struct perf_event_attr *attr) { return -ENOSYS; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 97 | static inline struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 98 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 99 | perf_overflow_handler_t triggered, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 100 | int cpu) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 101 | static inline struct perf_event ** |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 102 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 103 | perf_overflow_handler_t triggered) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 104 | static inline int |
| 105 | register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 106 | static inline int |
| 107 | __register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 108 | static inline void unregister_hw_breakpoint(struct perf_event *bp) { } |
| 109 | static inline void |
| 110 | unregister_wide_hw_breakpoint(struct perf_event **cpu_events) { } |
| 111 | static inline int |
| 112 | reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; } |
| 113 | static inline void release_bp_slot(struct perf_event *bp) { } |
| 114 | |
| 115 | static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { } |
| 116 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 117 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 118 | { |
| 119 | return NULL; |
| 120 | } |
| 121 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 122 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Frederic Weisbecker | 5093eba | 2009-11-22 05:21:35 +0100 | [diff] [blame] | 123 | #endif /* __KERNEL__ */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 124 | |
| 125 | #endif /* _LINUX_HW_BREAKPOINT_H */ |