Przeglądaj źródła

scoot pinning around

JackDoan 5 miesięcy temu
rodzic
commit
67bd9e848a
4 zmienionych plików z 9 dodań i 7 usunięć
  1. 2 1
      interface.go
  2. 1 0
      main.go
  3. 3 3
      util/cpupin_linux.go
  4. 3 3
      util/cpupin_other.go

+ 2 - 1
interface.go

@@ -13,6 +13,7 @@ import (
 
 	"github.com/gaissmai/bart"
 	"github.com/rcrowley/go-metrics"
+	"github.com/slackhq/nebula/util"
 
 	"github.com/slackhq/nebula/config"
 	"github.com/slackhq/nebula/firewall"
@@ -387,7 +388,7 @@ func (f *Interface) listenIn(reader tio.Queue, i int) {
 	if n := len(f.cpuAffinity); n > 0 {
 		cpu = f.cpuAffinity[i%n]
 	}
-	if err := pinThreadToCPU(cpu); err != nil {
+	if err := util.PinThreadToCPU(cpu); err != nil {
 		f.l.Warn("failed to pin tun reader to CPU", "queue", i, "cpu", cpu, "err", err)
 	}
 	rejectBuf := make([]byte, mtu)

+ 1 - 0
main.go

@@ -6,6 +6,7 @@ import (
 	"log/slog"
 	"net"
 	"net/netip"
+	"runtime"
 	"runtime/debug"
 	"strings"
 	"time"

+ 3 - 3
cpupin_linux.go → util/cpupin_linux.go

@@ -1,6 +1,6 @@
 //go:build linux && !android && !e2e_testing
 
-package nebula
+package util
 
 import (
 	"runtime"
@@ -8,13 +8,13 @@ import (
 	"golang.org/x/sys/unix"
 )
 
-// pinThreadToCPU restricts the calling OS thread to the given CPU via
+// 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 {
+func PinThreadToCPU(cpu int) error {
 	runtime.LockOSThread()
 	var set unix.CPUSet
 	set.Zero()

+ 3 - 3
cpupin_other.go → util/cpupin_other.go

@@ -1,11 +1,11 @@
 //go:build !linux || android || e2e_testing
 
-package nebula
+package util
 
-// pinThreadToCPU is a no-op outside Linux: only Linux exposes a stable
+// PinThreadToCPU is a no-op outside Linux: only Linux exposes a stable
 // per-thread CPU affinity API and only Linux has XPS-driven TX ring
 // selection in the first place. On every other platform there's nothing
 // to fix here.
-func pinThreadToCPU(_ int) error {
+func PinThreadToCPU(_ int) error {
 	return nil
 }