Re: [RFC/PATCH 4/5] cputime: use do_div() for nsec resolutionconversion helpers

From: Frederic Weisbecker
Date: Tue Feb 26 2013 - 10:22:03 EST


2013/2/21 Kevin Hilman <khilman@xxxxxxxxxx>:
> From a8a0a8b8b12512a7f862ade459cd88d2b48e2bf3 Mon Sep 17 00:00:00 2001
> From: Kevin Hilman <khilman@xxxxxxxxxx>
> Date: Thu, 14 Feb 2013 11:27:36 -0800
> Subject: [PATCH 4/5] cputime: use do_div() for nsec resolution conversion
> helpers
>
> For the nsec resolution conversions to be useful on non 64-bit
> architectures, do_div() needs to be used for the 64-bit divisions.
>
> Special thanks to Namhyung Kim for pointing out omissions of the
> __force attribute in an earlier version.
>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Signed-off-by: Kevin Hilman <khilman@xxxxxxxxxx>
> ---
> include/asm-generic/cputime_nsecs.h | 51 +++++++++++++++++++++++++++----------
> 1 file changed, 37 insertions(+), 14 deletions(-)
>
> diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
> index b6485ca..d4944c9 100644
> --- a/include/asm-generic/cputime_nsecs.h
> +++ b/include/asm-generic/cputime_nsecs.h
> @@ -24,13 +24,17 @@ typedef u64 __nocast cputime64_t;
> /*
> * Convert cputime <-> jiffies (HZ)
> */
> -#define cputime_to_jiffies(__ct) \
> - ((__force u64)(__ct) / (NSEC_PER_SEC / HZ))
> +static inline u64 cputime_to_jiffies(const cputime_t ct)
> +{
> + u64 __ct = (__force u64) ct;
> +
> + do_div(__ct, NSEC_PER_SEC / HZ);

So, when you don't need the remainder, could you please rather use
div_u64() ? It defaults to use do_div() anyway if the arch doesn't
override it. And none does apparently yet. But at least it paves the
way for further optimizations. And you can directly return the result.

Also, how about:

#define cputime_div(cputime, divisor) div_u64((__force u64)cputime, divisor)

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/