]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tracing: Improve benchmark test performance by using do_div()
authorThorsten Blum <thorsten.blum@toblux.com>
Fri, 29 Mar 2024 16:02:30 +0000 (17:02 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 14 May 2024 00:00:57 +0000 (20:00 -0400)
Partially revert commit d6cb38e10810 ("tracing: Use div64_u64() instead
of do_div()") and use do_div() again to utilize its faster 64-by-32
division compared to the 64-by-64 division done by div64_u64().

Explicitly cast the divisor bm_cnt to u32 to prevent a Coccinelle
warning reported by do_div.cocci. The warning was removed with commit
d6cb38e10810 ("tracing: Use div64_u64() instead of do_div()").

Using the faster 64-by-32 division and casting bm_cnt to u32 is safe
because we return early from trace_do_benchmark() if bm_cnt > UINT_MAX.
This approach is already used twice in trace_do_benchmark() when
calculating the standard deviation:

do_div(stddev, (u32)bm_cnt);
do_div(stddev, (u32)bm_cnt - 1);

Link: https://lore.kernel.org/linux-trace-kernel/20240329160229.4874-2-thorsten.blum@toblux.com
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_benchmark.c

index 811b08439406a04cb96fe2f5b51a01d0233ee1a4..e19c32f2a9381a070f1c28080710543eaf66ffdf 100644 (file)
@@ -104,7 +104,7 @@ static void trace_do_benchmark(void)
                stddev = 0;
 
        delta = bm_total;
-       delta = div64_u64(delta, bm_cnt);
+       do_div(delta, (u32)bm_cnt);
        avg = delta;
 
        if (stddev > 0) {