tracing: Factorize the events profile accounting
[linux-2.6-block.git] / kernel / trace / trace_event_profile.c
CommitLineData
ac199db0
PZ
1/*
2 * trace event based perf counter profiling
3 *
4 * Copyright (C) 2009 Red Hat Inc, Peter Zijlstra <pzijlstr@redhat.com>
5 *
6 */
7
558e6547 8#include <linux/module.h>
ac199db0
PZ
9#include "trace.h"
10
e5e25cf4
FW
11static int ftrace_profile_enable_event(struct ftrace_event_call *event)
12{
13 if (atomic_inc_return(&event->profile_count))
14 return 0;
15
16 return event->profile_enable();
17}
18
ac199db0
PZ
19int ftrace_profile_enable(int event_id)
20{
21 struct ftrace_event_call *event;
20c8928a 22 int ret = -EINVAL;
ac199db0 23
20c8928a 24 mutex_lock(&event_mutex);
a59fd602 25 list_for_each_entry(event, &ftrace_events, list) {
558e6547
LZ
26 if (event->id == event_id && event->profile_enable &&
27 try_module_get(event->mod)) {
e5e25cf4 28 ret = ftrace_profile_enable_event(event);
20c8928a
LZ
29 break;
30 }
ac199db0 31 }
20c8928a 32 mutex_unlock(&event_mutex);
ac199db0 33
20c8928a 34 return ret;
ac199db0
PZ
35}
36
e5e25cf4
FW
37static void ftrace_profile_disable_event(struct ftrace_event_call *event)
38{
39 if (!atomic_add_negative(-1, &event->profile_count))
40 return;
41
42 event->profile_disable();
43}
44
ac199db0
PZ
45void ftrace_profile_disable(int event_id)
46{
47 struct ftrace_event_call *event;
48
20c8928a 49 mutex_lock(&event_mutex);
a59fd602 50 list_for_each_entry(event, &ftrace_events, list) {
20c8928a 51 if (event->id == event_id) {
e5e25cf4 52 ftrace_profile_disable_event(event);
558e6547 53 module_put(event->mod);
20c8928a
LZ
54 break;
55 }
ac199db0 56 }
20c8928a 57 mutex_unlock(&event_mutex);
ac199db0 58}