* [PATCH] time: Use div64_long() instead of do_div()
@ 2024-02-25 23:25 Thorsten Blum
2024-02-26 3:28 ` Liao, Chang
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2024-02-25 23:25 UTC (permalink / raw)
To: linux-kernel
Cc: Thomas Gleixner, Anna-Maria Behnsen, Frederic Weisbecker,
Peter Zijlstra, John Stultz, Thorsten Blum
Fixes Coccinelle/coccicheck warning reported by do_div.cocci.
Compared to do_div(), div64_long() does not implicitly cast the divisor and
does not unnecessarily calculate the remainder.
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
kernel/time/jiffies.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index bc4db9e5ab70..9d23178e2b6a 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -91,7 +91,7 @@ int register_refined_jiffies(long cycles_per_second)
/* shift_hz stores hz<<8 for extra accuracy */
shift_hz = (u64)cycles_per_second << 8;
shift_hz += cycles_per_tick/2;
- do_div(shift_hz, cycles_per_tick);
+ shift_hz = div64_long(shift_hz, cycles_per_tick);
/* Calculate nsec_per_tick using shift_hz */
nsec_per_tick = (u64)NSEC_PER_SEC << 8;
nsec_per_tick += (u32)shift_hz/2;
--
2.43.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] time: Use div64_long() instead of do_div()
2024-02-25 23:25 [PATCH] time: Use div64_long() instead of do_div() Thorsten Blum
@ 2024-02-26 3:28 ` Liao, Chang
2024-02-26 8:27 ` Thorsten Blum
0 siblings, 1 reply; 5+ messages in thread
From: Liao, Chang @ 2024-02-26 3:28 UTC (permalink / raw)
To: Thorsten Blum, linux-kernel
Cc: Thomas Gleixner, Anna-Maria Behnsen, Frederic Weisbecker,
Peter Zijlstra, John Stultz
Thorsten,
在 2024/2/26 7:25, Thorsten Blum 写道:
> Fixes Coccinelle/coccicheck warning reported by do_div.cocci.
>
> Compared to do_div(), div64_long() does not implicitly cast the divisor and
> does not unnecessarily calculate the remainder.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
> kernel/time/jiffies.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
> index bc4db9e5ab70..9d23178e2b6a 100644
> --- a/kernel/time/jiffies.c
> +++ b/kernel/time/jiffies.c
> @@ -91,7 +91,7 @@ int register_refined_jiffies(long cycles_per_second)
> /* shift_hz stores hz<<8 for extra accuracy */
> shift_hz = (u64)cycles_per_second << 8;
> shift_hz += cycles_per_tick/2;
> - do_div(shift_hz, cycles_per_tick);
> + shift_hz = div64_long(shift_hz, cycles_per_tick);
I am considering using div64_ul() to calculate the result. as shift_hz is
unsigned long, assume the sign bit of divisor cycles_per_tick never be set
in this context,then div64_long() will do a extra sign extension for result.
Or are there other recommendations?
Thanks.
> /* Calculate nsec_per_tick using shift_hz */
> nsec_per_tick = (u64)NSEC_PER_SEC << 8;
> nsec_per_tick += (u32)shift_hz/2;
--
BR
Liao, Chang
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] time: Use div64_long() instead of do_div()
2024-02-26 3:28 ` Liao, Chang
@ 2024-02-26 8:27 ` Thorsten Blum
2024-02-26 9:03 ` [PATCH v2] time: Use div64_ul() " Thorsten Blum
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2024-02-26 8:27 UTC (permalink / raw)
To: Liao, Chang
Cc: linux-kernel, Thomas Gleixner, Anna-Maria Behnsen,
Frederic Weisbecker, Peter Zijlstra, John Stultz
> On Feb 26, 2024, at 04:28, Liao, Chang <liaochang1@huawei.com> wrote:
>
> I am considering using div64_ul() to calculate the result. as shift_hz is
> unsigned long, assume the sign bit of divisor cycles_per_tick never be set
> in this context,then div64_long() will do a extra sign extension for result.
Yes, div64_ul() is better and also removes the warning.
I'll submit a v2 shortly.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] time: Use div64_ul() instead of do_div()
2024-02-26 8:27 ` Thorsten Blum
@ 2024-02-26 9:03 ` Thorsten Blum
2024-02-26 11:34 ` Liao, Chang
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2024-02-26 9:03 UTC (permalink / raw)
To: thorsten.blum
Cc: anna-maria, frederic, jstultz, liaochang1, linux-kernel, peterz, tglx
Fixes Coccinelle/coccicheck warning reported by do_div.cocci.
Compared to do_div(), div64_ul() does not implicitly cast the divisor and
does not unnecessarily calculate the remainder.
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
Changes in v2:
- s/div64_long/div64_ul/ as suggested by Chang Liao
---
kernel/time/jiffies.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index bc4db9e5ab70..fccee15e94d5 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -91,7 +91,7 @@ int register_refined_jiffies(long cycles_per_second)
/* shift_hz stores hz<<8 for extra accuracy */
shift_hz = (u64)cycles_per_second << 8;
shift_hz += cycles_per_tick/2;
- do_div(shift_hz, cycles_per_tick);
+ shift_hz = div64_ul(shift_hz, cycles_per_tick);
/* Calculate nsec_per_tick using shift_hz */
nsec_per_tick = (u64)NSEC_PER_SEC << 8;
nsec_per_tick += (u32)shift_hz/2;
--
2.43.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] time: Use div64_ul() instead of do_div()
2024-02-26 9:03 ` [PATCH v2] time: Use div64_ul() " Thorsten Blum
@ 2024-02-26 11:34 ` Liao, Chang
0 siblings, 0 replies; 5+ messages in thread
From: Liao, Chang @ 2024-02-26 11:34 UTC (permalink / raw)
To: Thorsten Blum; +Cc: anna-maria, frederic, jstultz, linux-kernel, peterz, tglx
在 2024/2/26 17:03, Thorsten Blum 写道:
> Fixes Coccinelle/coccicheck warning reported by do_div.cocci.
>
> Compared to do_div(), div64_ul() does not implicitly cast the divisor and
> does not unnecessarily calculate the remainder.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
> Changes in v2:
> - s/div64_long/div64_ul/ as suggested by Chang Liao
> ---
> kernel/time/jiffies.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
> index bc4db9e5ab70..fccee15e94d5 100644
> --- a/kernel/time/jiffies.c
> +++ b/kernel/time/jiffies.c
> @@ -91,7 +91,7 @@ int register_refined_jiffies(long cycles_per_second)
> /* shift_hz stores hz<<8 for extra accuracy */
> shift_hz = (u64)cycles_per_second << 8;
> shift_hz += cycles_per_tick/2;
> - do_div(shift_hz, cycles_per_tick);
> + shift_hz = div64_ul(shift_hz, cycles_per_tick);
LGTM
Reviewed-by: Liao Chang <liaochang1@huawei.com>
> /* Calculate nsec_per_tick using shift_hz */
> nsec_per_tick = (u64)NSEC_PER_SEC << 8;
> nsec_per_tick += (u32)shift_hz/2;
--
BR
Liao, Chang
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-26 11:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-25 23:25 [PATCH] time: Use div64_long() instead of do_div() Thorsten Blum
2024-02-26 3:28 ` Liao, Chang
2024-02-26 8:27 ` Thorsten Blum
2024-02-26 9:03 ` [PATCH v2] time: Use div64_ul() " Thorsten Blum
2024-02-26 11:34 ` Liao, Chang
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).