public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting
@ 2014-03-06 17:56 Frederic Weisbecker
  2014-03-06 17:56 ` [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast Frederic Weisbecker
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-06 17:56 UTC (permalink / raw)
  To: LKML
  Cc: Frederic Weisbecker, Archs, Ingo Molnar, Marcelo Tosatti,
	Peter Zijlstra, Thomas Gleixner, Huiqingding

Hi,

The main purpose of this set is to fix a bug on full dynticks configs
where steal time accounting appears to be zero in /proc/stat even
after a few seconds of competing guests running busy loops in a same
host CPU. It's not a regression though as it was there since the
beginning with full dynticks.

So patch [4/6] is the most important. The rest is preparatory work
to fix the bug and various cleanups.

Thanks.

---
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
	timers/cputime-fix-steal

Frederic Weisbecker (6):
  cputime: Fix nsecs_to_cputime() return type cast
  cputime: Default implementation of nsecs -> cputime conversion
  cputime: Bring cputime -> nsecs conversion
  cputime: Fix jiffies based cputime assumption on steal accounting
  sched: Remove needless round trip nsecs <-> tick conversion of steal
    time
  arch: Remove stub cputime.h headers

 arch/alpha/include/asm/Kbuild         |  1 +
 arch/alpha/include/asm/cputime.h      |  6 ------
 arch/cris/include/asm/Kbuild          |  1 +
 arch/cris/include/asm/cputime.h       |  6 ------
 arch/frv/include/asm/Kbuild           |  1 +
 arch/frv/include/asm/cputime.h        |  6 ------
 arch/m32r/include/asm/Kbuild          |  1 +
 arch/m32r/include/asm/cputime.h       |  6 ------
 arch/microblaze/include/asm/Kbuild    |  1 +
 arch/microblaze/include/asm/cputime.h |  1 -
 arch/mn10300/include/asm/Kbuild       |  1 +
 arch/mn10300/include/asm/cputime.h    |  1 -
 arch/score/include/asm/Kbuild         |  2 +-
 arch/score/include/asm/cputime.h      |  6 ------
 arch/x86/include/asm/Kbuild           |  1 +
 arch/x86/include/asm/cputime.h        |  1 -
 drivers/cpufreq/cpufreq_stats.c       |  2 +-
 drivers/s390/cio/cio.c                |  2 +-
 fs/proc/stat.c                        |  2 +-
 fs/proc/uptime.c                      |  2 +-
 include/asm-generic/cputime_jiffies.h |  4 +++-
 include/asm-generic/cputime_nsecs.h   |  5 ++++-
 include/linux/cputime.h               | 16 ++++++++++++++++
 include/linux/kernel_stat.h           |  2 +-
 include/linux/sched.h                 |  2 +-
 kernel/sched/core.c                   |  6 ------
 kernel/sched/cputime.c                | 11 ++++++-----
 kernel/sched/sched.h                  | 10 ----------
 28 files changed, 43 insertions(+), 63 deletions(-)
 delete mode 100644 arch/alpha/include/asm/cputime.h
 delete mode 100644 arch/cris/include/asm/cputime.h
 delete mode 100644 arch/frv/include/asm/cputime.h
 delete mode 100644 arch/m32r/include/asm/cputime.h
 delete mode 100644 arch/microblaze/include/asm/cputime.h
 delete mode 100644 arch/mn10300/include/asm/cputime.h
 delete mode 100644 arch/score/include/asm/cputime.h
 delete mode 100644 arch/x86/include/asm/cputime.h
 create mode 100644 include/linux/cputime.h

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast
  2014-03-06 17:56 [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting Frederic Weisbecker
@ 2014-03-06 17:56 ` Frederic Weisbecker
  2014-03-06 18:57   ` Rik van Riel
  2014-03-06 17:56 ` [PATCH 2/6] cputime: Default implementation of nsecs -> cputime conversion Frederic Weisbecker
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-06 17:56 UTC (permalink / raw)
  To: LKML
  Cc: Frederic Weisbecker, Ingo Molnar, Marcelo Tosatti, Peter Zijlstra,
	Thomas Gleixner

Even though nsec based cputime_t maps to u64, nsecs_to_cputime() must
return a cputime_t value. We want to enforce this kind of cast in order
to track down buggy manipulations of cputime_t such as direct access
of its values under wrong assumptions on its backend type (nsecs,
jiffies, etc...) by core code.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 include/asm-generic/cputime_nsecs.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
index 2c9e62c..768294f 100644
--- a/include/asm-generic/cputime_nsecs.h
+++ b/include/asm-generic/cputime_nsecs.h
@@ -44,7 +44,8 @@ typedef u64 __nocast cputime64_t;
 /*
  * Convert cputime <-> nanoseconds
  */
