Skip to contentSkip to conversation

Tick: Introduce tick_nohz_check() to check nohz enable status

PATCH Superseded Lan Tianyu 4 participants 12 messages Oct 29, 2013 – Nov 15, 2013

Subsystems (2)
lore
Share & tools
lore

Lan Tianyu

author
#0 lore raw

PATCH 1/2 Tick: Introduce tick_nohz_check() to check nohz enable status

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

---
 include/linux/tick.h     | 2 ++
 kernel/rcutree_plugin.h  | 4 +---
 kernel/time/tick-sched.c | 8 +++++++-
 3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/tick.h +2 -0
index 5128d33..a9c5374 100644
@@ -136,6 +136,7 @@ static inline int tick_nohz_tick_stopped(void)
 extern void tick_nohz_idle_enter(void);
 extern void tick_nohz_idle_exit(void);
 extern void tick_nohz_irq_exit(void);
+extern int tick_nohz_check(void);
 extern ktime_t tick_nohz_get_sleep_length(void);
 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
@@ -155,6 +156,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
 
 	return len;
 }
+static inline int tick_nohz_check(void) { return 0; }
 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
 static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
 # endif /* !CONFIG_NO_HZ_COMMON */
kernel/rcutree_plugin.h +1 -3
index 130c97b..af167ec 100644
@@ -1627,8 +1627,6 @@ module_param(rcu_idle_gp_delay, int, 0644);
 static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
 module_param(rcu_idle_lazy_gp_delay, int, 0644);
 
-extern int tick_nohz_enabled;
-
 /*
  * Try to advance callbacks for all flavors of RCU on the current CPU.
  * Afterwards, if there are any callbacks ready for immediate invocation,
@@ -1718,7 +1716,7 @@ static void rcu_prepare_for_idle(int cpu)
 	int tne;
 
 	/* Handle nohz enablement switches conservatively. */
-	tne = ACCESS_ONCE(tick_nohz_enabled);
+	tne = tick_nohz_check();
 	if (tne != rdtp->tick_nohz_enabled_snap) {
 		if (rcu_cpu_has_callbacks(cpu, NULL))
 			invoke_rcu_core(); /* force nohz to see update. */
kernel/time/tick-sched.c +7 -1
index 3612fc7..d381a22 100644
@@ -361,7 +361,13 @@ void __init tick_nohz_init(void)
 /*
  * NO HZ enabled ?
  */
-int tick_nohz_enabled __read_mostly  = 1;
+static int tick_nohz_enabled __read_mostly  = 1;
+
+int tick_nohz_check(void)
+{
+	return	tick_nohz_enabled;
+}
+EXPORT_SYMBOL_GPL(tick_nohz_check);
 
 /*
  * Enable / Disable tickless mode
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
author
#1 lore raw

PATCH 2/2 Cpufreq/gov: use tick_nohz_check() to check idle micro accouting support

Current, od_init() uses get_cpu_idle_time_us() to check whether idle micro accouting is supported. The get_cpu_idle_time_us() returns -1 only when tick nohz is disabled. This patch is to use tick_nohz_check() directly to check nohz enable status instead of get_cpu_idle_time_us(). This can avoid unnecessary getting and putting cpu.

---
 drivers/cpufreq/cpufreq_ondemand.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/cpufreq/cpufreq_ondemand.c +1 -4
index 32f26f6..79986a9 100644
@@ -485,10 +485,7 @@ static int od_init(struct dbs_data *dbs_data)
 		return -ENOMEM;
 	}
 
-	cpu = get_cpu();
-	idle_time = get_cpu_idle_time_us(cpu, NULL);
-	put_cpu();
-	if (idle_time != -1ULL) {
+	if (tick_nohz_check()) {
 		/* Idle micro accounting is supported. Use finer thresholds */
 		tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
 		/*
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
#2 lore raw
In reply to Lan Tianyu
Quoted 5 lines · Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

NACK on the rcutree change unless you put the ACCESS_ONCE() in.

Or is there some reason that ACCESS_ONCE() is not needed? If so, what is that reason?

Thanx, Paul

Quoted 70 lines
---
 include/linux/tick.h     | 2 ++
 kernel/rcutree_plugin.h  | 4 +---
 kernel/time/tick-sched.c | 8 +++++++-
 3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/tick.h +2 -0
index 5128d33..a9c5374 100644
@@ -136,6 +136,7 @@ static inline int tick_nohz_tick_stopped(void)
 extern void tick_nohz_idle_enter(void);
 extern void tick_nohz_idle_exit(void);
 extern void tick_nohz_irq_exit(void);
+extern int tick_nohz_check(void);
 extern ktime_t tick_nohz_get_sleep_length(void);
 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
@@ -155,6 +156,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
 
 	return len;
 }
+static inline int tick_nohz_check(void) { return 0; }
 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
 static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
 # endif /* !CONFIG_NO_HZ_COMMON */
kernel/rcutree_plugin.h +1 -3
index 130c97b..af167ec 100644
@@ -1627,8 +1627,6 @@ module_param(rcu_idle_gp_delay, int, 0644);
 static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
 module_param(rcu_idle_lazy_gp_delay, int, 0644);
 
-extern int tick_nohz_enabled;
-
 /*
  * Try to advance callbacks for all flavors of RCU on the current CPU.
  * Afterwards, if there are any callbacks ready for immediate invocation,
@@ -1718,7 +1716,7 @@ static void rcu_prepare_for_idle(int cpu)
 	int tne;
 
 	/* Handle nohz enablement switches conservatively. */
-	tne = ACCESS_ONCE(tick_nohz_enabled);
+	tne = tick_nohz_check();
 	if (tne != rdtp->tick_nohz_enabled_snap) {
 		if (rcu_cpu_has_callbacks(cpu, NULL))
 			invoke_rcu_core(); /* force nohz to see update. */
kernel/time/tick-sched.c +7 -1
index 3612fc7..d381a22 100644
@@ -361,7 +361,13 @@ void __init tick_nohz_init(void)
 /*
  * NO HZ enabled ?
  */
-int tick_nohz_enabled __read_mostly  = 1;
+static int tick_nohz_enabled __read_mostly  = 1;
+
+int tick_nohz_check(void)
+{
+	return	tick_nohz_enabled;
+}
+EXPORT_SYMBOL_GPL(tick_nohz_check);
 
 /*
  * Enable / Disable tickless mode
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
author
#3 lore raw
Quoted 11 lines · Paul E. McKenney
Quoted 5 lines · Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

NACK on the rcutree change unless you put the ACCESS_ONCE() in.

Or is there some reason that ACCESS_ONCE() is not needed? If so, what is that reason?

Hi Paul:

Thanks for review. When I change this code, I find the tick_nohz_enabled isn't changed dynamically. It's only changed during parsing kernel params when "nohz=off/on" is set. Except this, it will not be changed. So I ignored ACCESS_ONCE(). If necessary, I can add it back.

Quoted 74 lines

Thanx, Paul

Quoted 70 lines
---
  include/linux/tick.h     | 2 ++
  kernel/rcutree_plugin.h  | 4 +---
  kernel/time/tick-sched.c | 8 +++++++-
  3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/tick.h +2 -0
index 5128d33..a9c5374 100644
@@ -136,6 +136,7 @@ static inline int tick_nohz_tick_stopped(void)
  extern void tick_nohz_idle_enter(void);
  extern void tick_nohz_idle_exit(void);
  extern void tick_nohz_irq_exit(void);
+extern int tick_nohz_check(void);
  extern ktime_t tick_nohz_get_sleep_length(void);
  extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
@@ -155,6 +156,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
 
  	return len;
  }
+static inline int tick_nohz_check(void) { return 0; }
  static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
  static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
  # endif /* !CONFIG_NO_HZ_COMMON */
kernel/rcutree_plugin.h +1 -3
index 130c97b..af167ec 100644
@@ -1627,8 +1627,6 @@ module_param(rcu_idle_gp_delay, int, 0644);
  static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
  module_param(rcu_idle_lazy_gp_delay, int, 0644);
 
-extern int tick_nohz_enabled;
-
  /*
   * Try to advance callbacks for all flavors of RCU on the current CPU.
   * Afterwards, if there are any callbacks ready for immediate invocation,
@@ -1718,7 +1716,7 @@ static void rcu_prepare_for_idle(int cpu)
  	int tne;
 
  	/* Handle nohz enablement switches conservatively. */
-	tne = ACCESS_ONCE(tick_nohz_enabled);
+	tne = tick_nohz_check();
  	if (tne != rdtp->tick_nohz_enabled_snap) {
  		if (rcu_cpu_has_callbacks(cpu, NULL))
  			invoke_rcu_core(); /* force nohz to see update. */
kernel/time/tick-sched.c +7 -2
index 3612fc7..d381a22 100644
@@ -361,7 +361,13 @@ void __init tick_nohz_init(void)
  /*
   * NO HZ enabled ?
   */
-int tick_nohz_enabled __read_mostly  = 1;
+static int tick_nohz_enabled __read_mostly  = 1;
+
+int tick_nohz_check(void)
+{
+	return	tick_nohz_enabled;
+}
+EXPORT_SYMBOL_GPL(tick_nohz_check);
 
  /*
   * Enable / Disable tickless mode
--

1.8.4.rc0.1.g8f6a3e5.dirty

author
#4 lore raw
Quoted 16 lines · Lan Tianyu
Quoted 8 lines · Paul E. McKenney
Quoted 7 lines · Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq
ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value
And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

Quoted 6 lines
Quoted 1 line

NACK on the rcutree change unless you put the ACCESS_ONCE() in.

Or is there some reason that ACCESS_ONCE() is not needed? If so, what is that reason?

Quoted 6 lines

Hi Paul:

Thanks for review. When I change this code, I find the tick_nohz_enabled isn't changed dynamically. It's only changed during parsing kernel params when "nohz=off/on" is set. Except this, it will not be changed. So I ignored ACCESS_ONCE(). If necessary, I can add it back.

Hi Paul:
Does this reason make sense to you? Or you still prefer to add
ACCESS_ONCE() in the new tick_nohz_check()?

Quoted 80 lines
Quoted 79 lines

Thanx, Paul

Quoted 74 lines
---
  include/linux/tick.h     | 2 ++
  kernel/rcutree_plugin.h  | 4 +---
  kernel/time/tick-sched.c | 8 +++++++-
  3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/tick.h +2 -0
index 5128d33..a9c5374 100644
@@ -136,6 +136,7 @@ static inline int tick_nohz_tick_stopped(void)
  extern void tick_nohz_idle_enter(void);
  extern void tick_nohz_idle_exit(void);
  extern void tick_nohz_irq_exit(void);
+extern int tick_nohz_check(void);
  extern ktime_t tick_nohz_get_sleep_length(void);
  extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
@@ -155,6 +156,7 @@ static inline ktime_t
 tick_nohz_get_sleep_length(void)
 
      return len;
  }
+static inline int tick_nohz_check(void) { return 0; }
  static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) {
 return -1; }

static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) {
return -1; }

  # endif /* !CONFIG_NO_HZ_COMMON */
kernel/rcutree_plugin.h +0 -2
index 130c97b..af167ec 100644
@@ -1627,8 +1627,6 @@ module_param(rcu_idle_gp_delay, int, 0644);
  static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
  module_param(rcu_idle_lazy_gp_delay, int, 0644);
 
-extern int tick_nohz_enabled;
-
  /*
   * Try to advance callbacks for all flavors of RCU on the current CPU.
   * Afterwards, if there are any callbacks ready for immediate

invocation,

kernel/rcutree_plugin.h +1 -1
@@ -1718,7 +1716,7 @@ static void rcu_prepare_for_idle(int cpu)
      int tne;
 
      /* Handle nohz enablement switches conservatively. */
-    tne = ACCESS_ONCE(tick_nohz_enabled);
+    tne = tick_nohz_check();
      if (tne != rdtp->tick_nohz_enabled_snap) {
          if (rcu_cpu_has_callbacks(cpu, NULL))
              invoke_rcu_core(); /* force nohz to see update. */
kernel/time/tick-sched.c +7 -1
index 3612fc7..d381a22 100644
@@ -361,7 +361,13 @@ void __init tick_nohz_init(void)
  /*
   * NO HZ enabled ?
   */
-int tick_nohz_enabled __read_mostly  = 1;
+static int tick_nohz_enabled __read_mostly  = 1;
+
+int tick_nohz_check(void)
+{
+    return    tick_nohz_enabled;
+}
+EXPORT_SYMBOL_GPL(tick_nohz_check);
 
  /*
   * Enable / Disable tickless mode
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
Signature · 2 lines
Best regards
Tianyu Lan
#5 lore raw
Quoted 19 lines · Lan Tianyu
Quoted 18 lines · Lan Tianyu
Quoted 8 lines · Paul E. McKenney
Quoted 7 lines · Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq
ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value
And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

Quoted 6 lines
Quoted 1 line

NACK on the rcutree change unless you put the ACCESS_ONCE() in.

Or is there some reason that ACCESS_ONCE() is not needed? If so, what is that reason?

Hi Paul:

Quoted 8 lines
Quoted 4 lines

Thanks for review. When I change this code, I find the tick_nohz_enabled isn't changed dynamically. It's only changed during parsing kernel params when "nohz=off/on" is set. Except this, it will not be changed. So I ignored ACCESS_ONCE(). If necessary, I can add it back.

Hi Paul:
Does this reason make sense to you? Or you still prefer to add
ACCESS_ONCE() in the new tick_nohz_check()?

I prefer the ACCESS_ONCE(). It adds little or no overhead, and Frederic has been heard to say that he mkight allow tick_nohz_check() to change in the future.

Thanx, Paul

Quoted 82 lines
Quoted 76 lines
Quoted 75 lines
Quoted 74 lines
---
  include/linux/tick.h     | 2 ++
  kernel/rcutree_plugin.h  | 4 +---
  kernel/time/tick-sched.c | 8 +++++++-
  3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/tick.h +2 -0
index 5128d33..a9c5374 100644
@@ -136,6 +136,7 @@ static inline int tick_nohz_tick_stopped(void)
  extern void tick_nohz_idle_enter(void);
  extern void tick_nohz_idle_exit(void);
  extern void tick_nohz_irq_exit(void);
+extern int tick_nohz_check(void);
  extern ktime_t tick_nohz_get_sleep_length(void);
  extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
@@ -155,6 +156,7 @@ static inline ktime_t
 tick_nohz_get_sleep_length(void)
 
      return len;
  }
+static inline int tick_nohz_check(void) { return 0; }
  static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) {
 return -1; }

static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) {
return -1; }

  # endif /* !CONFIG_NO_HZ_COMMON */
kernel/rcutree_plugin.h +0 -2
index 130c97b..af167ec 100644
@@ -1627,8 +1627,6 @@ module_param(rcu_idle_gp_delay, int, 0644);
  static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
  module_param(rcu_idle_lazy_gp_delay, int, 0644);
 
-extern int tick_nohz_enabled;
-
  /*
   * Try to advance callbacks for all flavors of RCU on the current CPU.
   * Afterwards, if there are any callbacks ready for immediate

invocation,

kernel/rcutree_plugin.h +1 -1
@@ -1718,7 +1716,7 @@ static void rcu_prepare_for_idle(int cpu)
      int tne;
 
      /* Handle nohz enablement switches conservatively. */
-    tne = ACCESS_ONCE(tick_nohz_enabled);
+    tne = tick_nohz_check();
      if (tne != rdtp->tick_nohz_enabled_snap) {
          if (rcu_cpu_has_callbacks(cpu, NULL))
              invoke_rcu_core(); /* force nohz to see update. */
kernel/time/tick-sched.c +7 -1
index 3612fc7..d381a22 100644
@@ -361,7 +361,13 @@ void __init tick_nohz_init(void)
  /*
   * NO HZ enabled ?
   */
-int tick_nohz_enabled __read_mostly  = 1;
+static int tick_nohz_enabled __read_mostly  = 1;
+
+int tick_nohz_check(void)
+{
+    return    tick_nohz_enabled;
+}
+EXPORT_SYMBOL_GPL(tick_nohz_check);
 
  /*
   * Enable / Disable tickless mode
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
Signature · 2 lines
Best regards
Tianyu Lan
author
#6 lore raw
Quoted 25 lines · Paul E. McKenney
Quoted 24 lines · Lan Tianyu
Quoted 22 lines · Lan Tianyu
Quoted 8 lines · Paul E. McKenney
Quoted 7 lines · Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq
ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value
And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

Quoted 6 lines
Quoted 1 line

NACK on the rcutree change unless you put the ACCESS_ONCE() in.

Or is there some reason that ACCESS_ONCE() is not needed? If so, what is that reason?

Hi Paul:

Thanks for review. When I change this code, I find the tick_nohz_enabled isn't changed dynamically. It's only changed during parsing kernel params when "nohz=off/on" is set. Except this, it will not be changed. So I ignored ACCESS_ONCE(). If necessary, I can add it back.

Quoted 8 lines
Quoted 3 lines

Hi Paul:
Does this reason make sense to you? Or you still prefer to add
ACCESS_ONCE() in the new tick_nohz_check()?

I prefer the ACCESS_ONCE(). It adds little or no overhead, and Frederic has been heard to say that he mkight allow tick_nohz_check() to change in the future.

Ok. I will update it.

Quoted 85 lines

Thanx, Paul

Quoted 82 lines
Quoted 76 lines
Quoted 75 lines
Quoted 74 lines
---
  include/linux/tick.h     | 2 ++
  kernel/rcutree_plugin.h  | 4 +---
  kernel/time/tick-sched.c | 8 +++++++-
  3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/tick.h +2 -0
index 5128d33..a9c5374 100644
@@ -136,6 +136,7 @@ static inline int tick_nohz_tick_stopped(void)
  extern void tick_nohz_idle_enter(void);
  extern void tick_nohz_idle_exit(void);
  extern void tick_nohz_irq_exit(void);
+extern int tick_nohz_check(void);
  extern ktime_t tick_nohz_get_sleep_length(void);
  extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
@@ -155,6 +156,7 @@ static inline ktime_t
 tick_nohz_get_sleep_length(void)
 
      return len;
  }
+static inline int tick_nohz_check(void) { return 0; }
  static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) {
 return -1; }

static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) {
return -1; }

  # endif /* !CONFIG_NO_HZ_COMMON */
kernel/rcutree_plugin.h +0 -2
index 130c97b..af167ec 100644
@@ -1627,8 +1627,6 @@ module_param(rcu_idle_gp_delay, int, 0644);
  static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
  module_param(rcu_idle_lazy_gp_delay, int, 0644);
 
-extern int tick_nohz_enabled;
-
  /*
   * Try to advance callbacks for all flavors of RCU on the current CPU.
   * Afterwards, if there are any callbacks ready for immediate

invocation,

kernel/rcutree_plugin.h +1 -1
@@ -1718,7 +1716,7 @@ static void rcu_prepare_for_idle(int cpu)
      int tne;
 
      /* Handle nohz enablement switches conservatively. */
-    tne = ACCESS_ONCE(tick_nohz_enabled);
+    tne = tick_nohz_check();
      if (tne != rdtp->tick_nohz_enabled_snap) {
          if (rcu_cpu_has_callbacks(cpu, NULL))
              invoke_rcu_core(); /* force nohz to see update. */
kernel/time/tick-sched.c +7 -1
index 3612fc7..d381a22 100644
@@ -361,7 +361,13 @@ void __init tick_nohz_init(void)
  /*
   * NO HZ enabled ?
   */
-int tick_nohz_enabled __read_mostly  = 1;
+static int tick_nohz_enabled __read_mostly  = 1;
+
+int tick_nohz_check(void)
+{
+    return    tick_nohz_enabled;
+}
+EXPORT_SYMBOL_GPL(tick_nohz_check);
 
  /*
   * Enable / Disable tickless mode
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
Signature · 2 lines
Best regards
Tianyu Lan
Signature · 2 lines
Best regards
Tianyu Lan
author
#7 lore raw

PATCH v2 1/2 Tick: Introduce tick_nohz_check() to check nohz enable status

In reply to Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

---

Change since V2:
Add ACCESS_ONCE to tick_nohz_check().

 include/linux/tick.h     | 2 ++
 kernel/rcutree_plugin.h  | 4 +---
 kernel/time/tick-sched.c | 8 +++++++-
 3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/tick.h +2 -0
index 5128d33..a9c5374 100644
@@ -136,6 +136,7 @@ static inline int tick_nohz_tick_stopped(void)
 extern void tick_nohz_idle_enter(void);
 extern void tick_nohz_idle_exit(void);
 extern void tick_nohz_irq_exit(void);
+extern int tick_nohz_check(void);
 extern ktime_t tick_nohz_get_sleep_length(void);
 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
@@ -155,6 +156,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
 
 	return len;
 }
+static inline int tick_nohz_check(void) { return 0; }
 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
 static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
 # endif /* !CONFIG_NO_HZ_COMMON */
kernel/rcutree_plugin.h +1 -3
index 130c97b..af167ec 100644
@@ -1627,8 +1627,6 @@ module_param(rcu_idle_gp_delay, int, 0644);
 static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
 module_param(rcu_idle_lazy_gp_delay, int, 0644);
 
-extern int tick_nohz_enabled;
-
 /*
  * Try to advance callbacks for all flavors of RCU on the current CPU.
  * Afterwards, if there are any callbacks ready for immediate invocation,
@@ -1718,7 +1716,7 @@ static void rcu_prepare_for_idle(int cpu)
 	int tne;
 
 	/* Handle nohz enablement switches conservatively. */
-	tne = ACCESS_ONCE(tick_nohz_enabled);
+	tne = tick_nohz_check();
 	if (tne != rdtp->tick_nohz_enabled_snap) {
 		if (rcu_cpu_has_callbacks(cpu, NULL))
 			invoke_rcu_core(); /* force nohz to see update. */
kernel/time/tick-sched.c +7 -1
index 3612fc7..a568845 100644
@@ -361,7 +361,13 @@ void __init tick_nohz_init(void)
 /*
  * NO HZ enabled ?
  */
-int tick_nohz_enabled __read_mostly  = 1;
+static int tick_nohz_enabled __read_mostly  = 1;
+
+int tick_nohz_check(void)
+{
+	return	ACCESS_ONCE(tick_nohz_enabled);
+}
+EXPORT_SYMBOL_GPL(tick_nohz_check);
 
 /*
  * Enable / Disable tickless mode
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
author
#8 lore raw

PATCH v2 2/2 Cpufreq/gov: use tick_nohz_check() to check idle micro accouting support

Current, od_init() uses get_cpu_idle_time_us() to check whether idle micro accouting is supported. The get_cpu_idle_time_us() returns -1 only when tick nohz is disabled. This patch is to use tick_nohz_check() directly to check nohz enable status instead of get_cpu_idle_time_us(). This can avoid unnecessary getting and putting cpu.

---
 drivers/cpufreq/cpufreq_ondemand.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/cpufreq/cpufreq_ondemand.c +1 -6
index 18d4091..7db2468 100644
@@ -475,8 +475,6 @@ static struct attribute_group od_attr_group_gov_pol = {
 static int od_init(struct dbs_data *dbs_data)
 {
 	struct od_dbs_tuners *tuners;
-	u64 idle_time;
-	int cpu;
 
 	tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
 	if (!tuners) {
@@ -484,10 +482,7 @@ static int od_init(struct dbs_data *dbs_data)
 		return -ENOMEM;
 	}
 
-	cpu = get_cpu();
-	idle_time = get_cpu_idle_time_us(cpu, NULL);
-	put_cpu();
-	if (idle_time != -1ULL) {
+	if (tick_nohz_check()) {
 		/* Idle micro accounting is supported. Use finer thresholds */
 		tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
 		/*
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
maintainer Acked-by on v2 2/2
#9 lore raw

Re: [PATCH V2 2/2] Cpufreq/gov: use tick_nohz_check() to check idle micro accouting support

Quoted 11 lines · Lan Tianyu

Current, od_init() uses get_cpu_idle_time_us() to check whether idle micro accouting is supported. The get_cpu_idle_time_us() returns -1 only when tick nohz is disabled. This patch is to use tick_nohz_check() directly to check nohz enable status instead of get_cpu_idle_time_us(). This can avoid unnecessary getting and putting cpu.

---
 drivers/cpufreq/cpufreq_ondemand.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
maintainer Acked-by on v2 1/2
#10 lore raw
In reply to Lan Tianyu
Quoted 7 lines · Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

---

Quoted 7 lines

Change since V2:
Add ACCESS_ONCE to tick_nohz_check().

 include/linux/tick.h     | 2 ++
 kernel/rcutree_plugin.h  | 4 +---
 kernel/time/tick-sched.c | 8 +++++++-
 3 files changed, 10 insertions(+), 4 deletions(-)
#11 lore raw
In reply to Lan Tianyu
Quoted 3 lines · Lan Tianyu

In some cases, nohz enable status needs to be checked. E.G, in RCU and cpufreq ondemand governor. So add tick_nohz_check() to return tick_nohz_enabled value And use tick_nohz_check() instead of referencing tick_nohz_enabled in the rcutree_plugin.h.

What's the point of this?

Checking for tick_nohz_enabled is wrong to begin with.

See https://lkml.org/lkml/2013/11/13/424