From: David Woodhouse <dwmw@amazon.co.uk>
Date: Wed, 15 Dec 2021 08:11:49 +0000 (+0000)
Subject: timing debug
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7654028db2131e22b98c2f858c722bf0fd639e39;p=users%2Fdwmw2%2Flinux.git

timing debug
---

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index bed2b606211b6..060fdc4db8b0d 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1332,6 +1332,8 @@ unreg_nmi:
 	return ret;
 }
 
+extern cycles_t cpu_up_times[100];
+#define t cpu_up_times
 int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
 {
 	int ret;
@@ -1342,24 +1344,24 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
 		if (ret)
 			return ret;
 	}
-
+	t[3] = get_cycles();
 	ret = do_wait_cpu_initialized(cpu);
 	if (ret)
 		return ret;
-
+	t[4] = get_cycles();
 	ret = do_wait_cpu_callin(cpu);
 	if (ret)
 		return ret;
-
+	t[5] = get_cycles();
 	ret = do_wait_cpu_online(cpu);
-
+	t[6] = get_cycles();
 	if (x86_platform.legacy.warm_reset) {
 		/*
 		 * Cleanup possible dangling ends...
 		 */
 		smpboot_restore_warm_reset_vector();
 	}
-
+	t[7] = get_cycles();
 	return ret;
 }
 
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 9979f670501b0..583a2ec25efa2 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -554,12 +554,16 @@ static int cpuhp_kick_ap(struct cpuhp_cpu_state *st, enum cpuhp_state target)
 	return ret;
 }
 
+cycles_t cpu_up_times[100];
+#define t cpu_up_times
+
 static int bringup_wait_for_ap(unsigned int cpu)
 {
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 
 	/* Wait for the CPU to reach CPUHP_AP_ONLINE_IDLE */
 	wait_for_ap_thread(st, true);
+	t[9] = get_cycles();
 	if (WARN_ON_ONCE((!cpu_online(cpu))))
 		return -ECANCELED;
 
@@ -599,6 +603,7 @@ static int bringup_cpu(unsigned int cpu)
 	irq_unlock_sparse();
 	if (ret)
 		return ret;
+	t[8] = get_cycles();
 	return bringup_wait_for_ap(cpu);
 }
 
@@ -1333,6 +1338,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
 	if (st->state >= target)
 		goto out;
 
+	t[0] = get_cycles();
 	if (st->state == CPUHP_OFFLINE) {
 		/* Let it fail before we try to bring the cpu up */
 		idle = idle_thread_get(cpu);
@@ -1349,6 +1355,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
 	 * If the current CPU state is in the range of the AP hotplug thread,
 	 * then we need to kick the thread once more.
 	 */
+	t[1] = get_cycles();
 	if (st->state > CPUHP_BRINGUP_CPU) {
 		ret = cpuhp_kick_ap_work(cpu);
 		/*
@@ -1358,7 +1365,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
 		if (ret)
 			goto out;
 	}
-
+	t[2] = get_cycles();
 	/*
 	 * Try to reach the target state. We max out on the BP at
 	 * CPUHP_BRINGUP_CPU. After that the AP hotplug thread is
@@ -1366,6 +1373,11 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
 	 */
 	target = min((int)target, CPUHP_BRINGUP_CPU);
 	ret = cpuhp_up_callbacks(cpu, st, target);
+	t[10] = get_cycles();
+
+	printk("CPU %d to %d/%s in %lld %lld %lld %lld . %lld %lld %lld %lld . %lld %lld\n", cpu, target,
+	       cpuhp_hp_states[target].name, t[1] - t[0], t[2] - t[1], t[3] - t[2], t[4] - t[3],
+	       t[5] - t[4], t[6] - t[5], t[7] - t[6], t[8] - t[7], t[9] - t[8], t[10] - t[9]);
 out:
 	cpus_write_unlock();
 	arch_smt_update();