-#define nsecs_to_cputime(__nsecs)	((__force u64)(__nsecs))
+#define nsecs_to_cputime(__nsecs)	\
+	(__force cputime_t)(__nsecs)
 
 
 /*
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 2/6] cputime: Default implementation of nsecs -> cputime conversion
  2014-03-06 17:56 [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting Frederic Weisbecker
  2014-03-06 17:56 ` [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast Frederic Weisbecker
@ 2014-03-06 17:56 ` Frederic Weisbecker
  2014-03-06 19:17   ` Rik van Riel
  2014-03-06 17:56 ` [PATCH 3/6] cputime: Bring cputime -> nsecs conversion Frederic Weisbecker
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-06 17:56 UTC (permalink / raw)
  To: LKML
  Cc: Frederic Weisbecker, Ingo Molnar, Marcelo Tosatti, Peter Zijlstra,
	Thomas Gleixner

The architectures that override cputime_t (s390, ppc) don't provide
any version of nsecs_to_cputime(). Indeed this cputime_t implementation
by backend only happens when CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y under
which the core code doesn't make any use of nsecs_to_cputime().

At least for now.

We are going to make a broader use of it so lets provide a default
version with a per usecs granularity. It should be good enough for most
usecases.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 drivers/cpufreq/cpufreq_stats.c |  2 +-
 drivers/s390/cio/cio.c          |  2 +-
 fs/proc/stat.c                  |  2 +-
 fs/proc/uptime.c                |  2 +-
 include/linux/cputime.h         | 11 +++++++++++
 include/linux/kernel_stat.h     |  2 +-
 include/linux/sched.h           |  2 +-
 7 files changed, 17 insertions(+), 6 deletions(-)
 create mode 100644 include/linux/cputime.h

diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 5793e14..79911a2 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -13,7 +13,7 @@
 #include <linux/cpufreq.h>
 #include <linux/module.h>
 #include <linux/slab.h>
-#include <asm/cputime.h>
+#include <linux/cputime.h>
 
 static spinlock_t cpufreq_stats_lock;
 
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 88e35d8..5154513 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -28,7 +28,7 @@
 #include <asm/chpid.h>
 #include <asm/airq.h>
 #include <asm/isc.h>
-#include <asm/cputime.h>
+#include <linux/cputime.h>
 #include <asm/fcx.h>
 #include <asm/nmi.h>
 #include <asm/crw.h>
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 6f599c6..9d231e9 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -9,7 +9,7 @@
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/irqnr.h>
-#include <asm/cputime.h>
+#include <linux/cputime.h>
 #include <linux/tick.h>
 
 #ifndef arch_irq_stat_cpu
diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c
index 7141b8d..33de567 100644
--- a/fs/proc/uptime.c
+++ b/fs/proc/uptime.c
@@ -5,7 +5,7 @@
 #include <linux/seq_file.h>
 #include <linux/time.h>
 #include <linux/kernel_stat.h>
-#include <asm/cputime.h>
+#include <linux/cputime.h>
 
 static int uptime_proc_show(struct seq_file *m, void *v)
 {
diff --git a/include/linux/cputime.h b/include/linux/cputime.h
new file mode 100644
index 0000000..2842ebe
--- /dev/null
+++ b/include/linux/cputime.h
@@ -0,0 +1,11 @@
+#ifndef __LINUX_CPUTIME_H
+#define __LINUX_CPUTIME_H
+
+#include <asm/cputime.h>
+
+#ifndef nsecs_to_cputime
+# define nsecs_to_cputime(__nsecs)	\
+	usecs_to_cputime((__nsecs) / NSEC_PER_USEC)
+#endif
+
+#endif /* __LINUX_CPUTIME_H */
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 51c72be..d7c6131 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -9,7 +9,7 @@
 #include <linux/sched.h>
 #include <linux/vtime.h>
 #include <asm/irq.h>
