* [Qemu-devel] [PATCH 1/4] Check effective suspension of TCG thread
2013-04-12 16:34 [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Stefan Weil
@ 2013-04-12 16:34 ` Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 2/4] Ensure good ordering of memory instruction in cpu_exec Stefan Weil
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Weil @ 2013-04-12 16:34 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Olivier Hainque, Stefan Weil, qemu-devel, Fabien Chouteau
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/4] Ensure good ordering of memory instruction in cpu_exec
2013-04-12 16:34 [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 1/4] Check effective suspension of TCG thread Stefan Weil
@ 2013-04-12 16:34 ` Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 3/4] Release SMP restriction on Windows Stefan Weil
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Weil @ 2013-04-12 16:34 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Olivier Hainque, Stefan Weil, qemu-devel, Fabien Chouteau
From: Olivier Hainque <hainque@adacore.com>
The IO thread, when it senses cpu_single_env == 0, expects exit_request
to be checked later on. A compiler scheduling constraint is not strong
enough to ensure this on modern architecture. A memory fence is needed
as well.
Signed-off-by: Olivier Hainque <hainque@adacore.com>
Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
cpu-exec.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/cpu-exec.c b/cpu-exec.c
index e74e556..aa8fa89 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -217,6 +217,14 @@ int cpu_exec(CPUArchState *env)
cpu_single_env = env;
+ /* As long as cpu_single_env is null, up to the assignment just above,
+ * requests by other threads to exit the execution loop are expected to
+ * be issued using the exit_request global. We must make sure that our
+ * evaluation of the global value is performed past the cpu_single_env
+ * value transition point, which requires a memory barrier as well as
+ * an instruction scheduling constraint on modern architectures. */
+ smp_mb();
+
if (unlikely(exit_request)) {
cpu->exit_request = 1;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/4] Release SMP restriction on Windows
2013-04-12 16:34 [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 1/4] Check effective suspension of TCG thread Stefan Weil
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 ` 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
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Weil @ 2013-04-12 16:34 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Stefan Weil, qemu-devel, Fabien Chouteau
From: Fabien Chouteau <chouteau@adacore.com>
The previous patches make QEMU SMP safe on Windows, we can now release
the restriction.
Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
os-win32.c | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/os-win32.c b/os-win32.c
index 9673a81..c7f6b5c 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -69,25 +69,7 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
void os_setup_early_signal_handling(void)
{
- /* Note: cpu_interrupt() is currently not SMP safe, so we force
- QEMU to run on a single CPU */
- HANDLE h;
- DWORD_PTR mask, smask;
- int i;
-
SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
-
- h = GetCurrentProcess();
- if (GetProcessAffinityMask(h, &mask, &smask)) {
- for(i = 0; i < 32; i++) {
- if (mask & (1 << i))
- break;
- }
- if (i != 32) {
- mask = 1 << i;
- SetProcessAffinityMask(h, mask);
- }
- }
}
/* Look for support files in the same directory as the executable. */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 4/4] qemu-timer: move timeBeginPeriod/timeEndPeriod to os-win32
2013-04-12 16:34 [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Stefan Weil
` (2 preceding siblings ...)
2013-04-12 16:34 ` [Qemu-devel] [PATCH 3/4] Release SMP restriction on Windows Stefan Weil
@ 2013-04-12 16:34 ` Stefan Weil
2013-04-13 12:34 ` [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Aurelien Jarno
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Weil @ 2013-04-12 16:34 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Paolo Bonzini, Stefan Weil, qemu-devel, qemu-stable
From: Paolo Bonzini <pbonzini@redhat.com>
These are needed for any of the Win32 alarm timer implementations.
They are not tied to mmtimer exclusively.
Jacob tested this patch with both mmtimer and Win32 timers.
Cc: qemu-stable@nongnu.org
Tested-by: Jacob Kroon <jacob.kroon@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
os-win32.c | 11 +++++++++++
qemu-timer.c | 24 ++++++------------------
2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/os-win32.c b/os-win32.c
index c7f6b5c..50b7f6f 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -23,6 +23,7 @@
* THE SOFTWARE.
*/
#include <windows.h>
+#include <mmsystem.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
@@ -67,9 +68,19 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
return TRUE;
}
+static TIMECAPS mm_tc;
+
+static void os_undo_timer_resolution(void)
+{
+ timeEndPeriod(mm_tc.wPeriodMin);
+}
+
void os_setup_early_signal_handling(void)
{
SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
+ timeGetDevCaps(&mm_tc, sizeof(mm_tc));
+ timeBeginPeriod(mm_tc.wPeriodMin);
+ atexit(os_undo_timer_resolution);
}
/* Look for support files in the same directory as the executable. */
diff --git a/qemu-timer.c b/qemu-timer.c
index 8fb5c75..b2d95e2 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -624,28 +624,14 @@ static void CALLBACK mm_alarm_handler(UINT uTimerID, UINT uMsg,
static int mm_start_timer(struct qemu_alarm_timer *t)
{
timeGetDevCaps(&mm_tc, sizeof(mm_tc));
-
- timeBeginPeriod(mm_tc.wPeriodMin);
-
- mm_timer = timeSetEvent(mm_tc.wPeriodMin, /* interval (ms) */
- mm_tc.wPeriodMin, /* resolution */
- mm_alarm_handler, /* function */
- (DWORD_PTR)t, /* parameter */
- TIME_ONESHOT | TIME_CALLBACK_FUNCTION);
-
- if (!mm_timer) {
- fprintf(stderr, "Failed to initialize win32 alarm timer\n");
- timeEndPeriod(mm_tc.wPeriodMin);
- return -1;
- }
-
return 0;
}
static void mm_stop_timer(struct qemu_alarm_timer *t)
{
- timeKillEvent(mm_timer);
- timeEndPeriod(mm_tc.wPeriodMin);
+ if (mm_timer) {
+ timeKillEvent(mm_timer);
+ }
}
static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta)
@@ -657,7 +643,9 @@ static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta)
nearest_delta_ms = mm_tc.wPeriodMax;
}
- timeKillEvent(mm_timer);
+ if (mm_timer) {
+ timeKillEvent(mm_timer);
+ }
mm_timer = timeSetEvent((UINT)nearest_delta_ms,
mm_tc.wPeriodMin,
mm_alarm_handler,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PULL 0/4] MinGW patches for QEMU
2013-04-12 16:34 [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Stefan Weil
` (3 preceding siblings ...)
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 ` Aurelien Jarno
4 siblings, 0 replies; 6+ messages in thread
From: Aurelien Jarno @ 2013-04-13 12:34 UTC (permalink / raw)
To: Stefan Weil; +Cc: Anthony Liguori, qemu-devel
On Fri, Apr 12, 2013 at 06:34:42PM +0200, Stefan Weil wrote:
> Hello Anthony,
>
> please pull these patches for QEMU git master.
> All of them were reviewed on qemu-devel.
>
> Thanks,
> Stefan W.
>
> The following changes since commit 93b48c201eb6c0404d15550a0eaa3c0f7937e35e:
>
> virtio-9p: Fix virtio-9p no longer building after hw-dirs branch merge (2013-04-09 07:47:00 -0500)
>
> are available in the git repository at:
>
> git://qemu.weilnetz.de/qemu.git mingw
>
> for you to fetch changes up to 0727b867542eea7fedfd2c53568e9782627fd3bd:
>
> qemu-timer: move timeBeginPeriod/timeEndPeriod to os-win32 (2013-04-12 18:27:16 +0200)
>
> ----------------------------------------------------------------
> Fabien Chouteau (1):
> Release SMP restriction on Windows
>
> Olivier Hainque (2):
> Check effective suspension of TCG thread
> Ensure good ordering of memory instruction in cpu_exec
>
> Paolo Bonzini (1):
> qemu-timer: move timeBeginPeriod/timeEndPeriod to os-win32
>
> cpu-exec.c | 8 ++++++++
> cpus.c | 24 ++++++++++++++++++++++--
> os-win32.c | 29 +++++++++++------------------
> qemu-timer.c | 24 ++++++------------------
> 4 files changed, 47 insertions(+), 38 deletions(-)
>
> [PATCH 1/4] Check effective suspension of TCG thread
> [PATCH 2/4] Ensure good ordering of memory instruction in cpu_exec
> [PATCH 3/4] Release SMP restriction on Windows
> [PATCH 4/4] qemu-timer: move timeBeginPeriod/timeEndPeriod to
>
Thanks, pulled.
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
^ permalink raw reply [flat|nested] 6+ messages in thread