2016-10-31 12:37:55

by Stanislaw Gruszka

[permalink] [raw]
Subject: [PATCH 0/4] cputime: some optimizations and cleanups

Patches remove accounting of utimescaled/stimescaled on architectures
that do not provide those values (scaled cputimes are equal to normal
cputimes) what is every architecture except powerpc and s390.

Patches do not change user visible behaviour.

There is very little documentation how scaled cputimes should be
interpreted and what useful information they provide (at least
I could not find that). Moreover they are exported to user-space
only via not commonly used taskstats and delayacct interfaces (i.e.
interfaces that are not used by standard linux tools AFICT). However
I assume they can not be removed by whole (i.e. replaced by normal
utimes/stimes on powerpc and s390).

Stanislaw Gruszka (4):
cputime/powerpc: remove cputime_last_delta global variable
cputime/powerpc: remove cputime_to_scaled()
cputime/powerpc/s390: make scaled cputime arch specific
cputime: simplify task_cputime()

arch/ia64/kernel/time.c | 4 +-
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/cputime.h | 14 ----
arch/powerpc/kernel/time.c | 8 +-
arch/s390/Kconfig | 1 +
arch/s390/kernel/vtime.c | 9 ++-
arch/x86/kernel/apm_32.c | 4 +-
include/asm-generic/cputime_jiffies.h | 1 -
include/asm-generic/cputime_nsecs.h | 1 -
include/linux/kernel_stat.h | 4 +-
include/linux/sched.h | 29 +++++---
kernel/fork.c | 2 +
kernel/sched/cputime.c | 124 +++++++++------------------------
kernel/time/posix-cpu-timers.c | 4 +-
14 files changed, 73 insertions(+), 133 deletions(-)


2016-10-31 12:38:01

by Stanislaw Gruszka

[permalink] [raw]
Subject: [PATCH 2/4] cputime/powerpc: remove cputime_to_scaled()

Currently cputime_to_scaled() just return it's argument on
all implementations, we don't need to call this function.

Signed-off-by: Stanislaw Gruszka <[email protected]>
---
arch/powerpc/include/asm/cputime.h | 7 -------
include/asm-generic/cputime_jiffies.h | 1 -
include/asm-generic/cputime_nsecs.h | 1 -
kernel/sched/cputime.c | 26 ++++++++++++--------------
4 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index 9f5dcf7..aa2e6a3 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -52,13 +52,6 @@ static inline unsigned long cputime_to_jiffies(const cputime_t ct)
return mulhdu((__force u64) ct, __cputime_jiffies_factor);
}

-/* Estimate the scaled cputime by scaling the real cputime based on
- * the last scaled to real ratio */
-static inline cputime_t cputime_to_scaled(const cputime_t ct)
-{
- return ct;
-}
-
static inline cputime_t jiffies_to_cputime(const unsigned long jif)
{
u64 ct;
diff --git a/include/asm-generic/cputime_jiffies.h b/include/asm-generic/cputime_jiffies.h
index fe386fc..6bb8cd4 100644
--- a/include/asm-generic/cputime_jiffies.h
+++ b/include/asm-generic/cputime_jiffies.h
@@ -7,7 +7,6 @@

#define cputime_one_jiffy jiffies_to_cputime(1)
#define cputime_to_jiffies(__ct) (__force unsigned long)(__ct)
-#define cputime_to_scaled(__ct) (__ct)
#define jiffies_to_cputime(__hz) (__force cputime_t)(__hz)

typedef u64 __nocast cputime64_t;
diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
index a84e28e..4e3b18e 100644
--- a/include/asm-generic/cputime_nsecs.h
+++ b/include/asm-generic/cputime_nsecs.h
@@ -34,7 +34,6 @@
*/
#define cputime_to_jiffies(__ct) \
cputime_div(__ct, NSEC_PER_SEC / HZ)
-#define cputime_to_scaled(__ct) (__ct)
#define jiffies_to_cputime(__jif) \
(__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ))
#define cputime64_to_jiffies64(__ct) \
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 5ebee31..3229c72 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -390,7 +390,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
struct rq *rq, int ticks)
{
u64 cputime = (__force u64) cputime_one_jiffy * ticks;
- cputime_t scaled, other;
+ cputime_t other;

/*
* When returning from idle, many ticks can get accounted at
@@ -403,7 +403,6 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
if (other >= cputime)
return;
cputime -= other;
- scaled = cputime_to_scaled(cputime);

if (this_cpu_ksoftirqd() == p) {
/*
@@ -411,15 +410,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
* So, we have to handle it separately here.
* Also, p->stime needs to be updated for ksoftirqd.
*/
- __account_system_time(p, cputime, scaled, CPUTIME_SOFTIRQ);
+ __account_system_time(p, cputime, cputime, CPUTIME_SOFTIRQ);
} else if (user_tick) {
- account_user_time(p, cputime, scaled);
+ account_user_time(p, cputime, cputime);
} else if (p == rq->idle) {
account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */
- account_guest_time(p, cputime, scaled);
+ account_guest_time(p, cputime, cputime);
} else {
- __account_system_time(p, cputime, scaled, CPUTIME_SYSTEM);
+ __account_system_time(p, cputime, cputime, CPUTIME_SYSTEM);
}
}

@@ -502,7 +501,7 @@ void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime
*/
void account_process_tick(struct task_struct *p, int user_tick)
{
- cputime_t cputime, scaled, steal;
+ cputime_t cputime, steal;
struct rq *rq = this_rq();

if (vtime_accounting_cpu_enabled())
@@ -520,12 +519,11 @@ void account_process_tick(struct task_struct *p, int user_tick)
return;

cputime -= steal;
- scaled = cputime_to_scaled(cputime);

if (user_tick)
- account_user_time(p, cputime, scaled);
+ account_user_time(p, cputime, cputime);
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
- account_system_time(p, HARDIRQ_OFFSET, cputime, scaled);
+ account_system_time(p, HARDIRQ_OFFSET, cputime, cputime);
else
account_idle_time(cputime);
}
@@ -746,7 +744,7 @@ static void __vtime_account_system(struct task_struct *tsk)
{
cputime_t delta_cpu = get_vtime_delta(tsk);

- account_system_time(tsk, irq_count(), delta_cpu, cputime_to_scaled(delta_cpu));
+ account_system_time(tsk, irq_count(), delta_cpu, delta_cpu);
}

void vtime_account_system(struct task_struct *tsk)
@@ -767,7 +765,7 @@ void vtime_account_user(struct task_struct *tsk)
tsk->vtime_snap_whence = VTIME_SYS;
if (vtime_delta(tsk)) {
delta_cpu = get_vtime_delta(tsk);
- account_user_time(tsk, delta_cpu, cputime_to_scaled(delta_cpu));
+ account_user_time(tsk, delta_cpu, delta_cpu);
}
write_seqcount_end(&tsk->vtime_seqcount);
}
@@ -940,8 +938,8 @@ void task_cputime_scaled(struct task_struct *t,
fetch_task_cputime(t, utimescaled, stimescaled,
&t->utimescaled, &t->stimescaled, &udelta, &sdelta);
if (utimescaled)
- *utimescaled += cputime_to_scaled(udelta);
+ *utimescaled += udelta;
if (stimescaled)
- *stimescaled += cputime_to_scaled(sdelta);
+ *stimescaled += sdelta;
}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
--
1.7.1

2016-10-31 12:37:59

by Stanislaw Gruszka

[permalink] [raw]
Subject: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

Only s390 and powerpc have hardware facilities allowing to measure
cputimes scaled by frequency. On all other architectures
utimescaled/stimescaled are equal to utime/stime (however they are
accounted separately).

Patch remove {u,s}timescaled accounting on all architectures except
powerpc and s390, where those values are explicitly accounted on proper
places.

Signed-off-by: Stanislaw Gruszka <[email protected]>
---
arch/ia64/kernel/time.c | 4 +-
arch/powerpc/Kconfig | 1 +
arch/powerpc/kernel/time.c | 6 +++-
arch/s390/Kconfig | 1 +
arch/s390/kernel/vtime.c | 9 ++++--
include/linux/kernel_stat.h | 4 +-
include/linux/sched.h | 23 ++++++++++++----
kernel/fork.c | 2 +
kernel/sched/cputime.c | 61 ++++++++++--------------------------------
9 files changed, 50 insertions(+), 61 deletions(-)

diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 6f892b9..021f44a 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -68,7 +68,7 @@ void vtime_account_user(struct task_struct *tsk)

if (ti->ac_utime) {
delta_utime = cycle_to_cputime(ti->ac_utime);
- account_user_time(tsk, delta_utime, delta_utime);
+ account_user_time(tsk, delta_utime);
ti->ac_utime = 0;
}
}
@@ -112,7 +112,7 @@ void vtime_account_system(struct task_struct *tsk)
{
cputime_t delta = vtime_delta(tsk);

- account_system_time(tsk, 0, delta, delta);
+ account_system_time(tsk, 0, delta);
}
EXPORT_SYMBOL_GPL(vtime_account_system);

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 65fba4c..c7f120a 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -160,6 +160,7 @@ config PPC
select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
select GENERIC_CPU_AUTOPROBE
select HAVE_VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE
select HAVE_ARCH_HARDENED_USERCOPY
select HAVE_KERNEL_GZIP

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 8105198..be9751f 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -358,7 +358,8 @@ void vtime_account_system(struct task_struct *tsk)
unsigned long delta, sys_scaled, stolen;

delta = vtime_delta(tsk, &sys_scaled, &stolen);
- account_system_time(tsk, 0, delta, sys_scaled);
+ account_system_time(tsk, 0, delta);
+ tsk->stimescaled += sys_scaled;
if (stolen)
account_steal_time(stolen);
}
@@ -391,7 +392,8 @@ void vtime_account_user(struct task_struct *tsk)
acct->user_time = 0;
acct->user_time_scaled = 0;
acct->utime_sspurr = 0;
- account_user_time(tsk, utime, utimescaled);
+ account_user_time(tsk, utime);
+ tsk->utimescaled += utimescaled;
}

#ifdef CONFIG_PPC32
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 426481d..028f97b 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -171,6 +171,7 @@ config S390
select SYSCTL_EXCEPTION_TRACE
select TTY
select VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME
select VIRT_TO_BUS
select HAVE_NMI

diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 856e30d..90eeb7c 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -137,8 +137,10 @@ static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
user_scaled = (user_scaled * mult) / div;
system_scaled = (system_scaled * mult) / div;
}
- account_user_time(tsk, user, user_scaled);
- account_system_time(tsk, hardirq_offset, system, system_scaled);
+ account_user_time(tsk, user);
+ tsk->utimescaled += user_scaled;
+ account_system_time(tsk, hardirq_offset, system)
+ tsk->stimescaled += system_scaled;

steal = S390_lowcore.steal_timer;
if ((s64) steal > 0) {
@@ -202,7 +204,8 @@ void vtime_account_irq_enter(struct task_struct *tsk)

system_scaled = (system_scaled * mult) / div;
}
- account_system_time(tsk, 0, system, system_scaled);
+ account_system_time(tsk, 0, system);
+ tsk->stimescaled += system_scaled;

virt_timer_forward(system);
}
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 44fda64..00f7768 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -78,8 +78,8 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
return kstat_cpu(cpu).irqs_sum;
}

-extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
-extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
+extern void account_user_time(struct task_struct *, cputime_t);
+extern void account_system_time(struct task_struct *, int, cputime_t);
extern void account_steal_time(cputime_t);
extern void account_idle_time(cputime_t);

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 348f51b..36a2c2e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1627,7 +1627,10 @@ struct task_struct {
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */

- cputime_t utime, stime, utimescaled, stimescaled;
+ cputime_t utime, stime;
+#ifdef ARCH_HAS_SCALED_CPUTIME
+ cputime_t utimescaled, stimescaled;
+#endif
cputime_t gtime;
struct prev_cputime prev_cputime;
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
@@ -2220,8 +2223,6 @@ static inline void put_task_struct(struct task_struct *t)
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
extern void task_cputime(struct task_struct *t,
cputime_t *utime, cputime_t *stime);
-extern void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled);
extern cputime_t task_gtime(struct task_struct *t);
#else
static inline void task_cputime(struct task_struct *t,
@@ -2233,6 +2234,13 @@ static inline void task_cputime(struct task_struct *t,
*stime = t->stime;
}

+static inline cputime_t task_gtime(struct task_struct *t)
+{
+ return t->gtime;
+}
+#endif
+
+#ifdef ARCH_HAS_SCALED_CPUTIME
static inline void task_cputime_scaled(struct task_struct *t,
cputime_t *utimescaled,
cputime_t *stimescaled)
@@ -2242,12 +2250,15 @@ static inline void task_cputime_scaled(struct task_struct *t,
if (stimescaled)
*stimescaled = t->stimescaled;
}
-
-static inline cputime_t task_gtime(struct task_struct *t)
+#else
+static inline void task_cputime_scaled(struct task_struct *t,
+ cputime_t *utimescaled,
+ cputime_t *stimescaled)
{
- return t->gtime;
+ task_cputime(t, utimescaled, stimescaled);
}
#endif
+
extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);

diff --git a/kernel/fork.c b/kernel/fork.c
index 623259f..dbc9f60 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1548,7 +1548,9 @@ static void posix_cpu_timers_init(struct task_struct *tsk)
init_sigpending(&p->pending);

p->utime = p->stime = p->gtime = 0;
+#ifdef ARCH_HAS_SCALED_CPUTIME
p->utimescaled = p->stimescaled = 0;
+#endif
prev_cputime_init(&p->prev_cputime);

#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 3229c72..d427def 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -128,16 +128,13 @@ static inline void task_group_account_field(struct task_struct *p, int index,
* Account user cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @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, cputime_t cputime)
{
int index;

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

index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
@@ -153,16 +150,13 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
* Account guest cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in virtual machine since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
-static void account_guest_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled)
+static void account_guest_time(struct task_struct *p, cputime_t cputime)
{
u64 *cpustat = kcpustat_this_cpu->cpustat;

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

@@ -180,16 +174,13 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
* Account system cpu time to a process and desired cpustat field
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
- * @target_cputime64: pointer to cpustat field that has to be updated
+ * @index: pointer to cpustat field that has to be updated
*/
static inline
-void __account_system_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled, int index)
+void __account_system_time(struct task_struct *p, cputime_t cputime, int index)
{
/* Add system time to process. */
p->stime += cputime;
- p->stimescaled += cputime_scaled;
account_group_system_time(p, cputime);

/* Add system time to cpustat. */
@@ -204,15 +195,14 @@ void __account_system_time(struct task_struct *p, cputime_t cputime,
* @p: the process that the cpu time gets accounted to
* @hardirq_offset: the offset to subtract from hardirq_count()
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
void account_system_time(struct task_struct *p, int hardirq_offset,
- cputime_t cputime, cputime_t cputime_scaled)
+ cputime_t cputime)
{
int index;

if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
- account_guest_time(p, cputime, cputime_scaled);
+ account_guest_time(p, cputime);
return;
}

@@ -223,7 +213,7 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
else
index = CPUTIME_SYSTEM;

- __account_system_time(p, cputime, cputime_scaled, index);
+ __account_system_time(p, cputime, index);
}

/*
@@ -410,15 +400,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
* So, we have to handle it separately here.
* Also, p->stime needs to be updated for ksoftirqd.
*/
- __account_system_time(p, cputime, cputime, CPUTIME_SOFTIRQ);
+ __account_system_time(p, cputime, CPUTIME_SOFTIRQ);
} else if (user_tick) {
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
} else if (p == rq->idle) {
account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */
- account_guest_time(p, cputime, cputime);
+ account_guest_time(p, cputime);
} else {
- __account_system_time(p, cputime, cputime, CPUTIME_SYSTEM);
+ __account_system_time(p, cputime CPUTIME_SYSTEM);
}
}

@@ -521,9 +511,9 @@ void account_process_tick(struct task_struct *p, int user_tick)
cputime -= steal;

if (user_tick)
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
- account_system_time(p, HARDIRQ_OFFSET, cputime, cputime);
+ account_system_time(p, HARDIRQ_OFFSET, cputime);
else
account_idle_time(cputime);
}
@@ -744,7 +734,7 @@ static void __vtime_account_system(struct task_struct *tsk)
{
cputime_t delta_cpu = get_vtime_delta(tsk);

- account_system_time(tsk, irq_count(), delta_cpu, delta_cpu);
+ account_system_time(tsk, irq_count(), delta_cpu);
}

void vtime_account_system(struct task_struct *tsk)
@@ -765,7 +755,7 @@ void vtime_account_user(struct task_struct *tsk)
tsk->vtime_snap_whence = VTIME_SYS;
if (vtime_delta(tsk)) {
delta_cpu = get_vtime_delta(tsk);
- account_user_time(tsk, delta_cpu, delta_cpu);
+ account_user_time(tsk, delta_cpu);
}
write_seqcount_end(&tsk->vtime_seqcount);
}
@@ -921,25 +911,4 @@ void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
if (stime)
*stime += sdelta;
}
-
-void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled)
-{
- cputime_t udelta, sdelta;
-
- if (!vtime_accounting_enabled()) {
- if (utimescaled)
- *utimescaled = t->utimescaled;
- if (stimescaled)
- *stimescaled = t->stimescaled;
- return;
- }
-
- fetch_task_cputime(t, utimescaled, stimescaled,
- &t->utimescaled, &t->stimescaled, &udelta, &sdelta);
- if (utimescaled)
- *utimescaled += udelta;
- if (stimescaled)
- *stimescaled += sdelta;
-}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
--
1.7.1

2016-10-31 12:38:26

by Stanislaw Gruszka

[permalink] [raw]
Subject: [PATCH 4/4] cputime: simplify task_cputime()

Now since fetch_task_cputime() has no other users than task_cputime(),
it's code could be used directly in task_cputime(). Moreover since
only 2 task_cputime() calls of 17 use NULL argument, we can
add dummy variables to those calls and remove NULL checks from
task_cputimes().

Do also remove NULL checks on task_cputimes_scaled().

Signed-off-by: Stanislaw Gruszka <[email protected]>
---
arch/x86/kernel/apm_32.c | 4 +-
include/linux/sched.h | 12 +++-----
kernel/sched/cputime.c | 57 ++++++++++-----------------------------
kernel/time/posix-cpu-timers.c | 4 +-
4 files changed, 23 insertions(+), 54 deletions(-)

diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
index c7364bd..d90749b 100644
--- a/arch/x86/kernel/apm_32.c
+++ b/arch/x86/kernel/apm_32.c
@@ -906,14 +906,14 @@ static int apm_cpu_idle(struct cpuidle_device *dev,
static int use_apm_idle; /* = 0 */
static unsigned int last_jiffies; /* = 0 */
static unsigned int last_stime; /* = 0 */
- cputime_t stime;
+ cputime_t stime, utime;

int apm_idle_done = 0;
unsigned int jiffies_since_last_check = jiffies - last_jiffies;
unsigned int bucket;

recalc:
- task_cputime(current, NULL, &stime);
+ task_cputime(current, &utime, &stime);
if (jiffies_since_last_check > IDLE_CALC_LIMIT) {
use_apm_idle = 0;
} else if (jiffies_since_last_check > idle_period) {
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 36a2c2e..93fbae0 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2228,10 +2228,8 @@ extern void task_cputime(struct task_struct *t,
static inline void task_cputime(struct task_struct *t,
cputime_t *utime, cputime_t *stime)
{
- if (utime)
- *utime = t->utime;
- if (stime)
- *stime = t->stime;
+ *utime = t->utime;
+ *stime = t->stime;
}

static inline cputime_t task_gtime(struct task_struct *t)
@@ -2245,10 +2243,8 @@ static inline void task_cputime_scaled(struct task_struct *t,
cputime_t *utimescaled,
cputime_t *stimescaled)
{
- if (utimescaled)
- *utimescaled = t->utimescaled;
- if (stimescaled)
- *stimescaled = t->stimescaled;
+ *utimescaled = t->utimescaled;
+ *stimescaled = t->stimescaled;
}
#else
static inline void task_cputime_scaled(struct task_struct *t,
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index d427def..46a984e 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -851,29 +851,25 @@ cputime_t task_gtime(struct task_struct *t)
* add up the pending nohz execution time since the last
* cputime snapshot.
*/
-static void
-fetch_task_cputime(struct task_struct *t,
- cputime_t *u_dst, cputime_t *s_dst,
- cputime_t *u_src, cputime_t *s_src,
- cputime_t *udelta, cputime_t *sdelta)
+void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
{
+ cputime_t delta;
unsigned int seq;
- unsigned long long delta;

- do {
- *udelta = 0;
- *sdelta = 0;
+ if (!vtime_accounting_enabled()) {
+ *utime = t->utime;
+ *stime = t->stime;
+ return;
+ }

+ do {
seq = read_seqcount_begin(&t->vtime_seqcount);

- if (u_dst)
- *u_dst = *u_src;
- if (s_dst)
- *s_dst = *s_src;
+ *utime = t->utime;
+ *stime = t->stime;

/* Task is sleeping, nothing to add */
- if (t->vtime_snap_whence == VTIME_INACTIVE ||
- is_idle_task(t))
+ if (t->vtime_snap_whence == VTIME_INACTIVE || is_idle_task(t))
continue;

delta = vtime_delta(t);
@@ -882,33 +878,10 @@ cputime_t task_gtime(struct task_struct *t)
* Task runs either in user or kernel space, add pending nohz time to
* the right place.
*/
- if (t->vtime_snap_whence == VTIME_USER || t->flags & PF_VCPU) {
- *udelta = delta;
- } else {
- if (t->vtime_snap_whence == VTIME_SYS)
- *sdelta = delta;
- }
+ if (t->vtime_snap_whence == VTIME_USER || t->flags & PF_VCPU)
+ *utime += delta;
+ else if (t->vtime_snap_whence == VTIME_SYS)
+ *stime += delta;
} while (read_seqcount_retry(&t->vtime_seqcount, seq));
}
-
-
-void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
-{
- cputime_t udelta, sdelta;
-
- if (!vtime_accounting_enabled()) {
- if (utime)
- *utime = t->utime;
- if (stime)
- *stime = t->stime;
- return;
- }
-
- fetch_task_cputime(t, utime, stime, &t->utime,
- &t->stime, &udelta, &sdelta);
- if (utime)
- *utime += udelta;
- if (stime)
- *stime += sdelta;
-}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 39008d7..e887ffc 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -133,9 +133,9 @@ static inline unsigned long long prof_ticks(struct task_struct *p)
}
static inline unsigned long long virt_ticks(struct task_struct *p)
{
- cputime_t utime;
+ cputime_t utime, stime;

- task_cputime(p, &utime, NULL);
+ task_cputime(p, &utime, &stime);

return cputime_to_expires(utime);
}
--
1.7.1

2016-10-31 12:38:44

by Stanislaw Gruszka

[permalink] [raw]
Subject: [PATCH 1/4] cputime/powerpc: remove cputime_last_delta global variable

Since commit:

cf9efce0ce313 ("powerpc: Account time using timebase rather than PURR")

cputime_last_delta is not initialized to other value than 0, hence it's
not used except zero check and cputime_to_scaled() just returns
the argument.

Signed-off-by: Stanislaw Gruszka <[email protected]>
---
arch/powerpc/include/asm/cputime.h | 7 -------
arch/powerpc/kernel/time.c | 2 --
2 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index 4f60db0..9f5dcf7 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -46,8 +46,6 @@ static inline void setup_cputime_one_jiffy(void) { }
* Convert cputime <-> jiffies
*/
extern u64 __cputime_jiffies_factor;
-DECLARE_PER_CPU(unsigned long, cputime_last_delta);
-DECLARE_PER_CPU(unsigned long, cputime_scaled_last_delta);

static inline unsigned long cputime_to_jiffies(const cputime_t ct)
{
@@ -58,11 +56,6 @@ static inline unsigned long cputime_to_jiffies(const cputime_t ct)
* the last scaled to real ratio */
static inline cputime_t cputime_to_scaled(const cputime_t ct)
{
- if (cpu_has_feature(CPU_FTR_SPURR) &&
- __this_cpu_read(cputime_last_delta))
- return (__force u64) ct *
- __this_cpu_read(cputime_scaled_last_delta) /
- __this_cpu_read(cputime_last_delta);
return ct;
}

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index bc3f7d0..8105198 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -164,8 +164,6 @@ struct clock_event_device decrementer_clockevent = {
EXPORT_SYMBOL(__cputime_sec_factor);
u64 __cputime_clockt_factor;
EXPORT_SYMBOL(__cputime_clockt_factor);
-DEFINE_PER_CPU(unsigned long, cputime_last_delta);
-DEFINE_PER_CPU(unsigned long, cputime_scaled_last_delta);

cputime_t cputime_one_jiffy;

--
1.7.1

2016-10-31 13:03:17

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

Hi Stanislaw,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.9-rc3 next-20161028]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url: https://github.com/0day-ci/linux/commits/Stanislaw-Gruszka/cputime-powerpc-remove-cputime_last_delta-global-variable/20161031-204221
base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: x86_64-randconfig-x011-201644 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64

All errors (new ones prefixed by >>):

kernel/sched/cputime.c: In function 'irqtime_account_process_tick':
>> kernel/sched/cputime.c:388:36: error: expected ')' before 'CPUTIME_SYSTEM'
__account_system_time(p, cputime CPUTIME_SYSTEM);
^~~~~~~~~~~~~~
>> kernel/sched/cputime.c:388:3: error: too few arguments to function '__account_system_time'
__account_system_time(p, cputime CPUTIME_SYSTEM);
^~~~~~~~~~~~~~~~~~~~~
kernel/sched/cputime.c:191:6: note: declared here
void __account_system_time(struct task_struct *p, cputime_t cputime, int index)
^~~~~~~~~~~~~~~~~~~~~

vim +388 kernel/sched/cputime.c

382 account_user_time(p, cputime);
383 } else if (p == rq->idle) {
384 account_idle_time(cputime);
385 } else if (p->flags & PF_VCPU) { /* System time or guest time */
386 account_guest_time(p, cputime);
387 } else {
> 388 __account_system_time(p, cputime CPUTIME_SYSTEM);
389 }
390 }
391

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (1.99 kB)
.config.gz (23.93 kB)
Download all attachments

2016-10-31 13:14:35

by Stanislaw Gruszka

[permalink] [raw]
Subject: [PATCH v2 3/4] cputime/powerpc/s390: make scaled cputime arch specific

Only s390 and powerpc have hardware facilities allowing to measure
cputimes scaled by frequency. On all other architectures
utimescaled/stimescaled are equal to utime/stime (however they are
accounted separately).

Patch remove {u,s}timescaled accounting on all architectures except
powerpc and s390, where those values are explicitly accounted on proper
places.

Signed-off-by: Stanislaw Gruszka <[email protected]>
---
v1 -> v2 : fix compilation (missed comma)

arch/ia64/kernel/time.c | 4 +-
arch/powerpc/Kconfig | 1 +
arch/powerpc/kernel/time.c | 6 +++-
arch/s390/Kconfig | 1 +
arch/s390/kernel/vtime.c | 9 ++++--
include/linux/kernel_stat.h | 4 +-
include/linux/sched.h | 23 ++++++++++++----
kernel/fork.c | 2 +
kernel/sched/cputime.c | 61 ++++++++++--------------------------------
9 files changed, 50 insertions(+), 61 deletions(-)

diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 6f892b9..021f44a 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -68,7 +68,7 @@ void vtime_account_user(struct task_struct *tsk)

if (ti->ac_utime) {
delta_utime = cycle_to_cputime(ti->ac_utime);
- account_user_time(tsk, delta_utime, delta_utime);
+ account_user_time(tsk, delta_utime);
ti->ac_utime = 0;
}
}
@@ -112,7 +112,7 @@ void vtime_account_system(struct task_struct *tsk)
{
cputime_t delta = vtime_delta(tsk);

- account_system_time(tsk, 0, delta, delta);
+ account_system_time(tsk, 0, delta);
}
EXPORT_SYMBOL_GPL(vtime_account_system);

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 65fba4c..c7f120a 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -160,6 +160,7 @@ config PPC
select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
select GENERIC_CPU_AUTOPROBE
select HAVE_VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE
select HAVE_ARCH_HARDENED_USERCOPY
select HAVE_KERNEL_GZIP

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 8105198..be9751f 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -358,7 +358,8 @@ void vtime_account_system(struct task_struct *tsk)
unsigned long delta, sys_scaled, stolen;

delta = vtime_delta(tsk, &sys_scaled, &stolen);
- account_system_time(tsk, 0, delta, sys_scaled);
+ account_system_time(tsk, 0, delta);
+ tsk->stimescaled += sys_scaled;
if (stolen)
account_steal_time(stolen);
}
@@ -391,7 +392,8 @@ void vtime_account_user(struct task_struct *tsk)
acct->user_time = 0;
acct->user_time_scaled = 0;
acct->utime_sspurr = 0;
- account_user_time(tsk, utime, utimescaled);
+ account_user_time(tsk, utime);
+ tsk->utimescaled += utimescaled;
}

#ifdef CONFIG_PPC32
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 426481d..028f97b 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -171,6 +171,7 @@ config S390
select SYSCTL_EXCEPTION_TRACE
select TTY
select VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME
select VIRT_TO_BUS
select HAVE_NMI

diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 856e30d..90eeb7c 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -137,8 +137,10 @@ static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
user_scaled = (user_scaled * mult) / div;
system_scaled = (system_scaled * mult) / div;
}
- account_user_time(tsk, user, user_scaled);
- account_system_time(tsk, hardirq_offset, system, system_scaled);
+ account_user_time(tsk, user);
+ tsk->utimescaled += user_scaled;
+ account_system_time(tsk, hardirq_offset, system)
+ tsk->stimescaled += system_scaled;

steal = S390_lowcore.steal_timer;
if ((s64) steal > 0) {
@@ -202,7 +204,8 @@ void vtime_account_irq_enter(struct task_struct *tsk)

system_scaled = (system_scaled * mult) / div;
}
- account_system_time(tsk, 0, system, system_scaled);
+ account_system_time(tsk, 0, system);
+ tsk->stimescaled += system_scaled;

virt_timer_forward(system);
}
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 44fda64..00f7768 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -78,8 +78,8 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
return kstat_cpu(cpu).irqs_sum;
}

-extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
-extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
+extern void account_user_time(struct task_struct *, cputime_t);
+extern void account_system_time(struct task_struct *, int, cputime_t);
extern void account_steal_time(cputime_t);
extern void account_idle_time(cputime_t);

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 348f51b..36a2c2e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1627,7 +1627,10 @@ struct task_struct {
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */

- cputime_t utime, stime, utimescaled, stimescaled;
+ cputime_t utime, stime;
+#ifdef ARCH_HAS_SCALED_CPUTIME
+ cputime_t utimescaled, stimescaled;
+#endif
cputime_t gtime;
struct prev_cputime prev_cputime;
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
@@ -2220,8 +2223,6 @@ static inline void put_task_struct(struct task_struct *t)
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
extern void task_cputime(struct task_struct *t,
cputime_t *utime, cputime_t *stime);
-extern void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled);
extern cputime_t task_gtime(struct task_struct *t);
#else
static inline void task_cputime(struct task_struct *t,
@@ -2233,6 +2234,13 @@ static inline void task_cputime(struct task_struct *t,
*stime = t->stime;
}

+static inline cputime_t task_gtime(struct task_struct *t)
+{
+ return t->gtime;
+}
+#endif
+
+#ifdef ARCH_HAS_SCALED_CPUTIME
static inline void task_cputime_scaled(struct task_struct *t,
cputime_t *utimescaled,
cputime_t *stimescaled)
@@ -2242,12 +2250,15 @@ static inline void task_cputime_scaled(struct task_struct *t,
if (stimescaled)
*stimescaled = t->stimescaled;
}
-
-static inline cputime_t task_gtime(struct task_struct *t)
+#else
+static inline void task_cputime_scaled(struct task_struct *t,
+ cputime_t *utimescaled,
+ cputime_t *stimescaled)
{
- return t->gtime;
+ task_cputime(t, utimescaled, stimescaled);
}
#endif
+
extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);

diff --git a/kernel/fork.c b/kernel/fork.c
index 623259f..dbc9f60 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1548,7 +1548,9 @@ static void posix_cpu_timers_init(struct task_struct *tsk)
init_sigpending(&p->pending);

p->utime = p->stime = p->gtime = 0;
+#ifdef ARCH_HAS_SCALED_CPUTIME
p->utimescaled = p->stimescaled = 0;
+#endif
prev_cputime_init(&p->prev_cputime);

#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 3229c72..d427def 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -128,16 +128,13 @@ static inline void task_group_account_field(struct task_struct *p, int index,
* Account user cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @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, cputime_t cputime)
{
int index;

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

index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
@@ -153,16 +150,13 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
* Account guest cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in virtual machine since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
-static void account_guest_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled)
+static void account_guest_time(struct task_struct *p, cputime_t cputime)
{
u64 *cpustat = kcpustat_this_cpu->cpustat;

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

@@ -180,16 +174,13 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
* Account system cpu time to a process and desired cpustat field
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
- * @target_cputime64: pointer to cpustat field that has to be updated
+ * @index: pointer to cpustat field that has to be updated
*/
static inline
-void __account_system_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled, int index)
+void __account_system_time(struct task_struct *p, cputime_t cputime, int index)
{
/* Add system time to process. */
p->stime += cputime;
- p->stimescaled += cputime_scaled;
account_group_system_time(p, cputime);

/* Add system time to cpustat. */
@@ -204,15 +195,14 @@ void __account_system_time(struct task_struct *p, cputime_t cputime,
* @p: the process that the cpu time gets accounted to
* @hardirq_offset: the offset to subtract from hardirq_count()
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
void account_system_time(struct task_struct *p, int hardirq_offset,
- cputime_t cputime, cputime_t cputime_scaled)
+ cputime_t cputime)
{
int index;

if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
- account_guest_time(p, cputime, cputime_scaled);
+ account_guest_time(p, cputime);
return;
}

@@ -223,7 +213,7 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
else
index = CPUTIME_SYSTEM;

- __account_system_time(p, cputime, cputime_scaled, index);
+ __account_system_time(p, cputime, index);
}

/*
@@ -410,15 +400,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
* So, we have to handle it separately here.
* Also, p->stime needs to be updated for ksoftirqd.
*/
- __account_system_time(p, cputime, cputime, CPUTIME_SOFTIRQ);
+ __account_system_time(p, cputime, CPUTIME_SOFTIRQ);
} else if (user_tick) {
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
} else if (p == rq->idle) {
account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */
- account_guest_time(p, cputime, cputime);
+ account_guest_time(p, cputime);
} else {
- __account_system_time(p, cputime, cputime, CPUTIME_SYSTEM);
+ __account_system_time(p, cputime, CPUTIME_SYSTEM);
}
}

@@ -521,9 +511,9 @@ void account_process_tick(struct task_struct *p, int user_tick)
cputime -= steal;

if (user_tick)
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
- account_system_time(p, HARDIRQ_OFFSET, cputime, cputime);
+ account_system_time(p, HARDIRQ_OFFSET, cputime);
else
account_idle_time(cputime);
}
@@ -744,7 +734,7 @@ static void __vtime_account_system(struct task_struct *tsk)
{
cputime_t delta_cpu = get_vtime_delta(tsk);

- account_system_time(tsk, irq_count(), delta_cpu, delta_cpu);
+ account_system_time(tsk, irq_count(), delta_cpu);
}

void vtime_account_system(struct task_struct *tsk)
@@ -765,7 +755,7 @@ void vtime_account_user(struct task_struct *tsk)
tsk->vtime_snap_whence = VTIME_SYS;
if (vtime_delta(tsk)) {
delta_cpu = get_vtime_delta(tsk);
- account_user_time(tsk, delta_cpu, delta_cpu);
+ account_user_time(tsk, delta_cpu);
}
write_seqcount_end(&tsk->vtime_seqcount);
}
@@ -921,25 +911,4 @@ void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
if (stime)
*stime += sdelta;
}
-
-void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled)
-{
- cputime_t udelta, sdelta;
-
- if (!vtime_accounting_enabled()) {
- if (utimescaled)
- *utimescaled = t->utimescaled;
- if (stimescaled)
- *stimescaled = t->stimescaled;
- return;
- }
-
- fetch_task_cputime(t, utimescaled, stimescaled,
- &t->utimescaled, &t->stimescaled, &udelta, &sdelta);
- if (utimescaled)
- *utimescaled += udelta;
- if (stimescaled)
- *stimescaled += sdelta;
-}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
--
1.7.1

2016-10-31 14:14:11

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

Hi Stanislaw,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.9-rc3 next-20161028]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url: https://github.com/0day-ci/linux/commits/Stanislaw-Gruszka/cputime-powerpc-remove-cputime_last_delta-global-variable/20161031-204221
base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: s390-default_defconfig (attached as .config)
compiler: s390x-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=s390

All errors (new ones prefixed by >>):

arch/s390/kernel/vtime.c: In function 'do_account_vtime':
>> arch/s390/kernel/vtime.c:141:5: error: 'struct task_struct' has no member named 'utimescaled'
tsk->utimescaled += user_scaled;
^~
>> arch/s390/kernel/vtime.c:143:2: error: expected ';' before 'tsk'
tsk->stimescaled += system_scaled;
^~~
arch/s390/kernel/vtime.c: In function 'vtime_account_irq_enter':
>> arch/s390/kernel/vtime.c:208:5: error: 'struct task_struct' has no member named 'stimescaled'
tsk->stimescaled += system_scaled;
^~

vim +141 arch/s390/kernel/vtime.c

135 u64 div = __this_cpu_read(mt_scaling_div);
136
137 user_scaled = (user_scaled * mult) / div;
138 system_scaled = (system_scaled * mult) / div;
139 }
140 account_user_time(tsk, user);
> 141 tsk->utimescaled += user_scaled;
142 account_system_time(tsk, hardirq_offset, system)
> 143 tsk->stimescaled += system_scaled;
144
145 steal = S390_lowcore.steal_timer;
146 if ((s64) steal > 0) {
147 S390_lowcore.steal_timer = 0;
148 account_steal_time(steal);
149 }
150
151 return virt_timer_forward(user + system);
152 }
153
154 void vtime_task_switch(struct task_struct *prev)
155 {
156 struct thread_info *ti;
157
158 do_account_vtime(prev, 0);
159 ti = task_thread_info(prev);
160 ti->user_timer = S390_lowcore.user_timer;
161 ti->system_timer = S390_lowcore.system_timer;
162 ti = task_thread_info(current);
163 S390_lowcore.user_timer = ti->user_timer;
164 S390_lowcore.system_timer = ti->system_timer;
165 }
166
167 /*
168 * In s390, accounting pending user time also implies
169 * accounting system time in order to correctly compute
170 * the stolen time accounting.
171 */
172 void vtime_account_user(struct task_struct *tsk)
173 {
174 if (do_account_vtime(tsk, HARDIRQ_OFFSET))
175 virt_timer_expire();
176 }
177
178 /*
179 * Update process times based on virtual cpu times stored by entry.S
180 * to the lowcore fields user_timer, system_timer & steal_clock.
181 */
182 void vtime_account_irq_enter(struct task_struct *tsk)
183 {
184 struct thread_info *ti = task_thread_info(tsk);
185 u64 timer, system, system_scaled;
186
187 timer = S390_lowcore.last_update_timer;
188 S390_lowcore.last_update_timer = get_vtimer();
189 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
190
191 /* Update MT utilization calculation */
192 if (smp_cpu_mtid &&
193 time_after64(jiffies_64, this_cpu_read(mt_scaling_jiffies)))
194 update_mt_scaling();
195
196 system = S390_lowcore.system_timer - ti->system_timer;
197 S390_lowcore.steal_timer -= system;
198 ti->system_timer = S390_lowcore.system_timer;
199 system_scaled = system;
200 /* Do MT utilization scaling */
201 if (smp_cpu_mtid) {
202 u64 mult = __this_cpu_read(mt_scaling_mult);
203 u64 div = __this_cpu_read(mt_scaling_div);
204
205 system_scaled = (system_scaled * mult) / div;
206 }
207 account_system_time(tsk, 0, system);
> 208 tsk->stimescaled += system_scaled;
209
210 virt_timer_forward(system);
211 }

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (4.38 kB)
.config.gz (15.89 kB)
Download all attachments

2016-10-31 16:23:04

by Stanislaw Gruszka

[permalink] [raw]
Subject: [PATCH v3 3/4] cputime/powerpc/s390: make scaled cputime arch specific

Only s390 and powerpc have hardware facilities allowing to measure
cputimes scaled by frequency. On all other architectures
utimescaled/stimescaled are equal to utime/stime (however they are
accounted separately).

Patch remove {u,s}timescaled accounting on all architectures except
powerpc and s390, where those values are explicitly accounted on proper
places.

