scoot pinning around

This commit is contained in:
JackDoan
2026-05-05 12:58:33 -05:00
parent bc3f5d0400
commit 67bd9e848a
4 changed files with 9 additions and 7 deletions

23
util/cpupin_linux.go Normal file
View File

@@ -0,0 +1,23 @@
//go:build linux && !android && !e2e_testing
package util
import (
"runtime"
"golang.org/x/sys/unix"
)
// PinThreadToCPU restricts the calling OS thread to the given CPU via
// sched_setaffinity(2). Combined with runtime.LockOSThread on the
// goroutine, this prevents the kernel from migrating us across CPUs and
// in turn keeps every sendmmsg from this goroutine going through the
// same XPS-selected TX ring, eliminating the wire-side reorder that
// otherwise fragments one nebula flow across multiple rings.
func PinThreadToCPU(cpu int) error {
runtime.LockOSThread()
var set unix.CPUSet
set.Zero()
set.Set(cpu)
return unix.SchedSetaffinity(0, &set)
}