aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.go
AgeCommit message (Collapse)Author
2023-02-16runtime: reimplement GODEBUG=cgocheck=2 as a GOEXPERIMENTKeith Randall
Move this knob from a binary-startup thing to a build-time thing. This will enable followon optmizations to the write barrier. Change-Id: Ic3323348621c76a7dc390c09ff55016b19c43018 Reviewed-on: https://go-review.googlesource.com/c/go/+/447778 Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-02-08runtime: correct typosOleksandr Redko
- Fix typo in throw error message for arena. - Correct typos in assembly and Go comments. - Fix log message in TestTraceCPUProfile. Change-Id: I874c9e8cd46394448b6717bc6021aa3ecf319d16 GitHub-Last-Rev: d27fad4d3cea81cc7a4ca6917985bcf5fa49b0e0 GitHub-Pull-Request: golang/go#58375 Reviewed-on: https://go-review.googlesource.com/c/go/+/465975 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-05runtime: prioritize VDSO and libcall unwinding in profilerCherry Mui
In the profiler, when unwinding the stack, we have special handling for VDSO calls. Currently, the special handling is only used when the normal unwinding fails. If the signal lands in the function that makes the VDSO call (e.g. nanotime1) and after the stack switch, the normal unwinding doesn't fail but gets a stack trace with exactly one frame (the nanotime1 frame). The stack trace stops because of the stack switch. This 1-frame stack trace is not as helpful. Instead, if vdsoSP is set, we know we are in VDSO call or right before or after it, so use vdsoPC and vdsoSP for unwinding. Do the same for libcall. Also remove _TraceTrap for VDSO unwinding, as vdsoPC and vdsoSP correspond to a call, not an interrupted instruction. Fixes #56574. Change-Id: I799aa7644d0c1e2715ab038a9eef49481dd3a7f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/455166 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-18all: add missing periods in commentscui fliter
Change-Id: I69065f8adf101fdb28682c55997f503013a50e29 Reviewed-on: https://go-review.googlesource.com/c/go/+/449757 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joedian Reid <joedian@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-18runtime: add page tracerMichael Knyszek
This change adds a new GODEBUG flag called pagetrace that writes a low-overhead trace of how pages of memory are managed by the Go runtime. The page tracer is kept behind a GOEXPERIMENT flag due to a potential security risk for setuid binaries. Change-Id: I6f4a2447d02693c25214400846a5d2832ad6e5c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/444157 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-10runtime: consolidate some low-level error reportingIan Lance Taylor
Use a single writeErrStr function. Avoid using global variables. Use a single version of some error messages rather than duplicating the messages in OS-specific files. Change-Id: If259fbe78faf797f0a21337d14472160ca03efa0 Reviewed-on: https://go-review.googlesource.com/c/go/+/447055 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-11-07runtime: yield in goschedIfBusy if gp.preemptMichael Pratt
runtime.bgsweep contains an infinite loop. With aggressive enough inlining, it may not perform any CALLs on a typical iteration. If the runtime trying to preempt this goroutine, the lack of CALLs may prevent preemption for ever occurring. bgsweep does happen to call goschedIfBusy. Add a preempt check there to make sure we yield eventually. For #55022. Change-Id: If22eb86fd6a626094b3c56dc745c8e4243b0fb40 Reviewed-on: https://go-review.googlesource.com/c/go/+/447135 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-10-18runtime: always keep global reference to mp until mexit completesMichael Pratt
Ms are allocated via standard heap allocation (`new(m)`), which means we must keep them alive (i.e., reachable by the GC) until we are completely done using them. Ms are primarily reachable through runtime.allm. However, runtime.mexit drops the M from allm fairly early, long before it is done using the M structure. If that was the last reference to the M, it is now at risk of being freed by the GC and used for some other allocation, leading to memory corruption. Ms with a Go-allocated stack coincidentally already keep a reference to the M in sched.freem, so that the stack can be freed lazily. This reference has the side effect of keeping this Ms reachable. However, Ms with an OS stack skip this and are at risk of corruption. Fix this lifetime by extending sched.freem use to all Ms, with the value of mp.freeWait determining whether the stack needs to be freed or not. Fixes #56243. Change-Id: Ic0c01684775f5646970df507111c9abaac0ba52e Reviewed-on: https://go-review.googlesource.com/c/go/+/443716 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-10-05runtime: avoid initializing MemProfileRate in init functionWang Deyu
Fixes #55100 Change-Id: Ibbff921e74c3a416fd8bb019d20410273961c015 Reviewed-on: https://go-review.googlesource.com/c/go/+/431315 Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-09-27runtime/trace: add missing events for the locked g in extra M.doujiang24
Extra Ms may lead to the "no consistent ordering of events possible" error when parsing trace file with cgo enabled, since: 1. The gs in the extra Ms may be in `_Gdead` status while starting trace by invoking `runtime.StartTrace`, 2. and these gs will trigger `traceEvGoSysExit` events in `runtime.exitsyscall` when invoking go functions from c, 3. then, the events of those gs are under non-consistent ordering, due to missing the previous events. Add two events, `traceEvGoCreate` and `traceEvGoInSyscall`, in `runtime.StartTrace`, will make the trace parser happy. Fixes #29707 Change-Id: I2fd9d1713cda22f0ddb36efe1ab351f88da10881 GitHub-Last-Rev: 7bbfddb81b70041250e3c59ce53bea44f7afd2c3 GitHub-Pull-Request: golang/go#54974 Reviewed-on: https://go-review.googlesource.com/c/go/+/429858 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: xie cui <523516579@qq.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com>
2022-09-26runtime: add an exit hook facilityThan McIntosh
Add a new API (not public/exported) for registering a function with the runtime that should be called when program execution terminates, to be used in the new code coverage re-implementation. The API looks like func addExitHook(f func(), runOnNonZeroExit bool) The first argument is the function to be run, second argument controls whether the function is invoked even if there is a call to os.Exit with a non-zero status. Exit hooks are run in reverse order of registration, e.g. the first hook to be registered will be the last to run. Exit hook functions are not allowed to panic or to make calls to os.Exit. Updates #51430. Change-Id: I906f8c5184b7c1666f05a62cfc7833bf1a4300c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/354790 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-09-16runtime: tweak bgsweep "low-priority" heuristicMichael Anthony Knyszek
Currently bgsweep attempts to be a low-priority background goroutine that runs mainly when the application is mostly idle. To avoid complicating the scheduler further, it achieves this with a simple heuristic: call Gosched after each span swept. While this is somewhat inefficient as there's scheduling overhead on each iteration, it's mostly fine because it tends to just come out of idle time anyway. In a busy system, the call to Gosched quickly puts bgsweep at the back of scheduler queues. However, what's problematic about this heuristic is the number of tracing events it produces. Average span sweeping latencies have been measured as low as 30 ns, so every 30 ns in the sweep phase, with available idle time, there would be a few trace events emitted. This could result in an overwhelming number, making traces much larger than they need to be. It also pollutes other observability tools, like the scheduling latencies runtime metric, because bgsweep stays runnable the whole time. This change fixes these problems with two modifications to the heursitic: 1. Check if there are any idle Ps before yielding. If there are, don't yield. 2. Sweep at least 10 spans before trying to yield. (1) is doing most of the work here. This change assumes that the presence of idle Ps means that there is available CPU time, so bgsweep is already making use of idle time and there's no reason it should stop. This will have the biggest impact on the aforementioned issues. (2) is a mitigation for the case where GOMAXPROCS=1, because we won't ever observe a zero idle P count. It does mean that bgsweep is a little bit higher priority than before because it yields its time less often, so it could interfere with goroutine scheduling latencies more. However, by sweeping 10 spans before volunteering time, we directly reduce trace event production by 90% in all cases. The impact on scheduling latencies should be fairly minimal, as sweeping a span is already so fast, that sweeping 10 is unlikely to make a dent in any meaningful end-to-end latency. In fact, it may even improve application latencies overall by freeing up spans and sweep work from goroutines allocating memory. It may be worth considering pushing this number higher in the future. Another reason to do (2) is to reduce contention on npidle, which will be checked as part of (1), but this is a fairly minor concern. The main reason is to capture the GOMAXPROCS=1 case. Fixes #54767. Change-Id: I4361400f17197b8ab84c01f56203f20575b29fc6 Reviewed-on: https://go-review.googlesource.com/c/go/+/429615 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-09-16runtime/metrics: add /sync/mutex/wait/total:seconds metricMichael Anthony Knyszek
This change adds a metric to the runtime/metrics package which tracks total mutex wait time for sync.Mutex and sync.RWMutex. The purpose of this metric is to be able to quickly get an idea of the total mutex wait time. The implementation of this metric piggybacks off of the existing G runnable tracking infrastructure, as well as the wait reason set on a G when it goes into _Gwaiting. Fixes #49881. Change-Id: I4691abf64ac3574bec69b4d7d4428b1573130517 Reviewed-on: https://go-review.googlesource.com/c/go/+/427618 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-16runtime: set G wait reason more consistentlyMichael Anthony Knyszek
Currently, wait reasons are set somewhat inconsistently. In a follow-up CL, we're going to want to rely on the wait reason being there for casgstatus, so the status quo isn't really going to work for that. Plus this inconsistency means there are a whole bunch of cases where we could be more specific about the G's status but aren't. So, this change adds a new function, casGToWaiting which is like casgstatus but also sets the wait reason. The goal is that by using this API it'll be harder to forget to set a wait reason (or the lack thereof will at least be explicit). This change then updates all casgstatus(gp, ..., _Gwaiting) calls to casGToWaiting(gp, ..., waitReasonX) instead. For a number of these cases, we're missing a wait reason, and it wouldn't hurt to add a wait reason for them, so this change also adds those wait reasons. For #49881. Change-Id: Ia95e06ecb74ed17bb7bb94f1a362ebfe6bec1518 Reviewed-on: https://go-review.googlesource.com/c/go/+/427617 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-07runtime: simplify code using unsafe.{Slice,String}cuiweixie
Updates #54854 Change-Id: Ie18665e93e477b6f220acf4c6c070b2af4343064 Reviewed-on: https://go-review.googlesource.com/c/go/+/428157 Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-09-05runtime: refactor finalizer goroutine statusLeonard Wang
Use an atomic.Uint32 to represent the state of finalizer goroutine. fingStatus will only be changed to fingWake in non fingWait state, so it is safe to set fingRunningFinalizer status in runfinq. name old time/op new time/op delta Finalizer-8 592µs ± 4% 561µs ± 1% -5.22% (p=0.000 n=10+10) FinalizerRun-8 694ns ± 6% 675ns ± 7% ~ (p=0.059 n=9+8) Change-Id: I7e4da30cec98ce99f7d8cf4c97f933a8a2d1cae1 Reviewed-on: https://go-review.googlesource.com/c/go/+/400134 Reviewed-by: Joedian Reid <joedian@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-09-05runtime: convert g.atomicstatus to internal atomic typeAndy Pan
Note that this changes some unsynchronized operations of g.atomicstatus to synchronized operations. Updates #53821 Change-Id: If249d62420ea09fbec39b570942f96c63669c333 Reviewed-on: https://go-review.googlesource.com/c/go/+/425363 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-09-01Revert "runtime: convert ncgocall to atomic type"Michael Pratt
This reverts CL 426075. Reason for revert: Import missing from cgocall.go. Change-Id: Iac17e914045b83da30484dbe2a624cde526fb175 Reviewed-on: https://go-review.googlesource.com/c/go/+/427614 Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-09-01runtime: convert ncgocall to atomic typecuiweixie
For #53821 Change-Id: Ib0d62ee36487b3ed68e063976968f3cac6499e4b Reviewed-on: https://go-review.googlesource.com/c/go/+/426075 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: xie cui <523516579@qq.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-31runtime: convert p.numTimers and p.deletedTimers to internal atomic typesAndy Pan
Note that this changes the non-atomic operations in p.destroy() to atomic operations. For #53821 Change-Id: I7bba77c9a2287ba697c87cce2c79293e4d1b3334 Reviewed-on: https://go-review.googlesource.com/c/go/+/425774 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-08-31runtime: convert extram and extraMWaiters to internal atomic typeAndy Pan
Updates #53821 Change-Id: Id579b2f8e48dfbe9f37e02d2fa8c94354f9887a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/425480 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: hopehook <hopehook@golangcn.org> Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-26runtime: convert forcegcstate.idle to internal atomic typeAndy Pan
Note that this changes a few unsynchronized operations of forcegcstate.idle to synchronized operations. Updates #53821 Change-Id: I041654cc84a188fad45e2df7abce3a434f9a1f15 Reviewed-on: https://go-review.googlesource.com/c/go/+/425361 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-08-25runtime: convert netpollWaiters to internal atomic typeAndy Pan
Updates #53821 Change-Id: I8776382b3eb0b7752cfc0d9287b707039d3f05c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/425358 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: hopehook <hopehook@qq.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-08-18runtime: convert timer0When/timerModifiedEarliest to atomic.Int64Cuong Manh Le
So they match with when/nextwhen fields of timer struct. Updates #53821 Change-Id: Iad0cceb129796745774facfbbfe5756df3a320b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/423117 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-08-18runtime: convert m.cgoCallersUse to atomic typeCuong Manh Le
Updates #53821 Change-Id: I99b01f8e91b798e73275635c8a63fcdc4a8df9f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/423888 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-08-18runtime: convert p.timerModifiedEarliest to atomic typeCuong Manh Le
Updates #53821 Change-Id: Iac0d7a3871d9e3ee0ba38ee7ab989faca9c89666 Reviewed-on: https://go-review.googlesource.com/c/go/+/424397 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-08-17runtime: convert p.timer0When to atomic typeCuong Manh Le
Updates #53821 Change-Id: I523ec61116d290ecf7b7e3eb96e468695766cb4d Reviewed-on: https://go-review.googlesource.com/c/go/+/424396 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-17runtime: convert freezing to atomic typeCuong Manh Le
Updates #53821 Change-Id: I77fcdb972b8920e1fb42248ce5bd2c3d2d0bd27e Reviewed-on: https://go-review.googlesource.com/c/go/+/423885 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-08-17runtime: convert m.signalPending to atomic typeCuong Manh Le
Updates #53821 Change-Id: Ib455be9ca7120ded7c77d34556eff977aa61faa3 Reviewed-on: https://go-review.googlesource.com/c/go/+/423886 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-15Revert "runtime/trace: add missing events for the locked g in extra M."Cuong Manh Le
This reverts commit ea9c3fd42d94182ce6f87104b68a51ea92f1a571. Reason for revert: break linux/ricsv64, openbsd/arm, illumos/amd64 builders Change-Id: I98479a8f63e76eed89a0e8846acf2c73e8441377 Reviewed-on: https://go-review.googlesource.com/c/go/+/423437 Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-08-12runtime: fix a comment typo in runqget()Andy Pan
Change-Id: I79695e1cfda3b4cd911673f6e14dc316c451e2ed Reviewed-on: https://go-review.googlesource.com/c/go/+/423436 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-08-12runtime/trace: add missing events for the locked g in extra M.doujiang24
Extra Ms may lead to the "no consistent ordering of events possible" error when parsing trace file with cgo enabled, since: 1. The gs in the extra Ms may be in `_Gdead` status while starting trace by invoking `runtime.StartTrace`, 2. and these gs will trigger `traceEvGoSysExit` events in `runtime.exitsyscall` when invoking go functions from c, 3. then, the events of those gs are under non-consistent ordering, due to missing the previous events. Add two events, `traceEvGoCreate` and `traceEvGoInSyscall`, in `runtime.StartTrace`, will make the trace parser happy. Fixes #29707 Change-Id: I7cc4b80822d2c46591304a59c9da2c9fc470f1d0 GitHub-Last-Rev: 445de8eaf3fb54e12795ac31e26650f821c5efbc GitHub-Pull-Request: golang/go#53284 Reviewed-on: https://go-review.googlesource.com/c/go/+/411034 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-08-12runtime: synchronize P wakeup and dropping PsMichael Pratt
CL 310850 dropped work re-checks on non-spinning Ms to fix #43997. This introduced a new race condition: a non-spinning M may drop its P and then park at the same time a spinning M attempts to wake a P to handle some new work. The spinning M fails to find an idle P (because the non-spinning M hasn't quite made its P idle yet), and does nothing assuming that the system is fully loaded. This results in loss of work conservation. In the worst case we could have a complete deadlock if injectglist fails to wake anything just as all Ps are going idle. sched.needspinning adds new synchronization to cover this case. If work submission fails to find a P, it sets needspinning to indicate that a spinning M is required. When non-spinning Ms prepare to drop their P, they check needspinning and abort going idle to become a spinning M instead. This addresses the race without extra spurious wakeups. In the normal (non-racing case), an M will become spinning via the normal path and clear the flag. injectglist must change in addition to wakep because it is a similar form of work submission, notably used following netpoll at a point when we might not have a P that would guarantee the work runs. Fixes #45867 Change-Id: Ieb623a6d4162fb8c2be7b4ff8acdebcc3a0d69a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/389014 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2022-08-12runtime: convert prof.hz to atomic typeMichael Pratt
This converts several unsynchronized reads (reads without holding prof.signalLock) into atomic reads. For #53821. For #52912. Change-Id: I421b96a22fbe26d699bcc21010c8a9e0f4efc276 Reviewed-on: https://go-review.googlesource.com/c/go/+/420196 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12runtime: convert prof.signalLock to atomic typeMichael Pratt
For #53821. Change-Id: I3e757fc6a020be10ee69459c395cb7eee49b0dfb Reviewed-on: https://go-review.googlesource.com/c/go/+/420195 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
2022-08-12runtime: convert timeHistogram to atomic typesMichael Pratt
I've dropped the note that sched.timeToRun is protected by sched.lock, as it does not seem to be true. For #53821. Change-Id: I03f8dc6ca0bcd4ccf3ec113010a0aa39c6f7d6ef Reviewed-on: https://go-review.googlesource.com/c/go/+/419449 Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com>
2022-08-12runtime: convert schedt.sysmonwait to atomic typeMichael Pratt
This converts a few unsynchronized accesses. For #53821. Change-Id: Ie2728779111e3e042696f15648981c5d5a86ca6d Reviewed-on: https://go-review.googlesource.com/c/go/+/419448 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2022-08-12runtime: convert schedt.gcwaiting to atomic typeMichael Pratt
Note that this replaces numerous unsynchronized loads throughout the scheduler. For #53821. Change-Id: Ica80b04c9e8c184bfef186e549526fc3f117c387 Reviewed-on: https://go-review.googlesource.com/c/go/+/419447 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12runtime: convert schedt.nmspinning to atomic typeMichael Pratt
Note that this converts nmspinning from uint32 to int32 for consistency with the other count fields in schedt. For #53821. Change-Id: Ia6ca7a2b476128eda3b68e9f0c7775ae66c0c744 Reviewed-on: https://go-review.googlesource.com/c/go/+/419446 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Austin Clements <austin@google.com>
2022-08-12runtime: convert schedt.npidle to atomic typeMichael Pratt
Note that this converts npidle from uint32 to int32 for consistency with the other count fields in schedt and the type of p.id. Note that this changes previously unsynchronized operations to synchronized operations in: * handoffp * injectglist * schedtrace * schedEnableUser * sync_runtime_canSpin For #53821. Change-Id: I36d1b3b4a28131c9d47884fade6bc44439dd6937 Reviewed-on: https://go-review.googlesource.com/c/go/+/419445 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
2022-08-12runtime: convert schedt.ngsys to atomic typeMichael Pratt
Note that this converts ngsys from uint32 to int32 to match the other (non-atomic) counters. For #53821. Change-Id: I3acbfbbd1dabc59b0ea5ddc86a97e0d0afa9f80c Reviewed-on: https://go-review.googlesource.com/c/go/+/419444 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2022-08-12runtime: convert schedt.pollUntil to atomic typeMichael Pratt
Note that this converts pollUntil from uint64 to int64, the type used by nanotime(). For #53821. Change-Id: Iec9ec7e09d3350552561d0708ba6ea9e8a8ae7ab Reviewed-on: https://go-review.googlesource.com/c/go/+/419443 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12runtime: convert schedt.lastpoll to atomic typeMichael Pratt
Note that this changes the type from uint64 to int64, the type used by nanotime(). It also adds an atomic load in pollWork(), which used to use a non-atomic load. For #53821. Change-Id: I6173c90f20bfdc0e0a4bc3a7b1c798d1c429fff5 Reviewed-on: https://go-review.googlesource.com/c/go/+/419442 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12runtime: print irrelevant IDs as nil in schedtraceMichael Pratt
We currently print these as -1, but some are technically uint64. We can be more explicit about their irrelevance by printing 'nil' rather than -1. Change-Id: I267fd8830564c75032bfe9176af59047f5a90202 Reviewed-on: https://go-review.googlesource.com/c/go/+/419441 Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com>
2022-08-12runtime: convert g.goid to uint64Michael Pratt
schedt.goidgen and p.goidcache are already uint64, this makes all cases consistent. The only oddball here is schedtrace which prints -1 as an equivalent for N/A or nil. A future CL will make this more explicit. Change-Id: I489626f3232799f6ca333d0d103b71d9d3aa7494 Reviewed-on: https://go-review.googlesource.com/c/go/+/419440 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12runtime: convert schedt.goidgen to atomic typeMichael Pratt
For #53821. Change-Id: I84c96ade5982b8e68d1d1787bf1bfa16a17a4fb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/419439 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12runtime: convert panicking to atomic typeMichael Pratt
For #53821. Change-Id: I93409f377881a3c029b41b0f1fbcef5e21091f2f Reviewed-on: https://go-review.googlesource.com/c/go/+/419438 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12runtime: convert runningPanicDefers to atomic typeMichael Pratt
For #53821. Change-Id: Ib48a1f2ff85d667c86dbd0b7662efab5a0abd837 Reviewed-on: https://go-review.googlesource.com/c/go/+/419437 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2022-08-12runtime: convert pendingPreemptSignals to atomic typeMichael Pratt
For #53821. Change-Id: I106adbcb00b7b887d54001c2d7d97345a13cc662 Reviewed-on: https://go-review.googlesource.com/c/go/+/419436 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
2022-08-11runtime: don't use trace.lock for trace reader parkingAustin Clements
We're about to require that all uses of trace.lock be on the system stack. That's mostly easy, except that it's involving parking the trace reader. Fix this by changing that parking protocol so it instead synchronizes through an atomic. For #53979. Change-Id: Icd6db8678dd01094029d7ad1c612029f571b4cbb Reviewed-on: https://go-review.googlesource.com/c/go/+/418955 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>