[RFC PATCH 26/30] cputime: Push time to account_user_time() in nanosecs

From: Frederic Weisbecker
Date: Fri Nov 28 2014 - 13:25:09 EST


Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
Cc: Heiko Carstens <heiko.carstens@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Martin Schwidefsky <schwidefsky@xxxxxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Rik van Riel <riel@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Tony Luck <tony.luck@xxxxxxxxx>
Cc: Wu Fengguang <fengguang.wu@xxxxxxxxx>
Signed-off-by: Frederic Weisbecker <fweisbec@xxxxxxxxx>
---
arch/ia64/kernel/time.c | 5 ++++-
arch/powerpc/kernel/time.c | 3 ++-
arch/s390/kernel/vtime.c | 6 ++++--
include/linux/kernel_stat.h | 2 +-
kernel/sched/cputime.c | 24 +++++++++++++++---------
kernel/sched/stats.h | 4 ++--
6 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 9a0104a..0518131 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -89,8 +89,11 @@ void vtime_account_user(struct task_struct *tsk)
struct thread_info *ti = task_thread_info(tsk);

if (ti->ac_utime) {
+ u64 utime;
+ //TODO: cycle_to_nsec()
delta_utime = cycle_to_cputime(ti->ac_utime);
- account_user_time(tsk, delta_utime, delta_utime);
+ utime = cputime_to_nsecs(delta_utime);
+ account_user_time(tsk, utime, utime);
ti->ac_utime = 0;
}
}
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 7505599..c69c8cc 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -376,7 +376,8 @@ void vtime_account_user(struct task_struct *tsk)
get_paca()->user_time = 0;
get_paca()->user_time_scaled = 0;
get_paca()->utime_sspurr = 0;
- account_user_time(tsk, utime, utimescaled);
+ account_user_time(tsk, cputime_to_nsecs(utime),
+ cputime_to_nsecs(utimescaled));
}

#else /* ! CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 7f0089d..0ec68b8 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -60,7 +60,7 @@ static inline int virt_timer_forward(u64 elapsed)
static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
{
struct thread_info *ti = task_thread_info(tsk);
- u64 timer, clock, user, system, steal;
+ u64 timer, clock, user, system, steal, nsecs;

timer = S390_lowcore.last_update_timer;
clock = S390_lowcore.last_update_clock;
@@ -79,11 +79,13 @@ static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
user = S390_lowcore.user_timer - ti->user_timer;
S390_lowcore.steal_timer -= user;
ti->user_timer = S390_lowcore.user_timer;
- account_user_time(tsk, user, user);
+ nsecs = cputime_to_nsecs(user);
+ account_user_time(tsk, nsecs, nsecs);

system = S390_lowcore.system_timer - ti->system_timer;
S390_lowcore.steal_timer -= system;
ti->system_timer = S390_lowcore.system_timer;
+ nsecs = cputime_to_nsecs(system);
account_system_time(tsk, hardirq_offset, system, system);

steal = S390_lowcore.steal_timer;
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 585ced4..9ec9881 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -84,7 +84,7 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
*/
extern unsigned long long task_delta_exec(struct task_struct *);

-extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
+extern void account_user_time(struct task_struct *, u64, u64);
extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
extern void account_steal_time(cputime_t);
extern void account_idle_time(cputime_t);
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index f675008..02fd2e7 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -124,20 +124,19 @@ static inline void task_group_account_field(struct task_struct *p, int index,
* @cputime: the cpu time spent in user space since the last update
* @cputime_scaled: cputime scaled by cpu frequency
*/
-void account_user_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled)
+void account_user_time(struct task_struct *p, u64 cputime, u64 cputime_scaled)
{
int index;

/* Add user time to process. */
- p->utime += cputime_to_nsecs(cputime);
- p->utimescaled += cputime_to_nsecs(cputime_scaled);
+ p->utime += cputime;
+ p->utimescaled += cputime_scaled;
account_group_user_time(p, cputime);

index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;

/* Add user time to cpustat. */
- task_group_account_field(p, index, cputime_to_nsecs(cputime));
+ task_group_account_field(p, index, cputime);

/* Account for user time used */
acct_account_cputime(p);
@@ -157,7 +156,7 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
/* Add guest time to process. */
p->utime += cputime_to_nsecs(cputime);
p->utimescaled += cputime_to_nsecs(cputime_scaled);
- account_group_user_time(p, cputime);
+ account_group_user_time(p, cputime_to_nsecs(cputime));
p->gtime += cputime_to_nsecs(cputime);

/* Add guest time to cpustat. */
@@ -333,7 +332,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
{
cputime_t scaled = cputime_to_scaled(cputime_one_jiffy);
u64 cputime = (__force u64) cputime_one_jiffy;
- u64 nsec = cputime_to_nsecs(cputime); //TODO: make that build time
+ u64 nsec, nsec_scaled;

if (steal_account_process_tick())
return;
@@ -341,6 +340,9 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
cputime *= ticks;
scaled *= ticks;

+ nsec = cputime_to_nsecs(cputime);
+ nsec_scaled = cputime_to_nsecs(scaled);
+
if (irqtime_skip_tick(nsec))
return;

@@ -352,7 +354,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
*/
__account_system_time(p, cputime, scaled, CPUTIME_SOFTIRQ);
} else if (user_tick) {
- account_user_time(p, cputime, scaled);
+ account_user_time(p, nsec, nsec_scaled);
} else if (p == rq->idle) {
account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */
@@ -454,11 +456,15 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
void account_process_tick(struct task_struct *p, int user_tick)
{
cputime_t one_jiffy_scaled = cputime_to_scaled(cputime_one_jiffy);
+ u64 nsec, nsec_scaled;
struct rq *rq = this_rq();

if (vtime_accounting_enabled())
return;

+ nsec = cputime_to_nsecs(cputime_one_jiffy); //TODO: Make that build time
+ nsec_scaled = cputime_to_nsecs(one_jiffy_scaled); //Ditto
+
if (sched_clock_irqtime) {
irqtime_account_process_tick(p, user_tick, rq, 1);
return;
@@ -468,7 +474,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
return;

if (user_tick)
- account_user_time(p, cputime_one_jiffy, one_jiffy_scaled);
+ account_user_time(p, nsec, nsec_scaled);
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
account_system_time(p, HARDIRQ_OFFSET, cputime_one_jiffy,
one_jiffy_scaled);
diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
index 4ab7043..649b38c 100644
--- a/kernel/sched/stats.h
+++ b/kernel/sched/stats.h
@@ -208,7 +208,7 @@ static inline bool cputimer_running(struct task_struct *tsk)
* running CPU and update the utime field there.
*/
static inline void account_group_user_time(struct task_struct *tsk,
- cputime_t cputime)
+ u64 cputime)
{
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;

@@ -216,7 +216,7 @@ static inline void account_group_user_time(struct task_struct *tsk,
return;

raw_spin_lock(&cputimer->lock);
- cputimer->cputime.utime += cputime;
+ cputimer->cputime.utime += nsecs_to_cputime(cputime);
raw_spin_unlock(&cputimer->lock);
}

--
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/