Skip to contentSkip to conversation

PM/CPU: Parallel enalbing nonboot cpus with resume devices

RFC PATCH In review Lan Tianyu 3 participants 8 messages Sep 25, 2014 – Oct 22, 2014

Subsystems (2)
lore
Share & tools
lore

Lan Tianyu

author
#0 lore raw

v3 cover PM/CPU: Parallel enalbing nonboot cpus with resume devices

This patchset is to parallel enabling nonboot cpus with resuming devices during system resume in order to accelerate S2RAM. From test result on a 8 logical core Haswell machine, system resume time reduces from 347ms to 217ms with this patchset.

In the current world, all nonboot cpus are enabled serially during system resume. System resume sequence is that boot cpu enables nonboot cpu one by one and then resume devices. Before resuming devices, there are few tasks assigned to nonboot cpus after they are brought up. This wastes cpu usage.

This patchset is to allow boot cpu to go forward to resume devices after bringing up one nonboot cpu and starting a thread. The thread will be in charge of bringing up other frozen cpus. The thread will be scheduled to the first online cpu to run . This makes enabling cpu2~x parallel with resuming devices.

Patch 2 is to change the policy of init MTRR/PAT for nonboot cpus. Original code is to init all nonboot cpus' MTRR/PAT after all nonboot cpus coming online during system resume. Now parallel enabling nonboot cpus with resuming devices and nonboot cpus will be assigned with tasks before all cpus are online. So it's necessary to do init MTRR/PAT just after one nonboot cpus comes online just like dynamic single cpu online.

Patch 3 is to guarantee that all cpus are online before changing cpufreq_suspended flag in the cpufreq_resume() to avoid breaking cpufreq subsystem.

Lan Tianyu (3):
PM/CPU: Parallel enalbing nonboot cpus with resume devices X86/CPU: Initialize MTRR/PAT when each cpu is online during system
resume.
Cpufreq: Hold cpu_add_remove_lock before change cpufreq_suspended flag

 drivers/cpufreq/cpufreq.c |  2 ++
 kernel/cpu.c              | 64 +++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 55 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
author
#1 lore raw

RFC PATCH v3 1/3 PM/CPU: Parallel enalbing nonboot cpus with resume devices

In the current world, all nonboot cpus are enalbed serially during system resume. System resume sequence is that boot cpu enables nonboot cpu one by one and then resume devices. Before resuming devices, there are few tasks assigned to nonboot cpus after they are brought up. This waste cpu usage.

To accelerate S3, this patchset is to allow boot cpu to go forward to resume devices after bringing up one nonboot cpu and starting a thread. The thread will be in charge of bringing up other frozen cpus. The thread will be scheduled to the first online cpu to run . This makes enabling cpu2~x parallel with resuming devices.

---
 kernel/cpu.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 56 insertions(+), 11 deletions(-)
kernel/cpu.c +56 -11
index 356450f..24c4889 100644
@@ -572,8 +572,41 @@ void __weak arch_enable_nonboot_cpus_end(void)
 {
 }
 
