qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <sw@weilnetz.de>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Olivier Hainque <hainque@adacore.com>,
	Stefan Weil <sw@weilnetz.de>,
	qemu-devel@nongnu.org, Fabien Chouteau <chouteau@adacore.com>
Subject: [Qemu-devel] [PATCH 1/4] Check effective suspension of TCG thread
Date: Fri, 12 Apr 2013 18:34:43 +0200	[thread overview]
Message-ID: <1365784486-617-2-git-send-email-sw@weilnetz.de> (raw)
In-Reply-To: <1365784486-617-1-git-send-email-sw@weilnetz.de>

From: Olivier Hainque <hainque@adacore.com>

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 <chouteau@adacore.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 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
 }
-- 
1.7.10.4

  reply	other threads:[~2013-04-12 16:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 16:34 [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Stefan Weil
2013-04-12 16:34 ` Stefan Weil [this message]
2013-04-12 16:34 ` [Qemu-devel] [PATCH 2/4] Ensure good ordering of memory instruction in cpu_exec Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 3/4] Release SMP restriction on Windows Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 4/4] qemu-timer: move timeBeginPeriod/timeEndPeriod to os-win32 Stefan Weil
2013-04-13 12:34 ` [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365784486-617-2-git-send-email-sw@weilnetz.de \
    --to=sw@weilnetz.de \
    --cc=aliguori@us.ibm.com \
    --cc=chouteau@adacore.com \
    --cc=hainque@adacore.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).