* [PATCH] ftrace: Use this_cpu_ptr() instead of per_cpu_ptr(smp_processor_id())
@ 2024-08-19 6:01 Li Chen
2024-08-19 15:23 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Li Chen @ 2024-08-19 6:01 UTC (permalink / raw)
To: linux-trace-kernel, Mathieu Desnoyers, Steven Rostedt,
Masami Hiramatsu
From: Li Chen <chenl311@chinatelecom.cn>
Use this_cpu_ptr() instead of open coding the equivalent in various
ftrace functions.
Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
---
kernel/trace/trace_functions.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 3b0cea37e0297..65fed0bbc5c22 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -184,7 +184,6 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
struct trace_array_cpu *data;
unsigned int trace_ctx;
int bit;
- int cpu;
if (unlikely(!tr->function_enabled))
return;
@@ -195,8 +194,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
trace_ctx = tracing_gen_ctx();
- cpu = smp_processor_id();
- data = per_cpu_ptr(tr->array_buffer.data, cpu);
+ data = this_cpu_ptr(tr->array_buffer.data);
if (!atomic_read(&data->disabled))
trace_function(tr, ip, parent_ip, trace_ctx);
@@ -300,7 +298,6 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
unsigned int trace_ctx;
unsigned long flags;
int bit;
- int cpu;
if (unlikely(!tr->function_enabled))
return;
@@ -309,8 +306,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
if (bit < 0)
return;
- cpu = smp_processor_id();
- data = per_cpu_ptr(tr->array_buffer.data, cpu);
+ data = this_cpu_ptr(tr->array_buffer.data);
if (atomic_read(&data->disabled))
goto out;
@@ -321,7 +317,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
* TODO: think about a solution that is better than just hoping to be
* lucky.
*/
- last_info = per_cpu_ptr(tr->last_func_repeats, cpu);
+ last_info = this_cpu_ptr(tr->last_func_repeats);
if (is_repeat_check(tr, last_info, ip, parent_ip))
goto out;
--
2.46.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ftrace: Use this_cpu_ptr() instead of per_cpu_ptr(smp_processor_id())
2024-08-19 6:01 [PATCH] ftrace: Use this_cpu_ptr() instead of per_cpu_ptr(smp_processor_id()) Li Chen
@ 2024-08-19 15:23 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2024-08-19 15:23 UTC (permalink / raw)
To: Li Chen; +Cc: linux-trace-kernel, Mathieu Desnoyers, Masami Hiramatsu
On Mon, 19 Aug 2024 14:01:53 +0800
Li Chen <me@linux.beauty> wrote:
> From: Li Chen <chenl311@chinatelecom.cn>
>
> Use this_cpu_ptr() instead of open coding the equivalent in various
> ftrace functions.
Thanks.
This code was written (2009) before this_cpu_ptr() was introduced (2010).
-- Steve
>
> Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
> ---
> kernel/trace/trace_functions.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
> index 3b0cea37e0297..65fed0bbc5c22 100644
> --- a/kernel/trace/trace_functions.c
> +++ b/kernel/trace/trace_functions.c
> @@ -184,7 +184,6 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
> struct trace_array_cpu *data;
> unsigned int trace_ctx;
> int bit;
> - int cpu;
>
> if (unlikely(!tr->function_enabled))
> return;
> @@ -195,8 +194,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
>
> trace_ctx = tracing_gen_ctx();
>
> - cpu = smp_processor_id();
> - data = per_cpu_ptr(tr->array_buffer.data, cpu);
> + data = this_cpu_ptr(tr->array_buffer.data);
> if (!atomic_read(&data->disabled))
> trace_function(tr, ip, parent_ip, trace_ctx);
>
> @@ -300,7 +298,6 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> unsigned int trace_ctx;
> unsigned long flags;
> int bit;
> - int cpu;
>
> if (unlikely(!tr->function_enabled))
> return;
> @@ -309,8 +306,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> if (bit < 0)
> return;
>
> - cpu = smp_processor_id();
> - data = per_cpu_ptr(tr->array_buffer.data, cpu);
> + data = this_cpu_ptr(tr->array_buffer.data);
> if (atomic_read(&data->disabled))
> goto out;
>
> @@ -321,7 +317,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> * TODO: think about a solution that is better than just hoping to be
> * lucky.
> */
> - last_info = per_cpu_ptr(tr->last_func_repeats, cpu);
> + last_info = this_cpu_ptr(tr->last_func_repeats);
> if (is_repeat_check(tr, last_info, ip, parent_ip))
> goto out;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-19 15:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-19 6:01 [PATCH] ftrace: Use this_cpu_ptr() instead of per_cpu_ptr(smp_processor_id()) Li Chen
2024-08-19 15:23 ` Steven Rostedt
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).