mirror of
https://github.com/slackhq/nebula.git
synced 2026-08-15 07:17:00 +02:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user