...

Source file src/runtime/proflabel.go

     1	// Copyright 2017 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	package runtime
     6	
     7	import "unsafe"
     8	
     9	var labelSync uintptr
    10	
    11	//go:linkname runtime_setProfLabel runtime/pprof.runtime_setProfLabel
    12	func runtime_setProfLabel(labels unsafe.Pointer) {
    13		// Introduce race edge for read-back via profile.
    14		// This would more properly use &getg().labels as the sync address,
    15		// but we do the read in a signal handler and can't call the race runtime then.
    16		//
    17		// This uses racereleasemerge rather than just racerelease so
    18		// the acquire in profBuf.read synchronizes with *all* prior
    19		// setProfLabel operations, not just the most recent one. This
    20		// is important because profBuf.read will observe different
    21		// labels set by different setProfLabel operations on
    22		// different goroutines, so it needs to synchronize with all
    23		// of them (this wouldn't be an issue if we could synchronize
    24		// on &getg().labels since we would synchronize with each
    25		// most-recent labels write separately.)
    26		//
    27		// racereleasemerge is like a full read-modify-write on
    28		// labelSync, rather than just a store-release, so it carries
    29		// a dependency on the previous racereleasemerge, which
    30		// ultimately carries forward to the acquire in profBuf.read.
    31		if raceenabled {
    32			racereleasemerge(unsafe.Pointer(&labelSync))
    33		}
    34		getg().labels = labels
    35	}
    36	
    37	//go:linkname runtime_getProfLabel runtime/pprof.runtime_getProfLabel
    38	func runtime_getProfLabel() unsafe.Pointer {
    39		return getg().labels
    40	}
    41	

View as plain text