Signed-off-by: Stanislaw Gruszka <[email protected]>
---
v1 -> v2 : fix compilation (missed comma)
v2 -> v3 : fix compilation when ARCH_HAS_SCALED_CPUTIME should be selected

arch/Kconfig | 3 ++
arch/ia64/kernel/time.c | 4 +-
arch/powerpc/Kconfig | 1 +
arch/powerpc/kernel/time.c | 6 +++-
arch/s390/Kconfig | 1 +
arch/s390/kernel/vtime.c | 9 ++++--
include/linux/kernel_stat.h | 4 +-
include/linux/sched.h | 23 ++++++++++++----
kernel/fork.c | 2 +
kernel/sched/cputime.c | 61 ++++++++++--------------------------------
10 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 659bdd0..abab659 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -512,6 +512,9 @@ config HAVE_CONTEXT_TRACKING
config HAVE_VIRT_CPU_ACCOUNTING
bool

+config ARCH_HAS_SCALED_CPUTIME
+ bool
+
config HAVE_VIRT_CPU_ACCOUNTING_GEN
bool
default y if 64BIT
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 6f892b9..021f44a 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -68,7 +68,7 @@ void vtime_account_user(struct task_struct *tsk)

if (ti->ac_utime) {
delta_utime = cycle_to_cputime(ti->ac_utime);
- account_user_time(tsk, delta_utime, delta_utime);
+ account_user_time(tsk, delta_utime);
ti->ac_utime = 0;
}
}
@@ -112,7 +112,7 @@ void vtime_account_system(struct task_struct *tsk)
{
cputime_t delta = vtime_delta(tsk);

- account_system_time(tsk, 0, delta, delta);
+ account_system_time(tsk, 0, delta);
}
EXPORT_SYMBOL_GPL(vtime_account_system);

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 65fba4c..c7f120a 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -160,6 +160,7 @@ config PPC
select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
select GENERIC_CPU_AUTOPROBE
select HAVE_VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE
select HAVE_ARCH_HARDENED_USERCOPY
select HAVE_KERNEL_GZIP

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 8105198..be9751f 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -358,7 +358,8 @@ void vtime_account_system(struct task_struct *tsk)
unsigned long delta, sys_scaled, stolen;

delta = vtime_delta(tsk, &sys_scaled, &stolen);
- account_system_time(tsk, 0, delta, sys_scaled);
+ account_system_time(tsk, 0, delta);
+ tsk->stimescaled += sys_scaled;
if (stolen)
account_steal_time(stolen);
}
@@ -391,7 +392,8 @@ void vtime_account_user(struct task_struct *tsk)
acct->user_time = 0;
acct->user_time_scaled = 0;
acct->utime_sspurr = 0;
- account_user_time(tsk, utime, utimescaled);
+ account_user_time(tsk, utime);
+ tsk->utimescaled += utimescaled;
}

#ifdef CONFIG_PPC32
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 426481d..028f97b 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -171,6 +171,7 @@ config S390
select SYSCTL_EXCEPTION_TRACE
select TTY
select VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME
select VIRT_TO_BUS
select HAVE_NMI

diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 856e30d..90eeb7c 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -137,8 +137,10 @@ static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
user_scaled = (user_scaled * mult) / div;
system_scaled = (system_scaled * mult) / div;
}
- account_user_time(tsk, user, user_scaled);
- account_system_time(tsk, hardirq_offset, system, system_scaled);
+ account_user_time(tsk, user);
+ tsk->utimescaled += user_scaled;
+ account_system_time(tsk, hardirq_offset, system);
+ tsk->stimescaled += system_scaled;

steal = S390_lowcore.steal_timer;
if ((s64) steal > 0) {
@@ -202,7 +204,8 @@ void vtime_account_irq_enter(struct task_struct *tsk)

system_scaled = (system_scaled * mult) / div;
}
- account_system_time(tsk, 0, system, system_scaled);
+ account_system_time(tsk, 0, system);
+ tsk->stimescaled += system_scaled;

virt_timer_forward(system);
}
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 44fda64..00f7768 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -78,8 +78,8 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
return kstat_cpu(cpu).irqs_sum;
}

-extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
-extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
+extern void account_user_time(struct task_struct *, cputime_t);
+extern void account_system_time(struct task_struct *, int, cputime_t);
extern void account_steal_time(cputime_t);
extern void account_idle_time(cputime_t);

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 348f51b..49bbca2 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1627,7 +1627,10 @@ struct task_struct {
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */

- cputime_t utime, stime, utimescaled, stimescaled;
+ cputime_t utime, stime;
+#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
+ cputime_t utimescaled, stimescaled;
+#endif
cputime_t gtime;
struct prev_cputime prev_cputime;
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
@@ -2220,8 +2223,6 @@ static inline void put_task_struct(struct task_struct *t)
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
extern void task_cputime(struct task_struct *t,
cputime_t *utime, cputime_t *stime);
-extern void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled);
extern cputime_t task_gtime(struct task_struct *t);
#else
static inline void task_cputime(struct task_struct *t,
@@ -2233,6 +2234,13 @@ static inline void task_cputime(struct task_struct *t,
*stime = t->stime;
}

+static inline cputime_t task_gtime(struct task_struct *t)
+{
+ return t->gtime;
+}
+#endif
+
+#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
static inline void task_cputime_scaled(struct task_struct *t,
cputime_t *utimescaled,
cputime_t *stimescaled)
@@ -2242,12 +2250,15 @@ static inline void task_cputime_scaled(struct task_struct *t,
if (stimescaled)
*stimescaled = t->stimescaled;
}
-
-static inline cputime_t task_gtime(struct task_struct *t)
+#else
+static inline void task_cputime_scaled(struct task_struct *t,
+ cputime_t *utimescaled,
+ cputime_t *stimescaled)
{
- return t->gtime;
+ task_cputime(t, utimescaled, stimescaled);
}
#endif
+
extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);

diff --git a/kernel/fork.c b/kernel/fork.c
index 623259f..d0e8d4d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1548,7 +1548,9 @@ static void posix_cpu_timers_init(struct task_struct *tsk)
init_sigpending(&p->pending);

p->utime = p->stime = p->gtime = 0;
+#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
p->utimescaled = p->stimescaled = 0;
+#endif
prev_cputime_init(&p->prev_cputime);

#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 3229c72..ba55ebf 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -128,16 +128,13 @@ static inline void task_group_account_field(struct task_struct *p, int index,
* Account user cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @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, cputime_t cputime)
{
int index;

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

index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
@@ -153,16 +150,13 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
* Account guest cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in virtual machine since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
-static void account_guest_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled)
+static void account_guest_time(struct task_struct *p, cputime_t cputime)
{
u64 *cpustat = kcpustat_this_cpu->cpustat;

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

@@ -180,16 +174,13 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
* Account system cpu time to a process and desired cpustat field
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
- * @target_cputime64: pointer to cpustat field that has to be updated
+ * @index: pointer to cpustat field that has to be updated
*/
static inline
-void __account_system_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled, int index)
+void __account_system_time(struct task_struct *p, cputime_t cputime, int index)
{
/* Add system time to process. */
p->stime += cputime;
- p->stimescaled += cputime_scaled;
account_group_system_time(p, cputime);

/* Add system time to cpustat. */
@@ -204,15 +195,14 @@ void __account_system_time(struct task_struct *p, cputime_t cputime,
* @p: the process that the cpu time gets accounted to
* @hardirq_offset: the offset to subtract from hardirq_count()
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
void account_system_time(struct task_struct *p, int hardirq_offset,
- cputime_t cputime, cputime_t cputime_scaled)
+ cputime_t cputime)
{
int index;

if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
- account_guest_time(p, cputime, cputime_scaled);
+ account_guest_time(p, cputime);
return;
}

@@ -223,7 +213,7 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
else
index = CPUTIME_SYSTEM;

- __account_system_time(p, cputime, cputime_scaled, index);
+ __account_system_time(p, cputime, index);
}

/*
@@ -410,15 +400,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
* So, we have to handle it separately here.
* Also, p->stime needs to be updated for ksoftirqd.
*/
- __account_system_time(p, cputime, cputime, CPUTIME_SOFTIRQ);
+ __account_system_time(p, cputime, CPUTIME_SOFTIRQ);
} else if (user_tick) {
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
} else if (p == rq->idle) {
account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */
- account_guest_time(p, cputime, cputime);
+ account_guest_time(p, cputime);
} else {
- __account_system_time(p, cputime, cputime, CPUTIME_SYSTEM);
+ __account_system_time(p, cputime, CPUTIME_SYSTEM);
}
}

@@ -521,9 +511,9 @@ void account_process_tick(struct task_struct *p, int user_tick)
cputime -= steal;

if (user_tick)
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
- account_system_time(p, HARDIRQ_OFFSET, cputime, cputime);
+ account_system_time(p, HARDIRQ_OFFSET, cputime);
else
account_idle_time(cputime);
}
@@ -744,7 +734,7 @@ static void __vtime_account_system(struct task_struct *tsk)
{
cputime_t delta_cpu = get_vtime_delta(tsk);

- account_system_time(tsk, irq_count(), delta_cpu, delta_cpu);
+ account_system_time(tsk, irq_count(), delta_cpu);
}

void vtime_account_system(struct task_struct *tsk)
@@ -765,7 +755,7 @@ void vtime_account_user(struct task_struct *tsk)
tsk->vtime_snap_whence = VTIME_SYS;
if (vtime_delta(tsk)) {
delta_cpu = get_vtime_delta(tsk);
- account_user_time(tsk, delta_cpu, delta_cpu);
+ account_user_time(tsk, delta_cpu);
}
write_seqcount_end(&tsk->vtime_seqcount);
}
@@ -921,25 +911,4 @@ void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
if (stime)
*stime += sdelta;
}
-
-void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled)
-{
- cputime_t udelta, sdelta;
-
- if (!vtime_accounting_enabled()) {
- if (utimescaled)
- *utimescaled = t->utimescaled;
- if (stimescaled)
- *stimescaled = t->stimescaled;
- return;
- }
-
- fetch_task_cputime(t, utimescaled, stimescaled,
- &t->utimescaled, &t->stimescaled, &udelta, &sdelta);
- if (utimescaled)
- *utimescaled += udelta;
- if (stimescaled)
- *stimescaled += sdelta;
-}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
--
1.7.1

2016-11-02 09:11:45

by Christian Borntraeger

[permalink] [raw]
Subject: Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

