Commit c2425178 authored by Austin Clements's avatar Austin Clements

runtime: replace *g with guintptr in trace

trace's reader *g is going to cause write barriers in unfortunate
places, so replace it with a guintptr.

Change-Id: Ie8fb13bb89a78238f9d2a77ec77da703e96df8af
Reviewed-on: https://go-review.googlesource.com/31469
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: default avatarRick Hudson <rlh@golang.org>
parent 325c2aa5
...@@ -112,7 +112,7 @@ var trace struct { ...@@ -112,7 +112,7 @@ var trace struct {
empty traceBufPtr // stack of empty buffers empty traceBufPtr // stack of empty buffers
fullHead traceBufPtr // queue of full buffers fullHead traceBufPtr // queue of full buffers
fullTail traceBufPtr fullTail traceBufPtr
reader *g // goroutine that called ReadTrace, or nil reader guintptr // goroutine that called ReadTrace, or nil
stackTab traceStackTable // maps stack traces to unique ids stackTab traceStackTable // maps stack traces to unique ids
// Dictionary for traceEvString. // Dictionary for traceEvString.
...@@ -313,7 +313,7 @@ func StopTrace() { ...@@ -313,7 +313,7 @@ func StopTrace() {
if trace.fullHead != 0 || trace.fullTail != 0 { if trace.fullHead != 0 || trace.fullTail != 0 {
throw("trace: non-empty full trace buffer") throw("trace: non-empty full trace buffer")
} }
if trace.reading != 0 || trace.reader != nil { if trace.reading != 0 || trace.reader != 0 {
throw("trace: reading after shutdown") throw("trace: reading after shutdown")
} }
for trace.empty != 0 { for trace.empty != 0 {
...@@ -341,7 +341,7 @@ func ReadTrace() []byte { ...@@ -341,7 +341,7 @@ func ReadTrace() []byte {
lock(&trace.lock) lock(&trace.lock)
trace.lockOwner = getg() trace.lockOwner = getg()
if trace.reader != nil { if trace.reader != 0 {
// More than one goroutine reads trace. This is bad. // More than one goroutine reads trace. This is bad.
// But we rather do not crash the program because of tracing, // But we rather do not crash the program because of tracing,
// because tracing can be enabled at runtime on prod servers. // because tracing can be enabled at runtime on prod servers.
...@@ -365,7 +365,7 @@ func ReadTrace() []byte { ...@@ -365,7 +365,7 @@ func ReadTrace() []byte {
} }
// Wait for new data. // Wait for new data.
if trace.fullHead == 0 && !trace.shutdown { if trace.fullHead == 0 && !trace.shutdown {
trace.reader = getg() trace.reader.set(getg())
goparkunlock(&trace.lock, "trace reader (blocked)", traceEvGoBlock, 2) goparkunlock(&trace.lock, "trace reader (blocked)", traceEvGoBlock, 2)
lock(&trace.lock) lock(&trace.lock)
} }
...@@ -419,16 +419,16 @@ func ReadTrace() []byte { ...@@ -419,16 +419,16 @@ func ReadTrace() []byte {
// traceReader returns the trace reader that should be woken up, if any. // traceReader returns the trace reader that should be woken up, if any.
func traceReader() *g { func traceReader() *g {
if trace.reader == nil || (trace.fullHead == 0 && !trace.shutdown) { if trace.reader == 0 || (trace.fullHead == 0 && !trace.shutdown) {
return nil return nil
} }
lock(&trace.lock) lock(&trace.lock)
if trace.reader == nil || (trace.fullHead == 0 && !trace.shutdown) { if trace.reader == 0 || (trace.fullHead == 0 && !trace.shutdown) {
unlock(&trace.lock) unlock(&trace.lock)
return nil return nil
} }
gp := trace.reader gp := trace.reader.ptr()
trace.reader = nil trace.reader.set(nil)
unlock(&trace.lock) unlock(&trace.lock)
return gp return gp
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment