On 15 April 2015 at 23:00, Arnd Bergmann arnd@linaro.org wrote:
On Wednesday 15 April 2015 19:56:47 Baolin Wang wrote:
This patch introduces some functions for converting cputime to
timespec64 and abck,
that repalce the timespec type to timespec64 type, as well as for
arch/s390 and
arch/powerpc architecture.
Signed-off-by: Baolin Wang baolin.wang@linaro.org
arch/powerpc/include/asm/cputime.h | 24 ++++++++++++++++++++++++ arch/s390/include/asm/cputime.h | 26 ++++++++++++++++++++++++++ include/asm-generic/cputime_jiffies.h | 8 ++++++++ include/linux/jiffies.h | 3 +++ kernel/time/time.c | 21 +++++++++++++++++++++ 5 files changed, 82 insertions(+)
It might be better to split this up by architecture, but you could also try it as is.
diff --git a/arch/powerpc/include/asm/cputime.h
b/arch/powerpc/include/asm/cputime.h
index e245255..5a2b5ce 100644 --- a/arch/powerpc/include/asm/cputime.h +++ b/arch/powerpc/include/asm/cputime.h @@ -178,6 +178,30 @@ static inline cputime_t timespec_to_cputime(const
struct timespec *p)
}
/*
- Convert cputime <-> timespec64
- */
+static inline void cputime_to_timespec64(const cputime_t ct, struct
timespec64 *p)
+{
u64 x = (__force u64) ct;
unsigned int frac;
frac = do_div(x, tb_ticks_per_sec);
p->tv_sec = x;
x = (u64) frac * 1000000000;
do_div(x, tb_ticks_per_sec);
p->tv_nsec = x;
+}
+static inline cputime_t timespec64_to_cputime(const struct timespec64
*p)
+{
u64 ct;
ct = (u64) p->tv_nsec * tb_ticks_per_sec;
do_div(ct, 1000000000);
return (__force cputime_t)(ct + (u64) p->tv_sec *
tb_ticks_per_sec);
+}
+/*
- Convert cputime <-> timeval
*/
It might be better to replace the existing cputime_to_timespec64 and timespec64_to_cputime with wrappers around these for clarity. If you do it all in one patch, you can just add it in include/linux/cputime.h:
static inline cputime_t timespec_to_cputime(const struct timespec *ts) { struct timespec64 ts64 = timespec_to_timespec64(*ts); return timespec_to_cputime64(&ts64); }
which would then be used for all the implementations.
Arnd
*I have another confusion, if we add new *timespec_to_cputime/cputime_to_timespec *in **include/linux/cputime.h, * *the original *timespec_to_cputime/cputime_to_timespec *which located * *in include/asm-generic/cputime_jiffies.h, * *arch/s390/include/asm/cputime.h, and arch/powerpc/include/asm/cputime.h file will be removed?*