diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-02-15 09:51:49 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2012-02-21 11:08:24 -0500 |
commit | ceec0b6fc7cd43b38a40c2d40223f9cd0616f0cd (patch) | |
tree | 31e7deb76a5827883251dc578300bdc35ef62538 /kernel/trace/trace_event_perf.c | |
parent | e248491ac283b516958ca9ab62c8e74b6718bca8 (diff) |
ftrace, perf: Add open/close tracepoint perf registration actions
Adding TRACE_REG_PERF_OPEN and TRACE_REG_PERF_CLOSE to differentiate
register/unregister from open/close actions.
The register/unregister actions are invoked for the first/last
tracepoint user when opening/closing the event.
The open/close actions are invoked for each tracepoint user when
opening/closing the event.
Link: http://lkml.kernel.org/r/1329317514-8131-3-git-send-email-jolsa@redhat.com
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/trace_event_perf.c')
-rw-r--r-- | kernel/trace/trace_event_perf.c | 116 |
1 files changed, 75 insertions, 41 deletions
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 19a359d5e6d5..0cfcc37f63de 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c | |||
@@ -44,23 +44,17 @@ static int perf_trace_event_perm(struct ftrace_event_call *tp_event, | |||
44 | return 0; | 44 | return 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | static int perf_trace_event_init(struct ftrace_event_call *tp_event, | 47 | static int perf_trace_event_reg(struct ftrace_event_call *tp_event, |
48 | struct perf_event *p_event) | 48 | struct perf_event *p_event) |
49 | { | 49 | { |
50 | struct hlist_head __percpu *list; | 50 | struct hlist_head __percpu *list; |
51 | int ret; | 51 | int ret = -ENOMEM; |
52 | int cpu; | 52 | int cpu; |
53 | 53 | ||
54 | ret = perf_trace_event_perm(tp_event, p_event); | ||
55 | if (ret) | ||
56 | return ret; | ||
57 | |||
58 | p_event->tp_event = tp_event; | 54 | p_event->tp_event = tp_event; |
59 | if (tp_event->perf_refcount++ > 0) | 55 | if (tp_event->perf_refcount++ > 0) |
60 | return 0; | 56 | return 0; |
61 | 57 | ||
62 | ret = -ENOMEM; | ||
63 | |||
64 | list = alloc_percpu(struct hlist_head); | 58 | list = alloc_percpu(struct hlist_head); |
65 | if (!list) | 59 | if (!list) |
66 | goto fail; | 60 | goto fail; |
@@ -83,7 +77,7 @@ static int perf_trace_event_init(struct ftrace_event_call *tp_event, | |||
83 | } | 77 | } |
84 | } | 78 | } |
85 | 79 | ||
86 | ret = tp_event->class->reg(tp_event, TRACE_REG_PERF_REGISTER); | 80 | ret = tp_event->class->reg(tp_event, TRACE_REG_PERF_REGISTER, NULL); |
87 | if (ret) | 81 | if (ret) |
88 | goto fail; | 82 | goto fail; |
89 | 83 | ||
@@ -108,6 +102,69 @@ fail: | |||
108 | return ret; | 102 | return ret; |
109 | } | 103 | } |
110 | 104 | ||
105 | static void perf_trace_event_unreg(struct perf_event *p_event) | ||
106 | { | ||
107 | struct ftrace_event_call *tp_event = p_event->tp_event; | ||
108 | int i; | ||
109 | |||
110 | if (--tp_event->perf_refcount > 0) | ||
111 | goto out; | ||
112 | |||
113 | tp_event->class->reg(tp_event, TRACE_REG_PERF_UNREGISTER, NULL); | ||
114 | |||
115 | /* | ||
116 | * Ensure our callback won't be called anymore. The buffers | ||
117 | * will be freed after that. | ||
118 | */ | ||
119 | tracepoint_synchronize_unregister(); | ||
120 | |||
121 | free_percpu(tp_event->perf_events); | ||
122 | tp_event->perf_events = NULL; | ||
123 | |||
124 | if (!--total_ref_count) { | ||
125 | for (i = 0; i < PERF_NR_CONTEXTS; i++) { | ||
126 | free_percpu(perf_trace_buf[i]); | ||
127 | perf_trace_buf[i] = NULL; | ||
128 | } | ||
129 | } | ||
130 | out: | ||
131 | module_put(tp_event->mod); | ||
132 | } | ||
133 | |||
134 | static int perf_trace_event_open(struct perf_event *p_event) | ||
135 | { | ||
136 | struct ftrace_event_call *tp_event = p_event->tp_event; | ||
137 | return tp_event->class->reg(tp_event, TRACE_REG_PERF_OPEN, p_event); | ||
138 | } | ||
139 | |||
140 | static void perf_trace_event_close(struct perf_event *p_event) | ||
141 | { | ||
142 | struct ftrace_event_call *tp_event = p_event->tp_event; | ||
143 | tp_event->class->reg(tp_event, TRACE_REG_PERF_CLOSE, p_event); | ||
144 | } | ||
145 | |||
146 | static int perf_trace_event_init(struct ftrace_event_call *tp_event, | ||
147 | struct perf_event *p_event) | ||
148 | { | ||
149 | int ret; | ||
150 | |||
151 | ret = perf_trace_event_perm(tp_event, p_event); | ||
152 | if (ret) | ||
153 | return ret; | ||
154 | |||
155 | ret = perf_trace_event_reg(tp_event, p_event); | ||
156 | if (ret) | ||
157 | return ret; | ||
158 | |||
159 | ret = perf_trace_event_open(p_event); | ||
160 | if (ret) { | ||
161 | perf_trace_event_unreg(p_event); | ||
162 | return ret; | ||
163 | } | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
111 | int perf_trace_init(struct perf_event *p_event) | 168 | int perf_trace_init(struct perf_event *p_event) |
112 | { | 169 | { |
113 | struct ftrace_event_call *tp_event; | 170 | struct ftrace_event_call *tp_event; |
@@ -130,6 +187,14 @@ int perf_trace_init(struct perf_event *p_event) | |||
130 | return ret; | 187 | return ret; |
131 | } | 188 | } |
132 | 189 | ||
190 | void perf_trace_destroy(struct perf_event *p_event) | ||
191 | { | ||
192 | mutex_lock(&event_mutex); | ||
193 | perf_trace_event_close(p_event); | ||
194 | perf_trace_event_unreg(p_event); | ||
195 | mutex_unlock(&event_mutex); | ||
196 | } | ||
197 | |||
133 | int perf_trace_add(struct perf_event *p_event, int flags) | 198 | int perf_trace_add(struct perf_event *p_event, int flags) |
134 | { | 199 | { |
135 | struct ftrace_event_call *tp_event = p_event->tp_event; | 200 | struct ftrace_event_call *tp_event = p_event->tp_event; |
@@ -154,37 +219,6 @@ void perf_trace_del(struct perf_event *p_event, int flags) | |||
154 | hlist_del_rcu(&p_event->hlist_entry); | 219 | hlist_del_rcu(&p_event->hlist_entry); |
155 | } | 220 | } |
156 | 221 | ||
157 | void perf_trace_destroy(struct perf_event *p_event) | ||
158 | { | ||
159 | struct ftrace_event_call *tp_event = p_event->tp_event; | ||
160 | int i; | ||
161 | |||
162 | mutex_lock(&event_mutex); | ||
163 | if (--tp_event->perf_refcount > 0) | ||
164 | goto out; | ||
165 | |||
166 | tp_event->class->reg(tp_event, TRACE_REG_PERF_UNREGISTER); | ||
167 | |||
168 | /* | ||
169 | * Ensure our callback won't be called anymore. The buffers | ||
170 | * will be freed after that. | ||
171 | */ | ||
172 | tracepoint_synchronize_unregister(); | ||
173 | |||
174 | free_percpu(tp_event->perf_events); | ||
175 | tp_event->perf_events = NULL; | ||
176 | |||
177 | if (!--total_ref_count) { | ||
178 | for (i = 0; i < PERF_NR_CONTEXTS; i++) { | ||
179 | free_percpu(perf_trace_buf[i]); | ||
180 | perf_trace_buf[i] = NULL; | ||
181 | } | ||
182 | } | ||
183 | out: | ||
184 | module_put(tp_event->mod); | ||
185 | mutex_unlock(&event_mutex); | ||
186 | } | ||
187 | |||
188 | __kprobes void *perf_trace_buf_prepare(int size, unsigned short type, | 222 | __kprobes void *perf_trace_buf_prepare(int size, unsigned short type, |
189 | struct pt_regs *regs, int *rctxp) | 223 | struct pt_regs *regs, int *rctxp) |
190 | { | 224 | { |