aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/proc.c
AgeCommit message (Collapse)Author
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.
2014-09-06runtime: fix panic/wrapper/recover mathRuss Cox
The gp->panicwrap adjustment is just fatally flawed. Now that there is a Panic.argp field, update that instead. That can be done on entry only, so that unwinding doesn't need to worry about undoing anything. The wrappers emit a few more instructions in the prologue but everything else in the system gets much simpler. It also fixes (without trying) a broken test I never checked in. Fixes #7491. LGTM=khr R=khr CC=dvyukov, golang-codereviews, iant, r https://golang.org/cl/135490044
2014-09-06runtime: badreflectcall runs on the G stack - convert to Go.Keith Randall
LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/136260043
2014-09-06runtime: get rid of other Go->C calls in test exports.Keith Randall
testSchedLocal* tests need to malloc now because their stack frames are too big to fit on the G0 stack. LGTM=iant R=golang-codereviews, iant, khr CC=golang-codereviews https://golang.org/cl/133660043
2014-09-04runtime: use cas loop to coordinate with sigprofRuss Cox
sigprof and setcpuprofilerate coordinate the enabling/disabling of the handler using a Mutex. This has always been a bit dodgy: setcpuprofilerate must be careful to turn off signals before acquiring the lock to avoid a deadlock. Now the lock implementations use onM, and onM isn't okay on the signal stack. We know how to make it okay, but it's more work than is probably worth doing. Since this is super-dodgy anyway, replace the lock with a simple cas loop. It is only contended if setcpuprofilerate is being called, and that doesn't happen frequently enough to care about the raw speed or about using futexes/semaphores. TBR to fix freebsd/amd64 and dragonfly/amd64 builds. Happy to make changes in a follow-up CL. TBR=dvyukov CC=golang-codereviews https://golang.org/cl/141080044
2014-09-04runtime: use new #include "textflag.h"Russ Cox
I did this just to clean things up, but it will be important when we drop the pkg directory later. LGTM=bradfitz R=r, bradfitz CC=golang-codereviews https://golang.org/cl/132600043
2014-09-04runtime: more C to Go conversion adjustmentsRuss Cox
Mostly NOSPLIT additions. Had to rewrite atomic_arm.c in Go because it calls lock, and lock is too complex. With this CL, I find no Go -> C calls that can split the stack on any system except Solaris and Windows. Solaris and Windows need more work and will be done separately. LGTM=iant, dave R=golang-codereviews, bradfitz, iant, dave CC=dvyukov, golang-codereviews, khr, r https://golang.org/cl/137160043
2014-09-04runtime: make more functions safe for GoRuss Cox
Convert no-op race functions. Everything else is tiny and gets NOSPLITs. After this, all that is left on darwin is sysAlloc, panic, and gothrow (all pending). There may be system-specific calls in other builds. LGTM=iant R=golang-codereviews, iant CC=dvyukov, golang-codereviews, khr, r https://golang.org/cl/140240044
2014-09-04runtime: convert cgocall to GoDmitriy Vyukov
LGTM=khr, rsc R=golang-codereviews, khr, rsc CC=golang-codereviews https://golang.org/cl/131670043
2014-09-04runtime: use C for readgstatus, goroutine status valuesRuss Cox
When this code was written, there was no way for Go to reuse the C function and enum values. Now there is. LGTM=bradfitz R=rlh, bradfitz CC=dvyukov, golang-codereviews, iant, khr, r https://golang.org/cl/139150045
2014-09-04runtime: correct various Go -> C function callsRuss Cox
Some things get converted. Other things (too complex or too many C deps) get onM calls. Other things (too simple) get #pragma textflag NOSPLIT. After this CL, the offending function list is basically: - panic.c - netpoll.goc - mem*.c - race stuff - readgstatus - entersyscall/exitsyscall LGTM=r, iant R=golang-codereviews, r, iant CC=dvyukov, golang-codereviews, khr https://golang.org/cl/140930043
2014-09-03runtime: make entersyscall/exitsyscall safe for stack splitsRuss Cox
It is fundamentally unsafe to grow the stack once someone has made a call to syscall.Syscall. That function takes 6 uintptr arguments, but depending on the call some are pointers. In fact, some might be pointers to stack values, and we don't know which. That makes it impossible to copy the stack somewhere else. Since we want to delete all the stack splitting code, relying only on stack copying, make sure that Syscall never needs to split the stack. The only thing Syscall does is: call entersyscall make the system call call exitsyscall As long as we make sure that entersyscall and exitsyscall can live in the nosplit region, they won't ask for more stack. Do this by making entersyscall and exitsyscall set up the stack guard so that any call to a function with a split check will cause a crash. Then move non-essential slow-path work onto the m stack using onM and mark the rest of the work nosplit. The linker will verify that the chain of nosplits fits in the total nosplit budget. LGTM=iant R=golang-codereviews, iant CC=dvyukov, golang-codereviews, khr, r https://golang.org/cl/140950043
2014-09-03runtime: remove guard against uninitialized forcegc.gRuss Cox
The race was in the old C code. The new Go code does not have the race and does not need the check. LGTM=bradfitz, dvyukov R=golang-codereviews, bradfitz, dvyukov CC=golang-codereviews, rlh https://golang.org/cl/140180043
2014-09-03runtime: adopt race detector for runtime written in GoDmitriy Vyukov
Ignore memory access on g0/gsignal. See the issue for context and explanation. Fixes #8627. LGTM=khr R=golang-codereviews, mdempsky, khr CC=golang-codereviews, rsc https://golang.org/cl/137070043
2014-09-03runtime: Start and stop individual goroutines at gc safepointsRick Hudson
Code to bring goroutines to a gc safepoint one at a time, do some work such as scanning, and restart the goroutine, and then move on to the next goroutine. Currently this code does not do much useful work but this infrastructure will be critical to future concurrent GC work. Fixed comments reviewers. LGTM=rsc R=golang-codereviews, rsc, dvyukov CC=golang-codereviews https://golang.org/cl/131580043
2014-09-03runtime: make onM and mcall take Go func valuesRuss Cox
This gives them correct types in Go and also makes it possible to use them to run Go code on an m stack. LGTM=iant R=golang-codereviews, dave, iant CC=dvyukov, golang-codereviews, khr, r https://golang.org/cl/137970044
2014-09-03runtime: convert a few traceback-related functions from proc.c to traceback.goRuss Cox
They were in proc.c mainly because there was no portable traceback source file. As part of converting them to Go, move to traceback.go. In order to get access to the PC of _rt0_go, rename to runtime.rt0_go. LGTM=r R=golang-codereviews, r CC=dvyukov, golang-codereviews, iant, khr https://golang.org/cl/139110043
2014-09-02runtime: avoid race with forcegc helperRuss Cox
While we are here, give the gc helper a real function name that will appear in stack traces. LGTM=rlh R=rlh CC=dvyukov, golang-codereviews https://golang.org/cl/133470043
2014-09-02runtime: convert cpuprof from C to GoMatthew Dempsky
LGTM=dvyukov, rsc R=golang-codereviews, dvyukov, rsc CC=golang-codereviews https://golang.org/cl/132440043
2014-09-01runtime: fix race detector running Go code on g0 of non-main threadRuss Cox
It looks like this has just always been broken: the race detector handles running Go code on g0 of the main thread and on g0 of any extra threads created by non-Go code, but it does not handle running Go code on g0 of non-main threads created by Go. Handle that. Should fix the race build failures on the dashboard. We're running into this now because we are running more and more Go code on g0. TBR=dvyukov CC=golang-codereviews https://golang.org/cl/137910043
2014-09-01runtime: convert mprof.goc to mprof.goRuss Cox
The exported Go definitions appearing in mprof.go are copied verbatim from debug.go. The unexported Go funcs and types are new. The C Bucket type used a union and was not a line-for-line translation. LGTM=remyoudompheng R=golang-codereviews, remyoudompheng CC=dvyukov, golang-codereviews, iant, khr, r https://golang.org/cl/137040043
2014-08-29runtime: make allp a static arrayRuss Cox
It is anyway, just an allocated one. Giving it a sized type makes Go access nicer. LGTM=iant R=dvyukov, iant CC=golang-codereviews https://golang.org/cl/139960043
2014-08-29runtime: run runtime.initRuss Cox
Run it right before main.init. There is still some runtime initialization that happens before runtime.init, and some of that may call into Go code (for example to acquire locks) so this timing is not perfect, but I believe it is the best we can do. This came up because global variables intialized to func values are done in the generated init code, not in the linker. LGTM=dvyukov R=dvyukov CC=golang-codereviews, iant, khr, r https://golang.org/cl/135210043
2014-08-29runtime: convert forcegc helper to GoDmitriy Vyukov
Also fix a bunch of bugs: 1. Accesses to last_gc must be atomic (it's int64). 2. last_gc still can be 0 during first checks in sysmon, check for 0. 3. forcegc.g can be unitialized when sysmon accesses it: forcegc.g is initialized by main goroutine (forcegc.g = newproc1(...)), and main goroutine is unsynchronized with both sysmon and forcegc goroutine. Initialize forcegc.g in the forcegc goroutine itself instead. LGTM=khr R=golang-codereviews, khr CC=golang-codereviews, rsc https://golang.org/cl/136770043
2014-08-28runtime: convert print.c to GoRuss Cox
LGTM=iant R=golang-codereviews, iant CC=dvyukov, golang-codereviews, khr, r https://golang.org/cl/135930043
2014-08-27runtime: rename Lock to MutexRuss Cox
Mutex is consistent with package sync, and when in the unexported Go form it avoids having a conflcit between the type (now mutex) and the function (lock). LGTM=iant R=golang-codereviews, iant CC=dvyukov, golang-codereviews, r https://golang.org/cl/133140043
2014-08-27cmd/{ld,link,objdump}, runtime, debug/gosym: move linker-defined symbols ↵Matthew Dempsky
into runtime package Fixes #8092. LGTM=rsc R=iant, rsc CC=golang-codereviews https://golang.org/cl/126790043
2014-08-27runtime: changes to g->atomicstatus (nee status) to support concurrent GCRick Hudson
Every change to g->atomicstatus is now done atomically so that we can ensure that all gs pass through a gc safepoint on demand. This allows the GC to move from one phase to the next safely. In some phases the stack will be scanned. This CL only deals with the infrastructure that allows g->atomicstatus to go from one state to another. Future CLs will deal with scanning and monitoring what phase the GC is in. The major change was to moving to using a Gscan bit to indicate that the status is in a scan state. The only bug fix was in oldstack where I wasn't moving to a Gcopystack state in order to block scanning until the new stack was in place. The proc.go file is waiting for an atomic load instruction. LGTM=rsc R=golang-codereviews, dvyukov, josharian, rsc CC=golang-codereviews, khr https://golang.org/cl/132960044
2014-08-26runtime,sync: Convert procPin and procUnpin functions to Go.Sanjay Menakuru
LGTM=dvyukov R=golang-codereviews, dvyukov CC=golang-codereviews, khr https://golang.org/cl/132880043
2014-08-25runtime: restore scavenger constantsDmitriy Vyukov
Once and for all. Broken in cl/108640043. I've messed it before. To test scavenger-related changes one needs to alter the constants during final testing. And then it's very easy to submit with the altered constants. LGTM=rsc R=golang-codereviews CC=golang-codereviews, rsc https://golang.org/cl/136720044
2014-08-25runtime: remove dedicated scavenger threadDmitriy Vyukov
A whole thread is too much for background scavenger that sleeps all the time anyway. We already have sysmon thread that can do this work. Also remove g->isbackground and simplify enter/exitsyscall. LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews, khr, rlh https://golang.org/cl/108640043
2014-08-25runtime: refactor CPU profilingDmitriy Vyukov
Reduce duration of critical section, make pcbuf local to function. LGTM=rsc R=golang-codereviews CC=golang-codereviews, rsc https://golang.org/cl/102600043
2014-08-24runtime,runtime/debug: Converted some functions from goc to Go.Sanjay Menakuru
LGTM=khr R=golang-codereviews, khr CC=dvyukov, golang-codereviews https://golang.org/cl/131010044
2014-08-24runtime: convert channel operations to Go, part 1 (chansend1).Keith Randall
LGTM=dvyukov R=dvyukov, khr CC=golang-codereviews https://golang.org/cl/127460044
2014-08-23runtime: remove unused varDmitriy Vyukov
LGTM=bradfitz R=daniel.morsing, bradfitz CC=golang-codereviews https://golang.org/cl/130500044
2014-08-23runtime: run newproc1 on M stack.Daniel Morsing
This makes newproc invisible to the GC. This is a pretty simple change since parts of newproc already depends on being run on the M stack. LGTM=dvyukov R=golang-codereviews, dvyukov CC=golang-codereviews, khr https://golang.org/cl/129520043
2014-08-22runtime: convert note to GoDmitriy Vyukov
Note is required for timers and heap scavenger. LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews, khr, rlh https://golang.org/cl/128620043
2014-08-21runtime: convert common scheduler functions to GoDmitriy Vyukov
These are required for chans, semaphores, timers, etc. LGTM=khr R=golang-codereviews, khr CC=golang-codereviews, rlh, rsc https://golang.org/cl/123640043
2014-08-21runtime: init GC laterDmitriy Vyukov
Init GC later as it needs to read GOGC env var. Fixes #8562. LGTM=daniel.morsing, rsc R=golang-codereviews, daniel.morsing, rsc CC=golang-codereviews, khr, rlh https://golang.org/cl/130990043
2014-08-21runtime: fix deadlock when gctraceDmitriy Vyukov
Calling ReadMemStats which does stoptheworld on m0 holding locks was not a good idea. Stoptheworld holding locks is a recipe for deadlocks (added check for this). Stoptheworld on g0 may or may not work (added check for this as well). As far as I understand scavenger will print incorrect numbers now, as stack usage is not subtracted from heap. But it's better than deadlocking. LGTM=khr R=golang-codereviews, rsc, khr CC=golang-codereviews, rlh https://golang.org/cl/124670043
2014-08-19runtime: convert Gosched to GoDmitriy Vyukov
LGTM=rlh, khr R=golang-codereviews, rlh, bradfitz, khr CC=golang-codereviews, rsc https://golang.org/cl/127490043
2014-08-18runtime: fix dump of data/bssDmitriy Vyukov
Fixes #8530. LGTM=khr R=golang-codereviews, khr CC=golang-codereviews, rsc https://golang.org/cl/124440043
2014-08-08runtime: mark functions as static where possibleMatthew Dempsky
Update #8092 LGTM=dvyukov R=golang-codereviews, minux, dvyukov CC=golang-codereviews https://golang.org/cl/122250043
2014-08-07cmd/cc, runtime: eliminate use of the unnamed substructure C extensionPeter Collingbourne
Eliminating use of this extension makes it easier to port the Go runtime to other compilers. This CL also disables the extension in cc to prevent accidental use. LGTM=rsc, khr R=rsc, aram, khr, dvyukov CC=axwalk, golang-codereviews https://golang.org/cl/106790044
2014-08-07runtime: remove mal/malloc/FlagNoGC/FlagNoInvokeGCDmitriy Vyukov
FlagNoGC is unused now. FlagNoInvokeGC is unneeded as we don't invoke GC on g0 and when holding locks anyway. mal/malloc have very few uses and you never remember the exact set of flags they use and the difference between them. Moreover, eventually we need to give exact types to all allocations, something what mal/malloc do not support. LGTM=khr R=golang-codereviews, khr CC=golang-codereviews, rsc https://golang.org/cl/117580043
2014-07-31runtime: get rid of freeDmitriy Vyukov
Several reasons: 1. Significantly simplifies runtime. 2. This code proved to be buggy. 3. Free is incompatible with bump-the-pointer allocation. 4. We want to write runtime in Go, Go does not have free. 5. Too much code to free env strings on startup. LGTM=khr R=golang-codereviews, josharian, tracey.brendan, khr CC=bradfitz, golang-codereviews, r, rlh, rsc https://golang.org/cl/116390043
2014-07-30runtime: rewrite malloc in Go.Keith Randall
This change introduces gomallocgc, a Go clone of mallocgc. Only a few uses have been moved over, so there are still lots of uses from C. Many of these C uses will be moved over to Go (e.g. in slice.goc), but probably not all. What should remain of C's mallocgc is an open question. LGTM=rsc, dvyukov R=rsc, khr, dave, bradfitz, dvyukov CC=golang-codereviews https://golang.org/cl/108840046
2014-07-29runtime: generate type info for chansDmitriy Vyukov
LGTM=khr R=golang-codereviews, khr CC=golang-codereviews, khr https://golang.org/cl/115280043
2014-07-29runtime: simpler and faster GCDmitriy Vyukov
Implement the design described in: https://docs.google.com/document/d/1v4Oqa0WwHunqlb8C3ObL_uNQw3DfSY-ztoA-4wWbKcg/pub Summary of the changes: GC uses "2-bits per word" pointer type info embed directly into bitmap. Scanning of stacks/data/heap is unified. The old spans types go away. Compiler generates "sparse" 4-bits type info for GC (directly for GC bitmap). Linker generates "dense" 2-bits type info for data/bss (the same as stacks use). Summary of results: -1680 lines of code total (-1000+ in mgc0.c only) -25% memory consumption -3-7% binary size -15% GC pause reduction -7% run time reduction LGTM=khr R=golang-codereviews, rsc, christoph, khr CC=golang-codereviews, rlh https://golang.org/cl/106260045
2014-07-23runtime: fix unexpected return pc for runtime.newstackcallDmitriy Vyukov
With cl/112640043 TestCgoDeadlockCrash episodically print: unexpected return pc for runtime.newstackcall After adding debug output I see the following trace: runtime: unexpected return pc for runtime.newstackcall called from 0xc208011b00 runtime.throw(0x414da86) src/pkg/runtime/panic.c:523 +0x77 runtime.gentraceback(0x40165fc, 0xba440c28, 0x0, 0xc208d15200, 0xc200000000, 0xc208ddfd20, 0x20, 0x0, 0x0, 0x300) src/pkg/runtime/traceback_x86.c:185 +0xca4 runtime.callers(0x1, 0xc208ddfd20, 0x20) src/pkg/runtime/traceback_x86.c:438 +0x98 mcommoninit(0xc208ddfc00) src/pkg/runtime/proc.c:369 +0x5c runtime.allocm(0xc208052000) src/pkg/runtime/proc.c:686 +0xa6 newm(0x4017850, 0xc208052000) src/pkg/runtime/proc.c:933 +0x27 startm(0xc208052000, 0x100000001) src/pkg/runtime/proc.c:1011 +0xba wakep() src/pkg/runtime/proc.c:1071 +0x57 resetspinning() src/pkg/runtime/proc.c:1297 +0xa1 schedule() src/pkg/runtime/proc.c:1366 +0x14b runtime.gosched0(0xc20808e240) src/pkg/runtime/proc.c:1465 +0x5b runtime.newstack() src/pkg/runtime/stack.c:891 +0x44d runtime: unexpected return pc for runtime.newstackcall called from 0xc208011b00 runtime.newstackcall(0x4000cbd, 0x4000b80) src/pkg/runtime/asm_amd64.s:278 +0x6f I suspect that it can happen on any stack split. So don't unwind g0 stack. Also, that comment is lying -- we can traceback w/o mcache, CPU profiler does that. LGTM=rsc R=golang-codereviews CC=golang-codereviews, khr, rsc https://golang.org/cl/120040043