util: unlock the OS thread when CPU pinning fails

PinThreadToCPU left the goroutine locked to its OS thread even when
sched_setaffinity failed. The lock only exists to make the affinity
stick; without it the kernel migrates the thread anyway, so a failed pin
kept a dedicated thread for zero benefit. Unwind on the error path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
JackDoan
2026-07-27 15:40:14 -05:00
parent 56d2a3841d
commit 8006b58758
+7 -1
View File
@@ -19,7 +19,13 @@ func PinThreadToCPU(cpu int) error {
var set unix.CPUSet
set.Zero()
set.Set(cpu)
return unix.SchedSetaffinity(0, &set)
if err := unix.SchedSetaffinity(0, &set); err != nil {
// Without the affinity the thread lock buys no TX-ring stability;
// don't leave the goroutine wedded to one OS thread for nothing.
runtime.UnlockOSThread()
return err
}
return nil
}
// AllowedCPUs returns the CPU IDs the calling process is currently allowed to