mirror of
https://github.com/golang/go
synced 2024-11-24 20:50:11 -07:00
29cb72154d
This fixes Linux and the *BSD platforms on 386/amd64. A few OS/arch combinations were already saving registers and/or doing something that doesn't clearly resemble the SysV C ABI; those have been left alone. Fixes #18328. Change-Id: I6398f6c71020de108fc8b26ca5946f0ba0258667 Reviewed-on: https://go-review.googlesource.com/34501 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
// This program failed when run under the C/C++ ThreadSanitizer. The
|
|
// TSAN library was not keeping track of whether signals should be
|
|
// delivered on the alternate signal stack, and the Go signal handler
|
|
// was not preserving callee-saved registers from C callers.
|
|
|
|
/*
|
|
#cgo CFLAGS: -g -fsanitize=thread
|
|
#cgo LDFLAGS: -g -fsanitize=thread
|
|
|
|
#include <stdlib.h>
|
|
#include <sys/time.h>
|
|
|
|
void spin() {
|
|
size_t n;
|
|
struct timeval tvstart, tvnow;
|
|
int diff;
|
|
void *prev = NULL, *cur;
|
|
|
|
gettimeofday(&tvstart, NULL);
|
|
for (n = 0; n < 1<<20; n++) {
|
|
cur = malloc(n);
|
|
free(prev);
|
|
prev = cur;
|
|
|
|
gettimeofday(&tvnow, NULL);
|
|
diff = (tvnow.tv_sec - tvstart.tv_sec) * 1000 * 1000 + (tvnow.tv_usec - tvstart.tv_usec);
|
|
|
|
// Profile frequency is 100Hz so we should definitely
|
|
// get a signal in 50 milliseconds.
|
|
if (diff > 50 * 1000) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
free(prev);
|
|
}
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"runtime/pprof"
|
|
"time"
|
|
)
|
|
|
|
func goSpin() {
|
|
start := time.Now()
|
|
for n := 0; n < 1<<20; n++ {
|
|
_ = make([]byte, n)
|
|
if time.Since(start) > 50*time.Millisecond {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
pprof.StartCPUProfile(ioutil.Discard)
|
|
go C.spin()
|
|
goSpin()
|
|
pprof.StopCPUProfile()
|
|
}
|