Documentation
¶
Overview ¶
Package iouring implements an engine backed by Linux io_uring.
Index ¶
- type BufferGroup
- type BufferRing
- type Engine
- type Ring
- func (r *Ring) BeginCQ() (head, tail uint32)
- func (r *Ring) ClearPending()
- func (r *Ring) Close() error
- func (r *Ring) EndCQ(newHead uint32)
- func (r *Ring) GetSQE() unsafe.Pointer
- func (r *Ring) Pending() uint32
- func (r *Ring) RegisterFiles(count int) error
- func (r *Ring) RegisterPbufRing(groupID uint16, entries uint32, ringAddr unsafe.Pointer) error
- func (r *Ring) SQNeedWakeup() bool
- func (r *Ring) Submit() (int, error)
- func (r *Ring) SubmitAndWait() error
- func (r *Ring) SubmitAndWaitTimeout(timeout time.Duration) error
- func (r *Ring) UnregisterPbufRing(groupID uint16) error
- func (r *Ring) UpdateFixedFile(slot int, fd int) error
- func (r *Ring) WaitCQE() error
- func (r *Ring) WaitCQETimeout(timeout time.Duration) error
- func (r *Ring) WakeupSQPoll() error
- type SendZCProbeResult
- type TierStrategy
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferGroup ¶
type BufferGroup struct {
// contains filtered or unexported fields
}
BufferGroup manages a group of provided buffers for multishot recv. This is the legacy PROVIDE_BUFFERS approach, kept for fallback on older kernels.
func NewBufferGroup ¶
func NewBufferGroup(ring *Ring, groupID uint16, count, size int) (*BufferGroup, error)
NewBufferGroup creates and registers a provided buffer group with the ring.
func (*BufferGroup) AvailableCount ¶
func (bg *BufferGroup) AvailableCount() int
AvailableCount returns the number of available buffers.
func (*BufferGroup) GetBuffer ¶
func (bg *BufferGroup) GetBuffer(bufID uint16) []byte
GetBuffer returns the buffer for the given buffer ID.
func (*BufferGroup) ReturnBuffer ¶
func (bg *BufferGroup) ReturnBuffer(ring *Ring, bufID uint16) error
ReturnBuffer returns a buffer to the group and re-provides it to the kernel.
type BufferRing ¶ added in v1.1.0
type BufferRing struct {
// contains filtered or unexported fields
}
BufferRing manages a ring-mapped provided buffer group (IORING_REGISTER_PBUF_RING). Both ring and buffer memory are allocated via mmap outside the Go heap to avoid inflating GC accounting.
func NewBufferRing ¶ added in v1.1.0
func NewBufferRing(ring *Ring, groupID uint16, count, size int) (*BufferRing, error)
NewBufferRing creates and registers a ring-mapped provided buffer group. The buffers are mmap'd outside the Go heap. count must be a power of 2.
func (*BufferRing) Close ¶ added in v1.1.0
func (br *BufferRing) Close(ring *Ring)
Close unregisters the buffer ring and releases mmap'd memory.
func (*BufferRing) GetBuffer ¶ added in v1.1.0
func (br *BufferRing) GetBuffer(bufID uint16, dataLen int) []byte
GetBuffer returns a slice of the buffer for the given buffer ID and data length.
func (*BufferRing) PublishBuffers ¶ added in v1.1.0
func (br *BufferRing) PublishBuffers()
PublishBuffers makes all pushed entries visible to the kernel with a single atomic store. Call after one or more PushBuffer calls.
func (*BufferRing) PushBuffer ¶ added in v1.1.0
func (br *BufferRing) PushBuffer(bufID uint16)
PushBuffer queues a buffer for return without publishing to the kernel. Call PublishBuffers once after batching multiple PushBuffer calls.
func (*BufferRing) ReturnBuffer ¶ added in v1.1.0
func (br *BufferRing) ReturnBuffer(bufID uint16)
ReturnBuffer returns a buffer to the ring by pushing a new entry and publishing the updated tail. Must be called after the buffer data has been fully consumed.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine implements the io_uring-based I/O engine.
func (*Engine) Metrics ¶
func (e *Engine) Metrics() engine.EngineMetrics
Metrics returns a snapshot of engine metrics.
func (*Engine) PauseAccept ¶ added in v0.3.0
PauseAccept stops accepting new connections while keeping existing ones alive.
func (*Engine) ResumeAccept ¶ added in v0.3.0
ResumeAccept starts accepting new connections again. Wakes any suspended workers so they re-create listen sockets.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring is an io_uring instance with mmap'd SQ/CQ rings and SQE array.
func NewRing ¶
NewRing creates a new io_uring instance. sqPollIdle sets the kernel SQPOLL thread idle timeout in milliseconds (only used with IORING_SETUP_SQPOLL).
func NewRingCPU ¶ added in v1.1.0
NewRingCPU creates a new io_uring instance with optional SQPOLL CPU affinity. If cpuID >= 0 and SQPOLL is enabled, IORING_SETUP_SQ_AFF is set to pin the kernel's SQPOLL thread to the specified CPU, ensuring NUMA-local processing.
func (*Ring) BeginCQ ¶ added in v1.1.0
BeginCQ returns the current CQ head and tail for batch processing. Under SINGLE_ISSUER, cqHead is a plain load (we own it).
func (*Ring) ClearPending ¶ added in v1.1.0
func (r *Ring) ClearPending()
ClearPending resets the pending counter without issuing a syscall. Used with SQPOLL where the kernel thread submits SQEs automatically.
func (*Ring) EndCQ ¶ added in v1.1.0
EndCQ advances the CQ head to newHead with a single atomic store.
func (*Ring) GetSQE ¶
GetSQE returns a pointer to the next available SQE, or nil if the ring is full.
func (*Ring) Pending ¶ added in v1.1.0
Pending returns the number of SQEs submitted but not yet sent to the kernel.
func (*Ring) RegisterFiles ¶ added in v1.1.0
RegisterFiles pre-registers a fixed file table with the kernel. Each entry is initialized to -1 (empty). Use UpdateFixedFile to install FDs into slots.
func (*Ring) RegisterPbufRing ¶ added in v1.1.0
RegisterPbufRing registers a ring-mapped provided buffer ring with the kernel. The ring memory is allocated by the caller via mmap and passed in ringAddr. The caller is responsible for munmapping the ring memory after unregistering.
func (*Ring) SQNeedWakeup ¶ added in v1.1.0
SQNeedWakeup returns true if the SQPOLL kernel thread went idle and needs a wakeup via WakeupSQPoll() to resume submitting SQEs.
func (*Ring) SubmitAndWait ¶
SubmitAndWait submits pending SQEs and waits for at least one CQE.
func (*Ring) SubmitAndWaitTimeout ¶
SubmitAndWaitTimeout submits pending SQEs and waits for at least one CQE, with a timeout. Returns nil on timeout (ETIME) or EINTR.
func (*Ring) UnregisterPbufRing ¶ added in v1.1.0
UnregisterPbufRing unregisters a ring-mapped provided buffer ring.
func (*Ring) UpdateFixedFile ¶ added in v1.1.0
UpdateFixedFile installs or removes a file descriptor in a fixed file slot. Set fd to -1 to clear a slot.
func (*Ring) WaitCQETimeout ¶ added in v1.1.0
WaitCQETimeout waits for at least one CQE without submitting any SQEs. Used by SQPOLL workers where the kernel thread handles submission. Returns nil on timeout (ETIME) or EINTR.
func (*Ring) WakeupSQPoll ¶
WakeupSQPoll wakes up the SQPOLL thread if it went to sleep.
type SendZCProbeResult ¶ added in v1.1.0
type SendZCProbeResult int
SendZCProbeResult describes the outcome of the SEND_ZC runtime probe.
const ( // SendZCUnsupported means the kernel doesn't support the SEND_ZC opcode. SendZCUnsupported SendZCProbeResult = iota // SendZCBroken means the kernel accepts SEND_ZC but the notification CQE // never arrives (e.g., ENA driver DMA completion bug). SendZCBroken // SendZCCopyFallback means SEND_ZC works but the kernel copies data instead // of using DMA zero-copy. The notification arrives correctly. This happens // on loopback or NICs without scatter-gather DMA. SEND_ZC is functional // but provides no performance benefit over regular SEND. SendZCCopyFallback // SendZCTrueZeroCopy means SEND_ZC uses real DMA zero-copy. The notification // arrives and reports actual zero-copy usage. This is the optimal case. SendZCTrueZeroCopy )
func (SendZCProbeResult) String ¶ added in v1.1.0
func (r SendZCProbeResult) String() string
type TierStrategy ¶
type TierStrategy interface {
Tier() engine.Tier
SetupFlags() uint32
PrepareAccept(ring *Ring, listenFD int)
PrepareRecv(ring *Ring, fd int, buf []byte)
PrepareSend(ring *Ring, fd int, buf []byte, linked bool)
SupportsProvidedBuffers() bool
SupportsMultishotAccept() bool
SupportsMultishotRecv() bool
SupportsFixedFiles() bool
SupportsSendZC() bool
SQPollIdle() uint32
}
TierStrategy configures io_uring behavior based on detected capabilities.
func SelectTier ¶
func SelectTier(profile engine.CapabilityProfile, sqPollIdle time.Duration) TierStrategy
SelectTier returns the highest available tier strategy for the given profile. sqPollIdle is the objective-specific SQPOLL thread idle timeout; if zero, defaults to 2000ms.