Commit-ID:  bfce1d6006f383fbb55a89580af37819a77195b7
Gitweb:     http://git.kernel.org/tip/bfce1d6006f383fbb55a89580af37819a77195b7
Author:     Frederic Weisbecker <fweis...@gmail.com>
AuthorDate: Tue, 31 Jan 2017 04:09:42 +0100
Committer:  Ingo Molnar <mi...@kernel.org>
CommitDate: Wed, 1 Feb 2017 09:13:59 +0100

sched/cputime, vtime: Return nsecs instead of cputime_t to account

Turn the full dynticks cputime clock source to return nsec while keeping
its very internals jiffies based for performance reasons.

Signed-off-by: Frederic Weisbecker <fweis...@gmail.com>
Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org>
Cc: Fenghua Yu <fenghua...@intel.com>
Cc: Heiko Carstens <heiko.carst...@de.ibm.com>
Cc: Linus Torvalds <torva...@linux-foundation.org>
Cc: Martin Schwidefsky <schwidef...@de.ibm.com>
Cc: Michael Ellerman <m...@ellerman.id.au>
Cc: Paul Mackerras <pau...@samba.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Rik van Riel <r...@redhat.com>
Cc: Stanislaw Gruszka <sgrus...@redhat.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Tony Luck <tony.l...@intel.com>
Cc: Wanpeng Li <wanpeng...@hotmail.com>
Link: 
http://lkml.kernel.org/r/1485832191-26889-27-git-send-email-fweis...@gmail.com
Signed-off-by: Ingo Molnar <mi...@kernel.org>
---
 kernel/sched/cputime.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index f3a56bf..2ecec3a 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -678,20 +678,20 @@ void thread_group_cputime_adjusted(struct task_struct *p, 
u64 *ut, u64 *st)
 #endif /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
 
 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
-static cputime_t vtime_delta(struct task_struct *tsk)
+static u64 vtime_delta(struct task_struct *tsk)
 {
        unsigned long now = READ_ONCE(jiffies);
 
        if (time_before(now, (unsigned long)tsk->vtime_snap))
                return 0;
 
-       return jiffies_to_cputime(now - tsk->vtime_snap);
+       return jiffies_to_nsecs(now - tsk->vtime_snap);
 }
 
-static cputime_t get_vtime_delta(struct task_struct *tsk)
+static u64 get_vtime_delta(struct task_struct *tsk)
 {
        unsigned long now = READ_ONCE(jiffies);
-       cputime_t delta, other;
+       u64 delta, other;
 
        /*
         * Unlike tick based timing, vtime based timing never has lost
@@ -700,7 +700,7 @@ static cputime_t get_vtime_delta(struct task_struct *tsk)
         * elapsed time. Limit account_other_time to prevent rounding
         * errors from causing elapsed vtime to go negative.
         */
-       delta = jiffies_to_cputime(now - tsk->vtime_snap);
+       delta = jiffies_to_nsecs(now - tsk->vtime_snap);
        other = account_other_time(delta);
        WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
        tsk->vtime_snap = now;
@@ -710,9 +710,7 @@ static cputime_t get_vtime_delta(struct task_struct *tsk)
 
 static void __vtime_account_system(struct task_struct *tsk)
 {
-       cputime_t delta_cpu = get_vtime_delta(tsk);
-
-       account_system_time(tsk, irq_count(), cputime_to_nsecs(delta_cpu));
+       account_system_time(tsk, irq_count(), get_vtime_delta(tsk));
 }
 
 void vtime_account_system(struct task_struct *tsk)
@@ -727,15 +725,10 @@ void vtime_account_system(struct task_struct *tsk)
 
 void vtime_account_user(struct task_struct *tsk)
 {
-       cputime_t delta_cpu;
-
        write_seqcount_begin(&tsk->vtime_seqcount);
        tsk->vtime_snap_whence = VTIME_SYS;
-       if (vtime_delta(tsk)) {
-               u64 nsecs;
-               delta_cpu = get_vtime_delta(tsk);
-               account_user_time(tsk, cputime_to_nsecs(delta_cpu));
-       }
+       if (vtime_delta(tsk))
+               account_user_time(tsk, get_vtime_delta(tsk));
        write_seqcount_end(&tsk->vtime_seqcount);
 }
 
@@ -776,9 +769,7 @@ EXPORT_SYMBOL_GPL(vtime_guest_exit);
 
 void vtime_account_idle(struct task_struct *tsk)
 {
-       cputime_t delta_cpu = get_vtime_delta(tsk);
-
-       account_idle_time(cputime_to_nsecs(delta_cpu));
+       account_idle_time(get_vtime_delta(tsk));
 }
 
 void arch_vtime_task_switch(struct task_struct *prev)
@@ -818,7 +809,7 @@ u64 task_gtime(struct task_struct *t)
 
                gtime = t->gtime;
                if (t->vtime_snap_whence == VTIME_SYS && t->flags & PF_VCPU)
-                       gtime += cputime_to_nsecs(vtime_delta(t));
+                       gtime += vtime_delta(t);
 
        } while (read_seqcount_retry(&t->vtime_seqcount, seq));
 
@@ -851,7 +842,7 @@ void task_cputime(struct task_struct *t, u64 *utime, u64 
*stime)
                if (t->vtime_snap_whence == VTIME_INACTIVE || is_idle_task(t))
                        continue;
 
-               delta = cputime_to_nsecs(vtime_delta(t));
+               delta = vtime_delta(t);
 
                /*
                 * Task runs either in user or kernel space, add pending nohz 
time to

Reply via email to