Skip to content

Commit 93f9a39

Browse files
committed
libct: switch to (*CPUSet).Fill
Now that we've updated to golang.org/x/[email protected], CPUSet has a Fill helper that does the equivalent to our underflow trick to make setting all CPUs efficient. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent e3ab743 commit 93f9a39

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

libcontainer/process_linux.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,8 @@ func tryResetCPUAffinity(pid int) {
184184
//
185185
// So we can just pass a very large array of set cpumask bits and the
186186
// kernel will silently convert that to the correct value very cheaply.
187-
188-
// Ideally, we would just set the array to 0xFF...FF. Unfortunately, the
189-
// size depends on the architecture. It is also a private newtype, so we
190-
// can't use (^0) or generics since those require us to be able to name the
191-
// type. However, we can just underflow the zero value instead.
192-
// TODO: Once <https://golang.org/cl/698015> is merged, switch to that.
193-
cpuset := unix.CPUSet{}
194-
for i := range cpuset {
195-
cpuset[i]-- // underflow to 0xFF..FF
196-
}
187+
var cpuset unix.CPUSet
188+
cpuset.Fill() // set all bits
197189
if err := unix.SchedSetaffinity(pid, &cpuset); err != nil {
198190
logrus.WithError(
199191
os.NewSyscallError("sched_setaffinity", err),

0 commit comments

Comments
 (0)