Skip to content

Commit f45d122

Browse files
Divya Indirostedt
authored andcommitted
tracing: Kernel access to Ftrace instances
Ftrace provides the feature “instances” that provides the capability to create multiple Ftrace ring buffers. However, currently these buffers are created/accessed via userspace only. The kernel APIs providing these features are not exported, hence cannot be used by other kernel components. This patch aims to extend this infrastructure to provide the flexibility to create/log/remove/ enable-disable existing trace events to these buffers from within the kernel. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Divya Indi <[email protected]> Reviewed-by: Joe Jin <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 40ed29b commit f45d122

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

kernel/trace/trace.c

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,7 @@ void trace_printk_init_buffers(void)
30533053
if (global_trace.trace_buffer.buffer)
30543054
tracing_start_cmdline_record();
30553055
}
3056+
EXPORT_SYMBOL_GPL(trace_printk_init_buffers);
30563057

30573058
void trace_printk_start_comm(void)
30583059
{
@@ -3213,6 +3214,7 @@ int trace_array_printk(struct trace_array *tr,
32133214
va_end(ap);
32143215
return ret;
32153216
}
3217+
EXPORT_SYMBOL_GPL(trace_array_printk);
32163218

32173219
__printf(3, 4)
32183220
int trace_array_printk_buf(struct ring_buffer *buffer,
@@ -8037,7 +8039,7 @@ static void update_tracer_options(struct trace_array *tr)
80378039
mutex_unlock(&trace_types_lock);
80388040
}
80398041

8040-
static int instance_mkdir(const char *name)
8042+
struct trace_array *trace_array_create(const char *name)
80418043
{
80428044
struct trace_array *tr;
80438045
int ret;
@@ -8101,7 +8103,7 @@ static int instance_mkdir(const char *name)
81018103
mutex_unlock(&trace_types_lock);
81028104
mutex_unlock(&event_mutex);
81038105

8104-
return 0;
8106+
return tr;
81058107

81068108
out_free_tr:
81078109
free_trace_buffers(tr);
@@ -8113,33 +8115,21 @@ static int instance_mkdir(const char *name)
81138115
mutex_unlock(&trace_types_lock);
81148116
mutex_unlock(&event_mutex);
81158117

8116-
return ret;
8118+
return ERR_PTR(ret);
8119+
}
8120+
EXPORT_SYMBOL_GPL(trace_array_create);
81178121

8122+
static int instance_mkdir(const char *name)
8123+
{
8124+
return PTR_ERR_OR_ZERO(trace_array_create(name));
81188125
}
81198126

8120-
static int instance_rmdir(const char *name)
8127+
static int __remove_instance(struct trace_array *tr)
81218128
{
8122-
struct trace_array *tr;
8123-
int found = 0;
8124-
int ret;
81258129
int i;
81268130

8127-
mutex_lock(&event_mutex);
8128-
mutex_lock(&trace_types_lock);
8129-
8130-
ret = -ENODEV;
8131-
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
8132-
if (tr->name && strcmp(tr->name, name) == 0) {
8133-
found = 1;
8134-
break;
8135-
}
8136-
}
8137-
if (!found)
8138-
goto out_unlock;
8139-
8140-
ret = -EBUSY;
81418131
if (tr->ref || (tr->current_trace && tr->current_trace->ref))
8142-
goto out_unlock;
8132+
return -EBUSY;
81438133

81448134
list_del(&tr->list);
81458135

@@ -8165,10 +8155,46 @@ static int instance_rmdir(const char *name)
81658155
free_cpumask_var(tr->tracing_cpumask);
81668156
kfree(tr->name);
81678157
kfree(tr);
8158+
tr = NULL;
81688159

8169-
ret = 0;
8160+
return 0;
8161+
}
8162+
8163+
int trace_array_destroy(struct trace_array *tr)
8164+
{
8165+
int ret;
8166+
8167+
if (!tr)
8168+
return -EINVAL;
8169+
8170+
mutex_lock(&event_mutex);
8171+
mutex_lock(&trace_types_lock);
8172+
8173+
ret = __remove_instance(tr);
8174+
8175+
mutex_unlock(&trace_types_lock);
8176+
mutex_unlock(&event_mutex);
8177+
8178+
return ret;
8179+
}
8180+
EXPORT_SYMBOL_GPL(trace_array_destroy);
8181+
8182+
static int instance_rmdir(const char *name)
8183+
{
8184+
struct trace_array *tr;
8185+
int ret;
8186+
8187+
mutex_lock(&event_mutex);
8188+
mutex_lock(&trace_types_lock);
8189+
8190+
ret = -ENODEV;
8191+
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
8192+
if (tr->name && strcmp(tr->name, name) == 0) {
8193+
ret = __remove_instance(tr);
8194+
break;
8195+
}
8196+
}
81708197

8171-
out_unlock:
81728198
mutex_unlock(&trace_types_lock);
81738199
mutex_unlock(&event_mutex);
81748200

kernel/trace/trace_events.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
832832

833833
return ret;
834834
}
835+
EXPORT_SYMBOL_GPL(ftrace_set_clr_event);
835836

836837
/**
837838
* trace_set_clr_event - enable or disable an event

0 commit comments

Comments
 (0)