On 10/31/2016 01:36 PM, Stanislaw Gruszka wrote:
> Only s390 and powerpc have hardware facilities allowing to measure
> cputimes scaled by frequency. On all other architectures
> utimescaled/stimescaled are equal to utime/stime (however they are
> accounted separately).
>
> Patch remove {u,s}timescaled accounting on all architectures except
> powerpc and s390, where those values are explicitly accounted on proper
> places.

If we remove it everywhere else (and assuming that there are no users then)
I aks myself if we should remove this as well from s390.

We already had to optimize this because the initial code caused some
regressions (commit f341b8dff9 s390/vtime: limit MT scaling value updates).
The code still adds a multiply and a divide to do_account_vtime (and 2
multiplies and 2 divides into vtime_account_irq_enter) which is still
noticeable in perf annotate for switch intense workload.

Martin are you aware of any user of that values?

>
> Signed-off-by: Stanislaw Gruszka <[email protected]>
> ---
> arch/ia64/kernel/time.c | 4 +-
> arch/powerpc/Kconfig | 1 +
> arch/powerpc/kernel/time.c | 6 +++-
> arch/s390/Kconfig | 1 +
> arch/s390/kernel/vtime.c | 9 ++++--
> include/linux/kernel_stat.h | 4 +-
> include/linux/sched.h | 23 ++++++++++++----
> kernel/fork.c | 2 +
> kernel/sched/cputime.c | 61 ++++++++++--------------------------------
> 9 files changed, 50 insertions(+), 61 deletions(-)
>
> diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
> index 6f892b9..021f44a 100644
> --- a/arch/ia64/kernel/time.c
> +++ b/arch/ia64/kernel/time.c
> @@ -68,7 +68,7 @@ void vtime_account_user(struct task_struct *tsk)
>
> if (ti->ac_utime) {
> delta_utime = cycle_to_cputime(ti->ac_utime);
> - account_user_time(tsk, delta_utime, delta_utime);
> + account_user_time(tsk, delta_utime);
> ti->ac_utime = 0;
> }
> }
> @@ -112,7 +112,7 @@ void vtime_account_system(struct task_struct *tsk)
> {
> cputime_t delta = vtime_delta(tsk);
>
> - account_system_time(tsk, 0, delta, delta);
> + account_system_time(tsk, 0, delta);
> }
> EXPORT_SYMBOL_GPL(vtime_account_system);
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 65fba4c..c7f120a 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -160,6 +160,7 @@ config PPC
> select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
> select GENERIC_CPU_AUTOPROBE
> select HAVE_VIRT_CPU_ACCOUNTING
> + select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE
> select HAVE_ARCH_HARDENED_USERCOPY
> select HAVE_KERNEL_GZIP
>
> diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
> index 8105198..be9751f 100644
> --- a/arch/powerpc/kernel/time.c
> +++ b/arch/powerpc/kernel/time.c
> @@ -358,7 +358,8 @@ void vtime_account_system(struct task_struct *tsk)
> unsigned long delta, sys_scaled, stolen;
>
> delta = vtime_delta(tsk, &sys_scaled, &stolen);
> - account_system_time(tsk, 0, delta, sys_scaled);
> + account_system_time(tsk, 0, delta);
> + tsk->stimescaled += sys_scaled;
> if (stolen)
> account_steal_time(stolen);
> }
> @@ -391,7 +392,8 @@ void vtime_account_user(struct task_struct *tsk)
> acct->user_time = 0;
> acct->user_time_scaled = 0;
> acct->utime_sspurr = 0;
> - account_user_time(tsk, utime, utimescaled);
> + account_user_time(tsk, utime);
> + tsk->utimescaled += utimescaled;
> }
>
> #ifdef CONFIG_PPC32
> diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
> index 426481d..028f97b 100644
> --- a/arch/s390/Kconfig
> +++ b/arch/s390/Kconfig
> @@ -171,6 +171,7 @@ config S390
> select SYSCTL_EXCEPTION_TRACE
> select TTY
> select VIRT_CPU_ACCOUNTING
> + select ARCH_HAS_SCALED_CPUTIME
> select VIRT_TO_BUS
> select HAVE_NMI
>
> diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
> index 856e30d..90eeb7c 100644
> --- a/arch/s390/kernel/vtime.c
> +++ b/arch/s390/kernel/vtime.c
> @@ -137,8 +137,10 @@ static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
> user_scaled = (user_scaled * mult) / div;
> system_scaled = (system_scaled * mult) / div;
> }
> - account_user_time(tsk, user, user_scaled);
> - account_system_time(tsk, hardirq_offset, system, system_scaled);
> + account_user_time(tsk, user);
> + tsk->utimescaled += user_scaled;
> + account_system_time(tsk, hardirq_offset, system)
> + tsk->stimescaled += system_scaled;
>
> steal = S390_lowcore.steal_timer;
> if ((s64) steal > 0) {
> @@ -202,7 +204,8 @@ void vtime_account_irq_enter(struct task_struct *tsk)
>
> system_scaled = (system_scaled * mult) / div;
> }
> - account_system_time(tsk, 0, system, system_scaled);
> + account_system_time(tsk, 0, system);
> + tsk->stimescaled += system_scaled;
>
> virt_timer_forward(system);
> }
> diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
> index 44fda64..00f7768 100644
> --- a/include/linux/kernel_stat.h
> +++ b/include/linux/kernel_stat.h
> @@ -78,8 +78,8 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
> return kstat_cpu(cpu).irqs_sum;
> }
>
> -extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
> -extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
> +extern void account_user_time(struct task_struct *, cputime_t);
> +extern void account_system_time(struct task_struct *, int, cputime_t);
> extern void account_steal_time(cputime_t);
> extern void account_idle_time(cputime_t);
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 348f51b..36a2c2e 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1627,7 +1627,10 @@ struct task_struct {
> int __user *set_child_tid; /* CLONE_CHILD_SETTID */
> int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
>
> - cputime_t utime, stime, utimescaled, stimescaled;
> + cputime_t utime, stime;
> +#ifdef ARCH_HAS_SCALED_CPUTIME
> + cputime_t utimescaled, stimescaled;
> +#endif
> cputime_t gtime;
> struct prev_cputime prev_cputime;
> #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
> @@ -2220,8 +2223,6 @@ static inline void put_task_struct(struct task_struct *t)
> #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
> extern void task_cputime(struct task_struct *t,
> cputime_t *utime, cputime_t *stime);
> -extern void task_cputime_scaled(struct task_struct *t,
> - cputime_t *utimescaled, cputime_t *stimescaled);
> extern cputime_t task_gtime(struct task_struct *t);
> #else
> static inline void task_cputime(struct task_struct *t,
> @@ -2233,6 +2234,13 @@ static inline void task_cputime(struct task_struct *t,
> *stime = t->stime;
> }
>
> +static inline cputime_t task_gtime(struct task_struct *t)
> +{
> + return t->gtime;
> +}
> +#endif
> +
> +#ifdef ARCH_HAS_SCALED_CPUTIME
> static inline void task_cputime_scaled(struct task_struct *t,
> cputime_t *utimescaled,
> cputime_t *stimescaled)
> @@ -2242,12 +2250,15 @@ static inline void task_cputime_scaled(struct task_struct *t,
> if (stimescaled)
> *stimescaled = t->stimescaled;
> }
> -
> -static inline cputime_t task_gtime(struct task_struct *t)
> +#else
> +static inline void task_cputime_scaled(struct task_struct *t,
> + cputime_t *utimescaled,
> + cputime_t *stimescaled)
> {
> - return t->gtime;
> + task_cputime(t, utimescaled, stimescaled);
> }
> #endif
> +
> extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
> extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 623259f..dbc9f60 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1548,7 +1548,9 @@ static void posix_cpu_timers_init(struct task_struct *tsk)
> init_sigpending(&p->pending);
>
> p->utime = p->stime = p->gtime = 0;
> +#ifdef ARCH_HAS_SCALED_CPUTIME
> p->utimescaled = p->stimescaled = 0;
> +#endif
> prev_cputime_init(&p->prev_cputime);
>
> #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index 3229c72..d427def 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -128,16 +128,13 @@ static inline void task_group_account_field(struct task_struct *p, int index,
> * Account user cpu time to a process.
> * @p: the process that the cpu time gets accounted to
> * @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, cputime_t cputime)
> {
> int index;
>
> /* Add user time to process. */
> p->utime += cputime;
> - p->utimescaled += cputime_scaled;
> account_group_user_time(p, cputime);
>
> index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
> @@ -153,16 +150,13 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
> * Account guest cpu time to a process.
> * @p: the process that the cpu time gets accounted to
> * @cputime: the cpu time spent in virtual machine since the last update
> - * @cputime_scaled: cputime scaled by cpu frequency
> */
> -static void account_guest_time(struct task_struct *p, cputime_t cputime,
> - cputime_t cputime_scaled)
> +static void account_guest_time(struct task_struct *p, cputime_t cputime)
> {
> u64 *cpustat = kcpustat_this_cpu->cpustat;
>
> /* Add guest time to process. */
> p->utime += cputime;
> - p->utimescaled += cputime_scaled;
> account_group_user_time(p, cputime);
> p->gtime += cputime;
>
> @@ -180,16 +174,13 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
> * Account system cpu time to a process and desired cpustat field
> * @p: the process that the cpu time gets accounted to
> * @cputime: the cpu time spent in kernel space since the last update
> - * @cputime_scaled: cputime scaled by cpu frequency
> - * @target_cputime64: pointer to cpustat field that has to be updated
> + * @index: pointer to cpustat field that has to be updated
> */
> static inline
> -void __account_system_time(struct task_struct *p, cputime_t cputime,
> - cputime_t cputime_scaled, int index)
> +void __account_system_time(struct task_struct *p, cputime_t cputime, int index)
> {
> /* Add system time to process. */
> p->stime += cputime;
> - p->stimescaled += cputime_scaled;
> account_group_system_time(p, cputime);
>
> /* Add system time to cpustat. */
> @@ -204,15 +195,14 @@ void __account_system_time(struct task_struct *p, cputime_t cputime,
> * @p: the process that the cpu time gets accounted to
> * @hardirq_offset: the offset to subtract from hardirq_count()
> * @cputime: the cpu time spent in kernel space since the last update
> - * @cputime_scaled: cputime scaled by cpu frequency
> */
> void account_system_time(struct task_struct *p, int hardirq_offset,
> - cputime_t cputime, cputime_t cputime_scaled)
> + cputime_t cputime)
> {
> int index;
>
> if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
> - account_guest_time(p, cputime, cputime_scaled);
> + account_guest_time(p, cputime);
> return;
> }
>
> @@ -223,7 +213,7 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
> else
> index = CPUTIME_SYSTEM;
>
> - __account_system_time(p, cputime, cputime_scaled, index);
> + __account_system_time(p, cputime, index);
> }
>
> /*
> @@ -410,15 +400,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
> * So, we have to handle it separately here.
> * Also, p->stime needs to be updated for ksoftirqd.
> */
> - __account_system_time(p, cputime, cputime, CPUTIME_SOFTIRQ);
> + __account_system_time(p, cputime, CPUTIME_SOFTIRQ);
> } else if (user_tick) {
> - account_user_time(p, cputime, cputime);
> + account_user_time(p, cputime);
> } else if (p == rq->idle) {
> account_idle_time(cputime);
> } else if (p->flags & PF_VCPU) { /* System time or guest time */
> - account_guest_time(p, cputime, cputime);
> + account_guest_time(p, cputime);
> } else {
> - __account_system_time(p, cputime, cputime, CPUTIME_SYSTEM);
> + __account_system_time(p, cputime CPUTIME_SYSTEM);
> }
> }
>
> @@ -521,9 +511,9 @@ void account_process_tick(struct task_struct *p, int user_tick)
> cputime -= steal;
>
> if (user_tick)
> - account_user_time(p, cputime, cputime);
> + account_user_time(p, cputime);
> else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
> - account_system_time(p, HARDIRQ_OFFSET, cputime, cputime);
> + account_system_time(p, HARDIRQ_OFFSET, cputime);
> else
> account_idle_time(cputime);
> }
> @@ -744,7 +734,7 @@ static void __vtime_account_system(struct task_struct *tsk)
> {
> cputime_t delta_cpu = get_vtime_delta(tsk);
>
> - account_system_time(tsk, irq_count(), delta_cpu, delta_cpu);
> + account_system_time(tsk, irq_count(), delta_cpu);
> }
>
> void vtime_account_system(struct task_struct *tsk)
> @@ -765,7 +755,7 @@ void vtime_account_user(struct task_struct *tsk)
> tsk->vtime_snap_whence = VTIME_SYS;
> if (vtime_delta(tsk)) {
> delta_cpu = get_vtime_delta(tsk);
> - account_user_time(tsk, delta_cpu, delta_cpu);
> + account_user_time(tsk, delta_cpu);
> }
> write_seqcount_end(&tsk->vtime_seqcount);
> }
> @@ -921,25 +911,4 @@ void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
> if (stime)
> *stime += sdelta;
> }
> -
> -void task_cputime_scaled(struct task_struct *t,
> - cputime_t *utimescaled, cputime_t *stimescaled)
> -{
> - cputime_t udelta, sdelta;
> -
> - if (!vtime_accounting_enabled()) {
> - if (utimescaled)
> - *utimescaled = t->utimescaled;
> - if (stimescaled)
> - *stimescaled = t->stimescaled;
> - return;
> - }
> -
> - fetch_task_cputime(t, utimescaled, stimescaled,
> - &t->utimescaled, &t->stimescaled, &udelta, &sdelta);
> - if (utimescaled)
> - *utimescaled += udelta;
> - if (stimescaled)
> - *stimescaled += sdelta;
> -}
> #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
>

2016-11-02 09:39:43

by Stanislaw Gruszka

[permalink] [raw]
Subject: Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

On Wed, Nov 02, 2016 at 10:11:22AM +0100, Christian Borntraeger wrote:
> On 10/31/2016 01:36 PM, Stanislaw Gruszka wrote:
> > Only s390 and powerpc have hardware facilities allowing to measure
> > cputimes scaled by frequency. On all other architectures
> > utimescaled/stimescaled are equal to utime/stime (however they are
> > accounted separately).
> >
> > Patch remove {u,s}timescaled accounting on all architectures except
> > powerpc and s390, where those values are explicitly accounted on proper
> > places.
>
> If we remove it everywhere else (and assuming that there are no users then)
> I aks myself if we should remove this as well from s390.

There is one user of scaled cputimes values, it is taskstats (to users
space are exported ac_utimescaled, ac_stimescaled and
cpu_scaled_run_real_total which is calculated based on scaled times).
However on other than powerpc and s390 architectures scaled times are
equal to normal times (this is also true for older powerpc's without
SPURR/PURR registers).

Stanislaw

2016-11-02 21:22:20

by Martin Schwidefsky

[permalink] [raw]
Subject: Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

On Wed, 2 Nov 2016 10:38:20 +0100
Stanislaw Gruszka <[email protected]> wrote:

> On Wed, Nov 02, 2016 at 10:11:22AM +0100, Christian Borntraeger wrote:
> > On 10/31/2016 01:36 PM, Stanislaw Gruszka wrote:
> > > Only s390 and powerpc have hardware facilities allowing to measure
> > > cputimes scaled by frequency. On all other architectures
> > > utimescaled/stimescaled are equal to utime/stime (however they are
> > > accounted separately).
> > >
> > > Patch remove {u,s}timescaled accounting on all architectures except
> > > powerpc and s390, where those values are explicitly accounted on proper
> > > places.
> >
> > If we remove it everywhere else (and assuming that there are no users then)
> > I aks myself if we should remove this as well from s390.
>
> There is one user of scaled cputimes values, it is taskstats (to users
> space are exported ac_utimescaled, ac_stimescaled and
> cpu_scaled_run_real_total which is calculated based on scaled times).
> However on other than powerpc and s390 architectures scaled times are
> equal to normal times (this is also true for older powerpc's without
> SPURR/PURR registers).

The taskstats interface is the only user of the scaled cputime that
I am aware of. It is hard to say how valuable the information is.
Without the scaled number in the taskstats inferface you have no means
to detect if your workload has been affected by a another SMT thread
running on the same core.

--
blue skies,
Martin.

"Reality continues to ruin my life." - Calvin.

2016-11-03 01:02:36

by Paul Mackerras

[permalink] [raw]
Subject: Re: [PATCH 2/4] cputime/powerpc: remove cputime_to_scaled()

On Mon, Oct 31, 2016 at 01:36:27PM +0100, Stanislaw Gruszka wrote:
> Currently cputime_to_scaled() just return it's argument on
> all implementations, we don't need to call this function.
>
> Signed-off-by: Stanislaw Gruszka <[email protected]>

Looks OK to me.

Reviewed-by: Paul Mackerras <[email protected]>

2016-11-03 01:02:36

by Paul Mackerras

[permalink] [raw]
Subject: Re: [PATCH 1/4] cputime/powerpc: remove cputime_last_delta global variable

On Mon, Oct 31, 2016 at 01:36:26PM +0100, Stanislaw Gruszka wrote:
> Since commit:
>
> cf9efce0ce313 ("powerpc: Account time using timebase rather than PURR")
>
> cputime_last_delta is not initialized to other value than 0, hence it's
> not used except zero check and cputime_to_scaled() just returns
> the argument.
>
> Signed-off-by: Stanislaw Gruszka <[email protected]>

Yes, I should have removed them in that commit. We don't want to do
any scaling in the places where cputime_to_scaled() is used.

Acked-by: Paul Mackerras <[email protected]>

2016-11-09 13:01:30

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [PATCH 0/4] cputime: some optimizations and cleanups

2016-10-31 12:36 GMT+00:00 Stanislaw Gruszka <[email protected]>:
> Patches remove accounting of utimescaled/stimescaled on architectures
> that do not provide those values (scaled cputimes are equal to normal
> cputimes) what is every architecture except powerpc and s390.
>
> Patches do not change user visible behaviour.
>
> There is very little documentation how scaled cputimes should be
> interpreted and what useful information they provide (at least
> I could not find that). Moreover they are exported to user-space
> only via not commonly used taskstats and delayacct interfaces (i.e.
> interfaces that are not used by standard linux tools AFICT). However
> I assume they can not be removed by whole (i.e. replaced by normal
> utimes/stimes on powerpc and s390).
>
> Stanislaw Gruszka (4):
> cputime/powerpc: remove cputime_last_delta global variable
> cputime/powerpc: remove cputime_to_scaled()
> cputime/powerpc/s390: make scaled cputime arch specific
> cputime: simplify task_cputime()
>
> arch/ia64/kernel/time.c | 4 +-
> arch/powerpc/Kconfig | 1 +
> arch/powerpc/include/asm/cputime.h | 14 ----
> arch/powerpc/kernel/time.c | 8 +-
> arch/s390/Kconfig | 1 +
> arch/s390/kernel/vtime.c | 9 ++-
> arch/x86/kernel/apm_32.c | 4 +-
> include/asm-generic/cputime_jiffies.h | 1 -
> include/asm-generic/cputime_nsecs.h | 1 -
> include/linux/kernel_stat.h | 4 +-
> include/linux/sched.h | 29 +++++---
> kernel/fork.c | 2 +
> kernel/sched/cputime.c | 124 +++++++++------------------------
> kernel/time/posix-cpu-timers.c | 4 +-
> 14 files changed, 73 insertions(+), 133 deletions(-)
>

Excellent patchset!
Thanks a lot Stanislaw!

Acked-by: Frederic Weisbecker <[email protected]>

Subject: [tip:sched/core] sched/cputime, powerpc, s390: Make scaled cputime arch specific

Commit-ID: 40565b5aedd6d0ca88b7dfd3859d709d2f6f8cf9
Gitweb: http://git.kernel.org/tip/40565b5aedd6d0ca88b7dfd3859d709d2f6f8cf9
Author: Stanislaw Gruszka <[email protected]>
AuthorDate: Tue, 15 Nov 2016 03:06:51 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 15 Nov 2016 09:51:05 +0100

sched/cputime, powerpc, s390: Make scaled cputime arch specific

Only s390 and powerpc have hardware facilities allowing to measure
cputimes scaled by frequency. On all other architectures
utimescaled/stimescaled are equal to utime/stime (however they are
accounted separately).

Remove {u,s}timescaled accounting on all architectures except
powerpc and s390, where those values are explicitly accounted
in the proper places.

Signed-off-by: Stanislaw Gruszka <[email protected]>
Signed-off-by: Frederic Weisbecker <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Michael Neuling <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/Kconfig | 3 +++
arch/ia64/kernel/time.c | 4 +--
arch/powerpc/Kconfig | 1 +
arch/powerpc/kernel/time.c | 6 +++--
arch/s390/Kconfig | 1 +
arch/s390/kernel/vtime.c | 9 ++++---
include/linux/kernel_stat.h | 4 +--
include/linux/sched.h | 23 ++++++++++++-----
kernel/fork.c | 2 ++
kernel/sched/cputime.c | 61 +++++++++++----------------------------------
10 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 659bdd0..abab659 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -512,6 +512,9 @@ config HAVE_CONTEXT_TRACKING
config HAVE_VIRT_CPU_ACCOUNTING
bool

+config ARCH_HAS_SCALED_CPUTIME
+ bool
+
config HAVE_VIRT_CPU_ACCOUNTING_GEN
bool
default y if 64BIT
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 6f892b9..021f44a 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -68,7 +68,7 @@ void vtime_account_user(struct task_struct *tsk)

if (ti->ac_utime) {
delta_utime = cycle_to_cputime(ti->ac_utime);
- account_user_time(tsk, delta_utime, delta_utime);
+ account_user_time(tsk, delta_utime);
ti->ac_utime = 0;
}
}
@@ -112,7 +112,7 @@ void vtime_account_system(struct task_struct *tsk)
{
cputime_t delta = vtime_delta(tsk);

- account_system_time(tsk, 0, delta, delta);
+ account_system_time(tsk, 0, delta);
}
EXPORT_SYMBOL_GPL(vtime_account_system);

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 65fba4c..c7f120a 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -160,6 +160,7 @@ config PPC
select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
select GENERIC_CPU_AUTOPROBE
select HAVE_VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE
select HAVE_ARCH_HARDENED_USERCOPY
select HAVE_KERNEL_GZIP

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 8105198..be9751f 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -358,7 +358,8 @@ void vtime_account_system(struct task_struct *tsk)
unsigned long delta, sys_scaled, stolen;

delta = vtime_delta(tsk, &sys_scaled, &stolen);
- account_system_time(tsk, 0, delta, sys_scaled);
+ account_system_time(tsk, 0, delta);
+ tsk->stimescaled += sys_scaled;
if (stolen)
account_steal_time(stolen);
}
@@ -391,7 +392,8 @@ void vtime_account_user(struct task_struct *tsk)
acct->user_time = 0;
acct->user_time_scaled = 0;
acct->utime_sspurr = 0;
- account_user_time(tsk, utime, utimescaled);
+ account_user_time(tsk, utime);
+ tsk->utimescaled += utimescaled;
}

#ifdef CONFIG_PPC32
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 426481d..028f97b 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -171,6 +171,7 @@ config S390
select SYSCTL_EXCEPTION_TRACE
select TTY
select VIRT_CPU_ACCOUNTING
+ select ARCH_HAS_SCALED_CPUTIME
select VIRT_TO_BUS
select HAVE_NMI

diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 856e30d..1bd5dde 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -137,8 +137,10 @@ static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
user_scaled = (user_scaled * mult) / div;
system_scaled = (system_scaled * mult) / div;
}
- account_user_time(tsk, user, user_scaled);
- account_system_time(tsk, hardirq_offset, system, system_scaled);
+ account_user_time(tsk, user);
+ tsk->utimescaled += user_scaled;
+ account_system_time(tsk, hardirq_offset, system);
+ tsk->stimescaled += system_scaled;

steal = S390_lowcore.steal_timer;
if ((s64) steal > 0) {
@@ -202,7 +204,8 @@ void vtime_account_irq_enter(struct task_struct *tsk)

system_scaled = (system_scaled * mult) / div;
}
- account_system_time(tsk, 0, system, system_scaled);
+ account_system_time(tsk, 0, system);
+ tsk->stimescaled += system_scaled;

virt_timer_forward(system);
}
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 44fda64..00f7768 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -78,8 +78,8 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
return kstat_cpu(cpu).irqs_sum;
}

-extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
-extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
+extern void account_user_time(struct task_struct *, cputime_t);
+extern void account_system_time(struct task_struct *, int, cputime_t);
extern void account_steal_time(cputime_t);
extern void account_idle_time(cputime_t);

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3762fe4..f72e813 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1647,7 +1647,10 @@ struct task_struct {
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */

- cputime_t utime, stime, utimescaled, stimescaled;
+ cputime_t utime, stime;
+#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
+ cputime_t utimescaled, stimescaled;
+#endif
cputime_t gtime;
struct prev_cputime prev_cputime;
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
@@ -2240,8 +2243,6 @@ struct task_struct *try_get_task_struct(struct task_struct **ptask);
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
extern void task_cputime(struct task_struct *t,
cputime_t *utime, cputime_t *stime);
-extern void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled);
extern cputime_t task_gtime(struct task_struct *t);
#else
static inline void task_cputime(struct task_struct *t,
@@ -2253,6 +2254,13 @@ static inline void task_cputime(struct task_struct *t,
*stime = t->stime;
}

+static inline cputime_t task_gtime(struct task_struct *t)
+{
+ return t->gtime;
+}
+#endif
+
+#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
static inline void task_cputime_scaled(struct task_struct *t,
cputime_t *utimescaled,
cputime_t *stimescaled)
@@ -2262,12 +2270,15 @@ static inline void task_cputime_scaled(struct task_struct *t,
if (stimescaled)
*stimescaled = t->stimescaled;
}
-
-static inline cputime_t task_gtime(struct task_struct *t)
+#else
+static inline void task_cputime_scaled(struct task_struct *t,
+ cputime_t *utimescaled,
+ cputime_t *stimescaled)
{
- return t->gtime;
+ task_cputime(t, utimescaled, stimescaled);
}
#endif
+
extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);

diff --git a/kernel/fork.c b/kernel/fork.c
index 997ac1d..600e93b 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1551,7 +1551,9 @@ static __latent_entropy struct task_struct *copy_process(
init_sigpending(&p->pending);

p->utime = p->stime = p->gtime = 0;
+#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
p->utimescaled = p->stimescaled = 0;
+#endif
prev_cputime_init(&p->prev_cputime);

#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 3229c72..ba55ebf 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -128,16 +128,13 @@ static inline void task_group_account_field(struct task_struct *p, int index,
* Account user cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @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, cputime_t cputime)
{
int index;

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

index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
@@ -153,16 +150,13 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
* Account guest cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in virtual machine since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
-static void account_guest_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled)
+static void account_guest_time(struct task_struct *p, cputime_t cputime)
{
u64 *cpustat = kcpustat_this_cpu->cpustat;

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

@@ -180,16 +174,13 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
* Account system cpu time to a process and desired cpustat field
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
- * @target_cputime64: pointer to cpustat field that has to be updated
+ * @index: pointer to cpustat field that has to be updated
*/
static inline
-void __account_system_time(struct task_struct *p, cputime_t cputime,
- cputime_t cputime_scaled, int index)
+void __account_system_time(struct task_struct *p, cputime_t cputime, int index)
{
/* Add system time to process. */
p->stime += cputime;
- p->stimescaled += cputime_scaled;
account_group_system_time(p, cputime);

/* Add system time to cpustat. */
@@ -204,15 +195,14 @@ void __account_system_time(struct task_struct *p, cputime_t cputime,
* @p: the process that the cpu time gets accounted to
* @hardirq_offset: the offset to subtract from hardirq_count()
* @cputime: the cpu time spent in kernel space since the last update
- * @cputime_scaled: cputime scaled by cpu frequency
*/
void account_system_time(struct task_struct *p, int hardirq_offset,
- cputime_t cputime, cputime_t cputime_scaled)
+ cputime_t cputime)
{
int index;

if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
- account_guest_time(p, cputime, cputime_scaled);
+ account_guest_time(p, cputime);
return;
}

@@ -223,7 +213,7 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
else
index = CPUTIME_SYSTEM;

- __account_system_time(p, cputime, cputime_scaled, index);
+ __account_system_time(p, cputime, index);
}

/*
@@ -410,15 +400,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
* So, we have to handle it separately here.
* Also, p->stime needs to be updated for ksoftirqd.
*/
- __account_system_time(p, cputime, cputime, CPUTIME_SOFTIRQ);
+ __account_system_time(p, cputime, CPUTIME_SOFTIRQ);
} else if (user_tick) {
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
} else if (p == rq->idle) {
account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */
- account_guest_time(p, cputime, cputime);
+ account_guest_time(p, cputime);
} else {
- __account_system_time(p, cputime, cputime, CPUTIME_SYSTEM);
+ __account_system_time(p, cputime, CPUTIME_SYSTEM);
}
}

@@ -521,9 +511,9 @@ void account_process_tick(struct task_struct *p, int user_tick)
cputime -= steal;

if (user_tick)
- account_user_time(p, cputime, cputime);
+ account_user_time(p, cputime);
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
- account_system_time(p, HARDIRQ_OFFSET, cputime, cputime);
+ account_system_time(p, HARDIRQ_OFFSET, cputime);
else
account_idle_time(cputime);
}
@@ -744,7 +734,7 @@ static void __vtime_account_system(struct task_struct *tsk)
{
cputime_t delta_cpu = get_vtime_delta(tsk);

- account_system_time(tsk, irq_count(), delta_cpu, delta_cpu);
+ account_system_time(tsk, irq_count(), delta_cpu);
}

void vtime_account_system(struct task_struct *tsk)
@@ -765,7 +755,7 @@ void vtime_account_user(struct task_struct *tsk)
tsk->vtime_snap_whence = VTIME_SYS;
if (vtime_delta(tsk)) {
delta_cpu = get_vtime_delta(tsk);
- account_user_time(tsk, delta_cpu, delta_cpu);
+ account_user_time(tsk, delta_cpu);
}
write_seqcount_end(&tsk->vtime_seqcount);
}
@@ -921,25 +911,4 @@ void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
if (stime)
*stime += sdelta;
}
-
-void task_cputime_scaled(struct task_struct *t,
- cputime_t *utimescaled, cputime_t *stimescaled)
-{
- cputime_t udelta, sdelta;
-
- if (!vtime_accounting_enabled()) {
- if (utimescaled)
- *utimescaled = t->utimescaled;
- if (stimescaled)
- *stimescaled = t->stimescaled;
- return;
- }
-
- fetch_task_cputime(t, utimescaled, stimescaled,
- &t->utimescaled, &t->stimescaled, &udelta, &sdelta);
- if (utimescaled)
- *utimescaled += udelta;
- if (stimescaled)
- *stimescaled += sdelta;
-}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */