]> Cypherpunks repositories - gostls13.git/commitdiff
time: use an alternative method of yielding during Overflow timer test
authorDave Cheney <dave@cheney.net>
Sun, 2 Feb 2014 05:05:07 +0000 (16:05 +1100)
committerDave Cheney <dave@cheney.net>
Sun, 2 Feb 2014 05:05:07 +0000 (16:05 +1100)
Fixes #6874.

Use runtime.GC() as a stronger version of runtime.Gosched() which tends to bias the running goroutine in an otherwise idle system. This appears to reduce the worst case number of spins from 600 down to 30 on my 2 core system under high load.

LGTM=iant
R=golang-codereviews, lucio.dere, iant, dvyukov
CC=golang-codereviews
https://golang.org/cl/56540046

src/pkg/time/internal_test.go
src/pkg/time/sleep_test.go

index d9592954b24d57e0453e2387a36d0a688ffd272a..4ba6d478debac433b4307e657be6251b97bad1a7 100644 (file)
@@ -78,7 +78,15 @@ func CheckRuntimeTimerOverflow() error {
                        if Now().After(stop) {
                                return errors.New("runtime timer stuck: overflow in addtimer")
                        }
-                       runtime.Gosched()
+                       // Issue 6874. This test previously called runtime.Gosched to try to yield
+                       // to the goroutine servicing t, however the scheduler has a bias towards the
+                       // previously running goroutine in an idle system. Combined with high load due
+                       // to all CPUs busy running tests t's goroutine could be delayed beyond the
+                       // timeout window.
+                       //
+                       // Calling runtime.GC() reduces the worst case lantency for scheduling t by 20x
+                       // under the current Go 1.3 scheduler.
+                       runtime.GC()
                }
        }
 }
index 46872595094e97a4d06a8b93c6a63ab751932005..23cb3daebbf35493cb8fcc7bb0de97c39d26943c 100644 (file)
@@ -398,6 +398,9 @@ func TestIssue5745(t *testing.T) {
 }
 
 func TestOverflowRuntimeTimer(t *testing.T) {
+       if testing.Short() {
+               t.Skip("skipping in short mode, see issue 6874")
+       }
        if err := CheckRuntimeTimerOverflow(); err != nil {
                t.Fatalf(err.Error())
        }