Skip to content

Commit 6cb064c

Browse files
committed
Revert "runtime: convert g.waitreason from string to uint8"
This reverts commit 4eea887. Reason for revert: broke s390x build Change-Id: Id6c2b6a7319273c4d21f613d4cdd38b00d49f847 Reviewed-on: https://go-review.googlesource.com/100375 Reviewed-by: Josh Bleecher Snyder <[email protected]>
1 parent 911839c commit 6cb064c

15 files changed

Lines changed: 47 additions & 114 deletions

src/runtime/chan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func chansend(c *hchan, ep unsafe.Pointer, block bool, callerpc uintptr) bool {
142142
if !block {
143143
return false
144144
}
145-
gopark(nil, nil, waitReasonChanSendNilChan, traceEvGoStop, 2)
145+
gopark(nil, nil, "chan send (nil chan)", traceEvGoStop, 2)
146146
throw("unreachable")
147147
}
148148

@@ -231,7 +231,7 @@ func chansend(c *hchan, ep unsafe.Pointer, block bool, callerpc uintptr) bool {
231231
gp.waiting = mysg
232232
gp.param = nil
233233
c.sendq.enqueue(mysg)
234-
goparkunlock(&c.lock, waitReasonChanSend, traceEvGoBlockSend, 3)
234+
goparkunlock(&c.lock, "chan send", traceEvGoBlockSend, 3)
235235

236236
// someone woke us up.
237237
if mysg != gp.waiting {
@@ -426,7 +426,7 @@ func chanrecv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool)
426426
if !block {
427427
return
428428
}
429-
gopark(nil, nil, waitReasonChanReceiveNilChan, traceEvGoStop, 2)
429+
gopark(nil, nil, "chan receive (nil chan)", traceEvGoStop, 2)
430430
throw("unreachable")
431431
}
432432

@@ -517,7 +517,7 @@ func chanrecv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool)
517517
mysg.c = c
518518
gp.param = nil
519519
c.recvq.enqueue(mysg)
520-
goparkunlock(&c.lock, waitReasonChanReceive, traceEvGoBlockRecv, 3)
520+
goparkunlock(&c.lock, "chan receive", traceEvGoBlockRecv, 3)
521521

522522
// someone woke us up
523523
if mysg != gp.waiting {

src/runtime/heapdump.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func dumpgoroutine(gp *g) {
349349
dumpbool(isSystemGoroutine(gp))
350350
dumpbool(false) // isbackground
351351
dumpint(uint64(gp.waitsince))
352-
dumpstr(gp.waitreason.String())
352+
dumpstr(gp.waitreason)
353353
dumpint(uint64(uintptr(gp.sched.ctxt)))
354354
dumpint(uint64(uintptr(unsafe.Pointer(gp.m))))
355355
dumpint(uint64(uintptr(unsafe.Pointer(gp._defer))))
@@ -658,7 +658,7 @@ func mdump() {
658658
func writeheapdump_m(fd uintptr) {
659659
_g_ := getg()
660660
casgstatus(_g_.m.curg, _Grunning, _Gwaiting)
661-
_g_.waitreason = waitReasonDumpingHeap
661+
_g_.waitreason = "dumping heap"
662662

663663
// Update stats so we can dump them.
664664
// As a side effect, flushes all the MCaches so the MSpan.freelist

src/runtime/mfinal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func runfinq() {
172172
gp := getg()
173173
fing = gp
174174
fingwait = true
175-
goparkunlock(&finlock, waitReasonFinalizerWait, traceEvGoBlock, 1)
175+
goparkunlock(&finlock, "finalizer wait", traceEvGoBlock, 1)
176176
continue
177177
}
178178
unlock(&finlock)

src/runtime/mgc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func setGCPercent(in int32) (out int32) {
241241
gp := getg()
242242
gp.schedlink = work.sweepWaiters.head
243243
work.sweepWaiters.head.set(gp)
244-
goparkunlock(&work.sweepWaiters.lock, waitReasonWaitForGCCycle, traceEvGoBlock, 1)
244+
goparkunlock(&work.sweepWaiters.lock, "wait for GC cycle", traceEvGoBlock, 1)
245245
} else {
246246
// GC isn't active.
247247
unlock(&work.sweepWaiters.lock)
@@ -1100,7 +1100,7 @@ func GC() {
11001100
// termination of cycle N complete.
11011101
gp.schedlink = work.sweepWaiters.head
11021102
work.sweepWaiters.head.set(gp)
1103-
goparkunlock(&work.sweepWaiters.lock, waitReasonWaitForGCCycle, traceEvGoBlock, 1)
1103+
goparkunlock(&work.sweepWaiters.lock, "wait for GC cycle", traceEvGoBlock, 1)
11041104
} else {
11051105
// We're in sweep N already.
11061106
unlock(&work.sweepWaiters.lock)
@@ -1116,7 +1116,7 @@ func GC() {
11161116
if gcphase == _GCmark && atomic.Load(&work.cycles) == n+1 {
11171117
gp.schedlink = work.sweepWaiters.head
11181118
work.sweepWaiters.head.set(gp)
1119-
goparkunlock(&work.sweepWaiters.lock, waitReasonWaitForGCCycle, traceEvGoBlock, 1)
1119+
goparkunlock(&work.sweepWaiters.lock, "wait for GC cycle", traceEvGoBlock, 1)
11201120
} else {
11211121
unlock(&work.sweepWaiters.lock)
11221122
}
@@ -1530,7 +1530,7 @@ func gcMarkTermination(nextTriggerRatio float64) {
15301530
_g_.m.traceback = 2
15311531
gp := _g_.m.curg
15321532
casgstatus(gp, _Grunning, _Gwaiting)
1533-
gp.waitreason = waitReasonGarbageCollection
1533+
gp.waitreason = "garbage collection"
15341534

15351535
// Run gc on the g0 stack. We do this so that the g stack
15361536
// we're currently running on will no longer change. Cuts
@@ -1799,7 +1799,7 @@ func gcBgMarkWorker(_p_ *p) {
17991799
}
18001800
}
18011801
return true
1802-
}, unsafe.Pointer(park), waitReasonGCWorkerIdle, traceEvGoBlock, 0)
1802+
}, unsafe.Pointer(park), "GC worker (idle)", traceEvGoBlock, 0)
18031803

18041804
// Loop until the P dies and disassociates this
18051805
// worker (the P may later be reused, in which case

src/runtime/mgcmark.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func markroot(gcw *gcWork, i uint32) {
251251
selfScan := gp == userG && readgstatus(userG) == _Grunning
252252
if selfScan {
253253
casgstatus(userG, _Grunning, _Gwaiting)
254-
userG.waitreason = waitReasonGarbageCollectionScan
254+
userG.waitreason = "garbage collection scan"
255255
}
256256

257257
// TODO: scang blocks until gp's stack has
@@ -549,7 +549,7 @@ func gcAssistAlloc1(gp *g, scanWork int64) {
549549

550550
// gcDrainN requires the caller to be preemptible.
551551
casgstatus(gp, _Grunning, _Gwaiting)
552-
gp.waitreason = waitReasonGCAssistMarking
552+
gp.waitreason = "GC assist marking"
553553

554554
// drain own cached work first in the hopes that it
555555
// will be more cache friendly.
@@ -648,7 +648,7 @@ func gcParkAssist() bool {
648648
return false
649649
}
650650
// Park.
651-
goparkunlock(&work.assistQueue.lock, waitReasonGCAssistWait, traceEvGoBlockGC, 2)
651+
goparkunlock(&work.assistQueue.lock, "GC assist wait", traceEvGoBlockGC, 2)
652652
return true
653653
}
654654

src/runtime/mgcsweep.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func bgsweep(c chan int) {
4949
lock(&sweep.lock)
5050
sweep.parked = true
5151
c <- 1
52-
goparkunlock(&sweep.lock, waitReasonGCSweepWait, traceEvGoBlock, 1)
52+
goparkunlock(&sweep.lock, "GC sweep wait", traceEvGoBlock, 1)
5353

5454
for {
5555
for gosweepone() != ^uintptr(0) {
@@ -68,7 +68,7 @@ func bgsweep(c chan int) {
6868
continue
6969
}
7070
sweep.parked = true
71-
goparkunlock(&sweep.lock, waitReasonGCSweepWait, traceEvGoBlock, 1)
71+
goparkunlock(&sweep.lock, "GC sweep wait", traceEvGoBlock, 1)
7272
}
7373
}
7474

src/runtime/netpoll.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func netpollblock(pd *pollDesc, mode int32, waitio bool) bool {
363363
// this is necessary because runtime_pollUnblock/runtime_pollSetDeadline/deadlineimpl
364364
// do the opposite: store to closing/rd/wd, membarrier, load of rg/wg
365365
if waitio || netpollcheckerr(pd, mode) == 0 {
366-
gopark(netpollblockcommit, unsafe.Pointer(gpp), waitReasonIOWait, traceEvGoBlockNet, 5)
366+
gopark(netpollblockcommit, unsafe.Pointer(gpp), "IO wait", traceEvGoBlockNet, 5)
367367
}
368368
// be careful to not lose concurrent READY notification
369369
old := atomic.Xchguintptr(gpp, 0)

src/runtime/proc.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func main() {
214214
}
215215
}
216216
if atomic.Load(&panicking) != 0 {
217-
gopark(nil, nil, waitReasonPanicWait, traceEvGoStop, 1)
217+
gopark(nil, nil, "panicwait", traceEvGoStop, 1)
218218
}
219219

220220
exit(0)
@@ -245,7 +245,7 @@ func forcegchelper() {
245245
throw("forcegc: phase error")
246246
}
247247
atomic.Store(&forcegc.idle, 1)
248-
goparkunlock(&forcegc.lock, waitReasonForceGGIdle, traceEvGoBlock, 1)
248+
goparkunlock(&forcegc.lock, "force gc (idle)", traceEvGoBlock, 1)
249249
// this goroutine is explicitly resumed by sysmon
250250
if debug.gctrace > 0 {
251251
println("GC forced")
@@ -274,11 +274,7 @@ func goschedguarded() {
274274
// If unlockf returns false, the goroutine is resumed.
275275
// unlockf must not access this G's stack, as it may be moved between
276276
// the call to gopark and the call to unlockf.
277-
// Reason explains why the goroutine has been parked.
278-
// It is displayed in stack traces and heap dumps.
279-
// Reasons should be unique and descriptive.
280-
// Do not re-use reasons, add new ones.
281-
func gopark(unlockf func(*g, unsafe.Pointer) bool, lock unsafe.Pointer, reason waitReason, traceEv byte, traceskip int) {
277+
func gopark(unlockf func(*g, unsafe.Pointer) bool, lock unsafe.Pointer, reason string, traceEv byte, traceskip int) {
282278
mp := acquirem()
283279
gp := mp.curg
284280
status := readgstatus(gp)
@@ -297,7 +293,7 @@ func gopark(unlockf func(*g, unsafe.Pointer) bool, lock unsafe.Pointer, reason w
297293

298294
// Puts the current goroutine into a waiting state and unlocks the lock.
299295
// The goroutine can be made runnable again by calling goready(gp).
300-
func goparkunlock(lock *mutex, reason waitReason, traceEv byte, traceskip int) {
296+
func goparkunlock(lock *mutex, reason string, traceEv byte, traceskip int) {
301297
gopark(parkunlock_c, unsafe.Pointer(lock), reason, traceEv, traceskip)
302298
}
303299

@@ -2671,7 +2667,7 @@ func goexit0(gp *g) {
26712667
gp._defer = nil // should be true already but just in case.
26722668
gp._panic = nil // non-nil for Goexit during panic. points at stack-allocated data.
26732669
gp.writebuf = nil
2674-
gp.waitreason = 0
2670+
gp.waitreason = ""
26752671
gp.param = nil
26762672
gp.labels = nil
26772673
gp.timer = nil
@@ -4497,7 +4493,7 @@ func schedtrace(detailed bool) {
44974493
if lockedm != nil {
44984494
id2 = lockedm.id
44994495
}
4500-
print(" G", gp.goid, ": status=", readgstatus(gp), "(", gp.waitreason.String(), ") m=", id1, " lockedm=", id2, "\n")
4496+
print(" G", gp.goid, ": status=", readgstatus(gp), "(", gp.waitreason, ") m=", id1, " lockedm=", id2, "\n")
45014497
}
45024498
unlock(&allglock)
45034499
unlock(&sched.lock)

src/runtime/runtime2.go

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,20 @@ type g struct {
358358
atomicstatus uint32
359359
stackLock uint32 // sigprof/scang lock; TODO: fold in to atomicstatus
360360
goid int64
361+
waitsince int64 // approx time when the g become blocked
362+
waitreason string // if status==Gwaiting
361363
schedlink guintptr
362-
waitsince int64 // approx time when the g become blocked
363-
waitreason waitReason // if status==Gwaiting
364-
preempt bool // preemption signal, duplicates stackguard0 = stackpreempt
365-
paniconfault bool // panic (instead of crash) on unexpected fault address
366-
preemptscan bool // preempted g does scan for gc
367-
gcscandone bool // g has scanned stack; protected by _Gscan bit in status
368-
gcscanvalid bool // false at start of gc cycle, true if G has not run since last scan; TODO: remove?
369-
throwsplit bool // must not split stack
370-
raceignore int8 // ignore race detection events
371-
sysblocktraced bool // StartTrace has emitted EvGoInSyscall about this goroutine
372-
sysexitticks int64 // cputicks when syscall has returned (for tracing)
373-
traceseq uint64 // trace event sequencer
374-
tracelastp puintptr // last P emitted an event for this goroutine
364+
preempt bool // preemption signal, duplicates stackguard0 = stackpreempt
365+
paniconfault bool // panic (instead of crash) on unexpected fault address
366+
preemptscan bool // preempted g does scan for gc
367+
gcscandone bool // g has scanned stack; protected by _Gscan bit in status
368+
gcscanvalid bool // false at start of gc cycle, true if G has not run since last scan; TODO: remove?
369+
throwsplit bool // must not split stack
370+
raceignore int8 // ignore race detection events
371+
sysblocktraced bool // StartTrace has emitted EvGoInSyscall about this goroutine
372+
sysexitticks int64 // cputicks when syscall has returned (for tracing)
373+
traceseq uint64 // trace event sequencer
374+
tracelastp puintptr // last P emitted an event for this goroutine
375375
lockedm muintptr
376376
sig uint32
377377
writebuf []byte
@@ -752,69 +752,6 @@ const (
752752
// The maximum number of frames we print for a traceback
753753
const _TracebackMaxFrames = 100
754754

755-
// A waitReason explains why a goroutine has been stopped.
756-
// See gopark. Do not re-use waitReasons, add new ones.
757-
type waitReason uint8
758-
759-
const (
760-
waitReasonZero waitReason = iota // ""
761-
waitReasonGCAssistMarking // "GC assist marking"
762-
waitReasonIOWait // "IO wait"
763-
waitReasonChanReceiveNilChan // "chan receive (nil chan)"
764-
waitReasonChanSendNilChan // "chan send (nil chan)"
765-
waitReasonDumpingHeap // "dumping heap"
766-
waitReasonGarbageCollection // "garbage collection"
767-
waitReasonGarbageCollectionScan // "garbage collection scan"
768-
waitReasonPanicWait // "panicwait"
769-
waitReasonSelect // "select"
770-
waitReasonSelectNoCases // "select (no cases)"
771-
waitReasonGCAssistWait // "GC assist wait"
772-
waitReasonGCSweepWait // "GC sweep wait"
773-
waitReasonChanReceive // "chan receive"
774-
waitReasonChanSend // "chan send"
775-
waitReasonFinalizerWait // "finalizer wait"
776-
waitReasonForceGGIdle // "force gc (idle)"
777-
waitReasonSemacquire // "semacquire"
778-
waitReasonSleep // "sleep"
779-
waitReasonTimerGoroutineIdle // "timer goroutine (idle)"
780-
waitReasonTraceReaderBlocked // "trace reader (blocked)"
781-
waitReasonWaitForGCCycle // "wait for GC cycle"
782-
waitReasonGCWorkerIdle // "GC worker (idle)"
783-
)
784-
785-
var waitReasonStrings = [...]string{
786-
waitReasonZero: "",
787-
waitReasonGCAssistMarking: "GC assist marking",
788-
waitReasonIOWait: "IO wait",
789-
waitReasonChanReceiveNilChan: "chan receive (nil chan)",
790-
waitReasonChanSendNilChan: "chan send (nil chan)",
791-
waitReasonDumpingHeap: "dumping heap",
792-
waitReasonGarbageCollection: "garbage collection",
793-
waitReasonGarbageCollectionScan: "garbage collection scan",
794-
waitReasonPanicWait: "panicwait",
795-
waitReasonSelect: "select",
796-
waitReasonSelectNoCases: "select (no cases)",
797-
waitReasonGCAssistWait: "GC assist wait",
798-
waitReasonGCSweepWait: "GC sweep wait",
799-
waitReasonChanReceive: "chan receive",
800-
waitReasonChanSend: "chan send",
801-
waitReasonFinalizerWait: "finalizer wait",
802-
waitReasonForceGGIdle: "force gc (idle)",
803-
waitReasonSemacquire: "semacquire",
804-
waitReasonSleep: "sleep",
805-
waitReasonTimerGoroutineIdle: "timer goroutine (idle)",
806-
waitReasonTraceReaderBlocked: "trace reader (blocked)",
807-
waitReasonWaitForGCCycle: "wait for GC cycle",
808-
waitReasonGCWorkerIdle: "GC worker (idle)",
809-
}
810-
811-
func (w waitReason) String() string {
812-
if w < 0 || w >= waitReason(len(waitReasonStrings)) {
813-
return "unknown wait reason"
814-
}
815-
return waitReasonStrings[w]
816-
}
817-
818755
var (
819756
allglen uintptr
820757
allm *m

src/runtime/select.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func selparkcommit(gp *g, _ unsafe.Pointer) bool {
189189
}
190190

191191
func block() {
192-
gopark(nil, nil, waitReasonSelectNoCases, traceEvGoStop, 1) // forever
192+
gopark(nil, nil, "select (no cases)", traceEvGoStop, 1) // forever
193193
}
194194

195195
// selectgo implements the select statement.
@@ -389,7 +389,7 @@ loop:
389389

390390
// wait for someone to wake us up
391391
gp.param = nil
392-
gopark(selparkcommit, nil, waitReasonSelect, traceEvGoBlockSelect, 1)
392+
gopark(selparkcommit, nil, "select", traceEvGoBlockSelect, 1)
393393

394394
sellock(scases, lockorder)
395395

0 commit comments

Comments
 (0)