linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Tom Zanussi <zanussi@kernel.org>,
	artem.bityutskiy@linux.intel.com, linux-kernel@vger.kernel.org,
	linux-rt-users@vger.kernel.org
Subject: [PATCH 1/2] tracing: Fix synth event test to avoid using smp_processor_id()
Date: Mon, 17 Feb 2020 18:52:29 +0900	[thread overview]
Message-ID: <158193314931.8868.11386672578933699881.stgit@devnote2> (raw)
In-Reply-To: <158193313870.8868.10793333111731425487.stgit@devnote2>

Since smp_processor_id() requires irq-disabled or preempt-disabled,
synth event generation test module made some warnings. To prevent
that, use get_cpu()/put_cpu() instead of smp_processor_id().

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/synth_event_gen_test.c |   23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/kernel/trace/synth_event_gen_test.c b/kernel/trace/synth_event_gen_test.c
index 4aefe003cb7c..b7775fd6baf5 100644
--- a/kernel/trace/synth_event_gen_test.c
+++ b/kernel/trace/synth_event_gen_test.c
@@ -114,12 +114,13 @@ static int __init test_gen_synth_cmd(void)
 	vals[1] = (u64)"hula hoops";	/* next_comm_field */
 	vals[2] = 1000000;		/* ts_ns */
 	vals[3] = 1000;			/* ts_ms */
-	vals[4] = smp_processor_id();	/* cpu */
+	vals[4] = get_cpu();	/* cpu */
 	vals[5] = (u64)"thneed";	/* my_string_field */
 	vals[6] = 598;			/* my_int_field */
 
 	/* Now generate a gen_synth_test event */
 	ret = synth_event_trace_array(gen_synth_test, vals, ARRAY_SIZE(vals));
+	put_cpu();
  out:
 	return ret;
  delete:
@@ -221,12 +222,13 @@ static int __init test_empty_synth_event(void)
 	vals[1] = (u64)"tiddlywinks";	/* next_comm_field */
 	vals[2] = 1000000;		/* ts_ns */
 	vals[3] = 1000;			/* ts_ms */
-	vals[4] = smp_processor_id();	/* cpu */
+	vals[4] = get_cpu();		/* cpu */
 	vals[5] = (u64)"thneed_2.0";	/* my_string_field */
 	vals[6] = 399;			/* my_int_field */
 
 	/* Now trace an empty_synth_test event */
 	ret = synth_event_trace_array(empty_synth_test, vals, ARRAY_SIZE(vals));
+	put_cpu();
  out:
 	return ret;
  delete:
@@ -293,12 +295,13 @@ static int __init test_create_synth_event(void)
 	vals[1] = (u64)"tiddlywinks";	/* next_comm_field */
 	vals[2] = 1000000;		/* ts_ns */
 	vals[3] = 1000;			/* ts_ms */
-	vals[4] = smp_processor_id();	/* cpu */
+	vals[4] = get_cpu();		/* cpu */
 	vals[5] = (u64)"thneed";	/* my_string_field */
 	vals[6] = 398;			/* my_int_field */
 
 	/* Now generate a create_synth_test event */
 	ret = synth_event_trace_array(create_synth_test, vals, ARRAY_SIZE(vals));
+	put_cpu();
  out:
 	return ret;
  delete:
@@ -315,6 +318,7 @@ static int __init test_create_synth_event(void)
 static int __init test_add_next_synth_val(void)
 {
 	struct synth_event_trace_state trace_state;
+	unsigned int cpu;
 	int ret;
 
 	/* Start by reserving space in the trace buffer */
@@ -322,6 +326,8 @@ static int __init test_add_next_synth_val(void)
 	if (ret)
 		return ret;
 
+	cpu = get_cpu();
+
 	/* Write some bogus values into the trace buffer, one after another */
 
 	/* next_pid_field */
@@ -345,7 +351,7 @@ static int __init test_add_next_synth_val(void)
 		goto out;
 
 	/* cpu */
-	ret = synth_event_add_next_val(smp_processor_id(), &trace_state);
+	ret = synth_event_add_next_val(cpu, &trace_state);
 	if (ret)
 		goto out;
 
@@ -357,6 +363,7 @@ static int __init test_add_next_synth_val(void)
 	/* my_int_field */
 	ret = synth_event_add_next_val(395, &trace_state);
  out:
+	put_cpu();
 	/* Finally, commit the event */
 	ret = synth_event_trace_end(&trace_state);
 
@@ -371,6 +378,7 @@ static int __init test_add_next_synth_val(void)
 static int __init test_add_synth_val(void)
 {
 	struct synth_event_trace_state trace_state;
+	unsigned int cpu;
 	int ret;
 
 	/* Start by reserving space in the trace buffer */
@@ -378,6 +386,7 @@ static int __init test_add_synth_val(void)
 	if (ret)
 		return ret;
 
+	cpu = get_cpu();
 	/* Write some bogus values into the trace buffer, using field names */
 
 	ret = synth_event_add_val("ts_ns", 1000000, &trace_state);
@@ -388,7 +397,7 @@ static int __init test_add_synth_val(void)
 	if (ret)
 		goto out;
 
-	ret = synth_event_add_val("cpu", smp_processor_id(), &trace_state);
+	ret = synth_event_add_val("cpu", cpu, &trace_state);
 	if (ret)
 		goto out;
 
@@ -408,6 +417,7 @@ static int __init test_add_synth_val(void)
 
 	ret = synth_event_add_val("my_int_field", 3999, &trace_state);
  out:
+	put_cpu();
 	/* Finally, commit the event */
 	ret = synth_event_trace_end(&trace_state);
 
@@ -427,9 +437,10 @@ static int __init test_trace_synth_event(void)
 				(u64)"clackers",	/* next_comm_field */
 				1000000,		/* ts_ns */
 				1000,			/* ts_ms */
-				smp_processor_id(),	/* cpu */
+				get_cpu(),		/* cpu */
 				(u64)"Thneed",		/* my_string_field */
 				999);			/* my_int_field */
+	put_cpu();
 	return ret;
 }
 


  reply	other threads:[~2020-02-17  9:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-17  9:52 [PATCH 0/2] tracing: Fix synthetic event generation API and test Masami Hiramatsu
2020-02-17  9:52 ` Masami Hiramatsu [this message]
2020-02-20 22:48   ` [PATCH 1/2] tracing: Fix synth event test to avoid using smp_processor_id() Steven Rostedt
2020-02-20 22:56     ` Tom Zanussi
2020-02-21 10:24     ` Masami Hiramatsu
2020-02-17  9:52 ` [PATCH 2/2] tracing: Clear trace_state when starting trace Masami Hiramatsu
2020-02-18 15:18 ` [PATCH 0/2] tracing: Fix synthetic event generation API and test Tom Zanussi

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=158193314931.8868.11386672578933699881.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=zanussi@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).