mirror of
https://github.com/slackhq/nebula.git
synced 2026-08-16 12:07:01 +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
|
var set unix.CPUSet
|
||||||
set.Zero()
|
set.Zero()
|
||||||
set.Set(cpu)
|
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
|
// AllowedCPUs returns the CPU IDs the calling process is currently allowed to
|
||||||
|
|||||||
Reference in New Issue
Block a user