sched/cputime: Convert kcpustat to nsecs
authorFrederic Weisbecker <fweisbec@gmail.com>
Tue, 31 Jan 2017 03:09:19 +0000 (04:09 +0100)
committerIngo Molnar <mingo@kernel.org>
Wed, 1 Feb 2017 08:13:47 +0000 (09:13 +0100)
Kernel CPU stats are stored in cputime_t which is an architecture
defined type, and hence a bit opaque and requiring accessors and mutators
for any operation.

Converting them to nsecs simplifies the code and is one step toward
the removal of cputime_t in the core code.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Link: http://lkml.kernel.org/r/1485832191-26889-4-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/s390/appldata/appldata_os.c
drivers/cpufreq/cpufreq.c
drivers/cpufreq/cpufreq_governor.c
drivers/cpufreq/cpufreq_stats.c
drivers/macintosh/rack-meter.c
fs/proc/stat.c
fs/proc/uptime.c
kernel/sched/cpuacct.c
kernel/sched/cputime.c

index 69b23b25ac34a4f3f6c6faeb305648ef5a7e5b63..08b9e942a262eda28393f5d982f4f8d60093ca4b 100644 (file)
@@ -113,21 +113,21 @@ static void appldata_get_os_data(void *data)
        j = 0;
        for_each_online_cpu(i) {
                os_data->os_cpu[j].per_cpu_user =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_USER]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_USER]);
                os_data->os_cpu[j].per_cpu_nice =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_NICE]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_NICE]);
                os_data->os_cpu[j].per_cpu_system =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]);
                os_data->os_cpu[j].per_cpu_idle =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IDLE]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IDLE]);
                os_data->os_cpu[j].per_cpu_irq =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]);
                os_data->os_cpu[j].per_cpu_softirq =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]);
                os_data->os_cpu[j].per_cpu_iowait =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IOWAIT]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IOWAIT]);
                os_data->os_cpu[j].per_cpu_steal =
-                       cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_STEAL]);
+                       nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_STEAL]);
                os_data->os_cpu[j].cpu_id = i;
                j++;
        }
index cc475eff90b3e5a8964d3a3a28c5ad334657788b..3e9b319a2e79a50aa19fe12f62c7e16e2a92cafa 100644 (file)
@@ -132,7 +132,7 @@ static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
        u64 cur_wall_time;
        u64 busy_time;
 
-       cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
+       cur_wall_time = jiffies64_to_nsecs(get_jiffies_64());
 
        busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
        busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM];
@@ -143,9 +143,9 @@ static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
 
        idle_time = cur_wall_time - busy_time;
        if (wall)
-               *wall = cputime_to_usecs(cur_wall_time);
+               *wall = div_u64(cur_wall_time, NSEC_PER_USEC);
 
-       return cputime_to_usecs(idle_time);
+       return div_u64(idle_time, NSEC_PER_USEC);
 }
 
 u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
index 0196467280bd0baf85d5380434688e1e5c621523..631bd2c86c5e6e996e157b957754891936cb1c7a 100644 (file)
@@ -152,7 +152,7 @@ unsigned int dbs_update(struct cpufreq_policy *policy)
                if (ignore_nice) {
                        u64 cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
 
-                       idle_time += cputime_to_usecs(cur_nice - j_cdbs->prev_cpu_nice);
+                       idle_time += div_u64(cur_nice - j_cdbs->prev_cpu_nice, NSEC_PER_USEC);
                        j_cdbs->prev_cpu_nice = cur_nice;
                }
 
index ac284e66839c6f19c9156432c6f5c4995e6525fb..17048bbec287f5b8307197d765b73b6cafe633b1 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/cpufreq.h>
 #include <linux/module.h>
 #include <linux/slab.h>
-#include <linux/cputime.h>
 
 static DEFINE_SPINLOCK(cpufreq_stats_lock);
 
index 775527135b93b55aea664faf91d71f2e047dab11..c114594136d41d11cb54fc691a2014c756b40f51 100644 (file)
@@ -91,7 +91,7 @@ static inline cputime64_t get_cpu_idle_time(unsigned int cpu)
        if (rackmeter_ignore_nice)
                retval += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
 
