]> Cypherpunks repositories - gostls13.git/commit
runtime: preempt a goroutine which calls a lot of short system calls
authorAndrei Vagin <avagin@google.com>
Fri, 29 Mar 2019 17:43:31 +0000 (10:43 -0700)
committerDmitry Vyukov <dvyukov@google.com>
Tue, 9 Apr 2019 07:45:26 +0000 (07:45 +0000)
commit4166ff42c09cae4ca9e15154627e7cfc80586c65
tree135a22462d208dc313e3dd18369ae457362a6786
parent08e1823a632783e3f71b358f2f546ab0f13a6d98
runtime: preempt a goroutine which calls a lot of short system calls

A goroutine should be preempted if it runs for 10ms without blocking.
We found that this doesn't work for goroutines which call short system calls.

For example, the next program can stuck for seconds without this fix:

$ cat main.go
package main

import (
"runtime"
"syscall"
)

func main() {
runtime.GOMAXPROCS(1)
c := make(chan int)
go func() {
c <- 1
for {
t := syscall.Timespec{
Nsec: 300,
}
if true {
syscall.Nanosleep(&t, nil)
}
}
}()
<-c
}

$ time go run main.go

real 0m8.796s
user 0m0.367s
sys 0m0.893s

Updates #10958

Change-Id: Id3be54d3779cc28bfc8b33fe578f13778f1ae2a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/170138
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/runtime/export_test.go
src/runtime/proc.go
src/runtime/proc_test.go