Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cputime: Move default nsecs_to_cputime() to jiffies based cputime file

If the architecture doesn't provide an implementation of
nsecs_to_cputime(), the cputime accounting core uses a
default one that converts the nanoseconds to jiffies. However
this only makes sense if we use the jiffies based cputime.

For now it doesn't matter much because this API is only
called on code that uses jiffies based cputime accounting.

But the code may evolve and this API may be used more
broadly in the future. Keeping this default implementation
around is very error prone as it may introduce a bug and
hide it on architectures that don't override this API.

Fix this by moving this definition to the jiffies based
cputime headers as it is the only place where it belongs to.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Li Zhong <zhong@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>

+8 -6
+8 -2
include/asm-generic/cputime_jiffies.h
··· 13 13 #define cputime64_to_jiffies64(__ct) (__force u64)(__ct) 14 14 #define jiffies64_to_cputime64(__jif) (__force cputime64_t)(__jif) 15 15 16 - #define nsecs_to_cputime64(__ct) \ 17 - jiffies64_to_cputime64(nsecs_to_jiffies64(__ct)) 16 + 17 + /* 18 + * Convert nanoseconds to cputime 19 + */ 20 + #define nsecs_to_cputime64(__nsec) \ 21 + jiffies64_to_cputime64(nsecs_to_jiffies64(__nsec)) 22 + #define nsecs_to_cputime(__nsec) \ 23 + jiffies_to_cputime(nsecs_to_jiffies(__nsec)) 18 24 19 25 20 26 /*
-4
kernel/sched/cputime.c
··· 505 505 506 506 #else 507 507 508 - #ifndef nsecs_to_cputime 509 - # define nsecs_to_cputime(__nsecs) nsecs_to_jiffies(__nsecs) 510 - #endif 511 - 512 508 static cputime_t scale_utime(cputime_t utime, cputime_t rtime, cputime_t total) 513 509 { 514 510 u64 temp = (__force u64) rtime;