-#include <asm/cputime.h>
+#include <linux/cputime.h>
 
 /*
  * 'kernel_stat.h' contains the definitions needed for doing
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 68a0e84..1ac566c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -27,7 +27,7 @@ struct sched_param {
 
 #include <asm/page.h>
 #include <asm/ptrace.h>
-#include <asm/cputime.h>
+#include <linux/cputime.h>
 
 #include <linux/smp.h>
 #include <linux/sem.h>
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 3/6] cputime: Bring cputime -> nsecs conversion
  2014-03-06 17:56 [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting Frederic Weisbecker
  2014-03-06 17:56 ` [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast Frederic Weisbecker
  2014-03-06 17:56 ` [PATCH 2/6] cputime: Default implementation of nsecs -> cputime conversion Frederic Weisbecker
@ 2014-03-06 17:56 ` Frederic Weisbecker
  2014-03-06 19:24   ` Rik van Riel
  2014-03-06 17:56 ` [PATCH 4/6] cputime: Fix jiffies based cputime assumption on steal accounting Frederic Weisbecker
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-06 17:56 UTC (permalink / raw)
  To: LKML
  Cc: Frederic Weisbecker, Ingo Molnar, Marcelo Tosatti, Peter Zijlstra,
	Thomas Gleixner

We already have nsecs_to_cputime(). Now we need to be able to convert
the other way around in order to fix a bug on steal time accounting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 include/asm-generic/cputime_jiffies.h | 4 +++-
 include/asm-generic/cputime_nsecs.h   | 2 ++
 include/linux/cputime.h               | 5 +++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/cputime_jiffies.h b/include/asm-generic/cputime_jiffies.h
index 272ecba..d5cb78f5 100644
--- a/include/asm-generic/cputime_jiffies.h
+++ b/include/asm-generic/cputime_jiffies.h
@@ -15,8 +15,10 @@ typedef u64 __nocast cputime64_t;
 
 
 /*
- * Convert nanoseconds to cputime
+ * Convert nanoseconds <-> cputime
  */
+#define cputime_to_nsecs(__ct)		\
+	jiffies_to_nsecs(cputime_to_jiffies(__ct))
 #define nsecs_to_cputime64(__nsec)	\
 	jiffies64_to_cputime64(nsecs_to_jiffies64(__nsec))
 #define nsecs_to_cputime(__nsec)	\
diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
index 768294f..4e81760 100644
--- a/include/asm-generic/cputime_nsecs.h
+++ b/include/asm-generic/cputime_nsecs.h
@@ -44,6 +44,8 @@ typedef u64 __nocast cputime64_t;
 /*
  * Convert cputime <-> nanoseconds
  */
+#define cputime_to_nsecs(__ct)		\
+	(__force u64)(__ct)
 #define nsecs_to_cputime(__nsecs)	\
 	(__force cputime_t)(__nsecs)
 
diff --git a/include/linux/cputime.h b/include/linux/cputime.h
index 2842ebe..f2eb2ee 100644
--- a/include/linux/cputime.h
+++ b/include/linux/cputime.h
@@ -3,6 +3,11 @@
 
 #include <asm/cputime.h>
 
