aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/proc.c
AgeCommit message (Collapse)Author
2012-03-27runtime: work around false negative in deadlock detectionRuss Cox
Not a complete fix for issue 3342, but fixes the trivial case. There may still be a race in the instants before and after a scavenger-induced garbage collection. Intended to be "obviously safe": a call to runtime·gosched before main.main is no different than a call to runtime.Gosched at the beginning of main.main, and it is (or had better be) safe to call runtime.Gosched at any point during main. Update #3342. R=iant CC=golang-dev https://golang.org/cl/5919052
2012-03-27undo CL 5844051 / 5d0322034aa8Mikio Hara
Breaks closure test when GOMAXPROCS=2 or more. ««« original CL description runtime: restore deadlock detection in the simplest case. Fixes #3342. R=iant, r, dave, rsc CC=golang-dev, remy https://golang.org/cl/5844051 »»» R=rsc CC=golang-dev https://golang.org/cl/5924045
2012-03-26runtime: restore deadlock detection in the simplest case.Rémy Oudompheng
Fixes #3342. R=iant, r, dave, rsc CC=golang-dev, remy https://golang.org/cl/5844051
2012-03-15runtime: do not handle signals before configuring handlerRuss Cox
There was a small window during program initialization where a signal could come in before the handling mechanisms were set up to handle it. Delay the signal-handler installation until we're ready for the signals. Fixes #3314. R=golang-dev, dsymonds, mikioh.mikioh CC=golang-dev https://golang.org/cl/5833049
2012-03-155l, 6l, 8l: fix stack split logic for stacks near default segment sizeRuss Cox
Fixes #3310. R=golang-dev, r CC=golang-dev https://golang.org/cl/5823051
2012-03-05runtime: wait for main goroutine before setting GOMAXPROCS.Rémy Oudompheng
Fixes #3182. R=golang-dev, dvyukov, rsc CC=golang-dev, remy https://golang.org/cl/5732057
2012-03-01runtime: run init on main threadRuss Cox
Fixes #3125. R=golang-dev, r, minux.ma CC=golang-dev https://golang.org/cl/5714049
2012-02-28runtime/pprof: support OS X CPU profilingRuss Cox
Work around profiling kernel bug with signal masks. Still broken on 64-bit Snow Leopard kernel, but I think we can ignore that one and let people upgrade to Lion. Add new trivial tools addr2line and objdump to take the place of the GNU tools of the same name, since those are not installed on OS X. Adapt pprof to invoke 'go tool addr2line' and 'go tool objdump' if the system tools do not exist. Clean up disassembly of base register on amd64. Fixes #2008. R=golang-dev, bradfitz, mikioh.mikioh, r, iant CC=golang-dev https://golang.org/cl/5697066
2012-02-22runtime: goroutine profile, stack dumpsRuss Cox
R=golang-dev, r, r CC=golang-dev https://golang.org/cl/5687076
2012-02-19runtime: fix another memory leakRuss Cox
morebuf holds a pc/sp from the last stack split or reflect.call or panic/recover. If the pc is a closure, the reference will keep it from being collected. moreargp holds a pointer to the arguments from the last stack split or reflect.call or panic/recover. Normally it is a stack pointer and thus not of interest, but in the case of reflect.call it is an allocated argument list and holds up the arguments to the call. R=golang-dev, r CC=golang-dev https://golang.org/cl/5674109
2012-02-19runtime: fix tiny memory leakRuss Cox
The m->cret word holds the C return value when returning across a stack split boundary. It was not being cleared after use, which means that the return value (if a C function) or else the value of AX/R0 at the time of the last stack unsplit was being kept alive longer than necessary. Clear it. I think the effect here should be very small, but worth fixing anyway. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5677092
2012-02-17runtime: rename Cgocalls and Goroutines to NumCgoCall and NumGoroutine, ↵David Symonds
respectively. Update some other docs too. Update #2955. R=rsc CC=golang-dev https://golang.org/cl/5676060
2012-02-16runtime: release unused memory to the OS.Sébastien Paolacci
Periodically browse MHeap's freelists for long unused spans and release them if any. Current hardcoded settings: - GC is forced if none occured over the last 2 minutes. - spans are handed back after 5 minutes of uselessness. SysUnused (for Unix) is a wrapper on madvise MADV_DONTNEED on Linux and MADV_FREE on BSDs. R=rsc, dvyukov, remyoudompheng CC=golang-dev https://golang.org/cl/5451057
2012-02-14runtime: on 386, fix FP control word on all threads, not just initial threadRuss Cox
It is possible that Linux and Windows copy the FP control word from the parent thread when creating a new thread. Empirically, Darwin does not. Reset the FP control world in all cases. Enable the floating-point strconv test. Fixes #2917 (again). R=golang-dev, r, iant CC=golang-dev https://golang.org/cl/5660047
2012-02-08runtime, pprof: add profiling of thread creationRuss Cox
Same idea as heap profile: how did each thread get created? Low memory (256 bytes per OS thread), high reward for programs that suddenly have many threads running. Fixes #1477. R=golang-dev, r, dvyukov CC=golang-dev https://golang.org/cl/5639059
2012-02-02runtime: add runtime.cputicks() and seed fastrand with itDamian Gryski
This patch adds a function to get the current cpu ticks. This is deemed to be 'sufficiently random' to use to seed fastrand to mitigate the algorithmic complexity attacks on the hash table implementation. On AMD64 we use the RDTSC instruction. For 386, this instruction, while valid, is not recognized by 8a so I've inserted the opcode by hand. For ARM, this routine is currently stubbed to return a constant 0 value. Future work: update 8a to recognize RDTSC. Fixes #2630. R=rsc CC=golang-dev https://golang.org/cl/5606048
2011-12-16runtime: make more build-friendlyRuss Cox
Collapse the arch,os-specific directories into the main directory by renaming xxx/foo.c to foo_xxx.c, and so on. There are no substantial edits here, except to the Makefile. The assumption is that the Go tool will #define GOOS_darwin and GOARCH_amd64 and will make any file named something like signals_darwin.h available as signals_GOOS.h during the build. This replaces what used to be done with -I$(GOOS). There is still work to be done to make runtime build with standard tools, but this is a big step. After this we will have to write a script to generate all the generated files so they can be checked in (instead of generated during the build). R=r, iant, r, lucio.dere CC=golang-dev https://golang.org/cl/5490053
2011-11-14syscall: take over env implementationRuss Cox
The environment is needed by package time, which we want not to depend on os (so that os can use time.Time), so push down into syscall. Delete syscall.Sleep, now unnecessary. The package os environment API is preserved; it is only the implementation that is moving to syscall. Delete os.Envs, which was undocumented, uninitialized on Windows and Plan 9, and not maintained by Setenv and Clearenv. Code can call os.Environ instead. R=golang-dev, r CC=golang-dev https://golang.org/cl/5370091
2011-11-11runtime: remove declarations of nonexistent functionsIan Lance Taylor
R=rsc, r CC=golang-dev https://golang.org/cl/5369089
2011-11-09runtime: add timer support, use for package timeRuss Cox
This looks like it is just moving some code from time to runtime (and translating it to C), but the runtime can do a better job managing the goroutines, and it needs this functionality for its own maintenance (for example, for the garbage collector to hand back unused memory to the OS on a time delay). Might as well have just one copy of the timer logic, and runtime can't depend on time, so vice versa. It also unifies Sleep, NewTicker, and NewTimer behind one mechanism, so that there are no claims that one is more efficient than another. (For example, today people recommend using time.After instead of time.Sleep to avoid blocking an OS thread.) Fixes #1644. Fixes #1731. Fixes #2190. R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov CC=golang-dev https://golang.org/cl/5334051
2011-11-08runtime: add comments for various functions in proc.cIan Lance Taylor
R=rsc CC=golang-dev https://golang.org/cl/5357047
2011-11-08runtime: add windows callback testsAlex Brainman
Just a copy of cgo callback tests from misc/cgo/test. R=rsc CC=golang-dev, hectorchu https://golang.org/cl/5331062
2011-10-27runtime: lock the main goroutine to the main OS thread during initRuss Cox
We only guarantee that the main goroutine runs on the main OS thread for initialization. Programs that wish to preserve that property for main.main can call runtime.LockOSThread. This is what programs used to do before we unleashed goroutines during init, so it is both a simple fix and keeps existing programs working. R=iant, r, dave, dvyukov CC=golang-dev https://golang.org/cl/5309070
2011-10-25runtime: include bootstrap m in mcpu accountingHector Chu
R=rsc, dvyukov CC=golang-dev https://golang.org/cl/5307052
2011-10-13runtime: run goroutines during initRuss Cox
Fixes #583. Fixes #1776. Fixes #2001. Fixes #2112. R=golang-dev, bradfitz, r, gri CC=golang-dev https://golang.org/cl/5265044
2011-10-06runtime: fix spurious deadlock reportingDmitriy Vyukov
Fixes #2337. Unfortunate sequence of events is: 1. maxcpu=2, mcpu=1, grunning=1 2. starttheworld creates an extra M: maxcpu=2, mcpu=2, grunning=1 4. the goroutine calls runtime.GOMAXPROCS(1) maxcpu=1, mcpu=2, grunning=1 5. since it sees mcpu>maxcpu, it calls gosched() 6. schedule() deschedules the goroutine: maxcpu=1, mcpu=1, grunning=0 7. schedule() call getnextandunlock() which fails to pick up the goroutine again, because canaddcpu() fails, because mcpu==maxcpu 8. then it sees that grunning==0, reports deadlock and terminates R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5191044
2011-10-03runtime: fix usleep on linux/386 and re-enable parallel gcHector Chu
R=golang-dev, jsing, alex.brainman, cw, rsc CC=golang-dev https://golang.org/cl/5166047
2011-09-30runtime: disable parallel gcRuss Cox
Breaks on Linux/386 during parallel sync tests. TBR=r CC=golang-dev https://golang.org/cl/5168044
2011-09-30runtime: parallelize garbage collector mark + sweepRuss Cox
Running test/garbage/parser.out. On a 4-core Lenovo X201s (Linux): 31.12u 0.60s 31.74r 1 cpu, no atomics 32.27u 0.58s 32.86r 1 cpu, atomic instructions 33.04u 0.83s 27.47r 2 cpu On a 16-core Xeon (Linux): 33.08u 0.65s 33.80r 1 cpu, no atomics 34.87u 1.12s 29.60r 2 cpu 36.00u 1.87s 28.43r 3 cpu 36.46u 2.34s 27.10r 4 cpu 38.28u 3.85s 26.92r 5 cpu 37.72u 5.25s 26.73r 6 cpu 39.63u 7.11s 26.95r 7 cpu 39.67u 8.10s 26.68r 8 cpu On a 2-core MacBook Pro Core 2 Duo 2.26 (circa 2009, MacBookPro5,5): 39.43u 1.45s 41.27r 1 cpu, no atomics 43.98u 2.95s 38.69r 2 cpu On a 2-core Mac Mini Core 2 Duo 1.83 (circa 2008; Macmini2,1): 48.81u 2.12s 51.76r 1 cpu, no atomics 57.15u 4.72s 51.54r 2 cpu The handoff algorithm is really only good for two cores. Beyond that we will need to so something more sophisticated, like have each core hand off to the next one, around a circle. Even so, the code is a good checkpoint; for now we'll limit the number of gc procs to at most 2. R=dvyukov CC=golang-dev https://golang.org/cl/4641082
2011-08-23runtime: fix void warningsRuss Cox
Add -V flag to 6c command line to keep them fixed. R=ken2 CC=golang-dev https://golang.org/cl/4930046
2011-08-22runtime: simplify stack tracesRuss Cox
Make the stack traces more readable for new Go programmers while preserving their utility for old hands. - Change status number [4] to string. - Elide frames in runtime package (internal details). - Swap file:line and arguments. - Drop 'created by' for main goroutine. - Show goroutines in order of allocation: implies main goroutine first if nothing else. There is no option to get the extra frames back. Uncomment 'return 1' at the bottom of symtab.c. $ 6.out throw: all goroutines are asleep - deadlock! goroutine 1 [chan send]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:22 +0x8a goroutine 2 [select (no cases)]: main.sel() /Users/rsc/g/go/src/pkg/runtime/x.go:11 +0x18 created by main.main /Users/rsc/g/go/src/pkg/runtime/x.go:19 +0x23 goroutine 3 [chan receive]: main.recv(0xf8400010a0, 0x0) /Users/rsc/g/go/src/pkg/runtime/x.go:15 +0x2e created by main.main /Users/rsc/g/go/src/pkg/runtime/x.go:20 +0x50 goroutine 4 [chan receive (nil chan)]: main.recv(0x0, 0x0) /Users/rsc/g/go/src/pkg/runtime/x.go:15 +0x2e created by main.main /Users/rsc/g/go/src/pkg/runtime/x.go:21 +0x66 $ $ 6.out index panic: runtime error: index out of range goroutine 1 [running]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:25 +0xb9 $ $ 6.out nil panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0x22ca] goroutine 1 [running]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:28 +0x211 $ $ 6.out panic panic: panic goroutine 1 [running]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:30 +0x101 $ R=golang-dev, qyzhai, n13m3y3r, r CC=golang-dev https://golang.org/cl/4907048
2011-08-22runtime: Remove extraneous word in comment.Ian Lance Taylor
R=golang-dev, gri CC=golang-dev https://golang.org/cl/4938045
2011-08-18runtime: speed up cgo callsAlex Brainman
Allocate Defer on stack during cgo calls, as suggested by dvyukov. Also includes some comment corrections. benchmark old,ns/op new,ns/op BenchmarkCgoCall 669 330 (Intel Xeon CPU 1.80GHz * 4, Linux 386) R=dvyukov, rsc CC=golang-dev https://golang.org/cl/4910041
2011-08-16runtime: fix GC bitmap corruptionDmitriy Vyukov
The corruption can occur when GOMAXPROCS is changed from >1 to 1, since GOMAXPROCS=1 does not imply there is only 1 goroutine running, other goroutines can still be not parked after the change. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4873050
2011-08-04runtime: remove unnecessary lockingHector Chu
R=rsc, dvyukov CC=golang-dev https://golang.org/cl/4819051
2011-07-29runtime: fix scheduling raceHector Chu
Affects programs using cgo or runtime.LockOSThread. Fixes #2100. R=rsc, dvyukov CC=golang-dev https://golang.org/cl/4810059
2011-07-27runtime: higher goroutine arg limit, clearer errorRuss Cox
Fixes #591. R=ken2 CC=golang-dev https://golang.org/cl/4803054
2011-07-23runtime: faster entersyscall/exitsyscallRuss Cox
Replace cas with xadd in scheduler. Suggested by Dmitriy in last code review. Verified with Promela model. When there's actual contention for the atomic word, this avoids the looping that compare-and-swap requires. benchmark old ns/op new ns/op delta runtime_test.BenchmarkSyscall 32 26 -17.08% runtime_test.BenchmarkSyscall-2 155 59 -61.81% runtime_test.BenchmarkSyscall-3 112 52 -52.95% runtime_test.BenchmarkSyscall-4 94 48 -48.57% runtime_test.BenchmarkSyscallWork 871 872 +0.11% runtime_test.BenchmarkSyscallWork-2 481 477 -0.83% runtime_test.BenchmarkSyscallWork-3 338 335 -0.89% runtime_test.BenchmarkSyscallWork-4 263 256 -2.66% R=golang-dev, iant CC=golang-dev https://golang.org/cl/4800047
2011-07-21runtime: replace centralized ncgocall counter with a distributed oneDmitriy Vyukov
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4809042
2011-07-19runtime: faster entersyscall, exitsyscallRuss Cox
Uses atomic memory accesses to avoid the need to acquire and release schedlock on fast paths. benchmark old ns/op new ns/op delta runtime_test.BenchmarkSyscall 73 31 -56.63% runtime_test.BenchmarkSyscall-2 538 74 -86.23% runtime_test.BenchmarkSyscall-3 508 103 -79.72% runtime_test.BenchmarkSyscall-4 721 97 -86.52% runtime_test.BenchmarkSyscallWork 920 873 -5.11% runtime_test.BenchmarkSyscallWork-2 516 481 -6.78% runtime_test.BenchmarkSyscallWork-3 550 343 -37.64% runtime_test.BenchmarkSyscallWork-4 632 263 -58.39% (Intel Core i7 L640 2.13 GHz-based Lenovo X201s) Reduced a less artificial server benchmark from 11.5r 12.0u 8.0s to 8.3r 9.1u 1.0s. R=dvyukov, r, bradfitz, r, iant, iant CC=golang-dev https://golang.org/cl/4723042
2011-07-18runtime: track running goroutine countRuss Cox
Used to use mcpu+msyscall but that's problematic for packing into a single atomic word. The running goroutine count (where running == Go code or syscall) can be maintained separately, always manipulated under lock. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/4767041
2011-07-12runtime: replace runtime.mcpy with runtime.memmoveQuan Yong Zhai
faster string operations, and more tested on linux/386 runtime_test.BenchmarkSliceToString 642 532 -17.13% runtime_test.BenchmarkStringToSlice 636 528 -16.98% runtime_test.BenchmarkConcatString 1109 897 -19.12% R=r, iant, rsc CC=golang-dev https://golang.org/cl/4674042
2011-07-12runtime: eliminate false sharing during stack growthDmitriy Vyukov
Remove static variable from runtime·oldstack(). Benchmark results on HP Z600 (2 x Xeon E5620, 8 HT cores, 2.40GHz) are as follows (with CL 4657091 applied): benchmark old ns/op new ns/op delta BenchmarkStackGrowth 1183.00 1180.00 -0.25% BenchmarkStackGrowth-2 1249.00 1211.00 -3.04% BenchmarkStackGrowth-4 954.00 805.00 -15.62% BenchmarkStackGrowth-8 701.00 683.00 -2.57% BenchmarkStackGrowth-16 465.00 415.00 -10.75% R=rsc CC=golang-dev https://golang.org/cl/4693042
2011-07-12runtime: fix comment (lost in shuffle)Russ Cox
TBR=dvyukov CC=golang-dev https://golang.org/cl/4710041
2011-07-12runtime: eliminate contention during stack allocationDmitriy Vyukov
Standard-sized stack frames use plain malloc/free instead of centralized lock-protected FixAlloc. Benchmark results on HP Z600 (2 x Xeon E5620, 8 HT cores, 2.40GHz) are as follows: benchmark old ns/op new ns/op delta BenchmarkStackGrowth 1045.00 949.00 -9.19% BenchmarkStackGrowth-2 3450.00 800.00 -76.81% BenchmarkStackGrowth-4 5076.00 513.00 -89.89% BenchmarkStackGrowth-8 7805.00 471.00 -93.97% BenchmarkStackGrowth-16 11751.00 321.00 -97.27% R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4657091
2011-07-12runtime: eliminate false sharing on runtime.goidgenDmitriy Vyukov
runtime.goidgen can be quite frequently modified and shares cache line with the following variables, it leads to false sharing. 50c6b0 b nfname 50c6b4 b nfunc 50c6b8 b nfunc$17 50c6bc b nhist$17 50c6c0 B runtime.checking 50c6c4 B runtime.gcwaiting 50c6c8 B runtime.goidgen 50c6cc B runtime.gomaxprocs 50c6d0 B runtime.panicking 50c6d4 B strconv.IntSize 50c6d8 B src/pkg/runtime/_xtest_.ss 50c6e0 B src/pkg/runtime/_xtest_.stop 50c6e8 b addrfree 50c6f0 b addrmem 50c6f8 b argv R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4673054
2011-07-12runtime: eliminate false sharing on random number generatorsDmitriy Vyukov
Use machine-local random number generator instead of racy global ones. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4674049
2011-06-29runtime: windows/amd64 portWei Guangjing
R=rsc, alex.brainman, hectorchu, r CC=golang-dev https://golang.org/cl/3759042
2011-05-16runtime: make StackSystem part of StackGuardAlexey Borzenkov
Fixes #1779 R=rsc CC=golang-dev https://golang.org/cl/4543052
2011-05-02os: make Setenv update C environment variablesBrad Fitzpatrick
Fixes #1569 R=rsc, bradfitzwork CC=golang-dev https://golang.org/cl/4456045