-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
What version of Go are you using (go version)?
$ go version go version go1.20.4 linux/amd64
Does this issue reproduce with the latest release?
This issue reproduces ONLY with Go 1.20 (I have tried 1.20.3 and 1.20.4), and does not arise on 1.19 or earlier.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/pcuser/.cache/go-build" GOENV="/home/pcuser/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/pcuser/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/pcuser/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/go-1.20" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.20/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.20.4" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/pcuser/go/src/github.com/usnistgov/dastard/go.mod" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3739805746=/tmp/go-build -gno-record-gcc-switches" GOROOT/bin/go version: go version go1.20.4 linux/arm64 GOROOT/bin/go tool compile -V: compile version go1.20.4 uname -v: #78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023
What did you do?
A colleague and I run a large project that has to control and receive data from a special-purpose PCI-express card, running custom firmware. This is a data acquisition system for high-speed x-ray and gamma-ray detectors, arrays of superconducting sensors (just for context). It’s worked extremely well since we launched the Go program in 2017 (as a replacement for a C++ monstrosity).
We talk to this PCIe card by opening/closing and reading/writing device-special files provided (obviously) by a device driver. There are control registers for configuration and a scatter-gather DMA for transferring the high-speed data (typically 20 to 200 MB/second, depending on one’s instrument configuration) to the computer RAM.
Code hangs at the unix.Read call in the following, if running Go 1.20:
gobuffer := C.GoBytes(unsafe.Pointer(buffer), C.int(bufferLength))
n, err := unix.Read(int(fd), gobuffer)
Here
buffer *C.charis a buffer allocated in C code byposix_memalignbufferLengthis 33554432 (that is, 32 MB or 0x1000000)unixrefers to package"golang.org/x/sys/unix"fdis the descriptor of the open device special file to be read.
What did you expect to see?
Go 1.16, 1.17, 1.18, and 1.19 all run our program just fine. The device is read successfully, returning high speed data to the Go program. I expected to see the same when switching to Go 1.20.
What did you see instead?
When I build the program with Go 1.20 the program hangs (0% CPU load) at the point where the program tries to perform the system call to the unix.Read(...) function on the device file. The build succeeds, and the configuration steps (appear to) work correctly at run time--these steps set up the scatter-gather DMA cycle. When we try to read from the DMA buffer the first time, the program hangs, and only in Go 1.20!
I’m afraid I cannot provide a minimum reproducible example, owing to the fact that you’d need our specific hardware (running our specific firmware) and the corresponding device drivers. I am very sorry I can’t offer a demonstration in the playground. I realize this issue might be something no one but me can diagnose.
Still, maybe someone can offer ideas? Is there something special I should know about Go 1.20 that might help me track down the problem? I’ve read the 1.20 release notes a dozen times, but maybe I’m missing the significance of the key point in there? Or did something in cgo actually break in Go 1.20?
The info above says I'm using Ubuntu 22.04 with Go 1.20.4. The same problem has also been noted on a different PC running Ubuntu 20.04, and on both computers with Go 1.20.3. I have not tried earlier 1.20.x releases.
I checked with the Go Forum, without success.