+#ifndef cputime_to_nsecs
+# define cputime_to_nsecs(__ct)	\
+	(cputime_to_usecs(__ct) * NSEC_PER_USEC)
+#endif
+
 #ifndef nsecs_to_cputime
 # define nsecs_to_cputime(__nsecs)	\
 	usecs_to_cputime((__nsecs) / NSEC_PER_USEC)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 4/6] cputime: Fix jiffies based cputime assumption on steal accounting
  2014-03-06 17:56 [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting Frederic Weisbecker
                   ` (2 preceding siblings ...)
  2014-03-06 17:56 ` [PATCH 3/6] cputime: Bring cputime -> nsecs conversion Frederic Weisbecker
@ 2014-03-06 17:56 ` Frederic Weisbecker
  2014-03-06 19:36   ` Rik van Riel
  2014-03-06 17:56 ` [RFC PATCH 5/6] sched: Remove needless round trip nsecs <-> tick conversion of steal time Frederic Weisbecker
  2014-03-06 17:56 ` [PATCH 6/6] arch: Remove stub cputime.h headers Frederic Weisbecker
  5 siblings, 1 reply; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-06 17:56 UTC (permalink / raw)
  To: LKML
  Cc: Frederic Weisbecker, Ingo Molnar, Marcelo Tosatti, Peter Zijlstra,
	Thomas Gleixner

The steal guest time accounting code assumes that cputime_t is based on
jiffies. So when CONFIG_NO_HZ_FULL=y, which implies that cputime_t
is based on nsecs, steal_account_process_tick() passes the delta in
jiffies to account_steal_time() which then accounts it as if it's a
value in nsecs.

As a result, accounting 1 second of steal time (with HZ=100 that would
be 100 jiffies) is spuriously accounted as 100 nsecs.

As such /proc/stat may report 0 values of steal time even when two
guests have run concurrently for a few seconds on the same host and
same CPU.

In order to fix this, lets convert the nsecs based steal delta to
cputime instead of jiffies by using the right conversion API.

Given that the steal time is stored in cputime_t and this type can have
a smaller granularity than nsecs, we only account the rounded converted
value and leave the remaining nsecs for the next deltas.

Reported-by: Huiqingding <huding@redhat.com>
Reported-by: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/sched/cputime.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 9994791..e3d2612 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -258,16 +258,17 @@ static __always_inline bool steal_account_process_tick(void)
 {
 #ifdef CONFIG_PARAVIRT
 	if (static_key_false(&paravirt_steal_enabled)) {
-		u64 steal, st = 0;
+		u64 steal;
+		cputime_t steal_ct;
 
 		steal = paravirt_steal_clock(smp_processor_id());
 		steal -= this_rq()->prev_steal_time;
 
-		st = steal_ticks(steal);
-		this_rq()->prev_steal_time += st * TICK_NSEC;
+		steal_ct = nsecs_to_cputime(steal);
+		this_rq()->prev_steal_time += cputime_to_nsecs(steal_ct);
 
-		account_steal_time(st);
-		return st;
+		account_steal_time(steal_ct);
+		return steal_ct;
 	}
 #endif
 	return false;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [RFC PATCH 5/6] sched: Remove needless round trip nsecs <-> tick conversion of steal time
  2014-03-06 17:56 [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting Frederic Weisbecker
                   ` (3 preceding siblings ...)
  2014-03-06 17:56 ` [PATCH 4/6] cputime: Fix jiffies based cputime assumption on steal accounting Frederic Weisbecker
@ 2014-03-06 17:56 ` Frederic Weisbecker
  2014-03-06 19:39   ` Rik van Riel
  2014-03-06 17:56 ` [PATCH 6/6] arch: Remove stub cputime.h headers Frederic Weisbecker
  5 siblings, 1 reply; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-06 17:56 UTC (permalink / raw)
  To: LKML
  Cc: Frederic Weisbecker, Ingo Molnar, Marcelo Tosatti, Peter Zijlstra,
	Thomas Gleixner

When update_rq_clock_task() accounts the pending steal time for a task,
it converts the steal delta from nsecs to tick then from tick to nsecs.

There is no apparent good reason for doing that though because both
the task clock and the prev steal delta are u64 and store values
in nsecs.

So lets remove the needless conversion.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/sched/core.c  |  6 ------
 kernel/sched/sched.h | 10 ----------
 2 files changed, 16 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b46131e..b14a188 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -823,19 +823,13 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
 #endif
 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
 	if (static_key_false((&paravirt_steal_rq_enabled))) {
-		u64 st;
-
 		steal = paravirt_steal_clock(cpu_of(rq));
 		steal -= rq->prev_steal_time_rq;
 
 		if (unlikely(steal > delta))
 			steal = delta;
 
-		st = steal_ticks(steal);
-		steal = st * TICK_NSEC;
-
 		rq->prev_steal_time_rq += steal;
-
 		delta -= steal;
 	}
 #endif
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index c2119fd..5ec9910 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1214,16 +1214,6 @@ extern void update_idle_cpu_load(struct rq *this_rq);
 
 extern void init_task_runnable_average(struct task_struct *p);
 
-#ifdef CONFIG_PARAVIRT
-static inline u64 steal_ticks(u64 steal)
-{
-	if (unlikely(steal > NSEC_PER_SEC))
-		return div_u64(steal, TICK_NSEC);
-
-	return __iter_div_u64_rem(steal, TICK_NSEC, &steal);
-}
-#endif
-
 static inline void inc_nr_running(struct rq *rq)
 {
 	rq->nr_running++;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 6/6] arch: Remove stub cputime.h headers
  2014-03-06 17:56 [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting Frederic Weisbecker
                   ` (4 preceding siblings ...)
  2014-03-06 17:56 ` [RFC PATCH 5/6] sched: Remove needless round trip nsecs <-> tick conversion of steal time Frederic Weisbecker
@ 2014-03-06 17:56 ` Frederic Weisbecker
  2014-03-06 19:40   ` Rik van Riel
  5 siblings, 1 reply; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-06 17:56 UTC (permalink / raw)
  To: LKML
  Cc: Frederic Weisbecker, Archs, Ingo Molnar, Marcelo Tosatti,
	Peter Zijlstra, Thomas Gleixner

Many architectures have a stub cputime.h that only include the default
cputime.h

Lets remove the useless headers, we only need to mention that we want
the default headers on the Kbuild files.

Cc: Archs <linux-arch@vger.kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 arch/alpha/include/asm/Kbuild         | 1 +
 arch/alpha/include/asm/cputime.h      | 6 ------
 arch/cris/include/asm/Kbuild          | 1 +
 arch/cris/include/asm/cputime.h       | 6 ------
 arch/frv/include/asm/Kbuild           | 1 +
 arch/frv/include/asm/cputime.h        | 6 ------
 arch/m32r/include/asm/Kbuild          | 1 +
 arch/m32r/include/asm/cputime.h       | 6 ------
 arch/microblaze/include/asm/Kbuild    | 1 +
 arch/microblaze/include/asm/cputime.h | 1 -
 arch/mn10300/include/asm/Kbuild       | 1 +
 arch/mn10300/include/asm/cputime.h    | 1 -
 arch/score/include/asm/Kbuild         | 2 +-
 arch/score/include/asm/cputime.h      | 6 ------
 arch/x86/include/asm/Kbuild           | 1 +
 arch/x86/include/asm/cputime.h        | 1 -
 16 files changed, 8 insertions(+), 34 deletions(-)
 delete mode 100644 arch/alpha/include/asm/cputime.h
 delete mode 100644 arch/cris/include/asm/cputime.h
 delete mode 100644 arch/frv/include/asm/cputime.h
 delete mode 100644 arch/m32r/include/asm/cputime.h
 delete mode 100644 arch/microblaze/include/asm/cputime.h
 delete mode 100644 arch/mn10300/include/asm/cputime.h
 delete mode 100644 arch/score/include/asm/cputime.h
 delete mode 100644 arch/x86/include/asm/cputime.h

diff --git a/arch/alpha/include/asm/Kbuild b/arch/alpha/include/asm/Kbuild
index a73a8e2..1a81a8b 100644
--- a/arch/alpha/include/asm/Kbuild
+++ b/arch/alpha/include/asm/Kbuild
@@ -5,3 +5,4 @@ generic-y += exec.h
 generic-y += trace_clock.h
 generic-y += preempt.h
 generic-y += hash.h
+generic-y += cputime.h
\ No newline at end of file
diff --git a/arch/alpha/include/asm/cputime.h b/arch/alpha/include/asm/cputime.h
deleted file mode 100644
index 19577fd..0000000
--- a/arch/alpha/include/asm/cputime.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __ALPHA_CPUTIME_H
-#define __ALPHA_CPUTIME_H
-
-#include <asm-generic/cputime.h>
-
-#endif /* __ALPHA_CPUTIME_H */
diff --git a/arch/cris/include/asm/Kbuild b/arch/cris/include/asm/Kbuild
index f3fd876..9d02b45 100644
--- a/arch/cris/include/asm/Kbuild
+++ b/arch/cris/include/asm/Kbuild
@@ -14,3 +14,4 @@ generic-y += trace_clock.h
 generic-y += vga.h
 generic-y += xor.h
 generic-y += preempt.h
+generic-y += cputime.h
\ No newline at end of file
diff --git a/arch/cris/include/asm/cputime.h b/arch/cris/include/asm/cputime.h
deleted file mode 100644
index 4446a65..0000000
--- a/arch/cris/include/asm/cputime.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __CRIS_CPUTIME_H
-#define __CRIS_CPUTIME_H
-
-#include <asm-generic/cputime.h>
-
-#endif /* __CRIS_CPUTIME_H */
diff --git a/arch/frv/include/asm/Kbuild b/arch/frv/include/asm/Kbuild
index bc42f14..c5eca98 100644
--- a/arch/frv/include/asm/Kbuild
+++ b/arch/frv/include/asm/Kbuild
@@ -4,3 +4,4 @@ generic-y += exec.h
 generic-y += trace_clock.h
 generic-y += preempt.h
 generic-y += hash.h
+generic-y += cputime.h
diff --git a/arch/frv/include/asm/cputime.h b/arch/frv/include/asm/cputime.h
deleted file mode 100644
index f6c373a..0000000
--- a/arch/frv/include/asm/cputime.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _ASM_CPUTIME_H
-#define _ASM_CPUTIME_H
-
-#include <asm-generic/cputime.h>
-
-#endif /* _ASM_CPUTIME_H */
diff --git a/arch/m32r/include/asm/Kbuild b/arch/m32r/include/asm/Kbuild
index 932435a..fda061d 100644
--- a/arch/m32r/include/asm/Kbuild
+++ b/arch/m32r/include/asm/Kbuild
@@ -5,3 +5,4 @@ generic-y += module.h
 generic-y += trace_clock.h
 generic-y += preempt.h
 generic-y += hash.h
+generic-y += cputime.h
\ No newline at end of file
diff --git a/arch/m32r/include/asm/cputime.h b/arch/m32r/include/asm/cputime.h
deleted file mode 100644
index 0a47550..0000000
--- a/arch/m32r/include/asm/cputime.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __M32R_CPUTIME_H
-#define __M32R_CPUTIME_H
-
-#include <asm-generic/cputime.h>
-
-#endif /* __M32R_CPUTIME_H */
diff --git a/arch/microblaze/include/asm/Kbuild b/arch/microblaze/include/asm/Kbuild
index 2b98bc7..da88738a 100644
--- a/arch/microblaze/include/asm/Kbuild
+++ b/arch/microblaze/include/asm/Kbuild
@@ -6,3 +6,4 @@ generic-y += hash.h
 generic-y += trace_clock.h
 generic-y += syscalls.h
 generic-y += preempt.h
+generic-y += cputime.h
diff --git a/arch/microblaze/include/asm/cputime.h b/arch/microblaze/include/asm/cputime.h
deleted file mode 100644
index 6d68ad7..0000000
--- a/arch/microblaze/include/asm/cputime.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <asm-generic/cputime.h>
diff --git a/arch/mn10300/include/asm/Kbuild b/arch/mn10300/include/asm/Kbuild
index 992e989..e076269 100644
--- a/arch/mn10300/include/asm/Kbuild
+++ b/arch/mn10300/include/asm/Kbuild
@@ -5,3 +5,4 @@ generic-y += exec.h
 generic-y += hash.h
 generic-y += trace_clock.h
 generic-y += preempt.h
+generic-y += cputime.h
\ No newline at end of file
diff --git a/arch/mn10300/include/asm/cputime.h b/arch/mn10300/include/asm/cputime.h
deleted file mode 100644
index 6d68ad7..0000000
--- a/arch/mn10300/include/asm/cputime.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <asm-generic/cputime.h>
diff --git a/arch/score/include/asm/Kbuild b/arch/score/include/asm/Kbuild
index 146b9d5..1274e7a 100644
--- a/arch/score/include/asm/Kbuild
+++ b/arch/score/include/asm/Kbuild
@@ -7,4 +7,4 @@ generic-y += hash.h
 generic-y += trace_clock.h
 generic-y += xor.h
 generic-y += preempt.h
-
+generic-y += cputime.h
diff --git a/arch/score/include/asm/cputime.h b/arch/score/include/asm/cputime.h
deleted file mode 100644
index 1fced99..0000000
--- a/arch/score/include/asm/cputime.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _ASM_SCORE_CPUTIME_H
-#define _ASM_SCORE_CPUTIME_H
-
-#include <asm-generic/cputime.h>
-
-#endif /* _ASM_SCORE_CPUTIME_H */
diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 7f66985..875f34e 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -5,3 +5,4 @@ genhdr-y += unistd_64.h
 genhdr-y += unistd_x32.h
 
 generic-y += clkdev.h
+generic-y += cputime.h
diff --git a/arch/x86/include/asm/cputime.h b/arch/x86/include/asm/cputime.h
deleted file mode 100644
index 6d68ad7..0000000
--- a/arch/x86/include/asm/cputime.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <asm-generic/cputime.h>
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast
  2014-03-06 17:56 ` [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast Frederic Weisbecker
@ 2014-03-06 18:57   ` Rik van Riel
  2014-03-12  2:14     ` Frederic Weisbecker
  0 siblings, 1 reply; 15+ messages in thread
From: Rik van Riel @ 2014-03-06 18:57 UTC (permalink / raw)
  To: Frederic Weisbecker, LKML
  Cc: Ingo Molnar, Marcelo Tosatti, Peter Zijlstra, Thomas Gleixner

On 03/06/2014 12:56 PM, Frederic Weisbecker wrote:
> Even though nsec based cputime_t maps to u64, nsecs_to_cputime() must
> return a cputime_t value. We want to enforce this kind of cast in order
> to track down buggy manipulations of cputime_t such as direct access
> of its values under wrong assumptions on its backend type (nsecs,
> jiffies, etc...) by core code.
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Acked-by: Rik van Riel <riel@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/6] cputime: Default implementation of nsecs -> cputime conversion
  2014-03-06 17:56 ` [PATCH 2/6] cputime: Default implementation of nsecs -> cputime conversion Frederic Weisbecker
@ 2014-03-06 19:17   ` Rik van Riel
  0 siblings, 0 replies; 15+ messages in thread
From: Rik van Riel @ 2014-03-06 19:17 UTC (permalink / raw)
  To: Frederic Weisbecker, LKML
  Cc: Ingo Molnar, Marcelo Tosatti, Peter Zijlstra, Thomas Gleixner

On 03/06/2014 12:56 PM, Frederic Weisbecker wrote:
> The architectures that override cputime_t (s390, ppc) don't provide
> any version of nsecs_to_cputime(). Indeed this cputime_t implementation
> by backend only happens when CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y under
> which the core code doesn't make any use of nsecs_to_cputime().
>
> At least for now.
>
> We are going to make a broader use of it so lets provide a default
> version with a per usecs granularity. It should be good enough for most
> usecases.
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Acked-by: Rik van Riel <riel@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/6] cputime: Bring cputime -> nsecs conversion
  2014-03-06 17:56 ` [PATCH 3/6] cputime: Bring cputime -> nsecs conversion Frederic Weisbecker
@ 2014-03-06 19:24   ` Rik van Riel
  0 siblings, 0 replies; 15+ messages in thread
From: Rik van Riel @ 2014-03-06 19:24 UTC (permalink / raw)
  To: Frederic Weisbecker, LKML
  Cc: Ingo Molnar, Marcelo Tosatti, Peter Zijlstra, Thomas Gleixner

On 03/06/2014 12:56 PM, Frederic Weisbecker wrote:
> We already have nsecs_to_cputime(). Now we need to be able to convert
> the other way around in order to fix a bug on steal time accounting.
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Acked-by: Rik van Riel <riel@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 4/6] cputime: Fix jiffies based cputime assumption on steal accounting
  2014-03-06 17:56 ` [PATCH 4/6] cputime: Fix jiffies based cputime assumption on steal accounting Frederic Weisbecker
@ 2014-03-06 19:36   ` Rik van Riel
  0 siblings, 0 replies; 15+ messages in thread
From: Rik van Riel @ 2014-03-06 19:36 UTC (permalink / raw)
  To: Frederic Weisbecker, LKML
  Cc: Ingo Molnar, Marcelo Tosatti, Peter Zijlstra, Thomas Gleixner

On 03/06/2014 12:56 PM, Frederic Weisbecker wrote:
> The steal guest time accounting code assumes that cputime_t is based on
> jiffies. So when CONFIG_NO_HZ_FULL=y, which implies that cputime_t
> is based on nsecs, steal_account_process_tick() passes the delta in
> jiffies to account_steal_time() which then accounts it as if it's a
> value in nsecs.
>
> As a result, accounting 1 second of steal time (with HZ=100 that would
> be 100 jiffies) is spuriously accounted as 100 nsecs.
>
> As such /proc/stat may report 0 values of steal time even when two
> guests have run concurrently for a few seconds on the same host and
> same CPU.
>
> In order to fix this, lets convert the nsecs based steal delta to
> cputime instead of jiffies by using the right conversion API.
>
> Given that the steal time is stored in cputime_t and this type can have
> a smaller granularity than nsecs, we only account the rounded converted
> value and leave the remaining nsecs for the next deltas.
>
> Reported-by: Huiqingding <huding@redhat.com>
> Reported-by: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Acked-by: Rik van Riel <riel@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 5/6] sched: Remove needless round trip nsecs <-> tick conversion of steal time
  2014-03-06 17:56 ` [RFC PATCH 5/6] sched: Remove needless round trip nsecs <-> tick conversion of steal time Frederic Weisbecker
@ 2014-03-06 19:39   ` Rik van Riel
  0 siblings, 0 replies; 15+ messages in thread
