Skip to content

x/sys: SchedGetaffinity fails on systems with more than 1024 hardware threads #75566

Description

@dblueman

Go version

go version go1.25.0 (Red Hat 1.25.0-4.el10) linux/amd64 (from CentOS Stream 10)

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2000012266=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/golang'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.0 (Red Hat 1.25.0-4.el10)'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

import (
        "fmt"
        "os"

        "golang.org/x/sys/unix"
)

func main() {
        var cpuset unix.CPUSet
        err := unix.SchedGetaffinity(0, &cpuset)
        if err != nil {
                fmt.Printf("SchedGetaffinity: %v\n", err)
                os.Exit(1)
        }
        fmt.Printf("%d\n", cpuset.Count())
}

What did you see happen?

$ go run .
SchedGetaffinity: invalid argument
exit status 1
$ strace -f ./main
sched_getaffinity(0, 128, 0xc001386ea0) = -1 EINVAL (Invalid argument)

Here, we see a Golang called sched_getaffinity with a bitmask large enough for only 1024 threads; 8192 is the universally accepted limit and what libnuma and related uses.

What did you expect to see?

1920

I'm running on a 16-socket system with 1920 hardware threads.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions