mirror of
https://github.com/slackhq/nebula.git
synced 2026-02-16 01:34:22 +01:00
fix compile for 386
This commit is contained in:
@@ -18,18 +18,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ioringOpSendmsg = 9
|
||||
ioringOpRecvmsg = 10
|
||||
ioringEnterGetevents = 1 << 0
|
||||
ioringSetupClamp = 1 << 4
|
||||
ioringSetupCoopTaskrun = 1 << 8 // Kernel 5.19+: reduce thread creation
|
||||
ioringSetupSingleIssuer = 1 << 12 // Kernel 6.0+: single submitter optimization
|
||||
ioringRegisterIowqMaxWorkers = 19 // Register opcode to limit workers
|
||||
ioringOffSqRing = 0
|
||||
ioringOffCqRing = 0x8000000
|
||||
ioringOffSqes = 0x10000000
|
||||
defaultIoUringEntries = 256
|
||||
ioUringSqeSize = 64 // struct io_uring_sqe size defined by kernel ABI
|
||||
ioringOpSendmsg = 9
|
||||
ioringOpRecvmsg = 10
|
||||
ioringEnterGetevents = 1 << 0
|
||||
ioringSetupClamp = 1 << 4
|
||||
ioringSetupCoopTaskrun = 1 << 8 // Kernel 5.19+: reduce thread creation
|
||||
ioringSetupSingleIssuer = 1 << 12 // Kernel 6.0+: single submitter optimization
|
||||
ioringRegisterIowqMaxWorkers = 19 // Register opcode to limit workers
|
||||
ioringOffSqRing = 0
|
||||
ioringOffCqRing = 0x8000000
|
||||
ioringOffSqes = 0x10000000
|
||||
defaultIoUringEntries = 256
|
||||
ioUringSqeSize = 64 // struct io_uring_sqe size defined by kernel ABI
|
||||
)
|
||||
|
||||
type ioSqringOffsets struct {
|
||||
@@ -170,13 +170,13 @@ type ioUringState struct {
|
||||
|
||||
// recvBuffer represents a single receive operation with its associated buffers
|
||||
type recvBuffer struct {
|
||||
payloadBuf []byte // Buffer for packet data
|
||||
nameBuf []byte // Buffer for source address
|
||||
controlBuf []byte // Buffer for control messages
|
||||
msghdr *unix.Msghdr // Message header for recvmsg
|
||||
iovec *unix.Iovec // IO vector pointing to payloadBuf
|
||||
userData uint64 // User data for tracking this operation
|
||||
inFlight atomic.Bool // Whether this buffer has a pending io_uring operation
|
||||
payloadBuf []byte // Buffer for packet data
|
||||
nameBuf []byte // Buffer for source address
|
||||
controlBuf []byte // Buffer for control messages
|
||||
msghdr *unix.Msghdr // Message header for recvmsg
|
||||
iovec *unix.Iovec // IO vector pointing to payloadBuf
|
||||
userData uint64 // User data for tracking this operation
|
||||
inFlight atomic.Bool // Whether this buffer has a pending io_uring operation
|
||||
}
|
||||
|
||||
// ioUringRecvState manages a dedicated io_uring for receiving packets
|
||||
@@ -200,16 +200,16 @@ type ioUringRecvState struct {
|
||||
cqRingMask *uint32
|
||||
cqRingEntries *uint32
|
||||
|
||||
mu sync.Mutex
|
||||
userData uint64
|
||||
bufferPool []*recvBuffer // Pool of all receive buffers
|
||||
bufferMap map[uint64]*recvBuffer // Map userData -> buffer
|
||||
mu sync.Mutex
|
||||
userData uint64
|
||||
bufferPool []*recvBuffer // Pool of all receive buffers
|
||||
bufferMap map[uint64]*recvBuffer // Map userData -> buffer
|
||||
|
||||
sqEntryCount uint32
|
||||
cqEntryCount uint32
|
||||
|
||||
sockFd int // Socket file descriptor to receive from
|
||||
closed atomic.Bool
|
||||
sockFd int // Socket file descriptor to receive from
|
||||
closed atomic.Bool
|
||||
}
|
||||
|
||||
func alignUint32(v, alignment uint32) uint32 {
|
||||
@@ -240,7 +240,7 @@ func newIoUringState(entries uint32) (*ioUringState, error) {
|
||||
// Note: SINGLE_ISSUER causes EEXIST errors, so it's excluded
|
||||
flagSets := []uint32{
|
||||
ioringSetupClamp | ioringSetupCoopTaskrun, // Kernel 5.19+: reduce thread creation
|
||||
ioringSetupClamp, // All kernels
|
||||
ioringSetupClamp, // All kernels
|
||||
}
|
||||
flagSetIdx := 0
|
||||
|
||||
@@ -1049,7 +1049,7 @@ func newIoUringRecvState(sockFd int, entries uint32, poolSize int, bufferSize in
|
||||
// Note: SINGLE_ISSUER causes EEXIST errors, so it's excluded
|
||||
flagSets := []uint32{
|
||||
ioringSetupClamp | ioringSetupCoopTaskrun, // Kernel 5.19+: reduce thread creation
|
||||
ioringSetupClamp, // All kernels
|
||||
ioringSetupClamp, // All kernels
|
||||
}
|
||||
flagSetIdx := 0
|
||||
|
||||
@@ -1116,33 +1116,33 @@ func newIoUringRecvState(sockFd int, entries uint32, poolSize int, bufferSize in
|
||||
buf.msghdr.Iov = buf.iovec
|
||||
buf.msghdr.Iovlen = 1
|
||||
buf.msghdr.Control = &buf.controlBuf[0]
|
||||
buf.msghdr.Controllen = uint64(len(buf.controlBuf))
|
||||
buf.msghdr.Controllen = controllen(len(buf.controlBuf))
|
||||
|
||||
ring.bufferPool[i] = buf
|
||||
ring.bufferMap[buf.userData] = buf
|
||||
ring.bufferPool[i] = buf
|
||||
ring.bufferMap[buf.userData] = buf
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"poolSize": poolSize,
|
||||
"entries": ring.sqEntryCount,
|
||||
"bufferSize": bufferSize,
|
||||
}).Info("io_uring receive ring created")
|
||||
|
||||
// Limit kernel worker threads to prevent thousands being spawned
|
||||
// [0] = bounded workers, [1] = unbounded workers
|
||||
maxWorkers := [2]uint32{4, 4} // Limit to 4 workers of each type
|
||||
_, _, errno = unix.Syscall6(
|
||||
unix.SYS_IO_URING_REGISTER,
|
||||
uintptr(fd),
|
||||
uintptr(ioringRegisterIowqMaxWorkers),
|
||||
uintptr(unsafe.Pointer(&maxWorkers[0])),
|
||||
2, // array length
|
||||
0, 0,
|
||||
)
|
||||
// Ignore errors - older kernels don't support this
|
||||
|
||||
return ring, nil
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"poolSize": poolSize,
|
||||
"entries": ring.sqEntryCount,
|
||||
"bufferSize": bufferSize,
|
||||
}).Info("io_uring receive ring created")
|
||||
|
||||
// Limit kernel worker threads to prevent thousands being spawned
|
||||
// [0] = bounded workers, [1] = unbounded workers
|
||||
maxWorkers := [2]uint32{4, 4} // Limit to 4 workers of each type
|
||||
_, _, errno = unix.Syscall6(
|
||||
unix.SYS_IO_URING_REGISTER,
|
||||
uintptr(fd),
|
||||
uintptr(ioringRegisterIowqMaxWorkers),
|
||||
uintptr(unsafe.Pointer(&maxWorkers[0])),
|
||||
2, // array length
|
||||
0, 0,
|
||||
)
|
||||
// Ignore errors - older kernels don't support this
|
||||
|
||||
return ring, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ioUringRecvState) mapRings(params *ioUringParams) error {
|
||||
@@ -1215,7 +1215,7 @@ func (r *ioUringRecvState) submitRecvLocked(buf *recvBuffer) error {
|
||||
|
||||
// Reset buffer state for reuse
|
||||
buf.msghdr.Namelen = uint32(len(buf.nameBuf))
|
||||
buf.msghdr.Controllen = uint64(len(buf.controlBuf))
|
||||
buf.msghdr.Controllen = controllen(len(buf.controlBuf))
|
||||
buf.msghdr.Flags = 0
|
||||
buf.iovec.SetLen(len(buf.payloadBuf))
|
||||
|
||||
@@ -1414,12 +1414,12 @@ func (r *ioUringRecvState) receivePackets(wait bool) ([]RecvPacket, error) {
|
||||
}
|
||||
|
||||
packets = append(packets, RecvPacket{
|
||||
Data: dataBuf,
|
||||
N: n,
|
||||
From: &from,
|
||||
Flags: flags,
|
||||
Control: controlBuf,
|
||||
Controllen: controllen,
|
||||
Data: dataBuf,
|
||||
N: n,
|
||||
From: &from,
|
||||
Flags: flags,
|
||||
Control: controlBuf,
|
||||
Controllen: controllen,
|
||||
RecycleFunc: func() {
|
||||
// Return buffers to pool
|
||||
recvPacketDataPool.Put(dataBufPtr)
|
||||
|
||||
Reference in New Issue
Block a user