]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: disable dynamic priority boosting on windows
authorDmitriy Vyukov <dvyukov@google.com>
Sun, 4 Aug 2013 10:08:13 +0000 (14:08 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Sun, 4 Aug 2013 10:08:13 +0000 (14:08 +0400)
Windows dynamic priority boosting assumes that a process has different types
of dedicated threads -- GUI, IO, computational, etc. Go processes use
equivalent threads that all do a mix of GUI, IO, computations, etc.
In such context dynamic priority boosting does nothing but harm, so turn it off.
In particular, if 2 goroutines do heavy IO on a server uniprocessor machine,
windows rejects to schedule timer thread for 2+ seconds when priority boosting is enabled.
Fixes #5971.

R=alex.brainman
CC=golang-dev
https://golang.org/cl/12406043

src/pkg/net/timeout_test.go
src/pkg/runtime/netpoll_windows.c
src/pkg/runtime/os_windows.c

index ac552c05187c88b6e8728286e96aa783993b7ee7..2e92147b8e33e923390f92c9701a815d241b37dc 100644 (file)
@@ -423,8 +423,6 @@ func testVariousDeadlines(t *testing.T, maxProcs int) {
        switch runtime.GOOS {
        case "plan9":
                t.Skipf("skipping test on %q", runtime.GOOS)
-       case "windows":
-               t.Skipf("skipping test on %q, see issue 5971", runtime.GOOS)
        }
 
        defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(maxProcs))
index 972f1c30efb37251c4acf05714f2dc3f76e6fb70..e2153c540eab46574a64d3738bf03ac4b460c1c7 100644 (file)
@@ -78,8 +78,7 @@ retry:
        qty = 0;
        wait = INFINITE;
        if(!block)
-               // TODO(brainman): should use 0 here instead, but scheduler hogs CPU
-               wait = 1;
+               wait = 0;
        // TODO(brainman): Need a loop here to fetch all pending notifications
        // (or at least a batch). Scheduler will behave better if is given
        // a batch of newly runnable goroutines.
index d2ce9f8d11e560136eb9e01e985a393426c60391..ffd7e997e3091b55733a1f0539eae5e9061569d5 100644 (file)
@@ -24,6 +24,7 @@
 #pragma dynimport runtime·GetSystemTimeAsFileTime GetSystemTimeAsFileTime "kernel32.dll"
 #pragma dynimport runtime·GetThreadContext GetThreadContext "kernel32.dll"
 #pragma dynimport runtime·LoadLibrary LoadLibraryW "kernel32.dll"
+#pragma dynimport runtime·LoadLibraryA LoadLibraryA "kernel32.dll"
 #pragma dynimport runtime·ResumeThread ResumeThread "kernel32.dll"
 #pragma dynimport runtime·SetConsoleCtrlHandler SetConsoleCtrlHandler "kernel32.dll"
 #pragma dynimport runtime·SetEvent SetEvent "kernel32.dll"
@@ -55,6 +56,7 @@ extern void *runtime·GetSystemInfo;
 extern void *runtime·GetSystemTimeAsFileTime;
 extern void *runtime·GetThreadContext;
 extern void *runtime·LoadLibrary;
+extern void *runtime·LoadLibraryA;
 extern void *runtime·ResumeThread;
 extern void *runtime·SetConsoleCtrlHandler;
 extern void *runtime·SetEvent;
@@ -78,6 +80,9 @@ getproccount(void)
 void
 runtime·osinit(void)
 {
+       void *kernel32;
+       void *SetProcessPriorityBoost;
+
        // -1 = current process, -2 = current thread
        runtime·stdcall(runtime·DuplicateHandle, 7,
                (uintptr)-1, (uintptr)-2, (uintptr)-1, &m->thread,
@@ -85,6 +90,17 @@ runtime·osinit(void)
        runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (uintptr)1);
        runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1);
        runtime·ncpu = getproccount();
+
+       kernel32 = runtime·stdcall(runtime·LoadLibraryA, 1, "kernel32.dll");
+       if(kernel32 != nil) {
+               // Windows dynamic priority boosting assumes that a process has different types
+               // of dedicated threads -- GUI, IO, computational, etc. Go processes use
+               // equivalent threads that all do a mix of GUI, IO, computations, etc.
+               // In such context dynamic priority boosting does nothing but harm, so we turn it off.
+               SetProcessPriorityBoost = runtime·stdcall(runtime·GetProcAddress, 2, kernel32, "SetProcessPriorityBoost");
+               if(SetProcessPriorityBoost != nil)  // supported since Windows XP
+                       runtime·stdcall(SetProcessPriorityBoost, 2, (uintptr)-1, (uintptr)1);
+       }
 }
 
 void