• Dmitry Vyukov's avatar
    runtime: improve randomized stealing logic · ea0386f8
    Dmitry Vyukov authored
    During random stealing we steal 4*GOMAXPROCS times from random procs.
    One would expect that most of the time we check all procs this way,
    but due to low quality PRNG we actually miss procs with frightening
    probability. Below are modelling experiment results for 1e6 tries:
    
    GOMAXPROCS = 2 : missed 1 procs 7944 times
    
    GOMAXPROCS = 3 : missed 1 procs 101620 times
    GOMAXPROCS = 3 : missed 2 procs 3571 times
    
    GOMAXPROCS = 4 : missed 1 procs 63916 times
    GOMAXPROCS = 4 : missed 2 procs 61 times
    GOMAXPROCS = 4 : missed 3 procs 16 times
    
    GOMAXPROCS = 5 : missed 1 procs 133136 times
    GOMAXPROCS = 5 : missed 2 procs 1025 times
    GOMAXPROCS = 5 : missed 3 procs 101 times
    GOMAXPROCS = 5 : missed 4 procs 15 times
    
    GOMAXPROCS = 8 : missed 1 procs 151765 times
    GOMAXPROCS = 8 : missed 2 procs 5057 times
    GOMAXPROCS = 8 : missed 3 procs 1726 times
    GOMAXPROCS = 8 : missed 4 procs 68 times
    
    GOMAXPROCS = 12 : missed 1 procs 199081 times
    GOMAXPROCS = 12 : missed 2 procs 27489 times
    GOMAXPROCS = 12 : missed 3 procs 3113 times
    GOMAXPROCS = 12 : missed 4 procs 233 times
    GOMAXPROCS = 12 : missed 5 procs 9 times
    
    GOMAXPROCS = 16 : missed 1 procs 237477 times
    GOMAXPROCS = 16 : missed 2 procs 30037 times
    GOMAXPROCS = 16 : missed 3 procs 9466 times
    GOMAXPROCS = 16 : missed 4 procs 1334 times
    GOMAXPROCS = 16 : missed 5 procs 192 times
    GOMAXPROCS = 16 : missed 6 procs 5 times
    GOMAXPROCS = 16 : missed 7 procs 1 times
    GOMAXPROCS = 16 : missed 8 procs 1 times
    
    A missed proc won't lead to underutilization because we check all procs
    again after dropping P. But it can lead to an unpleasant situation
    when we miss a proc, drop P, check all procs, discover work, acquire P,
    miss the proc again, repeat.
    
    Improve stealing logic to cover all procs.
    Also don't enter spinning mode and try to steal when there is nobody around.
    
    Change-Id: Ibb6b122cc7fb836991bad7d0639b77c807aab4c2
    Reviewed-on: https://go-review.googlesource.com/20836Reviewed-by: 's avatarRick Hudson <rlh@golang.org>
    Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarAustin Clements <austin@google.com>
    Reviewed-by: 's avatarMarvin Stenger <marvin.stenger94@gmail.com>
    ea0386f8
proc_runtime_test.go 820 Bytes