diff options
| author | Keith Randall <khr@golang.org> | 2014-09-16 17:26:16 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2014-09-16 17:26:16 -0700 |
| commit | da8cf5438aa676a99e8bb55c94011b2581743e1a (patch) | |
| tree | c5ce0da4ace36faa3cae7e0a8f1891251cc0cfba /src/runtime/runtime.h | |
| parent | e28746c44494030e9b44aa523cd5a21ebfe39ff5 (diff) | |
| download | go-da8cf5438aa676a99e8bb55c94011b2581743e1a.tar.xz | |
runtime: always run semacquire on the G stack
semacquire might need to park the currently running G. It can
only park if called from the G stack (because it has no way of
saving the M stack state). So all calls to semacquire must come
from the G stack.
The three violators are GOMAXPROCS, ReadMemStats, and WriteHeapDump.
This change moves the semacquire call earlier, out of their C code
and into their Go code.
This seldom caused bugs because semacquire seldom actually had
to park the caller. But it did happen intermittently.
Fixes #8749
LGTM=dvyukov
R=golang-codereviews, dvyukov, bradfitz
CC=golang-codereviews
https://golang.org/cl/144940043
Diffstat (limited to 'src/runtime/runtime.h')
| -rw-r--r-- | src/runtime/runtime.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index adc74cf417..c034f3aa97 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -60,6 +60,7 @@ typedef struct SudoG SudoG; typedef struct Mutex Mutex; typedef struct M M; typedef struct P P; +typedef struct SchedType SchedType; typedef struct Note Note; typedef struct Slice Slice; typedef struct String String; @@ -433,6 +434,42 @@ enum { MaxGomaxprocs = 1<<8, }; +struct SchedType +{ + Mutex lock; + + uint64 goidgen; + + M* midle; // idle m's waiting for work + int32 nmidle; // number of idle m's waiting for work + int32 nmidlelocked; // number of locked m's waiting for work + int32 mcount; // number of m's that have been created + int32 maxmcount; // maximum number of m's allowed (or die) + + P* pidle; // idle P's + uint32 npidle; + uint32 nmspinning; + + // Global runnable queue. + G* runqhead; + G* runqtail; + int32 runqsize; + + // Global cache of dead G's. + Mutex gflock; + G* gfree; + int32 ngfree; + + uint32 gcwaiting; // gc is waiting to run + int32 stopwait; + Note stopnote; + uint32 sysmonwait; + Note sysmonnote; + uint64 lastpoll; + + int32 profilehz; // cpu profiling rate +}; + // The m->locked word holds two pieces of state counting active calls to LockOSThread/lockOSThread. // The low bit (LockExternal) is a boolean reporting whether any LockOSThread call is active. // External locks are not recursive; a second lock is silently ignored. @@ -716,6 +753,8 @@ extern DebugVars runtime·debug; extern uintptr runtime·maxstacksize; extern Note runtime·signote; extern ForceGCState runtime·forcegc; +extern SchedType runtime·sched; +extern int32 runtime·newprocs; /* * common functions and data |
