Skip to contentSkip to conversation

nohz: Cputime cleanups and tilegx isolation

PATCH New Frederic Weisbecker 1 participant 5 messages Jul 14, 2015

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover nohz: Cputime cleanups and tilegx isolation

That set has jiffies/cputime cleanups and fixes that were previously posted and a change on tilegx driver to be isolation-friendly.

If nobody opposes, I'll make a pull request to Ingo in a few days.

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/core-v3

HEAD: 572536be5b8e84c507d66203f53faa0ae2c8c244

Thanks,
Frederic
---

Frederic Weisbecker (3):
jiffies: Remove HZ > USEC_PER_SEC special case
apm32: Fix cputime == jiffies assumption
alpha: Fix jiffies based cputime assumption

Chris Metcalf (1):
nohz: Prevent tilegx network driver interrupts

 arch/alpha/kernel/osf_sys.c        | 13 +++++++++----
 arch/x86/kernel/apm_32.c           |  2 +-
 drivers/net/ethernet/tile/tilegx.c |  4 +++-
 include/linux/jiffies.h            |  9 +--------
 include/linux/tick.h               |  9 +++++++++
 kernel/time/time.c                 | 10 +++++++---
 6 files changed, 30 insertions(+), 17 deletions(-)
#1 lore raw

PATCH 1/4 jiffies: Remove HZ > USEC_PER_SEC special case

HZ never goes much further 1000 and a bit. And if we ever reach one tick per microsecond, we might be having a problem.

Lets stop maintaining this special case, just leave a paranoid check.

Cc Christoph Lameter <[email protected]>
Cc Ingo Molnar <[email protected]>

Cc; John Stultz <[email protected]>

Cc Peter Zijlstra <[email protected]>
Cc Preeti U Murthy <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Viresh Kumar <[email protected]>
---
 include/linux/jiffies.h |  9 +--------
 kernel/time/time.c      | 10 +++++++---
 2 files changed, 8 insertions(+), 11 deletions(-)
include/linux/jiffies.h +1 -8
index 535fd3b..7c6febe 100644
@@ -363,18 +363,11 @@ static inline unsigned long msecs_to_jiffies(const unsigned int m)
 }
 
 extern unsigned long __usecs_to_jiffies(const unsigned int u);
-#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
+#if !(USEC_PER_SEC % HZ)
 static inline unsigned long _usecs_to_jiffies(const unsigned int u)
 {
 	return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ);
 }
-#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
-static inline unsigned long _usecs_to_jiffies(const unsigned int u)
-{
-	return u * (HZ / USEC_PER_SEC);
-}
-static inline unsigned long _usecs_to_jiffies(const unsigned int u)
-{
 #else
 static inline unsigned long _usecs_to_jiffies(const unsigned int u)
 {
kernel/time/time.c +7 -3
index 85d5bb1..ad1bf23 100644
@@ -268,10 +268,14 @@ EXPORT_SYMBOL(jiffies_to_msecs);
 
 unsigned int jiffies_to_usecs(const unsigned long j)
 {
-#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
+	/*
+	 * Hz usually doesn't go much further MSEC_PER_SEC.
+	 * jiffies_to_usecs() and usecs_to_jiffies() depend on that.
+	 */
+	BUILD_BUG_ON(HZ > USEC_PER_SEC);
+
+#if !(USEC_PER_SEC % HZ)
 	return (USEC_PER_SEC / HZ) * j;
-#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
-	return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);
 #else
 # if BITS_PER_LONG == 32
 	return (HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/4 apm32: Fix cputime == jiffies assumption

In reply to Frederic Weisbecker

That code wrongly assumes that cputime_t wraps jiffies_t. Lets use the correct accessors/mutators.

No real harm now as that code can't be used with full dynticks.

Cc Christoph Lameter <[email protected]>
Cc Ingo Molnar <[email protected]>

Cc; John Stultz <[email protected]>

Cc Peter Zijlstra <[email protected]>
Cc Preeti U Murthy <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Viresh Kumar <[email protected]>
---
 arch/x86/kernel/apm_32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/apm_32.c +1 -1
index 927ec92..052c9c3 100644
@@ -919,7 +919,7 @@ recalc:
 	} else if (jiffies_since_last_check > idle_period) {
 		unsigned int idle_percentage;
 
-		idle_percentage = stime - last_stime;
+		idle_percentage = cputime_to_jiffies(stime - last_stime);
 		idle_percentage *= 100;
 		idle_percentage /= jiffies_since_last_check;
 		use_apm_idle = (idle_percentage > idle_threshold);
Signature · 1 line
2.1.4
#3 lore raw

PATCH 3/4 alpha: Fix jiffies based cputime assumption

In reply to Frederic Weisbecker

That code wrongly assumes that cputime_t wraps jiffies_t. Lets use the correct accessors/mutators.

In practice there should be no harm yet because alpha currently only support tick based cputime accounting which is always jiffies based.

Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Ingo Molnar <[email protected]>

Cc; John Stultz <[email protected]>

Cc Peter Zijlstra <[email protected]>
Cc Preeti U Murthy <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Viresh Kumar <[email protected]>
---
 arch/alpha/kernel/osf_sys.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
arch/alpha/kernel/osf_sys.c +9 -4
index 36dc91a..6cc0816 100644
@@ -1138,6 +1138,7 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
 {
 	struct rusage32 r;
 	cputime_t utime, stime;
+	unsigned long utime_jiffies, stime_jiffies;
 
 	if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
 		return -EINVAL;
@@ -1146,14 +1147,18 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
 	switch (who) {
 	case RUSAGE_SELF:
 		task_cputime(current, &utime, &stime);
-		jiffies_to_timeval32(utime, &r.ru_utime);
-		jiffies_to_timeval32(stime, &r.ru_stime);
+		utime_jiffies = cputime_to_jiffies(utime);
+		stime_jiffies = cputime_to_jiffies(stime);
+		jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
+		jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
 		r.ru_minflt = current->min_flt;
 		r.ru_majflt = current->maj_flt;
 		break;
 	case RUSAGE_CHILDREN:
-		jiffies_to_timeval32(current->signal->cutime, &r.ru_utime);
-		jiffies_to_timeval32(current->signal->cstime, &r.ru_stime);
+		utime_jiffies = cputime_to_jiffies(current->signal->cutime);
+		stime_jiffies = cputime_to_jiffies(current->signal->cstime);
+		jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
+		jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
 		r.ru_minflt = current->signal->cmin_flt;
 		r.ru_majflt = current->signal->cmaj_flt;
 		break;
Signature · 1 line
2.1.4
#4 lore raw

PATCH 4/4 nohz: Prevent tilegx network driver interrupts

In reply to Frederic Weisbecker

From: Chris Metcalf <[email protected]>

Normally the tilegx networking shim sends irqs to all the cores to distribute the load of processing incoming-packet interrupts, so that you can get to multiple Gb's of traffic inbound.

However, in nohz_full mode we don't want to interrupt the nohz_full cores by default, so we limit the set of cores we use to only the online housekeeping cores.

To make client code easier to read, we introduce a new nohz_full accessor, housekeeping_cpumask(), which returns a pointer to the housekeeping_mask if nohz_full is enabled, and otherwise returns the cpu_possible_mask.

Cc Christoph Lameter <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Preeti U Murthy <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Viresh Kumar <[email protected]>
---
 drivers/net/ethernet/tile/tilegx.c | 4 +++-
 include/linux/tick.h               | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/net/ethernet/tile/tilegx.c +3 -1
index a3f7610..0a15acc 100644
@@ -40,6 +40,7 @@
 #include <linux/tcp.h>
 #include <linux/net_tstamp.h>
 #include <linux/ptp_clock_kernel.h>
+#include <linux/tick.h>
 
 #include <asm/checksum.h>
 #include <asm/homecache.h>
@@ -2273,7 +2274,8 @@ static int __init tile_net_init_module(void)
 		tile_net_dev_init(name, mac);
 
 	if (!network_cpus_init())
-		network_cpus_map = *cpu_online_mask;
+		cpumask_and(&network_cpus_map, housekeeping_cpumask(),
+			    cpu_online_mask);
 
 	return 0;
 }
include/linux/tick.h +9 -0
index edbfc9a..1ca93f2 100644
@@ -163,6 +163,15 @@ static inline void tick_nohz_full_kick_all(void) { }
 static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
 #endif
 
+static inline const struct cpumask *housekeeping_cpumask(void)
+{
+#ifdef CONFIG_NO_HZ_FULL
+	if (tick_nohz_full_enabled())
+		return housekeeping_mask;
+#endif
+	return cpu_possible_mask;
+}
+
 static inline bool is_housekeeping_cpu(int cpu)
 {
 #ifdef CONFIG_NO_HZ_FULL
Signature · 1 line
2.1.4