+static int _cpu_up_for_pm(int cpu)
+{
+	int error;
+
+	trace_suspend_resume(TPS("CPU_ON"), cpu, true);
+	error = _cpu_up(cpu, 1);
+	trace_suspend_resume(TPS("CPU_ON"), cpu, false);
+	if (error) {
+		pr_warn("Error taking CPU%d up: %d\n", cpu, error);
+		return error;
+	}
+
+	pr_info("CPU%d is up\n", cpu);
+	return 0;
+}
+
+static int async_enable_nonboot_cpus(void *data)
+{
+	int cpu;
+
+	arch_enable_nonboot_cpus_begin();
+
+	for_each_cpu(cpu, frozen_cpus) {
+		_cpu_up_for_pm(cpu);
+	}
+
+	arch_enable_nonboot_cpus_end();
+	cpumask_clear(frozen_cpus);
+	cpu_maps_update_done();
+	return 0;
+}
+
 void __ref enable_nonboot_cpus(void)
 {
+	struct task_struct *tsk;
 	int cpu, error;
 
 	/* Allow everyone to use the CPU hotplug again */
@@ -584,21 +617,33 @@ void __ref enable_nonboot_cpus(void)
 
 	pr_info("Enabling non-boot CPUs ...\n");
 
-	arch_enable_nonboot_cpus_begin();
+	cpu = cpumask_first(frozen_cpus);
+	cpumask_clear_cpu(cpu, frozen_cpus);
+	error = _cpu_up_for_pm(cpu);
+	if (error) {
+		pr_err("Failed to bring up first non-boot cpu.\n");
+		goto fail;
+	}
 
-	for_each_cpu(cpu, frozen_cpus) {
-		trace_suspend_resume(TPS("CPU_ON"), cpu, true);
-		error = _cpu_up(cpu, 1);
-		trace_suspend_resume(TPS("CPU_ON"), cpu, false);
-		if (!error) {
-			pr_info("CPU%d is up\n", cpu);
-			continue;
-		}
-		pr_warn("Error taking CPU%d up: %d\n", cpu, error);
+	tsk = kthread_run(async_enable_nonboot_cpus,
+			NULL, "async-enable-nonboot-cpus");
+	if (IS_ERR(tsk)) {
+		pr_err("Failed to create async enable nonboot cpus thread.\n");
+		goto fail;
 	}
+	return;
 
+fail:
+	/*
+	 * If fail to bring up the first frozen cpu or
+	 * start async thread, enable these rest frozen cpus
+	 * on the boot cpu.
+	 */
+	arch_enable_nonboot_cpus_begin();
+	for_each_cpu(cpu, frozen_cpus) {
+		_cpu_up_for_pm(cpu);
+	}
 	arch_enable_nonboot_cpus_end();
-
 	cpumask_clear(frozen_cpus);
 out:
 	cpu_maps_update_done();
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
author
#2 lore raw

RFC PATCH v3 3/3 Cpufreq: Hold cpu_add_remove_lock before change cpufreq_suspended flag

In reply to Lan Tianyu

Now, enabling non-boot cpus will parallel with resuming devices. Cpu online may take place after cpufreq resume. But all cpu should be up before clearing cpufreq_suspended flag in the cpufreq_resume(). Cpufreq core uses this flag to decide to do light-weight init or full init. Light -weight init/tear down is dedicated for cpu hotplug during system pm. To keep this rule, hold cpu_add_remove_lock during changing cpufreq_suspended flag.

---
 drivers/cpufreq/cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/cpufreq/cpufreq.c +2 -0
index 37951ec..b03f7dd 100644
@@ -1689,7 +1689,9 @@ void cpufreq_resume(void)
 	if (!cpufreq_driver)
 		return;
 
+	cpu_maps_update_begin();
 	cpufreq_suspended = false;
+	cpu_maps_update_done();
 
 	if (!has_target())
 		return;
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
author
#3 lore raw

RFC PATCH v2 2/3 X86/CPU: Initialize MTRR/PAT when each cpu is online during system resume.

In reply to Lan Tianyu

SDM Vol 3a section titled "MTRR considerations in MP systems" specifies the need for synchronizing the logical cpu's while initializing/updating MTRR.

Commit d0af9eed5a(x86, pat/mtrr: Rendezvous all the cpus for MTRR/PAT init) delay the MTRR/PAT init for APs till all the logical cpu's come online and the rendezvous process at the end of AP's bringup, will initialize the MTRR/PAT for all AP's during boot and resume.

Currently, APs enabling are paralleled with resume devices during system resume and the AP will be assigned with task before all APs' bringup. MTRR/PAT should be initialized before running tasks. So this patch is to remove set_mtrr_aps_delayed_init() for system resume and do the MTRR/PAT init when the AP comes online just like dynamic single cpu online.

---
 kernel/cpu.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/cpu.c +0 -3
index 24c4889..30ffdd9 100644
@@ -592,13 +592,10 @@ static int async_enable_nonboot_cpus(void *data)
 {
 	int cpu;
 
-	arch_enable_nonboot_cpus_begin();
-
 	for_each_cpu(cpu, frozen_cpus) {
 		_cpu_up_for_pm(cpu);
 	}
 
-	arch_enable_nonboot_cpus_end();
 	cpumask_clear(frozen_cpus);
 	cpu_maps_update_done();
 	return 0;
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
maintainer
#4 lore raw
In reply to Lan Tianyu
Quoted 10 lines · Lan Tianyu

This patchset is to parallel enabling nonboot cpus with resuming devices during system resume in order to accelerate S2RAM. From test result on a 8 logical core Haswell machine, system resume time reduces from 347ms to 217ms with this patchset.

In the current world, all nonboot cpus are enabled serially during system resume. System resume sequence is that boot cpu enables nonboot cpu one by one and then resume devices. Before resuming devices, there are few tasks assigned to nonboot cpus after they are brought up. This wastes cpu usage.

Quoted 5 lines

This patchset is to allow boot cpu to go forward to resume devices after bringing up one nonboot cpu and starting a thread. The thread will be in charge of bringing up other frozen cpus. The thread will be scheduled to the first online cpu to run . This makes enabling cpu2~x parallel with resuming devices.

So I feel we should really clean up hotplug before doing anything like this. Its a trainwreck and just piling more and more hacks ontop isn't going to help any.

#5 lore raw
Quoted 17 lines · Peter Zijlstra
Quoted 10 lines · Lan Tianyu

This patchset is to parallel enabling nonboot cpus with resuming devices during system resume in order to accelerate S2RAM. From test result on a 8 logical core Haswell machine, system resume time reduces from 347ms to 217ms with this patchset.

In the current world, all nonboot cpus are enabled serially during system resume. System resume sequence is that boot cpu enables nonboot cpu one by one and then resume devices. Before resuming devices, there are few tasks assigned to nonboot cpus after they are brought up. This wastes cpu usage.

Quoted 5 lines

This patchset is to allow boot cpu to go forward to resume devices after bringing up one nonboot cpu and starting a thread. The thread will be in charge of bringing up other frozen cpus. The thread will be scheduled to the first online cpu to run . This makes enabling cpu2~x parallel with resuming devices.

Quoted 3 lines

So I feel we should really clean up hotplug before doing anything like this. Its a trainwreck and just piling more and more hacks ontop isn't going to help any.

Agreed.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
author
#6 lore raw
In reply to Peter Zijlstra
Quoted 17 lines · Peter Zijlstra
Quoted 10 lines · Lan Tianyu

This patchset is to parallel enabling nonboot cpus with resuming devices during system resume in order to accelerate S2RAM. From test result on a 8 logical core Haswell machine, system resume time reduces from 347ms to 217ms with this patchset.

In the current world, all nonboot cpus are enabled serially during system resume. System resume sequence is that boot cpu enables nonboot cpu one by one and then resume devices. Before resuming devices, there are few tasks assigned to nonboot cpus after they are brought up. This wastes cpu usage.

Quoted 5 lines

This patchset is to allow boot cpu to go forward to resume devices after bringing up one nonboot cpu and starting a thread. The thread will be in charge of bringing up other frozen cpus. The thread will be scheduled to the first online cpu to run . This makes enabling cpu2~x parallel with resuming devices.

Quoted 4 lines

So I feel we should really clean up hotplug before doing anything like this. Its a trainwreck and just piling more and more hacks ontop isn't going to help any.

Hi Peter:
Sorry, I don't know the gap of hotplug clearly. Could you elaborate it?

Signature · 2 lines
Best regards
Tianyu Lan
author
#7 lore raw
Quoted 18 lines · Lan Tianyu
Quoted 17 lines · Peter Zijlstra
Quoted 15 lines · Lan Tianyu

This patchset is to parallel enabling nonboot cpus with resuming devices during system resume in order to accelerate S2RAM. From test result on a 8 logical core Haswell machine, system resume time reduces from 347ms to 217ms with this patchset.

In the current world, all nonboot cpus are enabled serially during system resume. System resume sequence is that boot cpu enables nonboot cpu one by one and then resume devices. Before resuming devices, there are few tasks assigned to nonboot cpus after they are brought up. This wastes cpu usage.

This patchset is to allow boot cpu to go forward to resume devices after bringing up one nonboot cpu and starting a thread. The thread will be in charge of bringing up other frozen cpus. The thread will be scheduled to the first online cpu to run . This makes enabling cpu2~x parallel with resuming devices.

Quoted 8 lines
Quoted 4 lines

So I feel we should really clean up hotplug before doing anything like this. Its a trainwreck and just piling more and more hacks ontop isn't going to help any.

Hi Peter:
Sorry, I don't know the gap of hotplug clearly. Could you elaborate it?

Hi Peter:
Could you elaborate the gap of hotplug? Thanks.

Signature · 2 lines
Best regards
Tianyu Lan