From: Andy Pan Date: Sat, 27 Aug 2022 18:24:06 +0000 (+0800) Subject: runtime: convert mOS.profileTimerValid to internal atomic type X-Git-Tag: go1.20rc1~1330 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d3b35a42429cec6d57d0d1e167d9443d0fbd6e97;p=gostls13.git runtime: convert mOS.profileTimerValid to internal atomic type For #53821 Change-Id: I6ef90867e918d4907baa83c5a811f1f93e8c09a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/426196 Reviewed-by: Michael Knyszek TryBot-Result: Gopher Robot Auto-Submit: Michael Pratt Run-TryBot: Michael Knyszek Reviewed-by: Michael Pratt --- diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go index 25aea6522d..3ae665c83d 100644 --- a/src/runtime/os_linux.go +++ b/src/runtime/os_linux.go @@ -21,12 +21,12 @@ type mOS struct { // profileTimer holds the ID of the POSIX interval timer for profiling CPU // usage on this thread. // - // It is valid when the profileTimerValid field is non-zero. A thread + // It is valid when the profileTimerValid field is true. A thread // creates and manages its own timer, and these fields are read and written // only by this thread. But because some of the reads on profileTimerValid - // are in signal handling code, access to that field uses atomic operations. + // are in signal handling code, this field should be atomic type. profileTimer int32 - profileTimerValid uint32 + profileTimerValid atomic.Bool // needPerThreadSyscall indicates that a per-thread syscall is required // for doAllThreadsSyscall. @@ -593,7 +593,7 @@ func validSIGPROF(mp *m, c *sigctxt) bool { // Having an M means the thread interacts with the Go scheduler, and we can // check whether there's an active per-thread timer for this thread. - if atomic.Load(&mp.profileTimerValid) != 0 { + if mp.profileTimerValid.Load() { // If this M has its own per-thread CPU profiling interval timer, we // should track the SIGPROF signals that come from that timer (for // accurate reporting of its CPU usage; see issue 35057) and ignore any @@ -619,9 +619,9 @@ func setThreadCPUProfiler(hz int32) { } // destroy any active timer - if atomic.Load(&mp.profileTimerValid) != 0 { + if mp.profileTimerValid.Load() { timerid := mp.profileTimer - atomic.Store(&mp.profileTimerValid, 0) + mp.profileTimerValid.Store(false) mp.profileTimer = 0 ret := timer_delete(timerid) @@ -681,7 +681,7 @@ func setThreadCPUProfiler(hz int32) { } mp.profileTimer = timerid - atomic.Store(&mp.profileTimerValid, 1) + mp.profileTimerValid.Store(true) } // perThreadSyscallArgs contains the system call number, arguments, and