]> Cypherpunks repositories - gostls13.git/commit
runtime: fix CPU underutilization
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 11 Jul 2013 19:57:36 +0000 (15:57 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 11 Jul 2013 19:57:36 +0000 (15:57 -0400)
commit32fef9908a6dcd523ae44766717662764e6c14ee
treed3bf16cf454dfdf9326b2b3ab2a271ada622d80b
parent735cf529833c3600a9518505977c2a25f32bb901
runtime: fix CPU underutilization
runtime.newproc/ready are deliberately sloppy about waking new M's,
they only ensure that there is at least 1 spinning M.
Currently to compensate for that, schedule() checks if the current P
has local work and there are no spinning M's, it wakes up another one.
It does not work if goroutines do not call schedule.
With this change a spinning M wakes up another M when it finds work to do.
It's also not ideal, but it fixes the underutilization.
A proper check would require to know the exact number of runnable G's,
but it's too expensive to maintain.
Fixes #5586.
This is reincarnation of cl/9776044 with the bug fixed.
The bug was due to code added after cl/9776044 was created:
if(tick - (((uint64)tick*0x4325c53fu)>>36)*61 == 0 && runtime·sched.runqsize > 0) {
        runtime·lock(&runtime·sched);
        gp = globrunqget(m->p, 1);
        runtime·unlock(&runtime·sched);
}
If M gets gp from global runq here, it does not reset m->spinning.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/10743044
src/pkg/runtime/proc.c
src/pkg/runtime/proc_test.go