Skip to content

Commit 38ce2a9

Browse files
committed
tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers
As trace_array_printk() used with not global instances will not add noise to the main buffer, they are OK to have in the kernel (unlike trace_printk()). This require the subsystem to create their own tracing instance, and the trace_array_printk() only writes into those instances. Add trace_array_init_printk() to initialize the trace_printk() buffers without printing out the WARNING message. Reported-by: Sean Paul <[email protected]> Reviewed-by: Sean Paul <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 10de795 commit 38ce2a9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

include/linux/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct trace_array;
2929
void trace_printk_init_buffers(void);
3030
int trace_array_printk(struct trace_array *tr, unsigned long ip,
3131
const char *fmt, ...);
32+
int trace_array_init_printk(struct trace_array *tr);
3233
void trace_array_put(struct trace_array *tr);
3334
struct trace_array *trace_array_get_by_name(const char *name);
3435
int trace_array_destroy(struct trace_array *tr);

kernel/trace/trace.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,9 @@ static int alloc_percpu_trace_buffer(void)
31293129
{
31303130
struct trace_buffer_struct *buffers;
31313131

3132+
if (trace_percpu_buffer)
3133+
return 0;
3134+
31323135
buffers = alloc_percpu(struct trace_buffer_struct);
31333136
if (MEM_FAIL(!buffers, "Could not allocate percpu trace_printk buffer"))
31343137
return -ENOMEM;
@@ -3331,6 +3334,26 @@ int trace_array_vprintk(struct trace_array *tr,
33313334
return __trace_array_vprintk(tr->array_buffer.buffer, ip, fmt, args);
33323335
}
33333336

3337+
/**
3338+
* trace_array_printk - Print a message to a specific instance
3339+
* @tr: The instance trace_array descriptor
3340+
* @ip: The instruction pointer that this is called from.
3341+
* @fmt: The format to print (printf format)
3342+
*
3343+
* If a subsystem sets up its own instance, they have the right to
3344+
* printk strings into their tracing instance buffer using this
3345+
* function. Note, this function will not write into the top level
3346+
* buffer (use trace_printk() for that), as writing into the top level
3347+
* buffer should only have events that can be individually disabled.
3348+
* trace_printk() is only used for debugging a kernel, and should not
3349+
* be ever encorporated in normal use.
3350+
*
3351+
* trace_array_printk() can be used, as it will not add noise to the
3352+
* top level tracing buffer.
3353+
*
3354+
* Note, trace_array_init_printk() must be called on @tr before this
3355+
* can be used.
3356+
*/
33343357
__printf(3, 0)
33353358
int trace_array_printk(struct trace_array *tr,
33363359
unsigned long ip, const char *fmt, ...)
@@ -3355,6 +3378,27 @@ int trace_array_printk(struct trace_array *tr,
33553378
}
33563379
EXPORT_SYMBOL_GPL(trace_array_printk);
33573380

3381+
/**
3382+
* trace_array_init_printk - Initialize buffers for trace_array_printk()
3383+
* @tr: The trace array to initialize the buffers for
3384+
*
3385+
* As trace_array_printk() only writes into instances, they are OK to
3386+
* have in the kernel (unlike trace_printk()). This needs to be called
3387+
* before trace_array_printk() can be used on a trace_array.
3388+
*/
3389+
int trace_array_init_printk(struct trace_array *tr)
3390+
{
3391+
if (!tr)
3392+
return -ENOENT;
3393+
3394+
/* This is only allowed for created instances */
3395+
if (tr == &global_trace)
3396+
return -EINVAL;
3397+
3398+
return alloc_percpu_trace_buffer();
3399+
}
3400+
EXPORT_SYMBOL_GPL(trace_array_init_printk);
3401+
33583402
__printf(3, 4)
33593403
int trace_array_printk_buf(struct trace_buffer *buffer,
33603404
unsigned long ip, const char *fmt, ...)

0 commit comments

Comments
 (0)