Documentation
¶
Overview ¶
Package iouring implements an engine backed by Linux io_uring.
Index ¶
- type BufferGroup
- type BufferRing
- type Engine
- type Ring
- func (r *Ring) AdvanceCQ()
- func (r *Ring) Close() error
- func (r *Ring) GetSQE() unsafe.Pointer
- func (r *Ring) RegisterFiles(count int) error
- func (r *Ring) RegisterPbufRing(groupID uint16, entries uint32, ringAddr unsafe.Pointer) error
- 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) WakeupSQPoll() error
- 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 (*Ring) GetSQE ¶
GetSQE returns a pointer to the next available SQE, or nil if the ring is full.
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) 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) WakeupSQPoll ¶
WakeupSQPoll wakes up the SQPOLL thread if it went to sleep.
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
SQPollIdle() uint32
}
TierStrategy configures io_uring behavior based on detected capabilities.
func SelectTier ¶
func SelectTier(profile engine.CapabilityProfile) TierStrategy
SelectTier returns the highest available tier strategy for the given profile.