Commit fb8b049c authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar

sched/cputime: Push time to account_system_time() in nsecs

This is one more step toward converting cputime accounting to pure nsecs.
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Link: http://lkml.kernel.org/r/1485832191-26889-25-git-send-email-fweisbec@gmail.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 18b43a9b
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/timex.h> #include <linux/timex.h>
#include <linux/timekeeper_internal.h> #include <linux/timekeeper_internal.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/cputime.h>
#include <asm/machvec.h> #include <asm/machvec.h>
#include <asm/delay.h> #include <asm/delay.h>
...@@ -64,29 +65,29 @@ extern cputime_t cycle_to_cputime(u64 cyc); ...@@ -64,29 +65,29 @@ extern cputime_t cycle_to_cputime(u64 cyc);
void vtime_flush(struct task_struct *tsk) void vtime_flush(struct task_struct *tsk)
{ {
struct thread_info *ti = task_thread_info(tsk); struct thread_info *ti = task_thread_info(tsk);
cputime_t delta; u64 delta;
if (ti->utime) if (ti->utime)
account_user_time(tsk, cputime_to_nsecs(cycle_to_cputime(ti->utime))); account_user_time(tsk, cputime_to_nsecs(cycle_to_cputime(ti->utime)));
if (ti->gtime) if (ti->gtime)
account_guest_time(tsk, cycle_to_cputime(ti->gtime)); account_guest_time(tsk, cputime_to_nsecs(cycle_to_cputime(ti->gtime)));
if (ti->idle_time) if (ti->idle_time)
account_idle_time(cputime_to_nsecs(cycle_to_cputime(ti->idle_time))); account_idle_time(cputime_to_nsecs(cycle_to_cputime(ti->idle_time)));
if (ti->stime) { if (ti->stime) {
delta = cycle_to_cputime(ti->stime); delta = cputime_to_nsecs(cycle_to_cputime(ti->stime));
account_system_index_time(tsk, delta, CPUTIME_SYSTEM); account_system_index_time(tsk, delta, CPUTIME_SYSTEM);
} }
if (ti->hardirq_time) { if (ti->hardirq_time) {
delta = cycle_to_cputime(ti->hardirq_time); delta = cputime_to_nsecs(cycle_to_cputime(ti->hardirq_time));
account_system_index_time(tsk, delta, CPUTIME_IRQ); account_system_index_time(tsk, delta, CPUTIME_IRQ);
} }
if (ti->softirq_time) { if (ti->softirq_time) {
delta = cycle_to_cputime(ti->softirq_time); delta = cputime_to_nsecs(cycle_to_cputime(ti->softirq_time));
account_system_index_time(tsk, delta, CPUTIME_SOFTIRQ); account_system_index_time(tsk, delta, CPUTIME_SOFTIRQ);
} }
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <linux/clk-provider.h> #include <linux/clk-provider.h>
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/cputime.h>
#include <asm/trace.h> #include <asm/trace.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -72,7 +73,6 @@ ...@@ -72,7 +73,6 @@
#include <asm/smp.h> #include <asm/smp.h>
#include <asm/vdso_datapage.h> #include <asm/vdso_datapage.h>
#include <asm/firmware.h> #include <asm/firmware.h>
#include <asm/cputime.h>
#include <asm/asm-prototypes.h> #include <asm/asm-prototypes.h>
/* powerpc clocksource/clockevent code */ /* powerpc clocksource/clockevent code */
...@@ -399,7 +399,7 @@ void vtime_flush(struct task_struct *tsk) ...@@ -399,7 +399,7 @@ void vtime_flush(struct task_struct *tsk)
tsk->utimescaled += cputime_to_nsecs(acct->utime_scaled); tsk->utimescaled += cputime_to_nsecs(acct->utime_scaled);
if (acct->gtime) if (acct->gtime)
account_guest_time(tsk, acct->gtime); account_guest_time(tsk, cputime_to_nsecs(acct->gtime));
if (acct->steal_time) if (acct->steal_time)
account_steal_time(cputime_to_nsecs(acct->steal_time)); account_steal_time(cputime_to_nsecs(acct->steal_time));
...@@ -408,16 +408,17 @@ void vtime_flush(struct task_struct *tsk) ...@@ -408,16 +408,17 @@ void vtime_flush(struct task_struct *tsk)
account_idle_time(cputime_to_nsecs(acct->idle_time)); account_idle_time(cputime_to_nsecs(acct->idle_time));
if (acct->stime) if (acct->stime)
account_system_index_time(tsk, acct->stime, CPUTIME_SYSTEM); account_system_index_time(tsk, cputime_to_nsecs(acct->stime),
CPUTIME_SYSTEM);
if (acct->stime_scaled) if (acct->stime_scaled)
tsk->stimescaled += cputime_to_nsecs(acct->stime_scaled); tsk->stimescaled += cputime_to_nsecs(acct->stime_scaled);
if (acct->hardirq_time) if (acct->hardirq_time)
account_system_index_time(tsk, acct->hardirq_time, CPUTIME_IRQ); account_system_index_time(tsk, cputime_to_nsecs(acct->hardirq_time),
CPUTIME_IRQ);
if (acct->softirq_time) if (acct->softirq_time)
account_system_index_time(tsk, acct->softirq_time, CPUTIME_SOFTIRQ); account_system_index_time(tsk, cputime_to_nsecs(acct->softirq_time),
CPUTIME_SOFTIRQ);
acct->utime = 0; acct->utime = 0;
acct->utime_scaled = 0; acct->utime_scaled = 0;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <asm/cputime.h> #include <linux/cputime.h>
#include <asm/nmi.h> #include <asm/nmi.h>
#include <asm/smp.h> #include <asm/smp.h>
#include "entry.h" #include "entry.h"
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
*/ */
#include <linux/kernel_stat.h> #include <linux/kernel_stat.h>
#include <linux/cputime.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/timex.h> #include <linux/timex.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/time.h> #include <linux/time.h>
#include <asm/cputime.h>
#include <asm/vtimer.h> #include <asm/vtimer.h>
#include <asm/vtime.h> #include <asm/vtime.h>
#include <asm/cpu_mf.h> #include <asm/cpu_mf.h>
...@@ -115,7 +115,7 @@ static void account_system_index_scaled(struct task_struct *p, ...@@ -115,7 +115,7 @@ static void account_system_index_scaled(struct task_struct *p,
enum cpu_usage_stat index) enum cpu_usage_stat index)
{ {
p->stimescaled += cputime_to_nsecs(scaled); p->stimescaled += cputime_to_nsecs(scaled);
account_system_index_time(p, cputime, index); account_system_index_time(p, cputime_to_nsecs(cputime), index);
} }
/* /*
...@@ -171,7 +171,7 @@ static int do_account_vtime(struct task_struct *tsk) ...@@ -171,7 +171,7 @@ static int do_account_vtime(struct task_struct *tsk)
} }
if (guest) { if (guest) {
account_guest_time(tsk, guest); account_guest_time(tsk, cputime_to_nsecs(guest));
tsk->utimescaled += cputime_to_nsecs(scale_vtime(guest)); tsk->utimescaled += cputime_to_nsecs(scale_vtime(guest));
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/vtime.h> #include <linux/vtime.h>
#include <asm/irq.h> #include <asm/irq.h>
#include <linux/cputime.h>
/* /*
* 'kernel_stat.h' contains the definitions needed for doing * 'kernel_stat.h' contains the definitions needed for doing
...@@ -79,9 +78,9 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu) ...@@ -79,9 +78,9 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
} }
extern void account_user_time(struct task_struct *, u64); extern void account_user_time(struct task_struct *, u64);
extern void account_guest_time(struct task_struct *, cputime_t); extern void account_guest_time(struct task_struct *, u64);
extern void account_system_time(struct task_struct *, int, cputime_t); extern void account_system_time(struct task_struct *, int, u64);
extern void account_system_index_time(struct task_struct *, cputime_t, extern void account_system_index_time(struct task_struct *, u64,
enum cpu_usage_stat); enum cpu_usage_stat);
extern void account_steal_time(u64); extern void account_steal_time(u64);
extern void account_idle_time(u64); extern void account_idle_time(u64);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/kernel_stat.h> #include <linux/kernel_stat.h>
#include <linux/static_key.h> #include <linux/static_key.h>
#include <linux/context_tracking.h> #include <linux/context_tracking.h>
#include <linux/cputime.h>
#include "sched.h" #include "sched.h"
#ifdef CONFIG_PARAVIRT #ifdef CONFIG_PARAVIRT
#include <asm/paravirt.h> #include <asm/paravirt.h>
...@@ -138,22 +139,22 @@ void account_user_time(struct task_struct *p, u64 cputime) ...@@ -138,22 +139,22 @@ void account_user_time(struct task_struct *p, u64 cputime)
* @p: the process that the cpu time gets accounted to * @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in virtual machine since the last update * @cputime: the cpu time spent in virtual machine since the last update
*/ */
void account_guest_time(struct task_struct *p, cputime_t cputime) void account_guest_time(struct task_struct *p, u64 cputime)
{ {
u64 *cpustat = kcpustat_this_cpu->cpustat; u64 *cpustat = kcpustat_this_cpu->cpustat;
/* Add guest time to process. */ /* Add guest time to process. */
p->utime += cputime_to_nsecs(cputime); p->utime += cputime;
account_group_user_time(p, cputime_to_nsecs(cputime)); account_group_user_time(p, cputime);
p->gtime += cputime_to_nsecs(cputime); p->gtime += cputime;
/* Add guest time to cpustat. */ /* Add guest time to cpustat. */
if (task_nice(p) > 0) { if (task_nice(p) > 0) {
cpustat[CPUTIME_NICE] += cputime_to_nsecs(cputime); cpustat[CPUTIME_NICE] += cputime;
cpustat[CPUTIME_GUEST_NICE] += cputime_to_nsecs(cputime); cpustat[CPUTIME_GUEST_NICE] += cputime;
} else { } else {
cpustat[CPUTIME_USER] += cputime_to_nsecs(cputime); cpustat[CPUTIME_USER] += cputime;
cpustat[CPUTIME_GUEST] += cputime_to_nsecs(cputime); cpustat[CPUTIME_GUEST] += cputime;
} }
} }
...@@ -164,14 +165,14 @@ void account_guest_time(struct task_struct *p, cputime_t cputime) ...@@ -164,14 +165,14 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)
* @index: pointer to cpustat field that has to be updated * @index: pointer to cpustat field that has to be updated
*/ */
void account_system_index_time(struct task_struct *p, void account_system_index_time(struct task_struct *p,
cputime_t cputime, enum cpu_usage_stat index) u64 cputime, enum cpu_usage_stat index)
{ {
/* Add system time to process. */ /* Add system time to process. */
p->stime += cputime_to_nsecs(cputime); p->stime += cputime;
account_group_system_time(p, cputime_to_nsecs(cputime)); account_group_system_time(p, cputime);
/* Add system time to cpustat. */ /* Add system time to cpustat. */
task_group_account_field(p, index, cputime_to_nsecs(cputime)); task_group_account_field(p, index, cputime);
/* Account for system time used */ /* Account for system time used */
acct_account_cputime(p); acct_account_cputime(p);
...@@ -183,8 +184,7 @@ void account_system_index_time(struct task_struct *p, ...@@ -183,8 +184,7 @@ void account_system_index_time(struct task_struct *p,
* @hardirq_offset: the offset to subtract from hardirq_count() * @hardirq_offset: the offset to subtract from hardirq_count()
* @cputime: the cpu time spent in kernel space since the last update * @cputime: the cpu time spent in kernel space since the last update
*/ */
void account_system_time(struct task_struct *p, int hardirq_offset, void account_system_time(struct task_struct *p, int hardirq_offset, u64 cputime)
cputime_t cputime)
{ {
int index; int index;
...@@ -388,16 +388,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, ...@@ -388,16 +388,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
* So, we have to handle it separately here. * So, we have to handle it separately here.
* Also, p->stime needs to be updated for ksoftirqd. * Also, p->stime needs to be updated for ksoftirqd.
*/ */
account_system_index_time(p, old_cputime, CPUTIME_SOFTIRQ); account_system_index_time(p, cputime, CPUTIME_SOFTIRQ);
} else if (user_tick) { } else if (user_tick) {
account_user_time(p, cputime); account_user_time(p, cputime);
} else if (p == rq->idle) { } else if (p == rq->idle) {
account_idle_time(cputime); account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */ } else if (p->flags & PF_VCPU) { /* System time or guest time */
account_guest_time(p, cputime);
account_guest_time(p, old_cputime);
} else { } else {
account_system_index_time(p, old_cputime, CPUTIME_SYSTEM); account_system_index_time(p, cputime, CPUTIME_SYSTEM);
} }
} }
...@@ -502,7 +501,7 @@ void account_process_tick(struct task_struct *p, int user_tick) ...@@ -502,7 +501,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
if (user_tick) if (user_tick)
account_user_time(p, cputime); account_user_time(p, cputime);
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET)) else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
account_system_time(p, HARDIRQ_OFFSET, old_cputime); account_system_time(p, HARDIRQ_OFFSET, cputime);
else else
account_idle_time(cputime); account_idle_time(cputime);
} }
...@@ -722,7 +721,7 @@ static void __vtime_account_system(struct task_struct *tsk) ...@@ -722,7 +721,7 @@ static void __vtime_account_system(struct task_struct *tsk)
{ {
cputime_t delta_cpu = get_vtime_delta(tsk); cputime_t delta_cpu = get_vtime_delta(tsk);
account_system_time(tsk, irq_count(), delta_cpu); account_system_time(tsk, irq_count(), cputime_to_nsecs(delta_cpu));
} }
void vtime_account_system(struct task_struct *tsk) void vtime_account_system(struct task_struct *tsk)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment