[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4E5A47C3-E9DD-4FD2-BDC4-BED67EF791F2@toblux.com>
Date: Wed, 20 Mar 2024 17:30:00 +0100
From: Thorsten Blum <thorsten.blum@...lux.com>
To: "Masami Hiramatsu (Google)" <mhiramat@...nel.org>
Cc: Steven Rostedt <rostedt@...dmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org
Subject: Re: [PATCH] tracing: Explicitly cast divisor to fix Coccinelle
warning
On 20. Mar 2024, at 16:01, Thorsten Blum <thorsten.blum@...lux.com> wrote:
>
> Coccinelle also finds this one, but please ignore this patch as I just realized
> this was already fixed in another patch of mine from February.
>
> Sorry for the inconvenience.
>
> Link: https://lore.kernel.org/linux-kernel/20240225164507.232942-2-thorsten.blum@toblux.com/
Actually, I will submit a new patch to revert
delta = div64_u64(delta, bm_cnt);
back to
do_div(delta, bm_cnt);
but this time include an explicit cast to u32
do_div(delta, (u32)bm_cnt);
to remove the Coccinelle warning reported by do_div.cocci and to improve
performance.
The do_div() macro does a 64-by-32 division which is faster than the 64-by-64
division done by div64_u64(). Casting the divisor bm_cnt to u32 is safe since
we return early from trace_do_benchmark() if bm_cnt > UINT_MAX (something I
missed in d6cb38e10810).
This approach is already used when calculating the standard deviation:
do_div(stddev, (u32)bm_cnt);
do_div(stddev, (u32)bm_cnt - 1);
Thanks,
Thorsten
Powered by blists - more mailing lists