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

cputime: Default implementation of nsecs -> cputime conversion

The architectures that override cputime_t (s390, ppc) don't provide
any version of nsecs_to_cputime(). Indeed this cputime_t implementation
by backend only happens when CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y under
which the core code doesn't make any use of nsecs_to_cputime().

At least for now.

We are going to make a broader use of it so lets provide a default
version with a per usecs granularity. It should be good enough for most
usecases.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

+17 -6
+1 -1
drivers/cpufreq/cpufreq_stats.c
··· 13 13 #include <linux/cpufreq.h> 14 14 #include <linux/module.h> 15 15 #include <linux/slab.h> 16 - #include <asm/cputime.h> 16 + #include <linux/cputime.h> 17 17 18 18 static spinlock_t cpufreq_stats_lock; 19 19
+1 -1
drivers/s390/cio/cio.c
··· 28 28 #include <asm/chpid.h> 29 29 #include <asm/airq.h> 30 30 #include <asm/isc.h> 31 - #include <asm/cputime.h> 31 + #include <linux/cputime.h> 32 32 #include <asm/fcx.h> 33 33 #include <asm/nmi.h> 34 34 #include <asm/crw.h>
+1 -1
fs/proc/stat.c
··· 9 9 #include <linux/slab.h> 10 10 #include <linux/time.h> 11 11 #include <linux/irqnr.h> 12 - #include <asm/cputime.h> 12 + #include <linux/cputime.h> 13 13 #include <linux/tick.h> 14 14 15 15 #ifndef arch_irq_stat_cpu
+1 -1
fs/proc/uptime.c
··· 5 5 #include <linux/seq_file.h> 6 6 #include <linux/time.h> 7 7 #include <linux/kernel_stat.h> 8 - #include <asm/cputime.h> 8 + #include <linux/cputime.h> 9 9 10 10 static int uptime_proc_show(struct seq_file *m, void *v) 11 11 {
+11
include/linux/cputime.h
··· 1 + #ifndef __LINUX_CPUTIME_H 2 + #define __LINUX_CPUTIME_H 3 + 4 + #include <asm/cputime.h> 5 + 6 + #ifndef nsecs_to_cputime 7 + # define nsecs_to_cputime(__nsecs) \ 8 + usecs_to_cputime((__nsecs) / NSEC_PER_USEC) 9 + #endif 10 + 11 + #endif /* __LINUX_CPUTIME_H */
+1 -1
include/linux/kernel_stat.h
··· 9 9 #include <linux/sched.h> 10 10 #include <linux/vtime.h> 11 11 #include <asm/irq.h> 12 - #include <asm/cputime.h> 12 + #include <linux/cputime.h> 13 13 14 14 /* 15 15 * 'kernel_stat.h' contains the definitions needed for doing
+1 -1
include/linux/sched.h
··· 27 27 28 28 #include <asm/page.h> 29 29 #include <asm/ptrace.h> 30 - #include <asm/cputime.h> 30 + #include <linux/cputime.h> 31 31 32 32 #include <linux/smp.h> 33 33 #include <linux/sem.h>