diff options
-rw-r--r-- | kernel/trace/trace.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index bdaf60d3d337..40e983ed994f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -3093,6 +3093,121 @@ static void tracing_init_debugfs_percpu(long cpu) | |||
3093 | #include "trace_selftest.c" | 3093 | #include "trace_selftest.c" |
3094 | #endif | 3094 | #endif |
3095 | 3095 | ||
3096 | static ssize_t | ||
3097 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, | ||
3098 | loff_t *ppos) | ||
3099 | { | ||
3100 | long index = (long)filp->private_data; | ||
3101 | char *buf; | ||
3102 | |||
3103 | if (trace_flags & (1 << index)) | ||
3104 | buf = "1\n"; | ||
3105 | else | ||
3106 | buf = "0\n"; | ||
3107 | |||
3108 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | ||
3109 | } | ||
3110 | |||
3111 | static ssize_t | ||
3112 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, | ||
3113 | loff_t *ppos) | ||
3114 | { | ||
3115 | long index = (long)filp->private_data; | ||
3116 | char buf[64]; | ||
3117 | unsigned long val; | ||
3118 | int ret; | ||
3119 | |||
3120 | if (cnt >= sizeof(buf)) | ||
3121 | return -EINVAL; | ||
3122 | |||
3123 | if (copy_from_user(&buf, ubuf, cnt)) | ||
3124 | return -EFAULT; | ||
3125 | |||
3126 | buf[cnt] = 0; | ||
3127 | |||
3128 | ret = strict_strtoul(buf, 10, &val); | ||
3129 | if (ret < 0) | ||
3130 | return ret; | ||
3131 | |||
3132 | switch (val) { | ||
3133 | case 0: | ||
3134 | trace_flags &= ~(1 << index); | ||
3135 | break; | ||
3136 | case 1: | ||
3137 | trace_flags |= 1 << index; | ||
3138 | break; | ||
3139 | |||
3140 | default: | ||
3141 | return -EINVAL; | ||
3142 | } | ||
3143 | |||
3144 | *ppos += cnt; | ||
3145 | |||
3146 | return cnt; | ||
3147 | } | ||
3148 | |||
3149 | |||
3150 | static const struct file_operations trace_options_core_fops = { | ||
3151 | .open = tracing_open_generic, | ||
3152 | .read = trace_options_core_read, | ||
3153 | .write = trace_options_core_write, | ||
3154 | }; | ||
3155 | |||
3156 | static struct dentry *trace_options_init_dentry(void) | ||
3157 | { | ||
3158 | struct dentry *d_tracer; | ||
3159 | static struct dentry *t_options; | ||
3160 | |||
3161 | if (t_options) | ||
3162 | return t_options; | ||
3163 | |||
3164 | d_tracer = tracing_init_dentry(); | ||
3165 | if (!d_tracer) | ||
3166 | return NULL; | ||
3167 | |||
3168 | t_options = debugfs_create_dir("options", d_tracer); | ||
3169 | if (!t_options) { | ||
3170 | pr_warning("Could not create debugfs directory 'options'\n"); | ||
3171 | return NULL; | ||
3172 | } | ||
3173 | |||
3174 | return t_options; | ||
3175 | } | ||
3176 | |||
3177 | static struct dentry * | ||
3178 | create_trace_option_core_file(const char *option, long index) | ||
3179 | { | ||
3180 | struct dentry *t_options; | ||
3181 | struct dentry *entry; | ||
3182 | |||
3183 | t_options = trace_options_init_dentry(); | ||
3184 | if (!t_options) | ||
3185 | return NULL; | ||
3186 | |||
3187 | entry = debugfs_create_file(option, 0644, t_options, (void *)index, | ||
3188 | &trace_options_core_fops); | ||
3189 | |||
3190 | return entry; | ||
3191 | } | ||
3192 | |||
3193 | static __init void create_trace_options_dir(void) | ||
3194 | { | ||
3195 | struct dentry *t_options; | ||
3196 | struct dentry *entry; | ||
3197 | int i; | ||
3198 | |||
3199 | t_options = trace_options_init_dentry(); | ||
3200 | if (!t_options) | ||
3201 | return; | ||
3202 | |||
3203 | for (i = 0; trace_options[i]; i++) { | ||
3204 | entry = create_trace_option_core_file(trace_options[i], i); | ||
3205 | if (!entry) | ||
3206 | pr_warning("Could not create debugfs %s entry\n", | ||
3207 | trace_options[i]); | ||
3208 | } | ||
3209 | } | ||
3210 | |||
3096 | static __init int tracer_init_debugfs(void) | 3211 | static __init int tracer_init_debugfs(void) |
3097 | { | 3212 | { |
3098 | struct dentry *d_tracer; | 3213 | struct dentry *d_tracer; |
@@ -3111,6 +3226,8 @@ static __init int tracer_init_debugfs(void) | |||
3111 | if (!entry) | 3226 | if (!entry) |
3112 | pr_warning("Could not create debugfs 'trace_options' entry\n"); | 3227 | pr_warning("Could not create debugfs 'trace_options' entry\n"); |
3113 | 3228 | ||
3229 | create_trace_options_dir(); | ||
3230 | |||
3114 | entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer, | 3231 | entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer, |
3115 | NULL, &tracing_cpumask_fops); | 3232 | NULL, &tracing_cpumask_fops); |
3116 | if (!entry) | 3233 | if (!entry) |