Skip to contentSkip to conversation

cpu/hotplug: Convert scheduler to hotplug state machine

PATCH In review Thomas Gleixner 6 participants 38 messages Mar 10, 2016 – Jul 13, 2016

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

cover cpu/hotplug: Convert scheduler to hotplug state machine

The following series contains:

- cleanup of the notifier maze in the scheduler and conversion to the state machine.

- Handling of cpu active is distangled from cpu online and moved to the end of the hotplug process.

Patches are against tip:master rather than against tip:smp/hotplug because there is an interaction with the accounting fix pending in sched/urgent.

Thanks,

tglx

---
 arch/powerpc/kernel/smp.c  |    2 
 b/arch/s390/kernel/smp.c   |    2 
 include/linux/cpu.h        |   18 --
 include/linux/cpuhotplug.h |    2 
 include/linux/cpumask.h    |    6 
 include/linux/sched.h      |    4 
 kernel/cpu.c               |   77 ++++++--
 kernel/sched/core.c        |  399 +++++++++++++++++++--------------------------
 kernel/sched/fair.c        |   15 -
 kernel/sched/sched.h       |    4 
 10 files changed, 248 insertions(+), 281 deletions(-)
#1 lore raw

PATCH 1/15 cpu/hotplug: Document states better

---
 kernel/cpu.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
kernel/cpu.c +46 -1
@@ -1171,6 +1171,10 @@ static struct cpuhp_step cpuhp_bp_states
 		.teardown		= NULL,
 		.cant_stop		= true,
 	},
+	/*
+	 * Preparatory and dead notifiers. Will be replaced once the notifiers
+	 * are converted to states.
+	 */
 	[CPUHP_NOTIFY_PREPARE] = {
 		.name			= "notify:prepare",
 		.startup		= notify_prepare,
@@ -1178,12 +1182,17 @@ static struct cpuhp_step cpuhp_bp_states
 		.skip_onerr		= true,
 		.cant_stop		= true,
 	},
+	/* Kicks the plugged cpu into life */
 	[CPUHP_BRINGUP_CPU] = {
 		.name			= "cpu:bringup",
 		.startup		= bringup_cpu,
 		.teardown		= NULL,
 		.cant_stop		= true,
 	},
+	/*
+	 * Handled on controll processor until the plugged processor manages
+	 * this itself.
+	 */
 	[CPUHP_TEARDOWN_CPU] = {
 		.name			= "cpu:teardown",
 		.startup		= NULL,
@@ -1196,6 +1205,23 @@ static struct cpuhp_step cpuhp_bp_states
 /* Application processor state steps */
 static struct cpuhp_step cpuhp_ap_states[] = {
 #ifdef CONFIG_SMP
+	/* Final state before CPU kills itself */
+	[CPUHP_AP_IDLE_DEAD] = {
+		.name			= "idle:dead",
+	},
+	/*
+	 * Last state before CPU enters the idle loop to die. Transient state
+	 * for synchronization.
+	 */
+	[CPUHP_AP_OFFLINE] = {
+		.name			= "ap:offline",
+		.cant_stop		= true,
+	},
+	/*
+	 * Low level startup/teardown notifiers. Run with interrupts
+	 * disabled. Will be removed once the notifiers are converted to
+	 * states.
+	 */
 	[CPUHP_AP_NOTIFY_STARTING] = {
 		.name			= "notify:starting",
 		.startup		= notify_starting,
@@ -1203,17 +1229,32 @@ static struct cpuhp_step cpuhp_ap_states
 		.skip_onerr		= true,
 		.cant_stop		= true,
 	},
+	/* Entry state on starting. Interrupts enabled from here on. Transient
+	 * state for synchronsization */
+	[CPUHP_AP_ONLINE] = {
+		.name			= "ap:online",
+	},
+	/* Handle smpboot threads park/unpark */
 	[CPUHP_AP_SMPBOOT_THREADS] = {
 		.name			= "smpboot:threads",
 		.startup		= smpboot_unpark_threads,
 		.teardown		= smpboot_park_threads,
 	},
+	/*
+	 * Online/down_prepare notifiers. Will be removed once the notifiers
+	 * are converted to states.
+	 */
 	[CPUHP_AP_NOTIFY_ONLINE] = {
 		.name			= "notify:online",
 		.startup		= notify_online,
 		.teardown		= notify_down_prepare,
 	},
 #endif
+	/*
+	 * The dynamically registered state space is here
+	 */
+
+	/* CPU is fully up and running. */
 	[CPUHP_ONLINE] = {
 		.name			= "online",
 		.startup		= NULL,
@@ -1231,7 +1272,11 @@ static int cpuhp_cb_check(enum cpuhp_sta
 
 static bool cpuhp_is_ap_state(enum cpuhp_state state)
 {
-	return state > CPUHP_BRINGUP_CPU;
+	/*
+	 * The extra check for CPUHP_TEARDOWN_CPU is only for documentation
+	 * purposes as that state is handled explicitely in cpu_down.
+	 */
+	return state > CPUHP_BRINGUP_CPU && state != CPUHP_TEARDOWN_CPU;
 }
 
 static struct cpuhp_step *cpuhp_get_step(enum cpuhp_state state)
#2 lore raw

PATCH 3/15 sched: Make set_cpu_rq_start_time() a built in hotplug state

In reply to Thomas Gleixner

Start distangling the maze of hotplug notifiers in the scheduler.

---
 include/linux/cpuhotplug.h |    1 +
 include/linux/sched.h      |    1 +
 kernel/cpu.c               |    6 ++++++
 kernel/sched/core.c        |   16 +++++++++-------
 4 files changed, 17 insertions(+), 7 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -8,6 +8,7 @@ enum cpuhp_state {
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
 	CPUHP_AP_OFFLINE,
+	CPUHP_AP_SCHED_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
include/linux/sched.h +1 -0
@@ -373,6 +373,7 @@ extern void cpu_init (void);
 extern void trap_init(void);
 extern void update_process_times(int user);
 extern void scheduler_tick(void);
+extern int sched_cpu_starting(unsigned int cpu);
 
 extern void sched_show_task(struct task_struct *p);
 
kernel/cpu.c +6 -0
@@ -1217,6 +1217,12 @@ static struct cpuhp_step cpuhp_ap_states
 		.name			= "ap:offline",
 		.cant_stop		= true,
 	},
+	/* First state is scheduler control. Interrupts are disabled */
+	[CPUHP_AP_SCHED_STARTING] = {
+		.name			= "sched:starting",
+		.startup		= sched_cpu_starting,
+		.teardown		= NULL,
+	},
 	/*
 	 * Low level startup/teardown notifiers. Run with interrupts
 	 * disabled. Will be removed once the notifiers are converted to
kernel/sched/core.c +9 -7
@@ -5711,10 +5711,10 @@ static struct notifier_block migration_n
 	.priority = CPU_PRI_MIGRATION,
 };
 
-static void set_cpu_rq_start_time(void)
+static void set_cpu_rq_start_time(unsigned int cpu)
 {
-	int cpu = smp_processor_id();
 	struct rq *rq = cpu_rq(cpu);
+
 	rq->age_stamp = sched_clock_cpu(cpu);
 }
 
@@ -5724,10 +5724,6 @@ static int sched_cpu_active(struct notif
 	int cpu = (long)hcpu;
 
 	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		set_cpu_rq_start_time();
-		return NOTIFY_OK;
-
 	case CPU_DOWN_FAILED:
 		set_cpu_active(cpu, true);
 		return NOTIFY_OK;
@@ -5749,6 +5745,12 @@ static int sched_cpu_inactive(struct not
 	}
 }
 
+int sched_cpu_starting(unsigned int cpu)
+{
+	set_cpu_rq_start_time(cpu);
+	return 0;
+}
+
 static int __init migration_init(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
@@ -7659,7 +7661,7 @@ void __init sched_init(void)
 	if (cpu_isolated_map == NULL)
 		zalloc_cpumask_var(&cpu_isolated_map, GFP_NOWAIT);
 	idle_thread_set_boot_cpu();
-	set_cpu_rq_start_time();
+	set_cpu_rq_start_time(smp_processor_id());
 #endif
 	init_sched_fair_class();
 
#3 lore raw

PATCH 4/15 sched: Allow hotplug notifiers to be setup early

In reply to Thomas Gleixner

Prevent the SMP scheduler related notifiers to be executed before the smp scheduler is initialized and install them early.

This is a preparatory change for further consolidation of the hotplug notifier maze.

---
 kernel/sched/core.c |   59 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 23 deletions(-)
kernel/sched/core.c +36 -23
@@ -5256,6 +5256,8 @@ int task_can_attach(struct task_struct *
 
 #ifdef CONFIG_SMP
 
+static bool sched_smp_initialized __read_mostly;
+
 #ifdef CONFIG_NUMA_BALANCING
 /* Migrate current task p to target_cpu */
 int migrate_task_to(struct task_struct *p, int target_cpu)
@@ -5751,25 +5753,6 @@ int sched_cpu_starting(unsigned int cpu)
 	return 0;
 }
 
-static int __init migration_init(void)
-{
-	void *cpu = (void *)(long)smp_processor_id();
-	int err;
-
-	/* Initialize migration for the boot CPU */
-	err = migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
-	BUG_ON(err == NOTIFY_BAD);
-	migration_call(&migration_notifier, CPU_ONLINE, cpu);
-	register_cpu_notifier(&migration_notifier);
-
-	/* Register cpu active notifiers */
-	cpu_notifier(sched_cpu_active, CPU_PRI_SCHED_ACTIVE);
-	cpu_notifier(sched_cpu_inactive, CPU_PRI_SCHED_INACTIVE);
-
-	return 0;
-}
-early_initcall(migration_init);
-
 static cpumask_var_t sched_domains_tmpmask; /* sched_domains_mutex */
 
 #ifdef CONFIG_SCHED_DEBUG
@@ -6944,6 +6927,9 @@ static int sched_domains_numa_masks_upda
 {
 	int cpu = (long)hcpu;
 
+	if (!sched_smp_initialized)
+		return NOTIFY_DONE;
+
 	switch (action & ~CPU_TASKS_FROZEN) {
 	case CPU_ONLINE:
 		sched_domains_numa_masks_set(cpu);
@@ -7362,6 +7348,9 @@ static int num_cpus_frozen;	/* used to m
 static int cpuset_cpu_active(struct notifier_block *nfb, unsigned long action,
 			     void *hcpu)
 {
+	if (!sched_smp_initialized)
+		return NOTIFY_DONE;
+
 	switch (action) {
 	case CPU_ONLINE_FROZEN:
 	case CPU_DOWN_FAILED_FROZEN:
@@ -7402,6 +7391,9 @@ static int cpuset_cpu_inactive(struct no
 	bool overflow;
 	int cpus;
 
+	if (!sched_smp_initialized)
+		return NOTIFY_DONE;
+
 	switch (action) {
 	case CPU_DOWN_PREPARE:
 		rcu_read_lock_sched();
@@ -7449,10 +7441,6 @@ void __init sched_init_smp(void)
 		cpumask_set_cpu(smp_processor_id(), non_isolated_cpus);
 	mutex_unlock(&sched_domains_mutex);
 
-	hotcpu_notifier(sched_domains_numa_masks_update, CPU_PRI_SCHED_ACTIVE);
-	hotcpu_notifier(cpuset_cpu_active, CPU_PRI_CPUSET_ACTIVE);
-	hotcpu_notifier(cpuset_cpu_inactive, CPU_PRI_CPUSET_INACTIVE);
-
 	init_hrtick();
 
 	/* Move init over to a non-isolated CPU */
@@ -7463,7 +7451,32 @@ void __init sched_init_smp(void)
 
 	init_sched_rt_class();
 	init_sched_dl_class();
+	sched_smp_initialized = true;
 }
+
+static int __init migration_init(void)
+{
+	void *cpu = (void *)(long)smp_processor_id();
+	int err;
+
+	/* Initialize migration for the boot CPU */
+	err = migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
+	BUG_ON(err == NOTIFY_BAD);
+	migration_call(&migration_notifier, CPU_ONLINE, cpu);
+	register_cpu_notifier(&migration_notifier);
+
+	/* Register cpu active notifiers */
+	cpu_notifier(sched_cpu_active, CPU_PRI_SCHED_ACTIVE);
+	cpu_notifier(sched_cpu_inactive, CPU_PRI_SCHED_INACTIVE);
+
+	hotcpu_notifier(sched_domains_numa_masks_update, CPU_PRI_SCHED_ACTIVE);
+	hotcpu_notifier(cpuset_cpu_active, CPU_PRI_CPUSET_ACTIVE);
+	hotcpu_notifier(cpuset_cpu_inactive, CPU_PRI_CPUSET_INACTIVE);
+
+	return 0;
+}
+early_initcall(migration_init);
+
 #else
 void __init sched_init_smp(void)
 {
#4 lore raw

PATCH 5/15 sched: Consolidate the notifier maze

In reply to Thomas Gleixner

We can maintain the ordering of the scheduler cpu hotplug functionality nicely in one notifer. Get rid of the maze.

---
 include/linux/cpu.h |   12 +--
 kernel/sched/core.c |  174 ++++++++++++++++++++--------------------------------
 2 files changed, 73 insertions(+), 113 deletions(-)
include/linux/cpu.h +4 -8
@@ -61,19 +61,15 @@ struct notifier_block;
 enum {
 	/*
 	 * SCHED_ACTIVE marks a cpu which is coming up active during
-	 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
-	 * notifier.  CPUSET_ACTIVE adjusts cpuset according to
-	 * cpu_active mask right after SCHED_ACTIVE.  During
-	 * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
-	 * ordered in the similar way.
+	 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first notifier.  Is
+	 * also cpuset according to cpu_active mask right after activating the
+	 * cpu. During CPU_DOWN_PREPARE, SCHED_INACTIVE reversed the operation.
 	 *
 	 * This ordering guarantees consistent cpu_active mask and
 	 * migration behavior to all cpu notifiers.
 	 */
 	CPU_PRI_SCHED_ACTIVE	= INT_MAX,
-	CPU_PRI_CPUSET_ACTIVE	= INT_MAX - 1,
-	CPU_PRI_SCHED_INACTIVE	= INT_MIN + 1,
-	CPU_PRI_CPUSET_INACTIVE	= INT_MIN,
+	CPU_PRI_SCHED_INACTIVE	= INT_MIN,
 
 	/* migration should happen before other stuff but after perf */
 	CPU_PRI_PERF		= 20,
kernel/sched/core.c +69 -105

253 lines not on this page · raw message

#5 lore raw

PATCH 6/15 sched: Move sched_domains_numa_masks_clear() to DOWN_PREPARE

In reply to Thomas Gleixner

This is the last operation on the cpu before vanishing. No point in calling that on CPU_DEAD.

---
 kernel/sched/core.c |    3 ---
 1 file changed, 3 deletions(-)
kernel/sched/core.c +0 -3
@@ -7372,9 +7372,6 @@ static int sched_cpu_inactive(struct not
 			set_cpu_active(cpu, true);
 			return notifier_from_errno(ret);
 		}
-		return NOTIFY_OK;
-
-	case CPU_DEAD:
 		sched_domains_numa_masks_clear(cpu);
 		return NOTIFY_OK;
 	default:
#6 lore raw

PATCH 7/15 sched/hotplug: Convert cpu_[in]active notifiers to state machine

In reply to Thomas Gleixner

Now that we reduced everything into single notifiers, it's simple to move them into the hotplug state machine space.

---
 include/linux/cpu.h        |   12 --------
 include/linux/cpuhotplug.h |    1 
 include/linux/sched.h      |    2 +
 kernel/cpu.c               |    8 ++++-
 kernel/sched/core.c        |   67 ++++++++++++++-------------------------------
 5 files changed, 30 insertions(+), 60 deletions(-)
include/linux/cpu.h +0 -12
@@ -59,18 +59,6 @@ struct notifier_block;
  * CPU notifier priorities.
  */
 enum {
-	/*
-	 * SCHED_ACTIVE marks a cpu which is coming up active during
-	 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first notifier.  Is
-	 * also cpuset according to cpu_active mask right after activating the
-	 * cpu. During CPU_DOWN_PREPARE, SCHED_INACTIVE reversed the operation.
-	 *
-	 * This ordering guarantees consistent cpu_active mask and
-	 * migration behavior to all cpu notifiers.
-	 */
-	CPU_PRI_SCHED_ACTIVE	= INT_MAX,
-	CPU_PRI_SCHED_INACTIVE	= INT_MIN,
-
 	/* migration should happen before other stuff but after perf */
 	CPU_PRI_PERF		= 20,
 	CPU_PRI_MIGRATION	= 10,
include/linux/cpuhotplug.h +1 -0
@@ -13,6 +13,7 @@ enum cpuhp_state {
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
 	CPUHP_AP_ONLINE_IDLE,
+	CPUHP_AP_ACTIVE,
 	CPUHP_AP_SMPBOOT_THREADS,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
include/linux/sched.h +2 -0
@@ -374,6 +374,8 @@ extern void trap_init(void);
 extern void update_process_times(int user);
 extern void scheduler_tick(void);
 extern int sched_cpu_starting(unsigned int cpu);
+extern int sched_cpu_activate(unsigned int cpu);
+extern int sched_cpu_deactivate(unsigned int cpu);
 
 extern void sched_show_task(struct task_struct *p);
 
kernel/cpu.c +6 -2
@@ -904,8 +904,6 @@ void cpuhp_online_idle(enum cpuhp_state
 
 	st->state = CPUHP_AP_ONLINE_IDLE;
 
-	/* The cpu is marked online, set it active now */
-	set_cpu_active(cpu, true);
 	/* Unpark the stopper thread and the hotplug thread of this cpu */
 	stop_machine_unpark(cpu);
 	kthread_unpark(st->thread);
@@ -1240,6 +1238,12 @@ static struct cpuhp_step cpuhp_ap_states
 	[CPUHP_AP_ONLINE] = {
 		.name			= "ap:online",
 	},
+	/* First state is scheduler control. Interrupts are enabled */
+	[CPUHP_AP_ACTIVE] = {
+		.name			= "sched:active",
+		.startup		= sched_cpu_activate,
+		.teardown		= sched_cpu_deactivate,
+	},
 	/* Handle smpboot threads park/unpark */
 	[CPUHP_AP_SMPBOOT_THREADS] = {
 		.name			= "smpboot:threads",
kernel/sched/core.c +21 -46

120 lines not on this page · raw message

#7 lore raw

PATCH 8/15 sched, hotplug: Move sync_rcu to be with set_cpu_active(false)

In reply to Thomas Gleixner

From: Peter Zijlstra <[email protected]>

The sync_rcu stuff is specificically for clearing bits in the active mask, such that everybody will observe the bit cleared and will not consider the cleared CPU for load-balancing etc.

---
 kernel/cpu.c        |   15 ---------------
 kernel/sched/core.c |   14 ++++++++++++++
 2 files changed, 14 insertions(+), 15 deletions(-)
kernel/cpu.c +0 -15
@@ -691,21 +691,6 @@ static int takedown_cpu(unsigned int cpu
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	int err;
 
-	/*
-	 * By now we've cleared cpu_active_mask, wait for all preempt-disabled
-	 * and RCU users of this state to go away such that all new such users
-	 * will observe it.
-	 *
-	 * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might
-	 * not imply sync_sched(), so wait for both.
-	 *
-	 * Do sync before park smpboot threads to take care the rcu boost case.
-	 */
-	if (IS_ENABLED(CONFIG_PREEMPT))
-		synchronize_rcu_mult(call_rcu, call_rcu_sched);
-	else
-		synchronize_rcu();
-
 	/* Park the hotplug thread */
 	kthread_park(per_cpu_ptr(&cpuhp_state, cpu)->thread);
 
kernel/sched/core.c +14 -0
@@ -7345,6 +7345,20 @@ int sched_cpu_deactivate(unsigned int cp
 	int ret;
 
 	set_cpu_active(cpu, false);
+	/*
+	 * We've cleared cpu_active_mask, wait for all preempt-disabled and RCU
+	 * users of this state to go away such that all new such users will
+	 * observe it.
+	 *
+	 * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might
+	 * not imply sync_sched(), so wait for both.
+	 *
+	 * Do sync before park smpboot threads to take care the rcu boost case.
+	 */
+	if (IS_ENABLED(CONFIG_PREEMPT))
+		synchronize_rcu_mult(call_rcu, call_rcu_sched);
+	else
+		synchronize_rcu();
 
 	if (!sched_smp_initialized)
 		return 0;
#8 lore raw

[tip:smp/hotplug] sched/hotplug: Move sync_rcu to be with set_cpu_active(false)

sched/hotplug: Move sync_rcu to be with set_cpu_active(false)
Commit-ID:  c080b5a62379f0d26a5f3bc3eb80c93fdc888be4
Gitweb:     http://git.kernel.org/tip/c080b5a62379f0d26a5f3bc3eb80c93fdc888be4
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:14 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:53 +0200

sched/hotplug: Move sync_rcu to be with set_cpu_active(false)

The sync_rcu stuff is specificically for clearing bits in the active mask, such that everybody will observe the bit cleared and will not consider the cleared CPU for load-balancing etc.

---
 kernel/cpu.c        | 15 ---------------
 kernel/sched/core.c | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 15 deletions(-)
kernel/cpu.c +0 -15
index 15402b7..c134a35 100644
@@ -703,21 +703,6 @@ static int takedown_cpu(unsigned int cpu)
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	int err;
 
-	/*
-	 * By now we've cleared cpu_active_mask, wait for all preempt-disabled
-	 * and RCU users of this state to go away such that all new such users
-	 * will observe it.
-	 *
-	 * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might
-	 * not imply sync_sched(), so wait for both.
-	 *
-	 * Do sync before park smpboot threads to take care the rcu boost case.
-	 */
-	if (IS_ENABLED(CONFIG_PREEMPT))
-		synchronize_rcu_mult(call_rcu, call_rcu_sched);
-	else
-		synchronize_rcu();
-
 	/* Park the smpboot threads */
 	kthread_park(per_cpu_ptr(&cpuhp_state, cpu)->thread);
 	smpboot_park_threads(cpu);
kernel/sched/core.c +14 -0
index 73bcd93..0a31078 100644
@@ -7112,6 +7112,20 @@ int sched_cpu_deactivate(unsigned int cpu)
 	int ret;
 
 	set_cpu_active(cpu, false);
+	/*
+	 * We've cleared cpu_active_mask, wait for all preempt-disabled and RCU
+	 * users of this state to go away such that all new such users will
+	 * observe it.
+	 *
+	 * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might
+	 * not imply sync_sched(), so wait for both.
+	 *
+	 * Do sync before park smpboot threads to take care the rcu boost case.
+	 */
+	if (IS_ENABLED(CONFIG_PREEMPT))
+		synchronize_rcu_mult(call_rcu, call_rcu_sched);
+	else
+		synchronize_rcu();
 
 	if (!sched_smp_initialized)
 		return 0;
#9 lore raw

[tip:smp/hotplug] sched/hotplug: Move sync_rcu to be with set_cpu_active(false)

In reply to Thomas Gleixner
sched/hotplug: Move sync_rcu to be with set_cpu_active(false)
Commit-ID:  b2454caa8977ade27292a71f2def5e403e24b4d5
Gitweb:     http://git.kernel.org/tip/b2454caa8977ade27292a71f2def5e403e24b4d5
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:14 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:24 +0200

sched/hotplug: Move sync_rcu to be with set_cpu_active(false)

The sync_rcu stuff is specificically for clearing bits in the active mask, such that everybody will observe the bit cleared and will not consider the cleared CPU for load-balancing etc.

---
 kernel/cpu.c        | 15 ---------------
 kernel/sched/core.c | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 15 deletions(-)
kernel/cpu.c +0 -15
index 15402b7..c134a35 100644
@@ -703,21 +703,6 @@ static int takedown_cpu(unsigned int cpu)
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	int err;
 
-	/*
-	 * By now we've cleared cpu_active_mask, wait for all preempt-disabled
-	 * and RCU users of this state to go away such that all new such users
-	 * will observe it.
-	 *
-	 * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might
-	 * not imply sync_sched(), so wait for both.
-	 *
-	 * Do sync before park smpboot threads to take care the rcu boost case.
-	 */
-	if (IS_ENABLED(CONFIG_PREEMPT))
-		synchronize_rcu_mult(call_rcu, call_rcu_sched);
-	else
-		synchronize_rcu();
-
 	/* Park the smpboot threads */
 	kthread_park(per_cpu_ptr(&cpuhp_state, cpu)->thread);
 	smpboot_park_threads(cpu);
kernel/sched/core.c +14 -0
index 73bcd93..0a31078 100644
@@ -7112,6 +7112,20 @@ int sched_cpu_deactivate(unsigned int cpu)
 	int ret;
 
 	set_cpu_active(cpu, false);
+	/*
+	 * We've cleared cpu_active_mask, wait for all preempt-disabled and RCU
+	 * users of this state to go away such that all new such users will
+	 * observe it.
+	 *
+	 * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might
+	 * not imply sync_sched(), so wait for both.
+	 *
+	 * Do sync before park smpboot threads to take care the rcu boost case.
+	 */
+	if (IS_ENABLED(CONFIG_PREEMPT))
+		synchronize_rcu_mult(call_rcu, call_rcu_sched);
+	else
+		synchronize_rcu();
 
 	if (!sched_smp_initialized)
 		return 0;
#10 lore raw

PATCH 9/15 sched/migration: Move prepare transition to SCHED_STARTING state

In reply to Thomas Gleixner

We can piggy pack that on the SCHED_STARTING state. It's not required before the cpu actually comes online. Name the function proper as it has nothing to do with migration.

---
 kernel/sched/core.c |   20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
kernel/sched/core.c +11 -9
@@ -5662,11 +5662,6 @@ migration_call(struct notifier_block *nf
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 
-	case CPU_UP_PREPARE:
-		rq->calc_load_update = calc_load_update;
-		account_reset_rq(rq);
-		break;
-
 	case CPU_ONLINE:
 		/* Update our root-domain */
 		raw_spin_lock_irqsave(&rq->lock, flags);
@@ -7372,9 +7367,19 @@ int sched_cpu_deactivate(unsigned int cp
 	return 0;
 }
 
+static void sched_rq_cpu_starting(unsigned int cpu)
+{
+	struct rq *rq = cpu_rq(cpu);
+
+	rq->calc_load_update = calc_load_update;
+	account_reset_rq(rq);
+	update_max_interval();
+}
+
 int sched_cpu_starting(unsigned int cpu)
 {
 	set_cpu_rq_start_time(cpu);
+	sched_rq_cpu_starting(cpu);
 	return 0;
 }
 
@@ -7415,11 +7420,8 @@ void __init sched_init_smp(void)
 static int __init migration_init(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
-	int err;
 
-	/* Initialize migration for the boot CPU */
-	err = migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
-	BUG_ON(err == NOTIFY_BAD);
+	sched_rq_cpu_starting(smp_processor_id());
 	migration_call(&migration_notifier, CPU_ONLINE, cpu);
 	register_cpu_notifier(&migration_notifier);
 
#11 lore raw

[tip:smp/hotplug] sched/migration: Move prepare transition to SCHED_STARTING state

sched/migration: Move prepare transition to SCHED_STARTING state
Commit-ID:  42ee97d78a69d580d240e79b69a3bb151472270c
Gitweb:     http://git.kernel.org/tip/42ee97d78a69d580d240e79b69a3bb151472270c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:15 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:54 +0200

sched/migration: Move prepare transition to SCHED_STARTING state

We can piggy pack that on the SCHED_STARTING state. It's not required before the cpu actually comes online. Name the function proper as it has nothing to do with migration.

---
 kernel/sched/core.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
kernel/sched/core.c +11 -9
index 0a31078..bafc308 100644
@@ -5424,11 +5424,6 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 
-	case CPU_UP_PREPARE:
-		rq->calc_load_update = calc_load_update;
-		account_reset_rq(rq);
-		break;
-
 	case CPU_ONLINE:
 		/* Update our root-domain */
 		raw_spin_lock_irqsave(&rq->lock, flags);
@@ -7139,9 +7134,19 @@ int sched_cpu_deactivate(unsigned int cpu)
 	return 0;
 }
 
+static void sched_rq_cpu_starting(unsigned int cpu)
+{
+	struct rq *rq = cpu_rq(cpu);
+
+	rq->calc_load_update = calc_load_update;
+	account_reset_rq(rq);
+	update_max_interval();
+}
+
 int sched_cpu_starting(unsigned int cpu)
 {
 	set_cpu_rq_start_time(cpu);
+	sched_rq_cpu_starting(cpu);
 	return 0;
 }
 
@@ -7182,11 +7187,8 @@ void __init sched_init_smp(void)
 static int __init migration_init(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
-	int err;
 
-	/* Initialize migration for the boot CPU */
-	err = migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
-	BUG_ON(err == NOTIFY_BAD);
+	sched_rq_cpu_starting(smp_processor_id());
 	migration_call(&migration_notifier, CPU_ONLINE, cpu);
 	register_cpu_notifier(&migration_notifier);
 
#12 lore raw

[tip:smp/hotplug] sched/migration: Move prepare transition to SCHED_STARTING state

In reply to Thomas Gleixner
sched/migration: Move prepare transition to SCHED_STARTING state
Commit-ID:  94baf7a5d882cde0b4d591f4ab89cc32ee39ac6a
Gitweb:     http://git.kernel.org/tip/94baf7a5d882cde0b4d591f4ab89cc32ee39ac6a
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:15 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:24 +0200

sched/migration: Move prepare transition to SCHED_STARTING state

We can piggy pack that on the SCHED_STARTING state. It's not required before the cpu actually comes online. Name the function proper as it has nothing to do with migration.

---
 kernel/sched/core.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
kernel/sched/core.c +11 -9
index 0a31078..bafc308 100644
@@ -5424,11 +5424,6 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 
-	case CPU_UP_PREPARE:
-		rq->calc_load_update = calc_load_update;
-		account_reset_rq(rq);
-		break;
-
 	case CPU_ONLINE:
 		/* Update our root-domain */
 		raw_spin_lock_irqsave(&rq->lock, flags);
@@ -7139,9 +7134,19 @@ int sched_cpu_deactivate(unsigned int cpu)
 	return 0;
 }
 
+static void sched_rq_cpu_starting(unsigned int cpu)
+{
+	struct rq *rq = cpu_rq(cpu);
+
+	rq->calc_load_update = calc_load_update;
+	account_reset_rq(rq);
+	update_max_interval();
+}
+
 int sched_cpu_starting(unsigned int cpu)
 {
 	set_cpu_rq_start_time(cpu);
+	sched_rq_cpu_starting(cpu);
 	return 0;
 }
 
@@ -7182,11 +7187,8 @@ void __init sched_init_smp(void)
 static int __init migration_init(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
-	int err;
 
-	/* Initialize migration for the boot CPU */
-	err = migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
-	BUG_ON(err == NOTIFY_BAD);
+	sched_rq_cpu_starting(smp_processor_id());
 	migration_call(&migration_notifier, CPU_ONLINE, cpu);
 	register_cpu_notifier(&migration_notifier);
 
#13 lore raw

PATCH 10/15 sched/migration: Move calc_load_migrate() into CPU_DYING

In reply to Thomas Gleixner

It really does not matter when we fold the load for the outgoing cpu. It's almost dead anyway, so there is no harm if we fail to fold the few microseconds which are required for going fully away.

---
 kernel/sched/core.c |    3 ---
 1 file changed, 3 deletions(-)
kernel/sched/core.c +0 -3
Index: b/kernel/sched/core.c
===================================================================
@@ -5685,9 +5685,6 @@ migration_call(struct notifier_block *nf
 		migrate_tasks(rq);
 		BUG_ON(rq->nr_running != 1); /* the migration thread */
 		raw_spin_unlock_irqrestore(&rq->lock, flags);
-		break;
-
-	case CPU_DEAD:
 		calc_load_migrate(rq);
 		break;
 #endif
#14 lore raw

[tip:smp/hotplug] sched/migration: Move calc_load_migrate() into CPU_DYING

sched/migration: Move calc_load_migrate() into CPU_DYING
Commit-ID:  5dd44d07d3d373f0f3981b506152e3d7df5f5b75
Gitweb:     http://git.kernel.org/tip/5dd44d07d3d373f0f3981b506152e3d7df5f5b75
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:16 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:54 +0200

sched/migration: Move calc_load_migrate() into CPU_DYING

It really does not matter when we fold the load for the outgoing cpu. It's almost dead anyway, so there is no harm if we fail to fold the few microseconds which are required for going fully away.

---
 kernel/sched/core.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/sched/core.c +0 -3
index bafc308..688e8a8 100644
@@ -5447,9 +5447,6 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		migrate_tasks(rq);
 		BUG_ON(rq->nr_running != 1); /* the migration thread */
 		raw_spin_unlock_irqrestore(&rq->lock, flags);
-		break;
-
-	case CPU_DEAD:
 		calc_load_migrate(rq);
 		break;
 #endif
#15 lore raw

[tip:smp/hotplug] sched/migration: Move calc_load_migrate() into CPU_DYING

In reply to Thomas Gleixner
sched/migration: Move calc_load_migrate() into CPU_DYING
Commit-ID:  e9cd8fa4fcfd67c95db9b87c0fff88fa23cb00e5
Gitweb:     http://git.kernel.org/tip/e9cd8fa4fcfd67c95db9b87c0fff88fa23cb00e5
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:16 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:25 +0200

sched/migration: Move calc_load_migrate() into CPU_DYING

It really does not matter when we fold the load for the outgoing cpu. It's almost dead anyway, so there is no harm if we fail to fold the few microseconds which are required for going fully away.

---
 kernel/sched/core.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/sched/core.c +0 -3
index bafc308..688e8a8 100644
@@ -5447,9 +5447,6 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		migrate_tasks(rq);
 		BUG_ON(rq->nr_running != 1); /* the migration thread */
 		raw_spin_unlock_irqrestore(&rq->lock, flags);
-		break;
-
-	case CPU_DEAD:
 		calc_load_migrate(rq);
 		break;
 #endif
#16 lore raw

Re: [patch 10/15] sched/migration: Move calc_load_migrate() into CPU_DYING

In reply to Thomas Gleixner

Hi Thomas,

Quoted 3 lines

It really does not matter when we fold the load for the outgoing cpu. It's almost dead anyway, so there is no harm if we fail to fold the few microseconds which are required for going fully away.

We are seeing the load average shoot up when hot unplugging CPUs (+1 for every CPU we offline) on ppc64. This reproduces on bare metal as well as inside a KVM guest. A bisect points at this commit.

As an example, a completely idle box with 128 CPUS and 112 hot unplugged:

# uptime
 04:35:30 up  1:23,  2 users,  load average: 112.43, 122.94, 125.54

Anton

#17 lore raw

Re: [patch 10/15] sched/migration: Move calc_load_migrate() into CPU_DYING

Anton,

Quoted 8 lines · Anton Blanchard
Quoted 3 lines

It really does not matter when we fold the load for the outgoing cpu. It's almost dead anyway, so there is no harm if we fail to fold the few microseconds which are required for going fully away.

We are seeing the load average shoot up when hot unplugging CPUs (+1 for every CPU we offline) on ppc64. This reproduces on bare metal as well as inside a KVM guest. A bisect points at this commit.

Quoted 5 lines

As an example, a completely idle box with 128 CPUS and 112 hot unplugged:

# uptime
 04:35:30 up  1:23,  2 users,  load average: 112.43, 122.94, 125.54

Yes, it's an off by one as we now call that from the task which is tearing down the cpu. Does the patch below fix it?

Thanks,

tglx

8<----------------------

Subject: sched/migration: Correct off by one in load migration
From: Thomas Gleixner <[email protected]>

The move of calc_load_migrate() from CPU_DEAD to CPU_DYING did not take into account that the function is now called from a thread running on the outgoing CPU. As a result a cpu unplug leakes a load of 1 into the global load accounting mechanism.

Fix it by adjusting for the currently running thread which calls calc_load_migrate().

Fixes e9cd8fa4fcfd: "sched/migration: Move calc_load_migrate() into CPU_DYING"

---

kernel/sched/core.c +4 -2
index 51d7105f529a..97ee9ac7e97c 100644
@@ -5394,13 +5394,15 @@ void idle_task_exit(void)
 /*
  * Since this CPU is going 'away' for a while, fold any nr_active delta
  * we might have. Assumes we're called after migrate_tasks() so that the
- * nr_active count is stable.
+ * nr_active count is stable. We need to take the teardown thread which
+ * is calling this into account, so we hand in adjust = 1 to the load
+ * calculation.
  *
  * Also see the comment "Global load-average calculations".
  */
 static void calc_load_migrate(struct rq *rq)
 {
-	long delta = calc_load_fold_active(rq);
+	long delta = calc_load_fold_active(rq, 1);
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 }
kernel/sched/loadavg.c +4 -4
index b0b93fd33af9..a2d6eb71f06b 100644
@@ -78,11 +78,11 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
 	loads[2] = (avenrun[2] + offset) << shift;
 }
 
-long calc_load_fold_active(struct rq *this_rq)
+long calc_load_fold_active(struct rq *this_rq, long adjust)
 {
 	long nr_active, delta = 0;
 
-	nr_active = this_rq->nr_running;
+	nr_active = this_rq->nr_running - adjust;
 	nr_active += (long)this_rq->nr_uninterruptible;
 
 	if (nr_active != this_rq->calc_load_active) {
@@ -188,7 +188,7 @@ void calc_load_enter_idle(void)
 	 * We're going into NOHZ mode, if there's any pending delta, fold it
 	 * into the pending idle delta.
 	 */
-	delta = calc_load_fold_active(this_rq);
+	delta = calc_load_fold_active(this_rq, 0);
 	if (delta) {
 		int idx = calc_load_write_idx();
 
@@ -389,7 +389,7 @@ void calc_global_load_tick(struct rq *this_rq)
 	if (time_before(jiffies, this_rq->calc_load_update))
 		return;
 
-	delta  = calc_load_fold_active(this_rq);
+	delta  = calc_load_fold_active(this_rq, 0);
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 
kernel/sched/sched.h +1 -1
index 7cbeb92a1cb9..898c0d2f18fe 100644
@@ -28,7 +28,7 @@ extern unsigned long calc_load_update;
 extern atomic_long_t calc_load_tasks;
 
 extern void calc_global_load_tick(struct rq *this_rq);
-extern long calc_load_fold_active(struct rq *this_rq);
+extern long calc_load_fold_active(struct rq *this_rq, long adjust);
 
 #ifdef CONFIG_SMP
 extern void cpu_load_update_active(struct rq *this_rq);
#18 lore raw

Re: [patch 10/15] sched/migration: Move calc_load_migrate() into CPU_DYING

Quoted 11 lines · Thomas Gleixner

Anton,

Quoted 8 lines · Anton Blanchard
Quoted 3 lines

It really does not matter when we fold the load for the outgoing cpu. It's almost dead anyway, so there is no harm if we fail to fold the few microseconds which are required for going fully away.

We are seeing the load average shoot up when hot unplugging CPUs (+1 for every CPU we offline) on ppc64. This reproduces on bare metal as well as inside a KVM guest. A bisect points at this commit.

Quoted 8 lines
Quoted 5 lines

As an example, a completely idle box with 128 CPUS and 112 hot unplugged:

# uptime
 04:35:30 up  1:23,  2 users,  load average: 112.43, 122.94, 125.54

Yes, it's an off by one as we now call that from the task which is tearing down the cpu. Does the patch below fix it?

Hi Thomas,

Yes this patch fixes the issue. I was able to recreate the problem and also verify with this patch on 4.7.0-rc7.

Quoted 15 lines

Thanks,

tglx

8<----------------------

Subject: sched/migration: Correct off by one in load migration
From: Thomas Gleixner <[email protected]>

The move of calc_load_migrate() from CPU_DEAD to CPU_DYING did not take into account that the function is now called from a thread running on the outgoing CPU. As a result a cpu unplug leakes a load of 1 into the global load accounting mechanism.

Quoted 5 lines

Fix it by adjusting for the currently running thread which calls calc_load_migrate().

Fixes e9cd8fa4fcfd: "sched/migration: Move calc_load_migrate() into CPU_DYING"
Quoted 31 lines

---

kernel/sched/core.c +4 -2
index 51d7105f529a..97ee9ac7e97c 100644
@@ -5394,13 +5394,15 @@ void idle_task_exit(void)
 /*
  * Since this CPU is going 'away' for a while, fold any nr_active delta
  * we might have. Assumes we're called after migrate_tasks() so that the
- * nr_active count is stable.
+ * nr_active count is stable. We need to take the teardown thread which
+ * is calling this into account, so we hand in adjust = 1 to the load
+ * calculation.
  *
  * Also see the comment "Global load-average calculations".
  */
 static void calc_load_migrate(struct rq *rq)
 {
-	long delta = calc_load_fold_active(rq);
+	long delta = calc_load_fold_active(rq, 1);
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 }
kernel/sched/loadavg.c +0 -0
index b0b93fd33af9..a2d6eb71f06b 100644
@@ -78,11 +78,11 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
 	loads[2] = (avenrun[2] + offset) << shift;

kernel/sched/loadavg.c void get_avenrun(unsigned long *loads, unsigned long offset, int shift) · line 86

Quoted 10 lines
kernel/sched/loadavg.c +2 -2
 }
 
-long calc_load_fold_active(struct rq *this_rq)
+long calc_load_fold_active(struct rq *this_rq, long adjust)
 {
 	long nr_active, delta = 0;
 
-	nr_active = this_rq->nr_running;
+	nr_active = this_rq->nr_running - adjust;
 	nr_active += (long)this_rq->nr_uninterruptible;
	if (nr_active != this_rq->calc_load_active) {
		delta = nr_active - this_rq->calc_load_active;
		this_rq->calc_load_active = nr_active;
	}

	return delta;

Does the above calculation hold good even if we send adjust=1 and bump down nr_active? Tested ok though :)

--Vaidy

#19 lore raw

Re: [patch 10/15] sched/migration: Move calc_load_migrate() into CPU_DYING

In reply to Thomas Gleixner

Hi,

Quoted 11 lines · Thomas Gleixner

Anton,

Quoted 8 lines · Anton Blanchard
Quoted 3 lines

It really does not matter when we fold the load for the outgoing cpu. It's almost dead anyway, so there is no harm if we fail to fold the few microseconds which are required for going fully away.

We are seeing the load average shoot up when hot unplugging CPUs (+1 for every CPU we offline) on ppc64. This reproduces on bare metal as well as inside a KVM guest. A bisect points at this commit.

Quoted 8 lines
Quoted 5 lines

As an example, a completely idle box with 128 CPUS and 112 hot unplugged:

# uptime
 04:35:30 up  1:23,  2 users,  load average: 112.43, 122.94, 125.54

Yes, it's an off by one as we now call that from the task which is tearing down the cpu. Does the patch below fix it?

Tested your patch to see that on an idle box on offlinig the cpus I dont see increase in loadaverage.

# uptime
01:27:44 up 10 min,  1 user,  load average: 0.00, 0.18, 0.18
# lscpu | grep -Ei "on-line|off-line"
On-line CPU(s) list:   0-127
# ppc64_cpu --cores-on=2
# lscpu | grep -Ei "on-line|off-line"
On-line CPU(s) list:   0-15
Off-line CPU(s) list:  16-127
# sleep 60
# uptime
 01:28:52 up 11 min,  1 user,  load average: 0.11, 0.19, 0.18

Thanks and Regards,
Shilpa

Quoted 96 lines

Thanks,

tglx

8<----------------------

Subject: sched/migration: Correct off by one in load migration
From: Thomas Gleixner <[email protected]>

The move of calc_load_migrate() from CPU_DEAD to CPU_DYING did not take into account that the function is now called from a thread running on the outgoing CPU. As a result a cpu unplug leakes a load of 1 into the global load accounting mechanism.

Fix it by adjusting for the currently running thread which calls calc_load_migrate().

Fixes e9cd8fa4fcfd: "sched/migration: Move calc_load_migrate() into CPU_DYING"

---

kernel/sched/core.c +4 -2
index 51d7105f529a..97ee9ac7e97c 100644
@@ -5394,13 +5394,15 @@ void idle_task_exit(void)
 /*
  * Since this CPU is going 'away' for a while, fold any nr_active delta
  * we might have. Assumes we're called after migrate_tasks() so that the
- * nr_active count is stable.
+ * nr_active count is stable. We need to take the teardown thread which
+ * is calling this into account, so we hand in adjust = 1 to the load
+ * calculation.
  *
  * Also see the comment "Global load-average calculations".
  */
 static void calc_load_migrate(struct rq *rq)
 {
-	long delta = calc_load_fold_active(rq);
+	long delta = calc_load_fold_active(rq, 1);
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 }
kernel/sched/loadavg.c +4 -4
index b0b93fd33af9..a2d6eb71f06b 100644
@@ -78,11 +78,11 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
 	loads[2] = (avenrun[2] + offset) << shift;
 }
 
-long calc_load_fold_active(struct rq *this_rq)
+long calc_load_fold_active(struct rq *this_rq, long adjust)
 {
 	long nr_active, delta = 0;
 
-	nr_active = this_rq->nr_running;
+	nr_active = this_rq->nr_running - adjust;
 	nr_active += (long)this_rq->nr_uninterruptible;
 
 	if (nr_active != this_rq->calc_load_active) {
@@ -188,7 +188,7 @@ void calc_load_enter_idle(void)
 	 * We're going into NOHZ mode, if there's any pending delta, fold it
 	 * into the pending idle delta.
 	 */
-	delta = calc_load_fold_active(this_rq);
+	delta = calc_load_fold_active(this_rq, 0);
 	if (delta) {
 		int idx = calc_load_write_idx();
 
@@ -389,7 +389,7 @@ void calc_global_load_tick(struct rq *this_rq)
 	if (time_before(jiffies, this_rq->calc_load_update))
 		return;
 
-	delta  = calc_load_fold_active(this_rq);
+	delta  = calc_load_fold_active(this_rq, 0);
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 
kernel/sched/sched.h +1 -1
index 7cbeb92a1cb9..898c0d2f18fe 100644
@@ -28,7 +28,7 @@ extern unsigned long calc_load_update;
 extern atomic_long_t calc_load_tasks;
 
 extern void calc_global_load_tick(struct rq *this_rq);
-extern long calc_load_fold_active(struct rq *this_rq);
+extern long calc_load_fold_active(struct rq *this_rq, long adjust);
 
 #ifdef CONFIG_SMP
 extern void cpu_load_update_active(struct rq *this_rq);
maintainer
#20 lore raw

Re: [patch 10/15] sched/migration: Move calc_load_migrate() into CPU_DYING

In reply to Thomas Gleixner
Quoted 20 lines · Thomas Gleixner

Subject: sched/migration: Correct off by one in load migration
From: Thomas Gleixner <[email protected]>

The move of calc_load_migrate() from CPU_DEAD to CPU_DYING did not take into account that the function is now called from a thread running on the outgoing CPU. As a result a cpu unplug leakes a load of 1 into the global load accounting mechanism.

Fix it by adjusting for the currently running thread which calls calc_load_migrate().

Fixes e9cd8fa4fcfd: "sched/migration: Move calc_load_migrate() into CPU_DYING"

+++ b/kernel/sched/loadavg.c

kernel/sched/loadavg.c +0 -0
@@ -78,11 +78,11 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
 	loads[2] = (avenrun[2] + offset) << shift;
 }
 

kernel/sched/loadavg.c void get_avenrun(unsigned long *loads, unsigned long offset, int shift) · line 88

Quoted 10 lines
kernel/sched/loadavg.c +2 -2
-long calc_load_fold_active(struct rq *this_rq)
+long calc_load_fold_active(struct rq *this_rq, long adjust)
 {
 	long nr_active, delta = 0;
 
-	nr_active = this_rq->nr_running;
+	nr_active = this_rq->nr_running - adjust;
 	nr_active += (long)this_rq->nr_uninterruptible;
 
 	if (nr_active != this_rq->calc_load_active) {

Yeah, I think this is the only sensible approach.

How do you want to route this?

#21 lore raw

[tip:sched/urgent] sched/core: Correct off by one bug in load migration calculation

In reply to Thomas Gleixner
sched/core: Correct off by one bug in load migration calculation
Commit-ID:  d60585c5766e9620d5d83e2b25dc042c7bdada2c
Gitweb:     http://git.kernel.org/tip/d60585c5766e9620d5d83e2b25dc042c7bdada2c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 12 Jul 2016 18:33:56 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Jul 2016 14:58:20 +0200

sched/core: Correct off by one bug in load migration calculation

The move of calc_load_migrate() from CPU_DEAD to CPU_DYING did not take into account that the function is now called from a thread running on the outgoing CPU. As a result a cpu unplug leakes a load of 1 into the global load accounting mechanism.

Fix it by adjusting for the currently running thread which calls calc_load_migrate().

Cc Linus Torvalds <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Vaidyanathan Srinivasan <[email protected]>
Fixes e9cd8fa4fcfd: ("sched/migration: Move calc_load_migrate() into CPU_DYING")
---
 kernel/sched/core.c    | 6 ++++--
 kernel/sched/loadavg.c | 8 ++++----
 kernel/sched/sched.h   | 2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)
kernel/sched/core.c +4 -2
index 51d7105..97ee9ac 100644
@@ -5394,13 +5394,15 @@ void idle_task_exit(void)
 /*
  * Since this CPU is going 'away' for a while, fold any nr_active delta
  * we might have. Assumes we're called after migrate_tasks() so that the
- * nr_active count is stable.
+ * nr_active count is stable. We need to take the teardown thread which
+ * is calling this into account, so we hand in adjust = 1 to the load
+ * calculation.
  *
  * Also see the comment "Global load-average calculations".
  */
 static void calc_load_migrate(struct rq *rq)
 {
-	long delta = calc_load_fold_active(rq);
+	long delta = calc_load_fold_active(rq, 1);
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 }
kernel/sched/loadavg.c +4 -4
index b0b93fd..a2d6eb7 100644
@@ -78,11 +78,11 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
 	loads[2] = (avenrun[2] + offset) << shift;
 }
 
-long calc_load_fold_active(struct rq *this_rq)
+long calc_load_fold_active(struct rq *this_rq, long adjust)
 {
 	long nr_active, delta = 0;
 
-	nr_active = this_rq->nr_running;
+	nr_active = this_rq->nr_running - adjust;
 	nr_active += (long)this_rq->nr_uninterruptible;
 
 	if (nr_active != this_rq->calc_load_active) {
@@ -188,7 +188,7 @@ void calc_load_enter_idle(void)
 	 * We're going into NOHZ mode, if there's any pending delta, fold it
 	 * into the pending idle delta.
 	 */
-	delta = calc_load_fold_active(this_rq);
+	delta = calc_load_fold_active(this_rq, 0);
 	if (delta) {
 		int idx = calc_load_write_idx();
 
@@ -389,7 +389,7 @@ void calc_global_load_tick(struct rq *this_rq)
 	if (time_before(jiffies, this_rq->calc_load_update))
 		return;
 
-	delta  = calc_load_fold_active(this_rq);
+	delta  = calc_load_fold_active(this_rq, 0);
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 
kernel/sched/sched.h +1 -1
index 7cbeb92..898c0d2 100644
@@ -28,7 +28,7 @@ extern unsigned long calc_load_update;
 extern atomic_long_t calc_load_tasks;
 
 extern void calc_global_load_tick(struct rq *this_rq);
-extern long calc_load_fold_active(struct rq *this_rq);
+extern long calc_load_fold_active(struct rq *this_rq, long adjust);
 
 #ifdef CONFIG_SMP
 extern void cpu_load_update_active(struct rq *this_rq);
#22 lore raw

PATCH 11/15 sched/migration: Move CPU_ONLINE into scheduler state

In reply to Thomas Gleixner

The alleged requirement that the migration notifier has a lower priority than perf is completely undocumented and there is no indication at all that this is true. perf does not even handle the CPU_ONLINE notification and perf really has nothing to do with migration.

Move the CPU_ONLINE code into the sched_activate_cpu() state callback.

---
 kernel/sched/core.c |   33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
kernel/sched/core.c +22 -11
@@ -5662,17 +5662,6 @@ migration_call(struct notifier_block *nf
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 
-	case CPU_ONLINE:
-		/* Update our root-domain */
-		raw_spin_lock_irqsave(&rq->lock, flags);
-		if (rq->rd) {
-			BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
-
-			set_rq_online(rq);
-		}
-		raw_spin_unlock_irqrestore(&rq->lock, flags);
-		break;
-
 #ifdef CONFIG_HOTPLUG_CPU
 	case CPU_DYING:
 		sched_ttwu_pending();
@@ -7323,12 +7312,34 @@ static int cpuset_cpu_inactive(unsigned
 
 int sched_cpu_activate(unsigned int cpu)
 {
+	struct rq *rq = cpu_rq(cpu);
+	unsigned long flags;
+
 	set_cpu_active(cpu, true);
 
 	if (sched_smp_initialized) {
 		sched_domains_numa_masks_set(cpu);
 		cpuset_cpu_active();
 	}
+
+	/*
+	 * Put the rq online, if not already. This happens:
+	 *
+	 * 1) In the early boot process, because we build the real domains
+	 *    after all cpus have been brought up.
+	 *
+	 * 2) At runtime, if cpuset_cpu_active() fails to rebuild the
+	 *    domains.
+	 */
+	raw_spin_lock_irqsave(&rq->lock, flags);
+	if (rq->rd) {
+		BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
+		set_rq_online(rq);
+	}
+	raw_spin_unlock_irqrestore(&rq->lock, flags);
+
+	update_max_interval();
+
 	return 0;
 }
 
#23 lore raw

[tip:smp/hotplug] sched/migration: Move CPU_ONLINE into scheduler state

sched/migration: Move CPU_ONLINE into scheduler state
Commit-ID:  359aef5a0f04cf4bb62ae9e85a09b1b3608577ce
Gitweb:     http://git.kernel.org/tip/359aef5a0f04cf4bb62ae9e85a09b1b3608577ce
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:17 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:54 +0200

sched/migration: Move CPU_ONLINE into scheduler state

The alleged requirement that the migration notifier has a lower priority than perf is completely undocumented and there is no indication at all that this is true. perf does not even handle the CPU_ONLINE notification and perf really has nothing to do with migration.

Move the CPU_ONLINE code into the sched_activate_cpu() state callback.

---
 kernel/sched/core.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
kernel/sched/core.c +22 -11
index 688e8a8..8d8d903 100644
@@ -5424,17 +5424,6 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 
-	case CPU_ONLINE:
-		/* Update our root-domain */
-		raw_spin_lock_irqsave(&rq->lock, flags);
-		if (rq->rd) {
-			BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
-
-			set_rq_online(rq);
-		}
-		raw_spin_unlock_irqrestore(&rq->lock, flags);
-		break;
-
 #ifdef CONFIG_HOTPLUG_CPU
 	case CPU_DYING:
 		sched_ttwu_pending();
@@ -7090,12 +7079,34 @@ static int cpuset_cpu_inactive(unsigned int cpu)
 
 int sched_cpu_activate(unsigned int cpu)
 {
+	struct rq *rq = cpu_rq(cpu);
+	unsigned long flags;
+
 	set_cpu_active(cpu, true);
 
 	if (sched_smp_initialized) {
 		sched_domains_numa_masks_set(cpu);
 		cpuset_cpu_active();
 	}
+
+	/*
+	 * Put the rq online, if not already. This happens:
+	 *
+	 * 1) In the early boot process, because we build the real domains
+	 *    after all cpus have been brought up.
+	 *
+	 * 2) At runtime, if cpuset_cpu_active() fails to rebuild the
+	 *    domains.
+	 */
+	raw_spin_lock_irqsave(&rq->lock, flags);
+	if (rq->rd) {
+		BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
+		set_rq_online(rq);
+	}
+	raw_spin_unlock_irqrestore(&rq->lock, flags);
+
+	update_max_interval();
+
 	return 0;
 }
 
#24 lore raw

[tip:smp/hotplug] sched/migration: Move CPU_ONLINE into scheduler state

In reply to Thomas Gleixner
sched/migration: Move CPU_ONLINE into scheduler state
Commit-ID:  7d97669933eb94245ec9b715753753ec5ca8f646
Gitweb:     http://git.kernel.org/tip/7d97669933eb94245ec9b715753753ec5ca8f646
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:17 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:25 +0200

sched/migration: Move CPU_ONLINE into scheduler state

The alleged requirement that the migration notifier has a lower priority than perf is completely undocumented and there is no indication at all that this is true. perf does not even handle the CPU_ONLINE notification and perf really has nothing to do with migration.

Move the CPU_ONLINE code into the sched_activate_cpu() state callback.

---
 kernel/sched/core.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
kernel/sched/core.c +22 -11
index 688e8a8..8d8d903 100644
@@ -5424,17 +5424,6 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 
-	case CPU_ONLINE:
-		/* Update our root-domain */
-		raw_spin_lock_irqsave(&rq->lock, flags);
-		if (rq->rd) {
-			BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
-
-			set_rq_online(rq);
-		}
-		raw_spin_unlock_irqrestore(&rq->lock, flags);
-		break;
-
 #ifdef CONFIG_HOTPLUG_CPU
 	case CPU_DYING:
 		sched_ttwu_pending();
@@ -7090,12 +7079,34 @@ static int cpuset_cpu_inactive(unsigned int cpu)
 
 int sched_cpu_activate(unsigned int cpu)
 {
+	struct rq *rq = cpu_rq(cpu);
+	unsigned long flags;
+
 	set_cpu_active(cpu, true);
 
 	if (sched_smp_initialized) {
 		sched_domains_numa_masks_set(cpu);
 		cpuset_cpu_active();
 	}
+
+	/*
+	 * Put the rq online, if not already. This happens:
+	 *
+	 * 1) In the early boot process, because we build the real domains
+	 *    after all cpus have been brought up.
+	 *
+	 * 2) At runtime, if cpuset_cpu_active() fails to rebuild the
+	 *    domains.
+	 */
+	raw_spin_lock_irqsave(&rq->lock, flags);
+	if (rq->rd) {
+		BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
+		set_rq_online(rq);
+	}
+	raw_spin_unlock_irqrestore(&rq->lock, flags);
+
+	update_max_interval();
+
 	return 0;
 }
 
#25 lore raw

PATCH 12/15 sched/hotplug: Move migration CPU_DYING to sched_cpu_dying()

In reply to Thomas Gleixner

Remove the hotplug notifier and make it an explicit state.

---
 include/linux/cpu.h   |    2 -
 include/linux/sched.h |    1 
 kernel/cpu.c          |    2 -
 kernel/sched/core.c   |   70 ++++++++++++++------------------------------------
 4 files changed, 22 insertions(+), 53 deletions(-)
include/linux/cpu.h +0 -2
@@ -59,9 +59,7 @@ struct notifier_block;
  * CPU notifier priorities.
  */
 enum {
-	/* migration should happen before other stuff but after perf */
 	CPU_PRI_PERF		= 20,
-	CPU_PRI_MIGRATION	= 10,
 
 	/* bring up workqueues before normal notifiers and down after */
 	CPU_PRI_WORKQUEUE_UP	= 5,
include/linux/sched.h +1 -0
@@ -374,6 +374,7 @@ extern void trap_init(void);
 extern void update_process_times(int user);
 extern void scheduler_tick(void);
 extern int sched_cpu_starting(unsigned int cpu);
+extern int sched_cpu_dying(unsigned int cpu);
 extern int sched_cpu_activate(unsigned int cpu);
 extern int sched_cpu_deactivate(unsigned int cpu);
 
kernel/cpu.c +1 -1
@@ -1204,7 +1204,7 @@ static struct cpuhp_step cpuhp_ap_states
 	[CPUHP_AP_SCHED_STARTING] = {
 		.name			= "sched:starting",
 		.startup		= sched_cpu_starting,
-		.teardown		= NULL,
+		.teardown		= sched_cpu_dying,
 	},
 	/*
 	 * Low level startup/teardown notifiers. Run with interrupts
kernel/sched/core.c +20 -50

89 lines not on this page · raw message

#26 lore raw

[tip:smp/hotplug] sched/hotplug: Move migration CPU_DYING to sched_cpu_dying()

sched/hotplug: Move migration CPU_DYING to sched_cpu_dying()
Commit-ID:  9c793cb19c6ab8812c80a4897e6d7554fa9f77f1
Gitweb:     http://git.kernel.org/tip/9c793cb19c6ab8812c80a4897e6d7554fa9f77f1
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:18 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:54 +0200

sched/hotplug: Move migration CPU_DYING to sched_cpu_dying()

Remove the hotplug notifier and make it an explicit state.

---
 include/linux/cpu.h   |  2 --
 include/linux/sched.h |  1 +
 kernel/cpu.c          |  2 +-
 kernel/sched/core.c   | 70 +++++++++++++++------------------------------------
 4 files changed, 22 insertions(+), 53 deletions(-)
include/linux/cpu.h +0 -2
index b22b000..21597dc 100644
@@ -59,9 +59,7 @@ struct notifier_block;
  * CPU notifier priorities.
  */
 enum {
-	/* migration should happen before other stuff but after perf */
 	CPU_PRI_PERF		= 20,
-	CPU_PRI_MIGRATION	= 10,
 
 	/* bring up workqueues before normal notifiers and down after */
 	CPU_PRI_WORKQUEUE_UP	= 5,
include/linux/sched.h +1 -0
index 1e5f961..0e9e18a 100644
@@ -373,6 +373,7 @@ extern void trap_init(void);
 extern void update_process_times(int user);
 extern void scheduler_tick(void);
 extern int sched_cpu_starting(unsigned int cpu);
+extern int sched_cpu_dying(unsigned int cpu);
 extern int sched_cpu_activate(unsigned int cpu);
 extern int sched_cpu_deactivate(unsigned int cpu);
 
kernel/cpu.c +1 -1
index c134a35..d6eeb8c 100644
@@ -1223,7 +1223,7 @@ static struct cpuhp_step cpuhp_ap_states[] = {
 	[CPUHP_AP_SCHED_STARTING] = {
 		.name			= "sched:starting",
 		.startup		= sched_cpu_starting,
-		.teardown		= NULL,
+		.teardown		= sched_cpu_dying,
 	},
 	/*
 	 * Low level startup/teardown notifiers. Run with interrupts
kernel/sched/core.c +20 -50

89 lines not on this page · raw message

#27 lore raw

[tip:smp/hotplug] sched/hotplug: Move migration CPU_DYING to sched_cpu_dying()

In reply to Thomas Gleixner
sched/hotplug: Move migration CPU_DYING to sched_cpu_dying()
Commit-ID:  f2785ddb5367e217365099294b89d6a84668069e
Gitweb:     http://git.kernel.org/tip/f2785ddb5367e217365099294b89d6a84668069e
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:18 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:25 +0200

sched/hotplug: Move migration CPU_DYING to sched_cpu_dying()

Remove the hotplug notifier and make it an explicit state.

---
 include/linux/cpu.h   |  2 --
 include/linux/sched.h |  6 +++++
 kernel/cpu.c          |  2 +-
 kernel/sched/core.c   | 72 ++++++++++++++++-----------------------------------
 4 files changed, 29 insertions(+), 53 deletions(-)
include/linux/cpu.h +0 -2
index b22b000..21597dc 100644
@@ -59,9 +59,7 @@ struct notifier_block;
  * CPU notifier priorities.
  */
 enum {
-	/* migration should happen before other stuff but after perf */
 	CPU_PRI_PERF		= 20,
-	CPU_PRI_MIGRATION	= 10,
 
 	/* bring up workqueues before normal notifiers and down after */
 	CPU_PRI_WORKQUEUE_UP	= 5,
include/linux/sched.h +6 -0
index 1e5f961..47835cf 100644
@@ -376,6 +376,12 @@ extern int sched_cpu_starting(unsigned int cpu);
 extern int sched_cpu_activate(unsigned int cpu);
 extern int sched_cpu_deactivate(unsigned int cpu);
 
+#ifdef CONFIG_HOTPLUG_CPU
+extern int sched_cpu_dying(unsigned int cpu);
+#else
+# define sched_cpu_dying	NULL
+#endif
+
 extern void sched_show_task(struct task_struct *p);
 
 #ifdef CONFIG_LOCKUP_DETECTOR
kernel/cpu.c +1 -1
index c134a35..d6eeb8c 100644
@@ -1223,7 +1223,7 @@ static struct cpuhp_step cpuhp_ap_states[] = {
 	[CPUHP_AP_SCHED_STARTING] = {
 		.name			= "sched:starting",
 		.startup		= sched_cpu_starting,
-		.teardown		= NULL,
+		.teardown		= sched_cpu_dying,
 	},
 	/*
 	 * Low level startup/teardown notifiers. Run with interrupts
kernel/sched/core.c +22 -50

91 lines not on this page · raw message

#28 lore raw

PATCH 13/15 sched/hotplug: Make activate() the last hotplug step

In reply to Thomas Gleixner

The scheduler can handle per cpu threads before the cpu is set to active and it does not allow user space threads on the cpu before active is set. Attaching to the scheduling domains is also not required before user space threads can be handled.

Move the activation to the end of the hotplug state space. That also means that deactivation is the first action when a cpu is shut down.

---
 include/linux/cpuhotplug.h |    2 +-
 kernel/cpu.c               |   13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/cpuhotplug.h +1 -1
@@ -13,11 +13,11 @@ enum cpuhp_state {
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
 	CPUHP_AP_ONLINE_IDLE,
-	CPUHP_AP_ACTIVE,
 	CPUHP_AP_SMPBOOT_THREADS,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_ACTIVE,
 	CPUHP_ONLINE,
 };
 
kernel/cpu.c +7 -6
@@ -1223,12 +1223,6 @@ static struct cpuhp_step cpuhp_ap_states
 	[CPUHP_AP_ONLINE] = {
 		.name			= "ap:online",
 	},
-	/* First state is scheduler control. Interrupts are enabled */
-	[CPUHP_AP_ACTIVE] = {
-		.name			= "sched:active",
-		.startup		= sched_cpu_activate,
-		.teardown		= sched_cpu_deactivate,
-	},
 	/* Handle smpboot threads park/unpark */
 	[CPUHP_AP_SMPBOOT_THREADS] = {
 		.name			= "smpboot:threads",
@@ -1249,6 +1243,13 @@ static struct cpuhp_step cpuhp_ap_states
 	 * The dynamically registered state space is here
 	 */
 
+	/* Last state is scheduler control setting the cpu active */
+	[CPUHP_AP_ACTIVE] = {
+		.name			= "sched:active",
+		.startup		= sched_cpu_activate,
+		.teardown		= sched_cpu_deactivate,
+	},
+
 	/* CPU is fully up and running. */
 	[CPUHP_ONLINE] = {
 		.name			= "online",
#29 lore raw

[tip:smp/hotplug] sched/hotplug: Make activate() the last hotplug step

sched/hotplug: Make activate() the last hotplug step
Commit-ID:  b4f43a28647291a7dc1773924b77bc5ee7eccb16
Gitweb:     http://git.kernel.org/tip/b4f43a28647291a7dc1773924b77bc5ee7eccb16
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:19 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:54 +0200

sched/hotplug: Make activate() the last hotplug step

The scheduler can handle per cpu threads before the cpu is set to active and it does not allow user space threads on the cpu before active is set. Attaching to the scheduling domains is also not required before user space threads can be handled.

Move the activation to the end of the hotplug state space. That also means that deactivation is the first action when a cpu is shut down.

---
 include/linux/cpuhotplug.h |  2 +-
 kernel/cpu.c               | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/cpuhotplug.h +1 -1
index 9e07468..386374d 100644
@@ -13,11 +13,11 @@ enum cpuhp_state {
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
 	CPUHP_AP_ONLINE_IDLE,
-	CPUHP_AP_ACTIVE,
 	CPUHP_AP_SMPBOOT_THREADS,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_ACTIVE,
 	CPUHP_ONLINE,
 };
 
kernel/cpu.c +7 -6
index d6eeb8c..6180dd6 100644
@@ -1242,12 +1242,6 @@ static struct cpuhp_step cpuhp_ap_states[] = {
 	[CPUHP_AP_ONLINE] = {
 		.name			= "ap:online",
 	},
-	/* First state is scheduler control. Interrupts are enabled */
-	[CPUHP_AP_ACTIVE] = {
-		.name			= "sched:active",
-		.startup		= sched_cpu_activate,
-		.teardown		= sched_cpu_deactivate,
-	},
 	/* Handle smpboot threads park/unpark */
 	[CPUHP_AP_SMPBOOT_THREADS] = {
 		.name			= "smpboot:threads",
@@ -1269,6 +1263,13 @@ static struct cpuhp_step cpuhp_ap_states[] = {
 	 * The dynamically registered state space is here
 	 */
 
+	/* Last state is scheduler control setting the cpu active */
+	[CPUHP_AP_ACTIVE] = {
+		.name			= "sched:active",
+		.startup		= sched_cpu_activate,
+		.teardown		= sched_cpu_deactivate,
+	},
+
 	/* CPU is fully up and running. */
 	[CPUHP_ONLINE] = {
 		.name			= "online",
#30 lore raw

[tip:smp/hotplug] sched/hotplug: Make activate() the last hotplug step

In reply to Thomas Gleixner
sched/hotplug: Make activate() the last hotplug step
Commit-ID:  aaddd7d1c740ab3c5efaad7a34650b6dc680c21c
Gitweb:     http://git.kernel.org/tip/aaddd7d1c740ab3c5efaad7a34650b6dc680c21c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:19 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:25 +0200

sched/hotplug: Make activate() the last hotplug step

The scheduler can handle per cpu threads before the cpu is set to active and it does not allow user space threads on the cpu before active is set. Attaching to the scheduling domains is also not required before user space threads can be handled.

Move the activation to the end of the hotplug state space. That also means that deactivation is the first action when a cpu is shut down.

---
 include/linux/cpuhotplug.h |  2 +-
 kernel/cpu.c               | 15 +++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)
include/linux/cpuhotplug.h +1 -1
index 9e07468..386374d 100644
@@ -13,11 +13,11 @@ enum cpuhp_state {
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
 	CPUHP_AP_ONLINE_IDLE,
-	CPUHP_AP_ACTIVE,
 	CPUHP_AP_SMPBOOT_THREADS,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_ACTIVE,
 	CPUHP_ONLINE,
 };
 
kernel/cpu.c +9 -6
index d6eeb8c..d948e44 100644
@@ -1242,12 +1242,6 @@ static struct cpuhp_step cpuhp_ap_states[] = {
 	[CPUHP_AP_ONLINE] = {
 		.name			= "ap:online",
 	},
-	/* First state is scheduler control. Interrupts are enabled */
-	[CPUHP_AP_ACTIVE] = {
-		.name			= "sched:active",
-		.startup		= sched_cpu_activate,
-		.teardown		= sched_cpu_deactivate,
-	},
 	/* Handle smpboot threads park/unpark */
 	[CPUHP_AP_SMPBOOT_THREADS] = {
 		.name			= "smpboot:threads",
@@ -1269,6 +1263,15 @@ static struct cpuhp_step cpuhp_ap_states[] = {
 	 * The dynamically registered state space is here
 	 */
 
+#ifdef CONFIG_SMP
+	/* Last state is scheduler control setting the cpu active */
+	[CPUHP_AP_ACTIVE] = {
+		.name			= "sched:active",
+		.startup		= sched_cpu_activate,
+		.teardown		= sched_cpu_deactivate,
+	},
+#endif
+
 	/* CPU is fully up and running. */
 	[CPUHP_ONLINE] = {
 		.name			= "online",
#31 lore raw

PATCH 14/15 sched/fair: Make ilb_notifier an explicit call

In reply to Thomas Gleixner

No need for an extra notifier.

---
 kernel/sched/core.c  |    1 +
 kernel/sched/fair.c  |   15 +--------------
 kernel/sched/sched.h |    4 ++++
 3 files changed, 6 insertions(+), 14 deletions(-)
kernel/sched/core.c +1 -0
Index: b/kernel/sched/core.c
===================================================================
@@ -7363,6 +7363,7 @@ int sched_cpu_dying(unsigned int cpu)
 	raw_spin_unlock_irqrestore(&rq->lock, flags);
 	calc_load_migrate(rq);
 	update_max_interval();
+	nohz_balance_exit_idle(cpu);
 	return 0;
 }
 
kernel/sched/fair.c +1 -14
Index: b/kernel/sched/fair.c
===================================================================
@@ -7602,7 +7602,7 @@ static void nohz_balancer_kick(void)
 	return;
 }
 
-static inline void nohz_balance_exit_idle(int cpu)
+void nohz_balance_exit_idle(unsigned int cpu)
 {
 	if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)))) {
 		/*
@@ -7675,18 +7675,6 @@ void nohz_balance_enter_idle(int cpu)
 	atomic_inc(&nohz.nr_cpus);
 	set_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
 }
-
-static int sched_ilb_notifier(struct notifier_block *nfb,
-					unsigned long action, void *hcpu)
-{
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DYING:
-		nohz_balance_exit_idle(smp_processor_id());
-		return NOTIFY_OK;
-	default:
-		return NOTIFY_DONE;
-	}
-}
 #endif
 
 static DEFINE_SPINLOCK(balancing);
@@ -8486,7 +8474,6 @@ void show_numa_stats(struct task_struct
 #ifdef CONFIG_NO_HZ_COMMON
 	nohz.next_balance = jiffies;
 	zalloc_cpumask_var(&nohz.idle_cpus_mask, GFP_NOWAIT);
-	cpu_notifier(sched_ilb_notifier, 0);
 #endif
 #endif /* SMP */
 
kernel/sched/sched.h +4 -0
Index: b/kernel/sched/sched.h
===================================================================
@@ -1688,6 +1688,10 @@ enum rq_nohz_flag_bits {
 };
 
 #define nohz_flags(cpu)	(&cpu_rq(cpu)->nohz_flags)
+
+extern void nohz_balance_exit_idle(unsigned int cpu);
+#else
+static inline void nohz_balance_exit_idle(unsigned int cpu) { }
 #endif
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
#32 lore raw

[tip:smp/hotplug] sched/fair: Make ilb_notifier an explicit call

sched/fair: Make ilb_notifier an explicit call
Commit-ID:  95217bbf05fe4197e810757261332413fc5764e5
Gitweb:     http://git.kernel.org/tip/95217bbf05fe4197e810757261332413fc5764e5
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:20 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:55 +0200

sched/fair: Make ilb_notifier an explicit call

No need for an extra notifier.

---
 kernel/sched/core.c  |  1 +
 kernel/sched/fair.c  | 15 +--------------
 kernel/sched/sched.h |  4 ++++
 3 files changed, 6 insertions(+), 14 deletions(-)
kernel/sched/core.c +1 -0
index db92285..8d59c31 100644
@@ -7130,6 +7130,7 @@ int sched_cpu_dying(unsigned int cpu)
 	raw_spin_unlock_irqrestore(&rq->lock, flags);
 	calc_load_migrate(rq);
 	update_max_interval();
+	nohz_balance_exit_idle(cpu);
 	return 0;
 }
 
kernel/sched/fair.c +1 -14
index 0fe30e6..8b6db36 100644
@@ -7711,7 +7711,7 @@ static void nohz_balancer_kick(void)
 	return;
 }
 
-static inline void nohz_balance_exit_idle(int cpu)
+void nohz_balance_exit_idle(unsigned int cpu)
 {
 	if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)))) {
 		/*
@@ -7784,18 +7784,6 @@ void nohz_balance_enter_idle(int cpu)
 	atomic_inc(&nohz.nr_cpus);
 	set_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
 }
-
-static int sched_ilb_notifier(struct notifier_block *nfb,
-					unsigned long action, void *hcpu)
-{
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DYING:
-		nohz_balance_exit_idle(smp_processor_id());
-		return NOTIFY_OK;
-	default:
-		return NOTIFY_DONE;
-	}
-}
 #endif
 
 static DEFINE_SPINLOCK(balancing);
@@ -8600,7 +8588,6 @@ __init void init_sched_fair_class(void)
 #ifdef CONFIG_NO_HZ_COMMON
 	nohz.next_balance = jiffies;
 	zalloc_cpumask_var(&nohz.idle_cpus_mask, GFP_NOWAIT);
-	cpu_notifier(sched_ilb_notifier, 0);
 #endif
 #endif /* SMP */
 
kernel/sched/sched.h +4 -0
index ec2e8d2..16a27b6 100644
@@ -1743,6 +1743,10 @@ enum rq_nohz_flag_bits {
 };
 
 #define nohz_flags(cpu)	(&cpu_rq(cpu)->nohz_flags)
+
+extern void nohz_balance_exit_idle(unsigned int cpu);
+#else
+static inline void nohz_balance_exit_idle(unsigned int cpu) { }
 #endif
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
#33 lore raw

[tip:smp/hotplug] sched/fair: Make ilb_notifier an explicit call

In reply to Thomas Gleixner
sched/fair: Make ilb_notifier an explicit call
Commit-ID:  20a5c8cc74ade5027c2b0e2bc724278afd6054f3
Gitweb:     http://git.kernel.org/tip/20a5c8cc74ade5027c2b0e2bc724278afd6054f3
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:20 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:26 +0200

sched/fair: Make ilb_notifier an explicit call

No need for an extra notifier.

---
 kernel/sched/core.c  |  1 +
 kernel/sched/fair.c  | 15 +--------------
 kernel/sched/sched.h |  4 ++++
 3 files changed, 6 insertions(+), 14 deletions(-)
kernel/sched/core.c +1 -0
index a9a65ed..28ffd68 100644
@@ -7131,6 +7131,7 @@ int sched_cpu_dying(unsigned int cpu)
 	raw_spin_unlock_irqrestore(&rq->lock, flags);
 	calc_load_migrate(rq);
 	update_max_interval();
+	nohz_balance_exit_idle(cpu);
 	return 0;
 }
 #endif
kernel/sched/fair.c +1 -14
index 0fe30e6..8b6db36 100644
@@ -7711,7 +7711,7 @@ static void nohz_balancer_kick(void)
 	return;
 }
 
-static inline void nohz_balance_exit_idle(int cpu)
+void nohz_balance_exit_idle(unsigned int cpu)
 {
 	if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)))) {
 		/*
@@ -7784,18 +7784,6 @@ void nohz_balance_enter_idle(int cpu)
 	atomic_inc(&nohz.nr_cpus);
 	set_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
 }
-
-static int sched_ilb_notifier(struct notifier_block *nfb,
-					unsigned long action, void *hcpu)
-{
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DYING:
-		nohz_balance_exit_idle(smp_processor_id());
-		return NOTIFY_OK;
-	default:
-		return NOTIFY_DONE;
-	}
-}
 #endif
 
 static DEFINE_SPINLOCK(balancing);
@@ -8600,7 +8588,6 @@ __init void init_sched_fair_class(void)
 #ifdef CONFIG_NO_HZ_COMMON
 	nohz.next_balance = jiffies;
 	zalloc_cpumask_var(&nohz.idle_cpus_mask, GFP_NOWAIT);
-	cpu_notifier(sched_ilb_notifier, 0);
 #endif
 #endif /* SMP */
 
kernel/sched/sched.h +4 -0
index ec2e8d2..16a27b6 100644
@@ -1743,6 +1743,10 @@ enum rq_nohz_flag_bits {
 };
 
 #define nohz_flags(cpu)	(&cpu_rq(cpu)->nohz_flags)
+
+extern void nohz_balance_exit_idle(unsigned int cpu);
+#else
+static inline void nohz_balance_exit_idle(unsigned int cpu) { }
 #endif
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
#34 lore raw

PATCH 15/15 sched: Make hrtick_notifier an explicit call

In reply to Thomas Gleixner

No need for an extra notifier. We don't need to handle all these states. It's sufficient to kill the timer when the cpu dies.

---
 kernel/sched/core.c |   34 +---------------------------------
 1 file changed, 1 insertion(+), 33 deletions(-)
kernel/sched/core.c +1 -33
Index: b/kernel/sched/core.c
===================================================================
@@ -381,29 +381,6 @@ void hrtick_start(struct rq *rq, u64 del
 	}
 }
 
-static int
-hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu)
-{
-	int cpu = (int)(long)hcpu;
-
-	switch (action) {
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-	case CPU_DOWN_PREPARE:
-	case CPU_DOWN_PREPARE_FROZEN:
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		hrtick_clear(cpu_rq(cpu));
-		return NOTIFY_OK;
-	}
-
-	return NOTIFY_DONE;
-}
-
-static __init void init_hrtick(void)
-{
-	hotcpu_notifier(hotplug_hrtick, 0);
-}
 #else
 /*
  * Called to set the hrtick timer state.
@@ -420,10 +397,6 @@ void hrtick_start(struct rq *rq, u64 del
 	hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay),
 		      HRTIMER_MODE_REL_PINNED);
 }
-
-static inline void init_hrtick(void)
-{
-}
 #endif /* CONFIG_SMP */
 
 static void init_rq_hrtick(struct rq *rq)
@@ -447,10 +420,6 @@ static inline void hrtick_clear(struct r
 static inline void init_rq_hrtick(struct rq *rq)
 {
 }
-
-static inline void init_hrtick(void)
-{
-}
 #endif	/* CONFIG_SCHED_HRTICK */
 
 /*
@@ -7364,6 +7333,7 @@ int sched_cpu_dying(unsigned int cpu)
 	calc_load_migrate(rq);
 	update_max_interval();
 	nohz_balance_exit_idle(cpu);
+	hrtick_clear(rq);
 	return 0;
 }
 
@@ -7388,8 +7358,6 @@ void __init sched_init_smp(void)
 		cpumask_set_cpu(smp_processor_id(), non_isolated_cpus);
 	mutex_unlock(&sched_domains_mutex);
 
-	init_hrtick();
-
 	/* Move init over to a non-isolated CPU */
 	if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
 		BUG();
#35 lore raw

[tip:smp/hotplug] sched: Make hrtick_notifier an explicit call

sched: Make hrtick_notifier an explicit call
Commit-ID:  3a85aca729d63a1d09795b1e18b45890fe2ab0bf
Gitweb:     http://git.kernel.org/tip/3a85aca729d63a1d09795b1e18b45890fe2ab0bf
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:21 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 5 May 2016 13:17:55 +0200

sched: Make hrtick_notifier an explicit call

No need for an extra notifier. We don't need to handle all these states. It's sufficient to kill the timer when the cpu dies.

---
 kernel/sched/core.c | 34 +---------------------------------
 1 file changed, 1 insertion(+), 33 deletions(-)
kernel/sched/core.c +1 -33
index 8d59c31..2500ac1 100644
@@ -249,29 +249,6 @@ void hrtick_start(struct rq *rq, u64 delay)
 	}
 }
 
-static int
-hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu)
-{
-	int cpu = (int)(long)hcpu;
-
-	switch (action) {
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-	case CPU_DOWN_PREPARE:
-	case CPU_DOWN_PREPARE_FROZEN:
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		hrtick_clear(cpu_rq(cpu));
-		return NOTIFY_OK;
-	}
-
-	return NOTIFY_DONE;
-}
-
-static __init void init_hrtick(void)
-{
-	hotcpu_notifier(hotplug_hrtick, 0);
-}
 #else
 /*
  * Called to set the hrtick timer state.
@@ -288,10 +265,6 @@ void hrtick_start(struct rq *rq, u64 delay)
 	hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay),
 		      HRTIMER_MODE_REL_PINNED);
 }
-
-static inline void init_hrtick(void)
-{
-}
 #endif /* CONFIG_SMP */
 
 static void init_rq_hrtick(struct rq *rq)
@@ -315,10 +288,6 @@ static inline void hrtick_clear(struct rq *rq)
 static inline void init_rq_hrtick(struct rq *rq)
 {
 }
-
-static inline void init_hrtick(void)
-{
-}
 #endif	/* CONFIG_SCHED_HRTICK */
 
 /*
@@ -7131,6 +7100,7 @@ int sched_cpu_dying(unsigned int cpu)
 	calc_load_migrate(rq);
 	update_max_interval();
 	nohz_balance_exit_idle(cpu);
+	hrtick_clear(rq);
 	return 0;
 }
 
@@ -7155,8 +7125,6 @@ void __init sched_init_smp(void)
 		cpumask_set_cpu(smp_processor_id(), non_isolated_cpus);
 	mutex_unlock(&sched_domains_mutex);
 
-	init_hrtick();
-
 	/* Move init over to a non-isolated CPU */
 	if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
 		BUG();
#36 lore raw

[tip:smp/hotplug] sched: Make hrtick_notifier an explicit call

In reply to Thomas Gleixner
sched: Make hrtick_notifier an explicit call
Commit-ID:  e5ef27d0f5acf9f1db2882d7546a41c021f66820
Gitweb:     http://git.kernel.org/tip/e5ef27d0f5acf9f1db2882d7546a41c021f66820
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Thu, 10 Mar 2016 12:54:21 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 6 May 2016 14:58:26 +0200

sched: Make hrtick_notifier an explicit call

No need for an extra notifier. We don't need to handle all these states. It's sufficient to kill the timer when the cpu dies.

---
 kernel/sched/core.c | 34 +---------------------------------
 1 file changed, 1 insertion(+), 33 deletions(-)
kernel/sched/core.c +1 -33
index 28ffd68..9c710ad 100644
@@ -249,29 +249,6 @@ void hrtick_start(struct rq *rq, u64 delay)
 	}
 }
 
-static int
-hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu)
-{
-	int cpu = (int)(long)hcpu;
-
-	switch (action) {
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-	case CPU_DOWN_PREPARE:
-	case CPU_DOWN_PREPARE_FROZEN:
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		hrtick_clear(cpu_rq(cpu));
-		return NOTIFY_OK;
-	}
-
-	return NOTIFY_DONE;
-}
-
-static __init void init_hrtick(void)
-{
-	hotcpu_notifier(hotplug_hrtick, 0);
-}
 #else
 /*
  * Called to set the hrtick timer state.
@@ -288,10 +265,6 @@ void hrtick_start(struct rq *rq, u64 delay)
 	hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay),
 		      HRTIMER_MODE_REL_PINNED);
 }
-
-static inline void init_hrtick(void)
-{
-}
 #endif /* CONFIG_SMP */
 
 static void init_rq_hrtick(struct rq *rq)
@@ -315,10 +288,6 @@ static inline void hrtick_clear(struct rq *rq)
 static inline void init_rq_hrtick(struct rq *rq)
 {
 }
-
-static inline void init_hrtick(void)
-{
-}
 #endif	/* CONFIG_SCHED_HRTICK */
 
 /*
@@ -7132,6 +7101,7 @@ int sched_cpu_dying(unsigned int cpu)
 	calc_load_migrate(rq);
 	update_max_interval();
 	nohz_balance_exit_idle(cpu);
+	hrtick_clear(rq);
 	return 0;
 }
 #endif
@@ -7157,8 +7127,6 @@ void __init sched_init_smp(void)
 		cpumask_set_cpu(smp_processor_id(), non_isolated_cpus);
 	mutex_unlock(&sched_domains_mutex);
 
-	init_hrtick();
-
 	/* Move init over to a non-isolated CPU */
 	if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
 		BUG();
maintainer Acked-by on the v1 series
#37 lore raw
In reply to Thomas Gleixner
Quoted 10 lines · Thomas Gleixner

The following series contains:

- cleanup of the notifier maze in the scheduler and conversion to the state machine.

- Handling of cpu active is distangled from cpu online and moved to the end of the hotplug process.

Patches are against tip:master rather than against tip:smp/hotplug because there is an interaction with the accounting fix pending in sched/urgent.

I'm thinking you want this through the hotplug tree, so