-       return retval;
+       return nsecs_to_cputime64(retval);
 }
 
 static void rackmeter_setup_i2s(struct rackmeter *rm)
index d700c42b357263b8e5106a7aed6fe1e301a7892c..44475a44cbf179f0d8821b00f444d480fdf08336 100644 (file)
 
 #ifdef arch_idle_time
 
-static cputime64_t get_idle_time(int cpu)
+static u64 get_idle_time(int cpu)
 {
-       cputime64_t idle;
+       u64 idle;
 
        idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE];
        if (cpu_online(cpu) && !nr_iowait_cpu(cpu))
-               idle += arch_idle_time(cpu);
+               idle += cputime_to_nsecs(arch_idle_time(cpu));
        return idle;
 }
 
-static cputime64_t get_iowait_time(int cpu)
+static u64 get_iowait_time(int cpu)
 {
-       cputime64_t iowait;
+       u64 iowait;
 
        iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT];
        if (cpu_online(cpu) && nr_iowait_cpu(cpu))
-               iowait += arch_idle_time(cpu);
+               iowait += cputime_to_nsecs(arch_idle_time(cpu));
        return iowait;
 }
 
@@ -45,32 +45,32 @@ static cputime64_t get_iowait_time(int cpu)
 
 static u64 get_idle_time(int cpu)
 {
-       u64 idle, idle_time = -1ULL;
+       u64 idle, idle_usecs = -1ULL;
 
        if (cpu_online(cpu))
-               idle_time = get_cpu_idle_time_us(cpu, NULL);
+               idle_usecs = get_cpu_idle_time_us(cpu, NULL);
 
-       if (idle_time == -1ULL)
+       if (idle_usecs == -1ULL)
                /* !NO_HZ or cpu offline so we can rely on cpustat.idle */
                idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE];
        else
-               idle = usecs_to_cputime64(idle_time);
+               idle = idle_usecs * NSEC_PER_USEC;
 
        return idle;
 }
 
 static u64 get_iowait_time(int cpu)
 {
-       u64 iowait, iowait_time = -1ULL;
+       u64 iowait, iowait_usecs = -1ULL;
 
        if (cpu_online(cpu))
-               iowait_time = get_cpu_iowait_time_us(cpu, NULL);
+               iowait_usecs = get_cpu_iowait_time_us(cpu, NULL);
 
-       if (iowait_time == -1ULL)
+       if (iowait_usecs == -1ULL)
                /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */
                iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT];
        else
-               iowait = usecs_to_cputime64(iowait_time);
+               iowait = iowait_usecs * NSEC_PER_USEC;
 
        return iowait;
 }
@@ -115,16 +115,16 @@ static int show_stat(struct seq_file *p, void *v)
        }
        sum += arch_irq_stat();
 
-       seq_put_decimal_ull(p, "cpu  ", cputime64_to_clock_t(user));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(nice));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(system));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(idle));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(iowait));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(irq));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(softirq));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(steal));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest));
-       seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest_nice));
+       seq_put_decimal_ull(p, "cpu  ", nsec_to_clock_t(user));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(system));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(idle));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(iowait));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(irq));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(softirq));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(steal));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest));
+       seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest_nice));
        seq_putc(p, '\n');
 
        for_each_online_cpu(i) {
@@ -140,16 +140,16 @@ static int show_stat(struct seq_file *p, void *v)
                guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
                guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
                seq_printf(p, "cpu%d", i);
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(user));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(nice));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(system));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(idle));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(iowait));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(irq));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(softirq));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(steal));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest));
-               seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest_nice));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(user));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(system));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(idle));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(iowait));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(irq));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(softirq));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(steal));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest));
+               seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest_nice));
                seq_putc(p, '\n');
        }
        seq_put_decimal_ull(p, "intr ", (unsigned long long)sum);
index 33de567c25af4b04a6ba283caaf5e4f6d9b4ecdb..7981c4ffe787a6afb80ae5a3017cef39f744c984 100644 (file)
@@ -5,23 +5,20 @@
 #include <linux/seq_file.h>
 #include <linux/time.h>
 #include <linux/kernel_stat.h>
