]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make time slice a const
authorAustin Clements <austin@google.com>
Mon, 23 Mar 2015 17:27:24 +0000 (13:27 -0400)
committerAustin Clements <austin@google.com>
Tue, 14 Apr 2015 22:06:32 +0000 (22:06 +0000)
A G will be preempted if it runs for 10ms without blocking. Currently
this constant is hard-coded in retake. Move it to a global const.
We'll use the time slice length in scheduling background GC.

Change-Id: I79a979948af2fad3afe5df9d4af4062f166554b7
Reviewed-on: https://go-review.googlesource.com/8838
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/proc1.go

index 65f83e2caa44b60904ee6c05820bb5dae26dd1e0..e3565a6d3356ec9069510e0837cc790d214e786a 100644 (file)
@@ -2874,6 +2874,10 @@ var pdesc [_MaxGomaxprocs]struct {
        syscallwhen int64
 }
 
+// forcePreemptNS is the time slice given to a G before it is
+// preempted.
+const forcePreemptNS = 10 * 1000 * 1000 // 10ms
+
 func retake(now int64) uint32 {
        n := 0
        for i := int32(0); i < gomaxprocs; i++ {
@@ -2913,14 +2917,14 @@ func retake(now int64) uint32 {
                        }
                        incidlelocked(1)
                } else if s == _Prunning {
-                       // Preempt G if it's running for more than 10ms.
+                       // Preempt G if it's running for too long.
                        t := int64(_p_.schedtick)
                        if int64(pd.schedtick) != t {
                                pd.schedtick = uint32(t)
                                pd.schedwhen = now
                                continue
                        }
-                       if pd.schedwhen+10*1000*1000 > now {
+                       if pd.schedwhen+forcePreemptNS > now {
                                continue
                        }
                        preemptone(_p_)