| 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 |
// runtime_setProfLabel should be an internal detail, |
| 12 |
// but widely used packages access it using linkname. |
| 13 |
// Notable members of the hall of shame include: |
| 14 |
// - github.com/cloudwego/localsession |
| 15 |
// |
| 16 |
// Do not remove or change the type signature. |
| 17 |
// See go.dev/issue/67401. |
| 18 |
// |
| 19 |
//go:linkname runtime_setProfLabel runtime/pprof.runtime_setProfLabel |
| 20 |
func runtime_setProfLabel(labels unsafe.Pointer) { |
| 21 |
// Introduce race edge for read-back via profile. |
| 22 |
// This would more properly use &getg().labels as the sync address, |
| 23 |
// but we do the read in a signal handler and can't call the race runtime then. |
| 24 |
// |
| 25 |
// This uses racereleasemerge rather than just racerelease so |
| 26 |
// the acquire in profBuf.read synchronizes with *all* prior |
| 27 |
// setProfLabel operations, not just the most recent one. This |
| 28 |
// is important because profBuf.read will observe different |
| 29 |
// labels set by different setProfLabel operations on |
| 30 |
// different goroutines, so it needs to synchronize with all |
| 31 |
// of them (this wouldn't be an issue if we could synchronize |
| 32 |
// on &getg().labels since we would synchronize with each |
| 33 |
// most-recent labels write separately.) |
| 34 |
// |
| 35 |
// racereleasemerge is like a full read-modify-write on |
| 36 |
// labelSync, rather than just a store-release, so it carries |
| 37 |
// a dependency on the previous racereleasemerge, which |
| 38 |
// ultimately carries forward to the acquire in profBuf.read. |
| 39 |
if raceenabled { |
| 40 |
racereleasemerge(unsafe.Pointer(&labelSync)) |
| 41 |
} |
| 42 |
getg().labels = labels |
| 43 |
} |
| 44 |
|
| 45 |
// runtime_getProfLabel should be an internal detail, |
| 46 |
// but widely used packages access it using linkname. |
| 47 |
// Notable members of the hall of shame include: |
| 48 |
// - github.com/cloudwego/localsession |
| 49 |
// |
| 50 |
// Do not remove or change the type signature. |
| 51 |
// See go.dev/issue/67401. |
| 52 |
// |
| 53 |
//go:linkname runtime_getProfLabel runtime/pprof.runtime_getProfLabel |
| 54 |
func runtime_getProfLabel() unsafe.Pointer { |
| 55 |
return getg().labels |
| 56 |
} |