From: Rik van Riel @ 2014-03-06 19:39 UTC (permalink / raw)
  To: Frederic Weisbecker, LKML
  Cc: Ingo Molnar, Marcelo Tosatti, Peter Zijlstra, Thomas Gleixner

On 03/06/2014 12:56 PM, Frederic Weisbecker wrote:
> When update_rq_clock_task() accounts the pending steal time for a task,
> it converts the steal delta from nsecs to tick then from tick to nsecs.
>
> There is no apparent good reason for doing that though because both
> the task clock and the prev steal delta are u64 and store values
> in nsecs.
>
> So lets remove the needless conversion.
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Acked-by: Rik van Riel <riel@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/6] arch: Remove stub cputime.h headers
  2014-03-06 17:56 ` [PATCH 6/6] arch: Remove stub cputime.h headers Frederic Weisbecker
@ 2014-03-06 19:40   ` Rik van Riel
  0 siblings, 0 replies; 15+ messages in thread
From: Rik van Riel @ 2014-03-06 19:40 UTC (permalink / raw)
  To: Frederic Weisbecker, LKML
  Cc: Archs, Ingo Molnar, Marcelo Tosatti, Peter Zijlstra,
	Thomas Gleixner

On 03/06/2014 12:56 PM, Frederic Weisbecker wrote:
> Many architectures have a stub cputime.h that only include the default
> cputime.h
>
> Lets remove the useless headers, we only need to mention that we want
> the default headers on the Kbuild files.
>
> Cc: Archs <linux-arch@vger.kernel.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Acked-by: Rik van Riel <riel@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 3/6] cputime: Bring cputime -> nsecs conversion
  2014-03-12  2:09 [GIT PULL] timers updates for 3.15 Frederic Weisbecker
@ 2014-03-12  2:09 ` Frederic Weisbecker
  0 siblings, 0 replies; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-12  2:09 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner
  Cc: LKML, Frederic Weisbecker, Marcelo Tosatti, Peter Zijlstra

We already have nsecs_to_cputime(). Now we need to be able to convert
the other way around in order to fix a bug on steal time accounting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 include/asm-generic/cputime_jiffies.h | 4 +++-
 include/asm-generic/cputime_nsecs.h   | 2 ++
 include/linux/cputime.h               | 5 +++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/cputime_jiffies.h b/include/asm-generic/cputime_jiffies.h
index 272ecba..d5cb78f5 100644
--- a/include/asm-generic/cputime_jiffies.h
+++ b/include/asm-generic/cputime_jiffies.h
@@ -15,8 +15,10 @@ typedef u64 __nocast cputime64_t;
 
 
 /*
- * Convert nanoseconds to cputime
+ * Convert nanoseconds <-> cputime
  */
+#define cputime_to_nsecs(__ct)		\
+	jiffies_to_nsecs(cputime_to_jiffies(__ct))
 #define nsecs_to_cputime64(__nsec)	\
 	jiffies64_to_cputime64(nsecs_to_jiffies64(__nsec))
 #define nsecs_to_cputime(__nsec)	\
diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
index 768294f..4e81760 100644
--- a/include/asm-generic/cputime_nsecs.h
+++ b/include/asm-generic/cputime_nsecs.h
@@ -44,6 +44,8 @@ typedef u64 __nocast cputime64_t;
 /*
  * Convert cputime <-> nanoseconds
  */
+#define cputime_to_nsecs(__ct)		\
+	(__force u64)(__ct)
 #define nsecs_to_cputime(__nsecs)	\
 	(__force cputime_t)(__nsecs)
 
diff --git a/include/linux/cputime.h b/include/linux/cputime.h
index 2842ebe..f2eb2ee 100644
--- a/include/linux/cputime.h
+++ b/include/linux/cputime.h
@@ -3,6 +3,11 @@
 
 #include <asm/cputime.h>
 
+#ifndef cputime_to_nsecs
+# define cputime_to_nsecs(__ct)	\
+	(cputime_to_usecs(__ct) * NSEC_PER_USEC)
+#endif
+
 #ifndef nsecs_to_cputime
 # define nsecs_to_cputime(__nsecs)	\
 	usecs_to_cputime((__nsecs) / NSEC_PER_USEC)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast
  2014-03-06 18:57   ` Rik van Riel
