Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions v3/pkg/util/cpuset/cpuset_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2017 ScyllaDB
// Copyright (C) 2026 ScyllaDB
//go:build linux
// +build linux

Expand All @@ -14,10 +14,7 @@ import (
"golang.org/x/sys/unix"
)

// AvailableCPUs returns a list of CPUs of length wantCPUs that does not contain
// any of the busyCPUs. If the conditions cannot be met error is returned.
// AvailableCPUs selects the CPUs with the highest available indexes to offload
// shard 0...
// AvailableCPUs returns a list of CPUs that does not contain any of the busyCPUs.
func AvailableCPUs(busyCPUs []int) ([]int, error) {
var cpus unix.CPUSet
if err := unix.SchedGetaffinity(os.Getpid(), &cpus); err != nil {
Expand All @@ -27,11 +24,6 @@ func AvailableCPUs(busyCPUs []int) ([]int, error) {
cpus.Clear(c)
}

n := cpus.Count()
if n == 0 {
return nil, errors.Errorf("no available CPUs")
}

return cpulist(&cpus), nil
}

Expand Down
17 changes: 17 additions & 0 deletions v3/pkg/util/cpuset/cpuset_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ func TestAvailableCPUs(t *testing.T) {
}
}

func TestAvailableCPUsAllBusy(t *testing.T) {
t.Parallel()

var cpus unix.CPUSet
if err := unix.SchedGetaffinity(0, &cpus); err != nil {
t.Fatal(err)
}

a, err := AvailableCPUs(cpulist(&cpus))
if err != nil {
t.Fatal(err)
}
if len(a) != 0 {
t.Fatalf("expected no available CPUs, got %d", len(a))
}
}

func TestSchedSetAffinity(t *testing.T) {
var cpus unix.CPUSet
if err := unix.SchedGetaffinity(0, &cpus); err != nil {
Expand Down
Loading