DO NOT MERGE: suspend: dump trace to debug s2idle_wait_head timeout

Bug: 190429220
Change-Id: Iedab3580e811f7f428e4a1b41de58b96121d643f
Signed-off-by: Woody Lin <woodylin@google.com>
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index efe094b..81fb69c 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -211,6 +211,16 @@
 	s2idle_state = S2IDLE_STATE_NONE;
 }
 
+static void cpu_show_backtrace(void *unused)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	pr_info("Show CPU%d call trace:\n", smp_processor_id());
+	dump_stack();
+	local_irq_restore(flags);
+}
+
 static void s2idle_enter(void)
 {
 	trace_suspend_resume(TPS("machine_suspend"), PM_SUSPEND_TO_IDLE, true);
@@ -232,8 +242,12 @@
 	/* Push all the CPUs into the idle loop. */
 	wake_up_all_idle_cpus();
 	/* Make the current CPU wait so it can enter the idle loop too. */
-	wait_event(s2idle_wait_head,
-		   s2idle_state == S2IDLE_STATE_WAKE);
+	while (!wait_event_timeout(s2idle_wait_head,
+			   s2idle_state == S2IDLE_STATE_WAKE,
+			   msecs_to_jiffies(2000))) {
+		pr_info("s2idle_wait_head timeout, dump cores\n");
+		smp_call_function(cpu_show_backtrace, NULL, 0);
+	}
 
 	cpuidle_pause();
 	put_online_cpus();