@ 2014-03-12  2:14     ` Frederic Weisbecker
  0 siblings, 0 replies; 15+ messages in thread
From: Frederic Weisbecker @ 2014-03-12  2:14 UTC (permalink / raw)
  To: Rik van Riel
  Cc: LKML, Ingo Molnar, Marcelo Tosatti, Peter Zijlstra,
	Thomas Gleixner

On Thu, Mar 06, 2014 at 01:57:17PM -0500, Rik van Riel wrote:
> On 03/06/2014 12:56 PM, Frederic Weisbecker wrote:
> >Even though nsec based cputime_t maps to u64, nsecs_to_cputime() must
> >return a cputime_t value. We want to enforce this kind of cast in order
> >to track down buggy manipulations of cputime_t such as direct access
> >of its values under wrong assumptions on its backend type (nsecs,
> >jiffies, etc...) by core code.
> >
> >Cc: Ingo Molnar <mingo@kernel.org>
> >Cc: Marcelo Tosatti <mtosatti@redhat.com>
> >Cc: Peter Zijlstra <peterz@infradead.org>
> >Cc: Thomas Gleixner <tglx@linutronix.de>
> >Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> 
> Acked-by: Rik van Riel <riel@redhat.com>
> 

Thanks a lot for your acks. I added them for the pull request.
Unfortunately git-send-email ignored them for the Cc (it seems to
depend on the version).

But the pull request can be found there: http://marc.info/?i=1394590202-772-1-git-send-email-fweisbec%40gmail.com

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-03-12  2:15 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-06 17:56 [PATCH 0/6] cputime: Fixes and cleanups on steal time accounting Frederic Weisbecker
2014-03-06 17:56 ` [PATCH 1/6] cputime: Fix nsecs_to_cputime() return type cast Frederic Weisbecker
2014-03-06 18:57   ` Rik van Riel
2014-03-12  2:14     ` Frederic Weisbecker
2014-03-06 17:56 ` [PATCH 2/6] cputime: Default implementation of nsecs -> cputime conversion Frederic Weisbecker
2014-03-06 19:17   ` Rik van Riel
2014-03-06 17:56 ` [PATCH 3/6] cputime: Bring cputime -> nsecs conversion Frederic Weisbecker
2014-03-06 19:24   ` Rik van Riel
2014-03-06 17:56 ` [PATCH 4/6] cputime: Fix jiffies based cputime assumption on steal accounting Frederic Weisbecker
2014-03-06 19:36   ` Rik van Riel
2014-03-06 17:56 ` [RFC PATCH 5/6] sched: Remove needless round trip nsecs <-> tick conversion of steal time Frederic Weisbecker
2014-03-06 19:39   ` Rik van Riel
2014-03-06 17:56 ` [PATCH 6/6] arch: Remove stub cputime.h headers Frederic Weisbecker
2014-03-06 19:40   ` Rik van Riel
  -- strict thread matches above, loose matches on Subject: below --
2014-03-12  2:09 [GIT PULL] timers updates for 3.15 Frederic Weisbecker
2014-03-12  2:09 ` [PATCH 3/6] cputime: Bring cputime -> nsecs conversion Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox