aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/proc.c
AgeCommit message (Collapse)Author
2014-01-16runtime: output how long goroutines are blockedDmitriy Vyukov
Example of output: goroutine 4 [sleep for 3 min]: time.Sleep(0x34630b8a000) src/pkg/runtime/time.goc:31 +0x31 main.func·002() block.go:16 +0x2c created by main.main block.go:17 +0x33 Full program and output are here: http://play.golang.org/p/NEZdADI3Td Fixes #6809. R=golang-codereviews, khr, kamil.kisiel, bradfitz, rsc CC=golang-codereviews https://golang.org/cl/50420043
2014-01-16runtime: use lock-free ring for work queuesDmitriy Vyukov
Use lock-free fixed-size ring for work queues instead of an unbounded mutex-protected array. The ring has single producer and multiple consumers. If the ring overflows, work is put onto global queue. benchmark old ns/op new ns/op delta BenchmarkMatmult 7 5 -18.12% BenchmarkMatmult-4 2 2 -18.98% BenchmarkMatmult-16 1 0 -12.84% BenchmarkCreateGoroutines 105 88 -16.10% BenchmarkCreateGoroutines-4 376 219 -41.76% BenchmarkCreateGoroutines-16 241 174 -27.80% BenchmarkCreateGoroutinesParallel 103 87 -14.66% BenchmarkCreateGoroutinesParallel-4 169 143 -15.38% BenchmarkCreateGoroutinesParallel-16 158 151 -4.43% R=golang-codereviews, rsc CC=ddetlefs, devon.odell, golang-codereviews https://golang.org/cl/46170044
2014-01-14runtime: fix commentDmitriy Vyukov
Void function can not return false. R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/52000043
2014-01-07runtime: use special records hung off the MSpan toKeith Randall
record finalizers and heap profile info. Enables removing the special bit from the heap bitmap. Also provides a generic mechanism for annotating occasional heap objects. finalizers overhead per obj old 680 B 80 B avg new 16 B/span 48 B profile overhead per obj old 32KB 24 B + hash tables new 16 B/span 24 B R=cshapiro, khr, dvyukov, gobot CC=golang-codereviews https://golang.org/cl/13314053
2013-12-13runtime: fix crash in runtime.GoroutineProfileRuss Cox
This is a possible Go 1.2.1 candidate. Fixes #6946. R=iant, r CC=golang-dev https://golang.org/cl/41640043
2013-10-18runtime: remove nomemprofDmitriy Vyukov
Nomemprof seems to be unneeded now, there is no recursion. If the recursion will be re-introduced, it will break loudly by deadlocking. Fixes #6566. R=golang-dev, minux.ma, rsc CC=golang-dev https://golang.org/cl/14695044
2013-10-17runtime: correct test for when to poll networkIan Lance Taylor
Fixes #6610. R=golang-dev, khr CC=golang-dev https://golang.org/cl/14793043
2013-09-20runtime: avoid allocation of internal panic valuesRuss Cox
If a fault happens in malloc, inevitably the next thing that happens is a deadlock trying to allocate the panic value that says the fault happened. Stop doing that, two ways. First, reject panic in malloc just as we reject panic in garbage collection. Second, runtime.panicstring was using an error implementation backed by a Go string, so the interface held an allocated *string. Since the actual errors are C strings, define a new error implementation backed by a C char*, which needs no indirection and therefore no allocation. This second fix will avoid allocation for errors like nil panic derefs or division by zero, so it is worth doing even though the first fix should take care of faults during malloc. Update #6419 R=golang-dev, dvyukov, dave CC=golang-dev https://golang.org/cl/13774043
2013-09-16build: disable precise collection of stack framesRuss Cox
The code for call site-specific pointer bitmaps was not ready in time, but the zeroing required without it is too expensive to use by default. We will have to wait for precise collection of stack frames until Go 1.3. The precise collection can be re-enabled by GOEXPERIMENT=precisestack ./all.bash but that will not be the default for a Go 1.2 build. Fixes #6087. R=golang-dev, jeremyjackins, dan.kortschak, r CC=golang-dev https://golang.org/cl/13677045
2013-09-15runtime: fix CPU profiling on WindowsRuss Cox
The test 'gp == m->curg' is not valid on Windows, because the goroutine being profiled is not from the current m. TBR=golang-dev CC=golang-dev https://golang.org/cl/13718043
2013-09-13runtime: avoid inconsistent goroutine state in profilerRuss Cox
Because profiling signals can arrive at any time, we must handle the case where a profiling signal arrives halfway through a goroutine switch. Luckily, although there is much to think through, very little needs to change. Fixes #6000. Fixes #6015. R=golang-dev, dvyukov CC=golang-dev https://golang.org/cl/13421048
2013-09-12runtime, cmd/gc, cmd/ld: ignore method wrappers in recoverRuss Cox
Bug #1: Issue 5406 identified an interesting case: defer iface.M() may end up calling a wrapper that copies an indirect receiver from the iface value and then calls the real M method. That's two calls down, not just one, and so recover() == nil always in the real M method, even during a panic. [For the purposes of this entire discussion, a wrapper's implementation is a function containing an ordinary call, not the optimized tail call form that is somtimes possible. The tail call does not create a second frame, so it is already handled correctly.] Fix this bug by introducing g->panicwrap, which counts the number of bytes on current stack segment that are due to wrapper calls that should not count against the recover check. All wrapper functions must now adjust g->panicwrap up on entry and back down on exit. This adds slightly to their expense; on the x86 it is a single instruction at entry and exit; on the ARM it is three. However, the alternative is to make a call to recover depend on being able to walk the stack, which I very much want to avoid. We have enough problems walking the stack for garbage collection and profiling. Also, if performance is critical in a specific case, it is already faster to use a pointer receiver and avoid this kind of wrapper entirely. Bug #2: The old code, which did not consider the possibility of two calls, already contained a check to see if the call had split its stack and so the panic-created segment was one behind the current segment. In the wrapper case, both of the two calls might split their stacks, so the panic-created segment can be two behind the current segment. Fix this by propagating the Stktop.panic flag forward during stack splits instead of looking backward during recover. Fixes #5406. R=golang-dev, iant CC=golang-dev https://golang.org/cl/13367052
2013-08-29runtime: jump to badmcall instead of calling it.Keith Randall
This replaces the mcall frame with the badmcall frame instead of leaving the mcall frame on the stack and adding the badmcall frame. Because mcall is no longer on the stack, traceback will now report what called mcall, which is what we would like to see in this situation. R=golang-dev, cshapiro CC=golang-dev https://golang.org/cl/13012044
2013-08-16runtime: impose thread count limitRuss Cox
Actually working to stay within the limit could cause subtle deadlocks. Crashing avoids the subtlety. Fixes #4056. R=golang-dev, r, dvyukov CC=golang-dev https://golang.org/cl/13037043
2013-08-16runtime: fix goroutine stack accountingDmitriy Vyukov
Fixes #6166. Fixes #6168. R=golang-dev, bradfitz, remyoudompheng CC=golang-dev https://golang.org/cl/12927045
2013-08-15runtime: impose stack size limitRuss Cox
The goal is to stop only those programs that would keep going and run the machine out of memory, but before they do that. 1 GB on 64-bit, 250 MB on 32-bit. That seems implausibly large, and it can be adjusted. Fixes #2556. Fixes #4494. Fixes #5173. R=khr, r, dvyukov CC=golang-dev https://golang.org/cl/12541052
2013-08-15runtime: remove old preemption checksDmitriy Vyukov
runtime.gcwaiting checks are not needed anymore R=golang-dev, khr CC=golang-dev https://golang.org/cl/12934043
2013-08-13runtime: fix build on armRuss Cox
Do not use ? : I cannot say this enough. TBR=dvyukov CC=golang-dev https://golang.org/cl/12903043
2013-08-14runtime: dump scheduler state if GODEBUG=schedtrace is setDmitriy Vyukov
The schedtrace value sets dump period in milliseconds. In default mode the trace looks as follows: SCHED 0ms: gomaxprocs=4 idleprocs=0 threads=3 idlethreads=0 runqueue=0 [1 0 0 0] SCHED 1001ms: gomaxprocs=4 idleprocs=3 threads=6 idlethreads=3 runqueue=0 [0 0 0 0] SCHED 2008ms: gomaxprocs=4 idleprocs=1 threads=6 idlethreads=1 runqueue=0 [0 1 0 0] If GODEBUG=scheddetail=1 is set as well, then the detailed trace is printed: SCHED 0ms: gomaxprocs=4 idleprocs=0 threads=3 idlethreads=0 runqueue=0 singleproc=0 gcwaiting=1 mlocked=0 nmspinning=0 stopwait=0 sysmonwait=0 P0: status=3 tick=1 m=0 runqsize=1/128 gfreecnt=0 P1: status=3 tick=0 m=-1 runqsize=0/128 gfreecnt=0 P2: status=3 tick=0 m=-1 runqsize=0/128 gfreecnt=0 P3: status=3 tick=0 m=-1 runqsize=0/128 gfreecnt=0 M2: p=-1 curg=-1 mallocing=0 throwing=0 gcing=0 locks=1 dying=0 helpgc=0 spinning=0 lockedg=-1 M1: p=-1 curg=-1 mallocing=0 throwing=0 gcing=0 locks=1 dying=0 helpgc=0 spinning=0 lockedg=-1 M0: p=0 curg=1 mallocing=0 throwing=0 gcing=0 locks=1 dying=0 helpgc=0 spinning=0 lockedg=1 G1: status=2() m=0 lockedm=0 G2: status=1() m=-1 lockedm=-1 R=golang-dev, raggi, rsc CC=golang-dev https://golang.org/cl/11435044
2013-08-13runtime: fix LockOSThreadDmitriy Vyukov
Fixes #6100. R=golang-dev, dave, bradfitz, rsc CC=golang-dev https://golang.org/cl/12703045
2013-08-13runtime: more reliable preemptionDmitriy Vyukov
Currently it's possible that a goroutine that periodically executes non-blocking cgo/syscalls is never preempted. This change splits scheduler and syscall ticks to prevent such situation. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12658045
2013-08-13runtime: do no lose CPU profiling signalsDmitriy Vyukov
Currently we lose lots of profiling signals. Most notably, GC is not accounted at all. But stack splits, scheduler, syscalls, etc are lost as well. This creates seriously misleading profile. With this change all profiling signals are accounted. Now I see these additional entries that were previously absent: 161 29.7% 29.7% 164 30.3% syscall.Syscall 12 2.2% 50.9% 12 2.2% scanblock 11 2.0% 55.0% 11 2.0% markonly 10 1.8% 58.9% 10 1.8% sweepspan 2 0.4% 85.8% 2 0.4% runtime.newstack It is still impossible to understand what causes stack splits, but at least it's clear how many time is spent on them. Update #2197. Update #5659. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12179043
2013-08-13runtime: fix false deadlock crashDmitriy Vyukov
Fixes #6070. Update #6055. R=golang-dev, nightlyone, rsc CC=golang-dev https://golang.org/cl/12602043
2013-08-13syscall: disable cpu profiling around forkDmitriy Vyukov
Fixes #5517. Fixes #5659. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/12183044
2013-08-12runtime: change textflags from numbers to symbolsKeith Randall
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/12798043
2013-08-09net: add special netFD mutexDmitriy Vyukov
The mutex, fdMutex, handles locking and lifetime of sysfd, and serializes Read and Write methods. This allows to strip 2 sync.Mutex.Lock calls, 2 sync.Mutex.Unlock calls, 1 defer and some amount of misc overhead from every network operation. On linux/amd64, Intel E5-2690: benchmark old ns/op new ns/op delta BenchmarkTCP4Persistent 9595 9454 -1.47% BenchmarkTCP4Persistent-2 8978 8772 -2.29% BenchmarkTCP4ConcurrentReadWrite 4900 4625 -5.61% BenchmarkTCP4ConcurrentReadWrite-2 2603 2500 -3.96% In general it strips 70-500 ns from every network operation depending on processor model. On my relatively new E5-2690 it accounts to ~5% of network op cost. Fixes #6074. R=golang-dev, bradfitz, alex.brainman, iant, mikioh.mikioh CC=golang-dev https://golang.org/cl/12418043
2013-08-09runtime: traceback running goroutinesDmitriy Vyukov
Introduce freezetheworld function that is a best-effort attempt to stop any concurrently running goroutines. Call it during crash. Fixes #5873. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12054044
2013-08-08runtime: fix traceback in cgo programsDmitriy Vyukov
Fixes #6061. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/12609043
2013-08-06runtime: use gcpc/gcsp during traceback of goroutines in syscallsDmitriy Vyukov
gcpc/gcsp are used by GC in similar situation. gcpc/gcsp are also more stable than gp->sched, because gp->sched is mutated by entersyscall/exitsyscall in morestack and mcall. So it has higher chances of being inconsistent. Also, rename gcpc/gcsp to syscallpc/syscallsp. This is the same as reverted change 12250043 with save marked as textflag 7. The problem was that if save calls morestack, then subsequent lessstack spoils g->sched.pc/sp. And that bad values were remembered in g->syscallpc/sp. Entersyscallblock had the same problem, but it was never triggered to date. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12478043
2013-08-05runtime/pprof: test multithreaded profile, remove OS X workaroundsRuss Cox
This means that pprof will no longer report profiles on OS X. That's unfortunate, but the profiles were often wrong and, worse, it was difficult to tell whether the profile was wrong or not. The workarounds were making the scheduler more complex, possibly caused a deadlock (see issue 5519), and did not actually deliver reliable results. It may be possible for adventurous users to apply a patch to their kernels to get working results, or perhaps having no results will encourage someone to do the work of creating a profiling thread like on Windows. Issue 6047 has details. Fixes #5519. Fixes #6047. R=golang-dev, bradfitz, r CC=golang-dev https://golang.org/cl/12429045
2013-08-05runtime: remove debugging knob to turn off preemptionRuss Cox
It's still easy to turn off, but the builders are happy. Also document. R=golang-dev, iant, dvyukov CC=golang-dev https://golang.org/cl/12371043
2013-08-05undo CL 12250043 / e911f94c4902Dmitriy Vyukov
Break all 386 builders. ««« original CL description runtime: use gcpc/gcsp during traceback of goroutines in syscalls gcpc/gcsp are used by GC in similar situation. gcpc/gcsp are also more stable than gp->sched, because gp->sched is mutated by entersyscall/exitsyscall in morestack and mcall. So it has higher chances of being inconsistent. Also, rename gcpc/gcsp to syscallpc/syscallsp. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12250043 »»» R=rsc CC=golang-dev https://golang.org/cl/12424045
2013-08-05runtime: remove singleproc varDmitriy Vyukov
It was needed for the old scheduler, because there temporary could be more threads than gomaxprocs. In the new scheduler gomaxprocs is always respected. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12438043
2013-08-05runtime: use gcpc/gcsp during traceback of goroutines in syscallsDmitriy Vyukov
gcpc/gcsp are used by GC in similar situation. gcpc/gcsp are also more stable than gp->sched, because gp->sched is mutated by entersyscall/exitsyscall in morestack and mcall. So it has higher chances of being inconsistent. Also, rename gcpc/gcsp to syscallpc/syscallsp. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12250043
2013-08-02runtime: reimplement reflect.call to not use stack splitting.Keith Randall
R=golang-dev, r, khr, rsc CC=golang-dev https://golang.org/cl/12053043
2013-08-01runtime: print "created by" for running goroutines in tracebackDmitriy Vyukov
This allows to at least determine goroutine "identity". Now it looks like: goroutine 12 [running]: goroutine running on other thread; stack unavailable created by testing.RunTests src/pkg/testing/testing.go:440 +0x88e R=golang-dev, r, rsc CC=golang-dev https://golang.org/cl/12248043
2013-07-31runtime: do not park sysmon thread if any goroutines are runningDmitriy Vyukov
Sysmon thread parks if no goroutines are running (runtime.sched.npidle == runtime.gomaxprocs). Currently it's unparked when a goroutine enters syscall, it was enough to retake P's from blocking syscalls. But it's not enough for reliable goroutine preemption. We need to ensure that sysmon runs if any goroutines are running. R=rsc CC=golang-dev https://golang.org/cl/12176043
2013-07-31undo CL 12167043 / 475e11851fc1Dmitriy Vyukov
Submitted with some unrelated changes that were not intended to go in. ««« original CL description runtime: do not park sysmon thread if any goroutines are running Sysmon thread parks if no goroutines are running (runtime.sched.npidle == runtime.gomaxprocs). Currently it's unparked when a goroutine enters syscall, it was enough to retake P's from blocking syscalls. But it's not enough for reliable goroutine preemption. We need to ensure that sysmon runs if any goroutines are running. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12167043 »»» R=rsc CC=golang-dev https://golang.org/cl/12171044
2013-07-31runtime: do not park sysmon thread if any goroutines are runningDmitriy Vyukov
Sysmon thread parks if no goroutines are running (runtime.sched.npidle == runtime.gomaxprocs). Currently it's unparked when a goroutine enters syscall, it was enough to retake P's from blocking syscalls. But it's not enough for reliable goroutine preemption. We need to ensure that sysmon runs if any goroutines are running. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12167043
2013-07-30runtime: enable goroutine preemptionDmitriy Vyukov
All known issues with preemption have beed fixed. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12008044
2013-07-29runtime: do not split stacks in syscall statusDmitriy Vyukov
Split stack checks (morestack) corrupt g->sched, but g->sched must be preserved consistent for GC/traceback. The change implements runtime.notetsleepg function, which does entersyscall/exitsyscall and is carefully arranged to not call any split functions in between. R=rsc CC=golang-dev https://golang.org/cl/11575044
2013-07-26runtime: handle runtime.Goexit during initRuss Cox
Fixes #5963. R=golang-dev, dsymonds, dvyukov CC=golang-dev https://golang.org/cl/11879045
2013-07-26runtime: refactor mallocgcDmitriy Vyukov
Make it accept type, combine flags. Several reasons for the change: 1. mallocgc and settype must be atomic wrt GC 2. settype is called from only one place now 3. it will help performance (eventually settype functionality must be combined with markallocated) 4. flags are easier to read now (no mallocgc(sz, 0, 1, 0) anymore) R=golang-dev, iant, nightlyone, rsc, dave, khr, bradfitz, r CC=golang-dev https://golang.org/cl/10136043
2013-07-24runtime: only define SEH when we need it.Keith Randall
R=golang-dev, iant CC=golang-dev https://golang.org/cl/11769043
2013-07-24runtime: more cgocallback_gofunc workRuss Cox
Debugging the Windows breakage I noticed that SEH only exists on 386, so we can balance the two stacks a little more on amd64 and reclaim another word. Now we're down to just one word consumed by cgocallback_gofunc, having reclaimed 25% of the overall budget (4 words out of 16). Separately, fix windows/386 - the SEH must be on the m0 stack, as must the saved SP, so we are forced to have a three-word frame for 386. It matters much less for 386, because there 128 bytes gives 32 words to use. R=dvyukov, alex.brainman CC=golang-dev https://golang.org/cl/11551044
2013-07-23runtime: reduce frame size for runtime.cgocallback_gofuncRuss Cox
Tying preemption to stack splits means that we have to able to complete the call to exitsyscall (inside cgocallbackg at least for now) without any stack split checks, meaning that the whole sequence has to work within 128 bytes of stack, unless we increase the size of the red zone. This CL frees up 24 bytes along that critical path on amd64. (The 32-bit systems have plenty of space because all their words are smaller.) R=dvyukov CC=golang-dev https://golang.org/cl/11676043
2013-07-22runtime: add a missing newline in a debug printf.David Symonds
Trivial, but annoying while debugging this code. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/11656043
2013-07-19runtime: prevent sysmon from polling network excessivlyDmitriy Vyukov
If the network is not polled for 10ms, sysmon starts polling network on every iteration (every 20us) until another thread blocks in netpoll. Fixes #5922. R=golang-dev, iant CC=golang-dev https://golang.org/cl/11569043
2013-07-19runtime: preempt long-running goroutinesDmitriy Vyukov
If a goroutine runs for more than 10ms, preempt it. Update #543. R=rsc CC=golang-dev https://golang.org/cl/10796043
2013-07-18runtime: handle morestack/lessstack in stack traceRuss Cox
If we start a garbage collection on g0 during a stack split or unsplit, we'll see morestack or lessstack at the top of the stack. Record an argument frame size for those, and record that they terminate the stack. R=golang-dev, dvyukov CC=golang-dev https://golang.org/cl/11533043