All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers
@ 2020-08-06 18:46 Steven Rostedt
  2020-08-06 19:22 ` Sean Paul
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2020-08-06 18:46 UTC (permalink / raw)
  To: LKML; +Cc: Sean Paul

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

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 <sean@poorly.run>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
Changes since v1:
  Added EXPORT_SYMBOL_GPL() to trace_array_init_printk() as it is
  required for another function that is exported.

 kernel/trace/trace.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 06c0feae5ff9..c5f822736261 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3129,6 +3129,9 @@ static int alloc_percpu_trace_buffer(void)
 {
 	struct trace_buffer_struct *buffers;
 
+	if (trace_percpu_buffer)
+		return 0;
+
 	buffers = alloc_percpu(struct trace_buffer_struct);
 	if (MEM_FAIL(!buffers, "Could not allocate percpu trace_printk buffer"))
 		return -ENOMEM;
@@ -3331,6 +3334,26 @@ int trace_array_vprintk(struct trace_array *tr,
 	return __trace_array_vprintk(tr->array_buffer.buffer, ip, fmt, args);
 }
 
+/**
+ * trace_array_printk - Print a message to a specific instance
+ * @tr: The instance trace_array descriptor
+ * @ip: The instruction pointer that this is called from.
+ * @fmt: The format to print (printf format)
+ *
+ * If a subsystem sets up its own instance, they have the right to
+ * printk strings into their tracing instance buffer using this
+ * function. Note, this function will not write into the top level
+ * buffer (use trace_printk() for that), as writing into the top level
+ * buffer should only have events that can be individually disabled.
+ * trace_printk() is only used for debugging a kernel, and should not
+ * be ever encorporated in normal use.
+ *
+ * trace_array_printk() can be used, as it will not add noise to the
+ * top level tracing buffer.
+ *
+ * Note, trace_array_init_printk() must be called on @tr before this
+ * can be used.
+ */
 __printf(3, 0)
 int trace_array_printk(struct trace_array *tr,
 		       unsigned long ip, const char *fmt, ...)
@@ -3355,6 +3378,27 @@ int trace_array_printk(struct trace_array *tr,
 }
 EXPORT_SYMBOL_GPL(trace_array_printk);
 
+/**
+ * trace_array_init_printk - Initialize buffers for trace_array_printk()
+ * @tr: The trace array to initialize the buffers for
+ *
+ * As trace_array_printk() only writes into instances, they are OK to
+ * have in the kernel (unlike trace_printk()). This needs to be called
+ * before trace_array_printk() can be used on a trace_array.
+ */
+int trace_array_init_printk(struct trace_array *tr)
+{
+	if (!tr)
+		return -ENOENT;
+
+	/* This is only allowed for created instances */
+	if (tr == &global_trace)
+		return -EINVAL;
+
+	return alloc_percpu_trace_buffer();
+}
+EXPORT_SYMBOL_GPL(trace_array_init_printk);
+
 __printf(3, 4)
 int trace_array_printk_buf(struct trace_buffer *buffer,
 			   unsigned long ip, const char *fmt, ...)
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers
  2020-08-06 18:46 [PATCH v2] tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers Steven Rostedt
@ 2020-08-06 19:22 ` Sean Paul
  2020-08-06 19:47   ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Paul @ 2020-08-06 19:22 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML

On Thu, Aug 6, 2020 at 2:46 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
>
> 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 <sean@poorly.run>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> Changes since v1:
>   Added EXPORT_SYMBOL_GPL() to trace_array_init_printk() as it is
>   required for another function that is exported.

Could we also add this to trace.h?

>
>  kernel/trace/trace.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 06c0feae5ff9..c5f822736261 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3129,6 +3129,9 @@ static int alloc_percpu_trace_buffer(void)
>  {
>         struct trace_buffer_struct *buffers;
>
> +       if (trace_percpu_buffer)
> +               return 0;
> +
>         buffers = alloc_percpu(struct trace_buffer_struct);
>         if (MEM_FAIL(!buffers, "Could not allocate percpu trace_printk buffer"))
>                 return -ENOMEM;
> @@ -3331,6 +3334,26 @@ int trace_array_vprintk(struct trace_array *tr,
>         return __trace_array_vprintk(tr->array_buffer.buffer, ip, fmt, args);
>  }
>
> +/**
> + * trace_array_printk - Print a message to a specific instance
> + * @tr: The instance trace_array descriptor
> + * @ip: The instruction pointer that this is called from.
> + * @fmt: The format to print (printf format)
> + *
> + * If a subsystem sets up its own instance, they have the right to
> + * printk strings into their tracing instance buffer using this
> + * function. Note, this function will not write into the top level
> + * buffer (use trace_printk() for that), as writing into the top level
> + * buffer should only have events that can be individually disabled.
> + * trace_printk() is only used for debugging a kernel, and should not
> + * be ever encorporated in normal use.
> + *
> + * trace_array_printk() can be used, as it will not add noise to the
> + * top level tracing buffer.
> + *
> + * Note, trace_array_init_printk() must be called on @tr before this
> + * can be used.
> + */
>  __printf(3, 0)
>  int trace_array_printk(struct trace_array *tr,
>                        unsigned long ip, const char *fmt, ...)
> @@ -3355,6 +3378,27 @@ int trace_array_printk(struct trace_array *tr,
>  }
>  EXPORT_SYMBOL_GPL(trace_array_printk);
>
> +/**
> + * trace_array_init_printk - Initialize buffers for trace_array_printk()
> + * @tr: The trace array to initialize the buffers for
> + *
> + * As trace_array_printk() only writes into instances, they are OK to
> + * have in the kernel (unlike trace_printk()). This needs to be called
> + * before trace_array_printk() can be used on a trace_array.
> + */
> +int trace_array_init_printk(struct trace_array *tr)
> +{
> +       if (!tr)
> +               return -ENOENT;
> +
> +       /* This is only allowed for created instances */
> +       if (tr == &global_trace)
> +               return -EINVAL;
> +
> +       return alloc_percpu_trace_buffer();
> +}
> +EXPORT_SYMBOL_GPL(trace_array_init_printk);
> +
>  __printf(3, 4)
>  int trace_array_printk_buf(struct trace_buffer *buffer,
>                            unsigned long ip, const char *fmt, ...)
> --
> 2.25.4
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers
  2020-08-06 19:22 ` Sean Paul
@ 2020-08-06 19:47   ` Steven Rostedt
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2020-08-06 19:47 UTC (permalink / raw)
  To: Sean Paul; +Cc: LKML

On Thu, 6 Aug 2020 15:22:23 -0400
Sean Paul <sean@poorly.run> wrote:

> > Changes since v1:
> >   Added EXPORT_SYMBOL_GPL() to trace_array_init_printk() as it is
> >   required for another function that is exported.  
> 
> Could we also add this to trace.h?

That might be helpful, wouldn't it.

kernel test robot just suggested the same thing ;-)

-- Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-06 19:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 18:46 [PATCH v2] tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers Steven Rostedt
2020-08-06 19:22 ` Sean Paul
2020-08-06 19:47   ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.