From patchwork Tue Apr 9 16:06:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien Chouteau X-Patchwork-Id: 235138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C35A82C009F for ; Wed, 10 Apr 2013 02:08:42 +1000 (EST) Received: from localhost ([::1]:36229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPb68-0007gP-Rm for incoming@patchwork.ozlabs.org; Tue, 09 Apr 2013 12:08:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPb4b-0005OO-Nk for qemu-devel@nongnu.org; Tue, 09 Apr 2013 12:07:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPb4Y-0004JM-Os for qemu-devel@nongnu.org; Tue, 09 Apr 2013 12:07:05 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:58698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPb4Y-0004H5-FY for qemu-devel@nongnu.org; Tue, 09 Apr 2013 12:07:02 -0400 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 232D5290007; Tue, 9 Apr 2013 18:07:01 +0200 (CEST) X-Virus-Scanned: amavisd-new at eu.adacore.com Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fLIROWUB0bcZ; Tue, 9 Apr 2013 18:07:01 +0200 (CEST) Received: from PomPomGalli.act-europe.fr (pompomgalli.act-europe.fr [10.10.1.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id E3C6E290039; Tue, 9 Apr 2013 18:07:00 +0200 (CEST) From: Fabien Chouteau To: qemu-devel@nongnu.org Date: Tue, 9 Apr 2013 18:06:53 +0200 Message-Id: <1365523615-5177-2-git-send-email-chouteau@adacore.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1365523615-5177-1-git-send-email-chouteau@adacore.com> References: <1365523615-5177-1-git-send-email-chouteau@adacore.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 194.98.77.210 Cc: hainque@adacore.com, peter.maydell@linaro.org, sw@weilnetz.de, blauwirbel@gmail.com, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 1/3] Check effective suspension of TCG thread X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Olivier Hainque On multi-core systems, SuspendThread does not guaranty immediate thread suspension. We add busy loop to wait for effective thread suspension after call to ThreadSuspend(). Signed-off-by: Fabien Chouteau --- cpus.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index e919dd7..97e9ab4 100644 --- a/cpus.c +++ b/cpus.c @@ -862,9 +862,29 @@ static void qemu_cpu_kick_thread(CPUState *cpu) } #else /* _WIN32 */ if (!qemu_cpu_is_self(cpu)) { - SuspendThread(cpu->hThread); + CONTEXT tcgContext; + + if (SuspendThread(cpu->hThread) == (DWORD)-1) { + fprintf(stderr, "qemu:%s: GetLastError:%d\n", __func__, + GetLastError()); + exit(1); + } + + /* On multi-core systems, we are not sure that the thread is actually + * suspended until we can get the context. + */ + tcgContext.ContextFlags = CONTEXT_CONTROL; + while (GetThreadContext(cpu->hThread, &tcgContext) != 0) { + continue; + } + cpu_signal(0); - ResumeThread(cpu->hThread); + + if (ResumeThread(cpu->hThread) == (DWORD)-1) { + fprintf(stderr, "qemu:%s: GetLastError:%d\n", __func__, + GetLastError()); + exit(1); + } } #endif }