summaryrefslogtreecommitdiffhomepage
path: root/pkg/coverage
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-01-22 19:48:08 +0000
committergVisor bot <gvisor-bot@google.com>2021-01-22 19:48:08 +0000
commit3814d20f28e68e132097e97764b2ed09c043a061 (patch)
tree8f0475ec0ca2c1915dc1386c41871668a7b6e2ea /pkg/coverage
parent42af1a172bff0fba31cf3d76689b44e1dcef273b (diff)
parent65594d30ad1b1a2ca676c7ea78f4815f83dc4d06 (diff)
Merge release-20210112.0-72-g65594d30a (automated)
Diffstat (limited to 'pkg/coverage')
-rw-r--r--pkg/coverage/coverage.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/pkg/coverage/coverage.go b/pkg/coverage/coverage.go
index fdfe31417..6f3d72e83 100644
--- a/pkg/coverage/coverage.go
+++ b/pkg/coverage/coverage.go
@@ -26,7 +26,6 @@ import (
"fmt"
"io"
"sort"
- "sync/atomic"
"testing"
"gvisor.dev/gvisor/pkg/sync"
@@ -69,12 +68,18 @@ var globalData struct {
}
// ClearCoverageData clears existing coverage data.
+//
+//go:norace
func ClearCoverageData() {
coverageMu.Lock()
defer coverageMu.Unlock()
+
+ // We do not use atomic operations while reading/writing to the counters,
+ // which would drastically degrade performance. Slight discrepancies due to
+ // racing is okay for the purposes of kcov.
for _, counters := range coverdata.Cover.Counters {
for index := 0; index < len(counters); index++ {
- atomic.StoreUint32(&counters[index], 0)
+ counters[index] = 0
}
}
}
@@ -114,6 +119,8 @@ var coveragePool = sync.Pool{
// ensure that each event is only reported once. Due to the limitations of Go
// coverage tools, we reset the global coverage data every time this function is
// run.
+//
+//go:norace
func ConsumeCoverageData(w io.Writer) int {
InitCoverageData()
@@ -125,11 +132,14 @@ func ConsumeCoverageData(w io.Writer) int {
for fileNum, file := range globalData.files {
counters := coverdata.Cover.Counters[file]
for index := 0; index < len(counters); index++ {
- if atomic.LoadUint32(&counters[index]) == 0 {
+ // We do not use atomic operations while reading/writing to the counters,
+ // which would drastically degrade performance. Slight discrepancies due to
+ // racing is okay for the purposes of kcov.
+ if counters[index] == 0 {
continue
}
// Non-zero coverage data found; consume it and report as a PC.
- atomic.StoreUint32(&counters[index], 0)
+ counters[index] = 0
pc := globalData.syntheticPCs[fileNum][index]
usermem.ByteOrder.PutUint64(pcBuffer[:], pc)
n, err := w.Write(pcBuffer[:])