diff options
author | Chressie Himpel <chressie@google.com> | 2023-05-05 14:17:38 +0000 |
---|---|---|
committer | Chressie Himpel <chressie@google.com> | 2023-05-05 14:37:29 +0000 |
commit | 72c33a5ef0eea8663328375d9d339ed150310ebb (patch) | |
tree | a4272daf751239fcb9b2f1b8e1730800629f738c /misc | |
parent | f379e78951a405e7e99a60fb231eeedbf976c108 (diff) | |
download | go-git-72c33a5ef0eea8663328375d9d339ed150310ebb.tar.gz |
Revert "runtime/cgo: store M for C-created thread in pthread key"
This reverts CL 485500.
Reason for revert: This breaks internal tests at Google, see b/280861579 and b/280820455.
Change-Id: I426278d400f7611170918fc07c524cb059b9cc55
Reviewed-on: https://go-review.googlesource.com/c/go/+/492995
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Chressie Himpel <chressie@google.com>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/cgo/test/cgo_test.go | 7 | ||||
-rw-r--r-- | misc/cgo/test/cthread_unix.c | 24 | ||||
-rw-r--r-- | misc/cgo/test/cthread_windows.c | 22 | ||||
-rw-r--r-- | misc/cgo/test/testx.go | 14 | ||||
-rw-r--r-- | misc/cgo/testcarchive/carchive_test.go | 54 | ||||
-rw-r--r-- | misc/cgo/testcarchive/testdata/libgo9/a.go | 14 | ||||
-rw-r--r-- | misc/cgo/testcarchive/testdata/main9.c | 24 | ||||
-rw-r--r-- | misc/cgo/testsanitizers/testdata/tsan14.go | 53 | ||||
-rw-r--r-- | misc/cgo/testsanitizers/tsan_test.go | 1 |
9 files changed, 3 insertions, 210 deletions
diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go index 0c3980c12d..5b298954f5 100644 --- a/misc/cgo/test/cgo_test.go +++ b/misc/cgo/test/cgo_test.go @@ -104,7 +104,6 @@ func TestThreadLock(t *testing.T) { testThreadLockFunc(t) } func TestUnsignedInt(t *testing.T) { testUnsignedInt(t) } func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) } -func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) } -func BenchmarkGoString(b *testing.B) { benchGoString(b) } -func BenchmarkCGoCallback(b *testing.B) { benchCallback(b) } -func BenchmarkCGoInCThread(b *testing.B) { benchCGoInCthread(b) } +func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) } +func BenchmarkGoString(b *testing.B) { benchGoString(b) } +func BenchmarkCGoCallback(b *testing.B) { benchCallback(b) } diff --git a/misc/cgo/test/cthread_unix.c b/misc/cgo/test/cthread_unix.c index d0da643158..b6ec39816b 100644 --- a/misc/cgo/test/cthread_unix.c +++ b/misc/cgo/test/cthread_unix.c @@ -32,27 +32,3 @@ doAdd(int max, int nthread) for(i=0; i<nthread; i++) pthread_join(thread_id[i], 0); } - -static void* -goDummyCallbackThread(void* p) -{ - int i, max; - - max = *(int*)p; - for(i=0; i<max; i++) - goDummy(); - return NULL; -} - -int -callGoInCThread(int max) -{ - pthread_t thread; - - if (pthread_create(&thread, NULL, goDummyCallbackThread, (void*)(&max)) != 0) - return -1; - if (pthread_join(thread, NULL) != 0) - return -1; - - return max; -} diff --git a/misc/cgo/test/cthread_windows.c b/misc/cgo/test/cthread_windows.c index 4e52209dee..3a62ddd373 100644 --- a/misc/cgo/test/cthread_windows.c +++ b/misc/cgo/test/cthread_windows.c @@ -35,25 +35,3 @@ doAdd(int max, int nthread) CloseHandle((HANDLE)thread_id[i]); } } - -__stdcall -static unsigned int -goDummyCallbackThread(void* p) -{ - int i, max; - - max = *(int*)p; - for(i=0; i<max; i++) - goDummy(); - return 0; -} - -int -callGoInCThread(int max) -{ - uintptr_t thread_id; - thread_id = _beginthreadex(0, 0, goDummyCallbackThread, &max, 0, 0); - WaitForSingleObject((HANDLE)thread_id, INFINITE); - CloseHandle((HANDLE)thread_id); - return max; -} diff --git a/misc/cgo/test/testx.go b/misc/cgo/test/testx.go index 0e2a51a522..6a8e97ddf3 100644 --- a/misc/cgo/test/testx.go +++ b/misc/cgo/test/testx.go @@ -24,7 +24,6 @@ import ( /* // threads extern void doAdd(int, int); -extern int callGoInCThread(int); // issue 1328 void IntoC(void); @@ -147,10 +146,6 @@ func Add(x int) { *p = 2 } -//export goDummy -func goDummy() { -} - func testCthread(t *testing.T) { if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && runtime.GOARCH == "arm64" { t.Skip("the iOS exec wrapper is unable to properly handle the panic from Add") @@ -164,15 +159,6 @@ func testCthread(t *testing.T) { } } -// Benchmark measuring overhead from C to Go in a C thread. -// Create a new C thread and invoke Go function repeatedly in the new C thread. -func benchCGoInCthread(b *testing.B) { - n := C.callGoInCThread(C.int(b.N)) - if int(n) != b.N { - b.Fatal("unmatch loop times") - } -} - // issue 1328 //export BackIntoGo diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go index 5996268018..8a39c24a6d 100644 --- a/misc/cgo/testcarchive/carchive_test.go +++ b/misc/cgo/testcarchive/carchive_test.go @@ -1247,57 +1247,3 @@ func TestPreemption(t *testing.T) { t.Error(err) } } - -// Issue 59294. Test calling Go function from C after using some -// stack space. -func TestDeepStack(t *testing.T) { - t.Parallel() - - if !testWork { - defer func() { - os.Remove("testp9" + exeSuffix) - os.Remove("libgo9.a") - os.Remove("libgo9.h") - }() - } - - cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo9.a", "./libgo9") - out, err := cmd.CombinedOutput() - t.Logf("%v\n%s", cmd.Args, out) - if err != nil { - t.Fatal(err) - } - checkLineComments(t, "libgo9.h") - checkArchive(t, "libgo9.a") - - // build with -O0 so the C compiler won't optimize out the large stack frame - ccArgs := append(cc, "-O0", "-o", "testp9"+exeSuffix, "main9.c", "libgo9.a") - out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput() - t.Logf("%v\n%s", ccArgs, out) - if err != nil { - t.Fatal(err) - } - - argv := cmdToRun("./testp9") - cmd = exec.Command(argv[0], argv[1:]...) - sb := new(strings.Builder) - cmd.Stdout = sb - cmd.Stderr = sb - if err := cmd.Start(); err != nil { - t.Fatal(err) - } - - timer := time.AfterFunc(time.Minute, - func() { - t.Error("test program timed out") - cmd.Process.Kill() - }, - ) - defer timer.Stop() - - err = cmd.Wait() - t.Logf("%v\n%s", cmd.Args, sb) - if err != nil { - t.Error(err) - } -} diff --git a/misc/cgo/testcarchive/testdata/libgo9/a.go b/misc/cgo/testcarchive/testdata/libgo9/a.go deleted file mode 100644 index acb08d90ec..0000000000 --- a/misc/cgo/testcarchive/testdata/libgo9/a.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2023 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 - -import "runtime" - -import "C" - -func main() {} - -//export GoF -func GoF() { runtime.GC() } diff --git a/misc/cgo/testcarchive/testdata/main9.c b/misc/cgo/testcarchive/testdata/main9.c deleted file mode 100644 index 95ad4dea49..0000000000 --- a/misc/cgo/testcarchive/testdata/main9.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2023 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. - -#include "libgo9.h" - -void use(int *x) { (*x)++; } - -void callGoFWithDeepStack() { - int x[10000]; - - use(&x[0]); - use(&x[9999]); - - GoF(); - - use(&x[0]); - use(&x[9999]); -} - -int main() { - GoF(); // call GoF without using much stack - callGoFWithDeepStack(); // call GoF with a deep stack -} diff --git a/misc/cgo/testsanitizers/testdata/tsan14.go b/misc/cgo/testsanitizers/testdata/tsan14.go deleted file mode 100644 index d594ffb5c0..0000000000 --- a/misc/cgo/testsanitizers/testdata/tsan14.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2023 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. -// -// cgocallback on a new thread calls into runtime.needm -> _cgo_getstackbound -// to update gp.stack.lo with the stack bounds. If the G itself is passed to -// _cgo_getstackbound, then writes to the same G can be seen on multiple -// threads (when the G is reused after thread exit). This would trigger TSAN. - -/* -#include <pthread.h> - -void go_callback(); - -static void *thr(void *arg) { - go_callback(); - return 0; -} - -static void foo() { - pthread_t th; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, 256 << 10); - pthread_create(&th, &attr, thr, 0); - pthread_join(th, 0); -} -*/ -import "C" - -import ( - "time" -) - -//export go_callback -func go_callback() { -} - -func main() { - for i := 0; i < 2; i++ { - go func() { - for { - C.foo() - } - }() - } - - time.Sleep(1000*time.Millisecond) -} diff --git a/misc/cgo/testsanitizers/tsan_test.go b/misc/cgo/testsanitizers/tsan_test.go index dffed96373..f65d842363 100644 --- a/misc/cgo/testsanitizers/tsan_test.go +++ b/misc/cgo/testsanitizers/tsan_test.go @@ -47,7 +47,6 @@ func TestTSAN(t *testing.T) { {src: "tsan11.go", needsRuntime: true}, {src: "tsan12.go", needsRuntime: true}, {src: "tsan13.go", needsRuntime: true}, - {src: "tsan14.go", needsRuntime: true}, } for _, tc := range cases { tc := tc |