diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /kernel/trace/tracelevel.c | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'kernel/trace/tracelevel.c')
-rw-r--r-- | kernel/trace/tracelevel.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/kernel/trace/tracelevel.c b/kernel/trace/tracelevel.c new file mode 100644 index 00000000000..9f8b8eedbb5 --- /dev/null +++ b/kernel/trace/tracelevel.c | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | * kernel/trace/tracelevel.c | ||
3 | * | ||
4 | * Copyright (c) 2011, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along with | ||
16 | * this program; if not, write to the Free Software Foundation, Inc., | ||
17 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <linux/ftrace_event.h> | ||
22 | #include <linux/list.h> | ||
23 | #include <linux/moduleparam.h> | ||
24 | #include <linux/mutex.h> | ||
25 | #include <linux/tracelevel.h> | ||
26 | #include <linux/vmalloc.h> | ||
27 | |||
28 | #include "trace.h" | ||
29 | |||
30 | #define TAG KERN_ERR "tracelevel: " | ||
31 | |||
32 | struct tracelevel_record { | ||
33 | struct list_head list; | ||
34 | char *name; | ||
35 | int level; | ||
36 | }; | ||
37 | |||
38 | static LIST_HEAD(tracelevel_list); | ||
39 | |||
40 | static bool started; | ||
41 | static unsigned int tracelevel_level = TRACELEVEL_DEFAULT; | ||
42 | |||
43 | static DEFINE_MUTEX(tracelevel_record_lock); | ||
44 | |||
45 | /* tracelevel_set_event sets a single event if set = 1, or | ||
46 | * clears an event if set = 0. | ||
47 | */ | ||
48 | static int tracelevel_set_event(struct tracelevel_record *evt, bool set) | ||
49 | { | ||
50 | if (trace_set_clr_event(NULL, evt->name, set) < 0) { | ||
51 | printk(TAG "failed to set event %s\n", evt->name); | ||
52 | return -EINVAL; | ||
53 | } | ||
54 | return 0; | ||
55 | } | ||
56 | |||
57 | /* Registers an event. If possible, it also sets it. | ||
58 | * If not, we'll set it in tracelevel_init. | ||
59 | */ | ||
60 | int __tracelevel_register(char *name, unsigned int level) | ||
61 | { | ||
62 | struct tracelevel_record *evt = (struct tracelevel_record *) | ||
63 | vmalloc(sizeof(struct tracelevel_record)); | ||
64 | if (!evt) { | ||
65 | printk(TAG "failed to allocate tracelevel_record for %s\n", | ||
66 | name); | ||
67 | return -ENOMEM; | ||
68 | } | ||
69 | |||
70 | evt->name = name; | ||
71 | evt->level = level; | ||
72 | |||
73 | mutex_lock(&tracelevel_record_lock); | ||
74 | list_add(&evt->list, &tracelevel_list); | ||
75 | mutex_unlock(&tracelevel_record_lock); | ||
76 | |||
77 | if (level >= tracelevel_level && started) | ||
78 | tracelevel_set_event(evt, 1); | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | /* tracelevel_set_level sets the global level, clears events | ||
83 | * lower than that level, and enables events greater or equal. | ||
84 | */ | ||
85 | int tracelevel_set_level(int level) | ||
86 | { | ||
87 | struct tracelevel_record *evt = NULL; | ||
88 | |||
89 | if (level < 0 || level > TRACELEVEL_MAX) | ||
90 | return -EINVAL; | ||
91 | tracelevel_level = level; | ||
92 | |||
93 | mutex_lock(&tracelevel_record_lock); | ||
94 | list_for_each_entry(evt, &tracelevel_list, list) { | ||
95 | if (evt->level >= level) | ||
96 | tracelevel_set_event(evt, 1); | ||
97 | else | ||
98 | tracelevel_set_event(evt, 0); | ||
99 | } | ||
100 | mutex_unlock(&tracelevel_record_lock); | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static int param_set_level(const char *val, const struct kernel_param *kp) | ||
105 | { | ||
106 | int level, ret; | ||
107 | ret = strict_strtol(val, 0, &level); | ||
108 | if (ret < 0) | ||
109 | return ret; | ||
110 | return tracelevel_set_level(level); | ||
111 | } | ||
112 | |||
113 | static int param_get_level(char *buffer, const struct kernel_param *kp) | ||
114 | { | ||
115 | return param_get_int(buffer, kp); | ||
116 | } | ||
117 | |||
118 | static struct kernel_param_ops tracelevel_level_ops = { | ||
119 | .set = param_set_level, | ||
120 | .get = param_get_level | ||
121 | }; | ||
122 | |||
123 | module_param_cb(level, &tracelevel_level_ops, &tracelevel_level, 0644); | ||
124 | |||
125 | /* Turn on the tracing that has been registered thus far. */ | ||
126 | static int __init tracelevel_init(void) | ||
127 | { | ||
128 | int ret; | ||
129 | started = true; | ||
130 | |||
131 | /* Ring buffer is initialize to 1 page until the user sets a tracer. | ||
132 | * Since we're doing this manually, we need to ask for expanded buffer. | ||
133 | */ | ||
134 | ret = tracing_update_buffers(); | ||
135 | if (ret < 0) | ||
136 | return ret; | ||
137 | |||
138 | return tracelevel_set_level(tracelevel_level); | ||
139 | } | ||
140 | |||
141 | /* Tracing mechanism is set up during fs_initcall. */ | ||
142 | fs_initcall_sync(tracelevel_init); | ||