linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: Use div64_u64() instead of do_div()
@ 2024-02-25 16:45 Thorsten Blum
  2024-02-25 22:21 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2024-02-25 16:45 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel, Thorsten Blum

Fixes Coccinelle/coccicheck warnings reported by do_div.cocci.

Compared to do_div(), div64_u64() does not implicitly cast the divisor and
does not unnecessarily calculate the remainder.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 kernel/trace/trace_benchmark.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_benchmark.c b/kernel/trace/trace_benchmark.c
index 54d5fa35c90a..811b08439406 100644
--- a/kernel/trace/trace_benchmark.c
+++ b/kernel/trace/trace_benchmark.c
@@ -92,7 +92,6 @@ static void trace_do_benchmark(void)
 	bm_total += delta;
 	bm_totalsq += delta * delta;
 
-
 	if (bm_cnt > 1) {
 		/*
 		 * Apply Welford's method to calculate standard deviation:
@@ -105,7 +104,7 @@ static void trace_do_benchmark(void)
 		stddev = 0;
 
 	delta = bm_total;
-	do_div(delta, bm_cnt);
+	delta = div64_u64(delta, bm_cnt);
 	avg = delta;
 
 	if (stddev > 0) {
@@ -127,7 +126,7 @@ static void trace_do_benchmark(void)
 			seed = stddev;
 			if (!last_seed)
 				break;
-			do_div(seed, last_seed);
+			seed = div64_u64(seed, last_seed);
 			seed += last_seed;
 			do_div(seed, 2);
 		} while (i++ < 10 && last_seed != seed);
-- 
2.43.2


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

* Re: [PATCH] tracing: Use div64_u64() instead of do_div()
  2024-02-25 16:45 [PATCH] tracing: Use div64_u64() instead of do_div() Thorsten Blum
@ 2024-02-25 22:21 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2024-02-25 22:21 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Steven Rostedt, Mathieu Desnoyers, linux-kernel, linux-trace-kernel

On Sun, 25 Feb 2024 17:45:08 +0100
Thorsten Blum <thorsten.blum@toblux.com> wrote:

> Fixes Coccinelle/coccicheck warnings reported by do_div.cocci.
> 
> Compared to do_div(), div64_u64() does not implicitly cast the divisor and
> does not unnecessarily calculate the remainder.
> 

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks!

> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  kernel/trace/trace_benchmark.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/trace/trace_benchmark.c b/kernel/trace/trace_benchmark.c
> index 54d5fa35c90a..811b08439406 100644
> --- a/kernel/trace/trace_benchmark.c
> +++ b/kernel/trace/trace_benchmark.c
> @@ -92,7 +92,6 @@ static void trace_do_benchmark(void)
>  	bm_total += delta;
>  	bm_totalsq += delta * delta;
>  
> -
>  	if (bm_cnt > 1) {
>  		/*
>  		 * Apply Welford's method to calculate standard deviation:
> @@ -105,7 +104,7 @@ static void trace_do_benchmark(void)
>  		stddev = 0;
>  
>  	delta = bm_total;
> -	do_div(delta, bm_cnt);
> +	delta = div64_u64(delta, bm_cnt);
>  	avg = delta;
>  
>  	if (stddev > 0) {
> @@ -127,7 +126,7 @@ static void trace_do_benchmark(void)
>  			seed = stddev;
>  			if (!last_seed)
>  				break;
> -			do_div(seed, last_seed);
> +			seed = div64_u64(seed, last_seed);
>  			seed += last_seed;
>  			do_div(seed, 2);
>  		} while (i++ < 10 && last_seed != seed);
> -- 
> 2.43.2
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

end of thread, other threads:[~2024-02-25 22:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-25 16:45 [PATCH] tracing: Use div64_u64() instead of do_div() Thorsten Blum
2024-02-25 22:21 ` Masami Hiramatsu

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).