-#include <linux/cputime.h>
 
 static int uptime_proc_show(struct seq_file *m, void *v)
 {
        struct timespec uptime;
        struct timespec idle;
-       u64 idletime;
        u64 nsec;
        u32 rem;
        int i;
 
-       idletime = 0;
+       nsec = 0;
        for_each_possible_cpu(i)
-               idletime += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE];
+               nsec += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE];
 
        get_monotonic_boottime(&uptime);
-       nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
        idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
        idle.tv_nsec = rem;
        seq_printf(m, "%lu.%02lu %lu.%02lu\n",
index 9add206b56082ee8ee35a878c9d9f87411f49359..f95ab29a45d0515d5651719143b38e335d366f4e 100644 (file)
@@ -297,7 +297,7 @@ static int cpuacct_stats_show(struct seq_file *sf, void *v)
        for (stat = 0; stat < CPUACCT_STAT_NSTATS; stat++) {
                seq_printf(sf, "%s %lld\n",
                           cpuacct_stat_desc[stat],
-                          (long long)cputime64_to_clock_t(val[stat]));
+                          (long long)nsec_to_clock_t(val[stat]));
        }
 
        return 0;
index f7c14cc71d06fa8805f1ec56e0db7707500234ce..61e270926e94b5809c67396cf1667fe5648a6a76 100644 (file)
@@ -75,9 +75,9 @@ static cputime_t irqtime_account_update(u64 irqtime, int idx, cputime_t maxtime)
        u64 *cpustat = kcpustat_this_cpu->cpustat;
        cputime_t irq_cputime;
 
-       irq_cputime = nsecs_to_cputime64(irqtime) - cpustat[idx];
+       irq_cputime = nsecs_to_cputime64(irqtime - cpustat[idx]);
        irq_cputime = min(irq_cputime, maxtime);
-       cpustat[idx] += irq_cputime;
+       cpustat[idx] += cputime_to_nsecs(irq_cputime);
 
        return irq_cputime;
 }
@@ -140,7 +140,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime)
        index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
 
        /* Add user time to cpustat. */
-       task_group_account_field(p, index, (__force u64) cputime);
+       task_group_account_field(p, index, cputime_to_nsecs(cputime));
 
        /* Account for user time used */
        acct_account_cputime(p);
@@ -162,11 +162,11 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)
 
        /* Add guest time to cpustat. */
        if (task_nice(p) > 0) {
-               cpustat[CPUTIME_NICE] += (__force u64) cputime;
-               cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime;
+               cpustat[CPUTIME_NICE] += cputime_to_nsecs(cputime);
+               cpustat[CPUTIME_GUEST_NICE] += cputime_to_nsecs(cputime);
        } else {
-               cpustat[CPUTIME_USER] += (__force u64) cputime;
-               cpustat[CPUTIME_GUEST] += (__force u64) cputime;
+               cpustat[CPUTIME_USER] += cputime_to_nsecs(cputime);
+               cpustat[CPUTIME_GUEST] += cputime_to_nsecs(cputime);
        }
 }
 
@@ -184,7 +184,7 @@ void account_system_index_time(struct task_struct *p,
        account_group_system_time(p, cputime);
 
        /* Add system time to cpustat. */
-       task_group_account_field(p, index, (__force u64) cputime);
+       task_group_account_field(p, index, cputime_to_nsecs(cputime));
 
        /* Account for system time used */
        acct_account_cputime(p);
@@ -224,7 +224,7 @@ void account_steal_time(cputime_t cputime)
 {
        u64 *cpustat = kcpustat_this_cpu->cpustat;
 
-       cpustat[CPUTIME_STEAL] += (__force u64) cputime;
+       cpustat[CPUTIME_STEAL] += cputime_to_nsecs(cputime);
 }
 
 /*
@@ -237,9 +237,9 @@ void account_idle_time(cputime_t cputime)
        struct rq *rq = this_rq();
 
        if (atomic_read(&rq->nr_iowait) > 0)
-               cpustat[CPUTIME_IOWAIT] += (__force u64) cputime;
+               cpustat[CPUTIME_IOWAIT] += cputime_to_nsecs(cputime);
        else
-               cpustat[CPUTIME_IDLE] += (__force u64) cputime;
+               cpustat[CPUTIME_IDLE] += cputime_to_nsecs(cputime);
 }
 
 /*