mirror of
https://github.com/golang/sys.git
synced 2026-02-08 03:36:03 +03:00
unix: fix TestSchedSetaffinity for smt settings
If a system has the ability to disable some cores, as on ppc64 with the ppc64_cpu command, then TestSchedSetaffinity will fail if the CPUset passed to Setaffinity includes one that has been disabled. This adds a check to use values from the oldMask, which are the valid cores returned from Getaffinity, to pass to Setaffinity. Fixes golang/go#27875 Change-Id: I9656f41867afc18e0eaedc4bdef5f75e137a1fcd Reviewed-on: https://go-review.googlesource.com/137675 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
@@ -273,6 +273,23 @@ func TestSchedSetaffinity(t *testing.T) {
|
||||
t.Skip("skipping setaffinity tests on android")
|
||||
}
|
||||
|
||||
// On a system like ppc64x where some cores can be disabled using ppc64_cpu,
|
||||
// setaffinity should only be called with enabled cores. The valid cores
|
||||
// are found from the oldMask, but if none are found then the setaffinity
|
||||
// tests are skipped. Issue #27875.
|
||||
if !oldMask.IsSet(cpu) {
|
||||
newMask.Zero()
|
||||
for i := 0; i < len(oldMask); i++ {
|
||||
if oldMask.IsSet(i) {
|
||||
newMask.Set(i)
|
||||
break
|
||||
}
|
||||
}
|
||||
if newMask.Count() == 0 {
|
||||
t.Skip("skipping setaffinity tests if CPU not available")
|
||||
}
|
||||
}
|
||||
|
||||
err = unix.SchedSetaffinity(0, &newMask)
|
||||
if err != nil {
|
||||
t.Fatalf("SchedSetaffinity: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user