linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Masami Hiramatsu <mhiramat@kernel.org>
Subject: [for-next][PATCH 24/26] tracing: Enable creating new instance early boot
Date: Mon, 21 Sep 2020 21:24:38 -0400	[thread overview]
Message-ID: <20200922012453.507002285@goodmis.org> (raw)
In-Reply-To: 20200922012414.115238201@goodmis.org

From: Masami Hiramatsu <mhiramat@kernel.org>

Enable creating new trace_array instance in early boot stage.
If the instances directory is not created, postpone it until
the tracefs is initialized.

Link: https://lkml.kernel.org/r/159974154763.478751.6289753509587233103.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/trace.c           | 53 +++++++++++++++++++++++++++-------
 kernel/trace/trace.h           |  7 +++++
 kernel/trace/trace_functions.c | 22 +++++++++-----
 3 files changed, 63 insertions(+), 19 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index c35fcd2f2529..6211a13b3327 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -8636,6 +8636,24 @@ struct trace_array *trace_array_find_get(const char *instance)
 	return tr;
 }
 
+static int trace_array_create_dir(struct trace_array *tr)
+{
+	int ret;
+
+	tr->dir = tracefs_create_dir(tr->name, trace_instance_dir);
+	if (!tr->dir)
+		return -EINVAL;
+
+	ret = event_trace_add_tracer(tr->dir, tr);
+	if (ret)
+		tracefs_remove(tr->dir);
+
+	init_tracer_tracefs(tr, tr->dir);
+	__update_tracer_options(tr);
+
+	return ret;
+}
+
 static struct trace_array *trace_array_create(const char *name)
 {
 	struct trace_array *tr;
@@ -8671,30 +8689,27 @@ static struct trace_array *trace_array_create(const char *name)
 	if (allocate_trace_buffers(tr, trace_buf_size) < 0)
 		goto out_free_tr;
 
-	tr->dir = tracefs_create_dir(name, trace_instance_dir);
-	if (!tr->dir)
-		goto out_free_tr;
-
-	ret = event_trace_add_tracer(tr->dir, tr);
-	if (ret) {
-		tracefs_remove(tr->dir);
+	if (ftrace_allocate_ftrace_ops(tr) < 0)
 		goto out_free_tr;
-	}
 
 	ftrace_init_trace_array(tr);
 
-	init_tracer_tracefs(tr, tr->dir);
 	init_trace_flags_index(tr);
-	__update_tracer_options(tr);
+
+	if (trace_instance_dir) {
+		ret = trace_array_create_dir(tr);
+		if (ret)
+			goto out_free_tr;
+	}
 
 	list_add(&tr->list, &ftrace_trace_arrays);
 
 	tr->ref++;
 
-
 	return tr;
 
  out_free_tr:
+	ftrace_free_ftrace_ops(tr);
 	free_trace_buffers(tr);
 	free_cpumask_var(tr->tracing_cpumask);
 	kfree(tr->name);
@@ -8852,11 +8867,27 @@ static int instance_rmdir(const char *name)
 
 static __init void create_trace_instances(struct dentry *d_tracer)
 {
+	struct trace_array *tr;
+
 	trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer,
 							 instance_mkdir,
 							 instance_rmdir);
 	if (MEM_FAIL(!trace_instance_dir, "Failed to create instances directory\n"))
 		return;
+
+	mutex_lock(&event_mutex);
+	mutex_lock(&trace_types_lock);
+
+	list_for_each_entry(tr, &ftrace_trace_arrays, list) {
+		if (!tr->name)
+			continue;
+		if (MEM_FAIL(trace_array_create_dir(tr) < 0,
+			     "Failed to create instance directory\n"))
+			break;
+	}
+
+	mutex_unlock(&trace_types_lock);
+	mutex_unlock(&event_mutex);
 }
 
 static void
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 0d3a405fe446..525434145eea 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1125,6 +1125,8 @@ extern int ftrace_is_dead(void);
 int ftrace_create_function_files(struct trace_array *tr,
 				 struct dentry *parent);
 void ftrace_destroy_function_files(struct trace_array *tr);
+int ftrace_allocate_ftrace_ops(struct trace_array *tr);
+void ftrace_free_ftrace_ops(struct trace_array *tr);
 void ftrace_init_global_array_ops(struct trace_array *tr);
 void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
 void ftrace_reset_array_ops(struct trace_array *tr);
@@ -1146,6 +1148,11 @@ ftrace_create_function_files(struct trace_array *tr,
 {
 	return 0;
 }
+static inline int ftrace_allocate_ftrace_ops(struct trace_array *tr)
+{
+	return 0;
+}
+static inline void ftrace_free_ftrace_ops(struct trace_array *tr) { }
 static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
 static inline __init void
 ftrace_init_global_array_ops(struct trace_array *tr) { }
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index dd4dff71d89a..2c2126e1871d 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -34,10 +34,14 @@ enum {
 	TRACE_FUNC_OPT_STACK	= 0x1,
 };
 
-static int allocate_ftrace_ops(struct trace_array *tr)
+int ftrace_allocate_ftrace_ops(struct trace_array *tr)
 {
 	struct ftrace_ops *ops;
 
+	/* The top level array uses the "global_ops" */
+	if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
+		return 0;
+
 	ops = kzalloc(sizeof(*ops), GFP_KERNEL);
 	if (!ops)
 		return -ENOMEM;
@@ -48,15 +52,19 @@ static int allocate_ftrace_ops(struct trace_array *tr)
 
 	tr->ops = ops;
 	ops->private = tr;
+
 	return 0;
 }
 
+void ftrace_free_ftrace_ops(struct trace_array *tr)
+{
+	kfree(tr->ops);
+	tr->ops = NULL;
+}
 
 int ftrace_create_function_files(struct trace_array *tr,
 				 struct dentry *parent)
 {
-	int ret;
-
 	/*
 	 * The top level array uses the "global_ops", and the files are
 	 * created on boot up.
@@ -64,9 +72,8 @@ int ftrace_create_function_files(struct trace_array *tr,
 	if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
 		return 0;
 
-	ret = allocate_ftrace_ops(tr);
-	if (ret)
-		return ret;
+	if (!tr->ops)
+		return -EINVAL;
 
 	ftrace_create_filter_files(tr->ops, parent);
 
@@ -76,8 +83,7 @@ int ftrace_create_function_files(struct trace_array *tr,
 void ftrace_destroy_function_files(struct trace_array *tr)
 {
 	ftrace_destroy_filter_files(tr->ops);
-	kfree(tr->ops);
-	tr->ops = NULL;
+	ftrace_free_ftrace_ops(tr);
 }
 
 static int function_trace_init(struct trace_array *tr)
-- 
2.28.0



  parent reply	other threads:[~2020-09-22  1:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  1:24 [for-next][PATCH 00/26] tracing: Updates for 5.10 Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 01/26] tools/bootconfig: Show bootconfig compact tree from bootconfig file Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 02/26] tools/bootconfig: Add list option Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 03/26] tools/bootconfig: Make all functions static Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 04/26] tools/bootconfig: Add a script to generate ftrace shell-command from bootconfig Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 05/26] tools/bootconfig: Add a script to generates bootconfig from ftrace Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 06/26] tools/bootconfig: Add --init option for bconf2ftrace.sh Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 07/26] tracing: toplevel d_entry already initialized Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 08/26] tracing: make tracing_init_dentry() returns an integer instead of a d_entry pointer Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 09/26] tracing: Delete repeated words in comments Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 10/26] tracing: Use __this_cpu_read() in trace_buffered_event_enable() Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 11/26] kprobes: Use module_name() macro Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 12/26] tracing: remove a pointless assignment Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 13/26] fgraph: Convert ret_stack tasklist scanning to rcu Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 14/26] tracing/boot: Add per-instance tracing_on option support Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 15/26] Documentation: tracing: Add tracing_on option to boot-time tracer Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 16/26] tracing/kprobes: Support perf-style return probe Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 17/26] tracing/uprobes: " Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 18/26] Documentation: tracing: Add %return suffix description Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 19/26] Documentation: tracing: boot: Add an example of tracing function-calls Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 20/26] selftests/ftrace: Add %return suffix tests Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 21/26] kprobes: Init kprobes in early_initcall Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 22/26] tracing: Define event fields early stage Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 23/26] tracing: Enable adding dynamic events " Steven Rostedt
2020-09-22  1:24 ` Steven Rostedt [this message]
2020-09-23 23:52   ` [for-next][PATCH 24/26] tracing: Enable creating new instance early boot Masami Hiramatsu
2020-09-24 16:40     ` [PATCH] tracing/boot: Initialize per-instance event list in " Masami Hiramatsu
2020-09-25 19:37       ` Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 25/26] tracing/boot, kprobe, synth: Initialize boot-time tracing earlier Steven Rostedt
2020-09-22  1:24 ` [for-next][PATCH 26/26] Documentation: tracing: Add the startup timing of boot-time tracing Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200922012453.507002285@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).