61 lines
1.9 KiB
Diff
61 lines
1.9 KiB
Diff
diff --git a/util/coroutine-windows.c b/util/coroutine-windows.c
|
|
--- a/util/coroutine-windows.c
|
|
+++ b/util/coroutine-windows.c
|
|
@@ -26,6 +26,8 @@
|
|
#include "qemu/coroutine_int.h"
|
|
#include "qemu/coroutine-tls.h"
|
|
|
|
+#define COROUTINE_INITIAL_COMMIT_SIZE (64 * 1024)
|
|
+
|
|
typedef struct
|
|
{
|
|
Coroutine base;
|
|
@@ -71,11 +73,26 @@
|
|
|
|
Coroutine *qemu_coroutine_new(void)
|
|
{
|
|
const size_t stack_size = COROUTINE_STACK_SIZE;
|
|
+ const size_t commit_size = MIN(COROUTINE_INITIAL_COMMIT_SIZE, stack_size);
|
|
CoroutineWin32 *co;
|
|
|
|
co = g_malloc0(sizeof(*co));
|
|
- co->fiber = CreateFiber(stack_size, coroutine_trampoline, &co->base);
|
|
+ /*
|
|
+ * CreateFiber(stack_size, ...) commits the full 1 MiB stack up front,
|
|
+ * which can exhaust Windows commit charge during burst disk I/O + GPU
|
|
+ * workloads and return NULL (later crashing inside SwitchToFiber(NULL)
|
|
+ * reading 0x10). Reserve stack_size while committing only 64 KiB upfront.
|
|
+ */
|
|
+ co->fiber = CreateFiberEx(commit_size, stack_size, 0,
|
|
+ coroutine_trampoline, &co->base);
|
|
+ if (!co->fiber) {
|
|
+ fprintf(stderr,
|
|
+ "qemu_coroutine_new: CreateFiberEx(commit=%zu, reserve=%zu) failed: "
|
|
+ "GetLastError()=%lu\n",
|
|
+ commit_size, stack_size, (unsigned long)GetLastError());
|
|
+ abort();
|
|
+ }
|
|
return &co->base;
|
|
}
|
|
|
|
@@ -96,7 +113,18 @@
|
|
|
|
current = &leader->base;
|
|
set_current(current);
|
|
- leader->fiber = ConvertThreadToFiber(NULL);
|
|
+ if (IsThreadAFiber()) {
|
|
+ leader->fiber = GetCurrentFiber();
|
|
+ } else {
|
|
+ leader->fiber = ConvertThreadToFiber(NULL);
|
|
+ }
|
|
+ if (!leader->fiber) {
|
|
+ fprintf(stderr,
|
|
+ "qemu_coroutine_self: ConvertThreadToFiber failed: "
|
|
+ "GetLastError()=%lu\n",
|
|
+ (unsigned long)GetLastError());
|
|
+ abort();
|
|
+ }
|
|
}
|
|
return current;
|
|
}
|