Skip to contentSkip to conversation

trace: use __this_cpu_inc/dec operation instead of __get_cpu_var

PATCH In review Shan Wei 3 participants 4 messages Nov 19, 2012 – Feb 3, 2013 Tracing

lore
Share & tools
lore

Shan Wei

author
#0 lore raw

PATCH 1/1 trace: use __this_cpu_inc/dec operation instead of __get_cpu_var

From: Shan Wei <[email protected]>

__this_cpu_inc_return() or __this_cpu_dec generates a single instruction, which is faster than __get_cpu_var operation.

---
 kernel/trace/trace.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
index 18c0aa8..3795694 100644
@@ -1313,7 +1313,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
 	 */
 	preempt_disable_notrace();
 
-	use_stack = ++__get_cpu_var(ftrace_stack_reserve);
+	use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
 	/*
 	 * We don't need any atomic variables, just a barrier.
 	 * If an interrupt comes in, we don't care, because it would
@@ -1367,7 +1367,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
  out:
 	/* Again, don't let gcc optimize things here */
 	barrier();
-	__get_cpu_var(ftrace_stack_reserve)--;
+	__this_cpu_dec(ftrace_stack_reserve);
 	preempt_enable_notrace();
 
 }
Signature · 1 line
1.7.1
author
#2 lore raw
In reply to Shan Wei

ping ......

Shan Wei said, at 2012/11/19 13:21:

Quoted 33 lines

From: Shan Wei <[email protected]>

__this_cpu_inc_return() or __this_cpu_dec generates a single instruction, which is faster than __get_cpu_var operation.

---
 kernel/trace/trace.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
index 18c0aa8..3795694 100644
@@ -1313,7 +1313,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
 	 */
 	preempt_disable_notrace();
 
-	use_stack = ++__get_cpu_var(ftrace_stack_reserve);
+	use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
 	/*
 	 * We don't need any atomic variables, just a barrier.
 	 * If an interrupt comes in, we don't care, because it would
@@ -1367,7 +1367,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
  out:
 	/* Again, don't let gcc optimize things here */
 	barrier();
-	__get_cpu_var(ftrace_stack_reserve)--;
+	__this_cpu_dec(ftrace_stack_reserve);
 	preempt_enable_notrace();
 
 }
#3 lore raw

[tip:perf/core] tracing: Use __this_cpu_inc/ dec operation instead of __get_cpu_var

In reply to Shan Wei
Commit-ID:  821465295b36136998ef294fe176fba4e09c1cd9
Gitweb:     http://git.kernel.org/tip/821465295b36136998ef294fe176fba4e09c1cd9
Author:     Shan Wei <[email protected]>
AuthorDate: Mon, 19 Nov 2012 13:21:01 +0800
Committer:  Steven Rostedt <[email protected]>
CommitDate: Fri, 25 Jan 2013 20:36:54 -0500

tracing: Use __this_cpu_inc/dec operation instead of __get_cpu_var

__this_cpu_inc_return() or __this_cpu_dec generates a single instruction, which is faster than __get_cpu_var operation.

---
 kernel/trace/trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
index ca9b7df..07888e1 100644
@@ -1344,7 +1344,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
 	 */
 	preempt_disable_notrace();
 
-	use_stack = ++__get_cpu_var(ftrace_stack_reserve);
+	use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
 	/*
 	 * We don't need any atomic variables, just a barrier.
 	 * If an interrupt comes in, we don't care, because it would
@@ -1398,7 +1398,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
  out:
 	/* Again, don't let gcc optimize things here */
 	barrier();
-	__get_cpu_var(ftrace_stack_reserve)--;
+	__this_cpu_dec(ftrace_stack_reserve);
 	preempt_enable_notrace();
 
 }