From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [PATCH kvm-unit-tests v2 3/2] arm/arm64: smp: detect deadlock cycles Date: Sat, 3 Jun 2017 10:28:16 +0200 Message-ID: <20170603082816.15348-1-drjones@redhat.com> References: <20170602153109.2904-1-drjones@redhat.com> Cc: pbonzini@redhat.com, rkrcmar@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:49230 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750759AbdFCI2U (ORCPT ); Sat, 3 Jun 2017 04:28:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DB977F6A1 for ; Sat, 3 Jun 2017 08:28:20 +0000 (UTC) In-Reply-To: <20170602153109.2904-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Andrew Jones --- lib/arm/smp.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/arm/smp.c b/lib/arm/smp.c index bb999243de63..5a6209ebcbfd 100644 --- a/lib/arm/smp.c +++ b/lib/arm/smp.c @@ -80,6 +80,35 @@ struct on_cpu_info { }; static struct on_cpu_info on_cpu_info[NR_CPUS]; +static void __deadlock_check(int cpu, const cpumask_t *waiters, bool *found) +{ + int i; + + for_each_cpu(i, waiters) { + if (i == cpu) { + printf("CPU%d", cpu); + *found = true; + return; + } + __deadlock_check(cpu, &on_cpu_info[i].waiters, found); + if (*found) { + printf(" <=> CPU%d", i); + return; + } + } +} + +static void deadlock_check(int me, int cpu) +{ + bool found = false; + + __deadlock_check(cpu, &on_cpu_info[me].waiters, &found); + if (found) { + printf(" <=> CPU%d deadlock detectd\n", me); + assert(0); + } +} + static void cpu_wait(int cpu) { int me = smp_processor_id(); @@ -88,7 +117,7 @@ static void cpu_wait(int cpu) return; cpumask_set_cpu(me, &on_cpu_info[cpu].waiters); - assert_msg(!cpumask_test_cpu(cpu, &on_cpu_info[me].waiters), "CPU%d <=> CPU%d deadlock detected", me, cpu); + deadlock_check(me, cpu); while (!cpu_idle(cpu)) wfe(); cpumask_clear_cpu(me, &on_cpu_info[cpu].waiters); @@ -166,7 +195,7 @@ void on_cpus(void (*func)(void)) if (cpu == me) continue; cpumask_set_cpu(me, &on_cpu_info[cpu].waiters); - assert_msg(!cpumask_test_cpu(cpu, &on_cpu_info[me].waiters), "CPU%d <=> CPU%d deadlock detected", me, cpu); + deadlock_check(me, cpu); } while (cpumask_weight(&cpu_idle_mask) < nr_cpus - 1) wfe(); -- 2.9.4