Documentation
¶
Index ¶
- Constants
- Variables
- func Enter(fd int, toSubmit uint, minComplete uint, flags uint, sigset *unix.Sigset_t) (int, error)
- func FastOpenAllowed() error
- func MmapRing(fd int, p *Params, sq *SubmitQueue, cq *CompletionQueue) error
- func RegisterBuffers(fd int, vecs []*syscall.Iovec) error
- func RegisterEventFd(ringFd int, fd int) error
- func RegisterEventFdAsync(ringFd int, fd int) error
- func RegisterFiles(fd int, files []int) error
- func ReregisterFiles(fd int, files []int) error
- func Setup(entries uint, params *Params) (int, error)
- func UnregisterBuffers(fd int, vecs []*syscall.Iovec) error
- func UnregisterEventFd(ringFd int, fd int) error
- func UnregisterFiles(fd int, files []int) error
- type CQRingOffset
- type CompletionEntry
- type CompletionQueue
- type FileRegistry
- type Opcode
- type Params
- type ReadWriteAtCloser
- type ReadWriteSeekerCloser
- type Ring
- func (r *Ring) CQ() *CompletionQueue
- func (r *Ring) CanEnter() bool
- func (r *Ring) Close(fd int) error
- func (r *Ring) CompleteHead() int
- func (r *Ring) CompleteTail() int
- func (r *Ring) Enter(toSubmit uint, minComplete uint, flags uint, sigset *unix.Sigset_t) (int, error)
- func (r *Ring) EventFd() int
- func (r *Ring) Fadvise(fd int, offset uint64, n uint32, advise int) error
- func (r *Ring) Fallocate(fd int, mode uint32, offset int64, n int64) error
- func (r *Ring) Fd() int
- func (r *Ring) FileReadWriter(f *os.File) (ReadWriteSeekerCloser, error)
- func (r *Ring) FileRegistry() FileRegistry
- func (r *Ring) Fsync(fd int, flags int) error
- func (r *Ring) ID() uint64
- func (r *Ring) NeedsEnter() bool
- func (r *Ring) Nop() error
- func (r *Ring) PollAdd(fd int, mask int) error
- func (r *Ring) PrepareAccept(fd int, addr syscall.Sockaddr, socklen uint32, flags int) (uint64, error)
- func (r *Ring) PrepareClose(fd int) (uint64, error)
- func (r *Ring) PrepareConnect(fd int, addr syscall.Sockaddr, socklen uint32) (uint64, error)
- func (r *Ring) PrepareFadvise(fd int, offset uint64, n uint32, advise int) (uint64, error)
- func (r *Ring) PrepareFallocate(fd int, mode uint32, offset int64, n int64) (uint64, error)
- func (r *Ring) PrepareFsync(fd int, flags int) (uint64, error)
- func (r *Ring) PrepareNop() (uint64, error)
- func (r *Ring) PreparePollAdd(fd int, mask int) (uint64, error)
- func (r *Ring) PrepareRead(fd int, b []byte, offset uint64, flags uint8) (uint64, error)
- func (r *Ring) PrepareReadFixed(fd int, b []byte, flags uint8) (uint64, error)
- func (r *Ring) PrepareReadv(fd int, iovecs []*syscall.Iovec, offset int) (uint64, error)
- func (r *Ring) PrepareRecv(fd int, b []byte, flags uint8) (uint64, error)
- func (r *Ring) PrepareRecvmsg(fd int, msg *syscall.Msghdr, flags int) (uint64, error)
- func (r *Ring) PrepareSend(fd int, b []byte, flags uint8) (uint64, error)
- func (r *Ring) PrepareSplice(inFd int, inOff *int64, outFd int, outOff *int64, n int, flags int) (uint64, error)
- func (r *Ring) PrepareStatx(dirfd int, path string, flags int, mask int, statx *unix.Statx_t) (uint64, error)
- func (r *Ring) PrepareTimeout(ts *syscall.Timespec, count int, flags int) (uint64, error)
- func (r *Ring) PrepareTimeoutRemove(data uint64, flags int) (uint64, error)
- func (r *Ring) PrepareWrite(fd int, b []byte, offset uint64, flags uint8) (uint64, error)
- func (r *Ring) PrepareWriteFixed(fd int, b []byte, flags uint8) (uint64, error)
- func (r *Ring) PrepareWritev(fd int, iovecs []*syscall.Iovec, offset int) (uint64, error)
- func (r *Ring) Recv(fd int, b []byte, flags uint8) error
- func (r *Ring) SQ() *SubmitQueue
- func (r *Ring) Send(fd int, b []byte, flags uint8) error
- func (r *Ring) ShouldFlush() bool
- func (r *Ring) SockoptListener(network, address string, errHandler func(error), sockopts ...int) (net.Listener, error)
- func (r *Ring) Splice(inFd int, inOff *int64, outFd int, outOff *int64, n int, flags int) (int64, error)
- func (r *Ring) Statx(dirfd int, path string, flags int, mask int, statx *unix.Statx_t) (err error)
- func (r *Ring) Stop() error
- func (r *Ring) SubmitEntry() (*SubmitEntry, func())
- func (r *Ring) SubmitHead() int
- func (r *Ring) SubmitTail() int
- type RingOption
- type SQRingOffset
- type SubmitEntry
- type SubmitQueue
Constants ¶
const ( POLLIN = 0x1 POLLPRI = 0x2 POLLOUT = 0x4 POLLERR = 0x8 POLLHUP = 0x10 POLLNVAL = 0x20 // SOReuseport is the socket option to reuse socket port. SOReuseport int = 0x0F // TCPFastopen is the socket option to open a TCP fast open. TCPFastopen int = 0x17 )
const ( // SetupSyscall defines the syscall number for io_uring_setup. SetupSyscall = 425 // EnterSyscall defines the syscall number for io_uring_enter. EnterSyscall = 426 // RegisterSyscall defines the syscall number for io_uring_register. RegisterSyscall = 427 )
const ( // FeatSingleMmap is used to configure a single mmap'd ring. FeatSingleMmap = (1 << 0) // FeatNoDrop is used to ensure that no CQEs are dropped. FeatNoDrop = (1 << 1) FeatSubmitStable = (1 << 2) FeatRwCurPos = (1 << 3) FeatCurPersonality = (1 << 4) )
const ( /* * sqe->flags */ SqeFixedFileBit = iota SqeIoDrainBit SqeIoLinkBit SqeIoHardlinkBit SqeAsyncBit SqeBufferSelectBit // SqeFixedFile use fixed fileset SqeFixedFile uint8 = (1 << SqeFixedFileBit) // SqeIoDrain issue after inflight IO SqeIoDrain uint8 = (1 << SqeIoDrainBit) // SqeIoLink is used to link multiple SQEs. SqeIoLink uint8 = (1 << SqeIoLinkBit) // SqeIoHardlink is a hard link to multiple SQEs SqeIoHardlink uint8 = (1 << SqeIoHardlinkBit) // SqeAsync is use to specify async io. SqeAsync uint8 = (1 << SqeAsyncBit) // SqeBufferSelect is used to specify buffer select. SqeBufferSelect uint8 = (1 << SqeBufferSelectBit) // SetupIOPoll io_context is polled SetupIOPoll uint32 = (1 << 0) // SetupSQPoll SQ poll thread SetupSQPoll uint32 = (1 << 1) // SetupSQAFF sq_thread_cpu is valid SetupSQAFF uint32 = (1 << 2) // SetupCqSize app defines CQ size SetupCqSize uint32 = (1 << 3) // SetupClamp clamp SQ/CQ ring sizes SetupClamp uint32 = (1 << 4) // SetupAttachWq attach to existing wq SetupAttachWq uint32 = (1 << 5) )
const ( // FsyncDatasync ... FsyncDatasync uint = (1 << 0) // SqRingOffset is the offset of the submission queue. SqRingOffset uint64 = 0 // CqRingOffset is the offset of the completion queue. CqRingOffset uint64 = 0x8000000 // SqeRingOffset is the offset of the submission queue entries. SqeRingOffset uint64 = 0x10000000 // SqNeedWakeup needs io_uring_enter wakeup SqNeedWakeup uint32 = (1 << 0) SqCqOverflow uint32 = (1 << 1) // EnterGetEvents ... EnterGetEvents uint = (1 << 0) // EnterSqWakeup ... EnterSqWakeup uint = (1 << 1) RegRegisterBuffers = 0 RegUnregisterBuffers = 1 RegRegisterFiles = 2 RegUnregisterFiles = 3 RegRegisterEventFd = 4 RegUnregisterEventfd = 5 RegRegisterFilesUpdate = 6 RegRegisterEventFdAsync = 7 RegRegisterProbe = 8 RegRegisterPersonality = 9 RegUnregisterPersonality = 10 )
const ( // CqSeenFlag is a nonstandard flag for handling concurrent readers // from the CompletionQueue. CqSeenFlag = 1 )
Variables ¶
var ( // ErrEntryNotFound is returned when a CQE is not found. ErrEntryNotFound = errors.New("Completion entry not found") )
Functions ¶
func FastOpenAllowed ¶
func FastOpenAllowed() error
FastOpenAllowed return nil if fast open is enabled.
func MmapRing ¶
func MmapRing(fd int, p *Params, sq *SubmitQueue, cq *CompletionQueue) error
MmapRing is used to configure the submit and completion queues, it should only be called after the Setup function has completed successfully. See: https://github.com/axboe/liburing/blob/master/src/setup.c#L22
func RegisterBuffers ¶
RegisterBuffers is used to register buffers to a ring.
func RegisterEventFd ¶
RegisterEventFd is used to register an event file descriptor to a ring.
func RegisterEventFdAsync ¶
RegisterEventFdAsync is used to register an event file descriptor for async polling on a ring.
func RegisterFiles ¶
RegisterFiles is used to register files to a ring.
func ReregisterFiles ¶
ReregisterFiles is used to reregister files to a ring.
func UnregisterBuffers ¶
UnregisterBuffers is used to unregister iovecs from a ring.
func UnregisterEventFd ¶
UnregisterEventFd is used to unregister a file descriptor to a ring.
func UnregisterFiles ¶
UnregisterFiles is used to unregister files to a ring.
Types ¶
type CQRingOffset ¶
type CQRingOffset struct { Head uint32 Tail uint32 RingMask uint32 Entries uint32 Overflow uint32 Cqes uint32 Flags uint32 Resv [2]uint64 }
CQRingOffset describes the various completion queue offsets.
type CompletionEntry ¶
type CompletionEntry struct { UserData uint64 /* sqe->data submission data passed back */ Res int32 /* result code for this event */ Flags uint32 }
CompletionEntry IO completion data structure (Completion Queue Entry).
func (*CompletionEntry) IsZero ¶
func (c *CompletionEntry) IsZero() bool
IsZero returns if the CQE is zero valued.
type CompletionQueue ¶
type CompletionQueue struct { Size uint32 Head *uint32 Tail *uint32 Mask *uint32 Overflow *uint32 Flags *uint32 // Entries must never be resized, it is mmap'd. Entries []CompletionEntry // contains filtered or unexported fields }
CompletionQueue represents the completion queue ring buffer.
func (*CompletionQueue) Advance ¶
func (c *CompletionQueue) Advance(count int)
Advance is used to advance the completion queue by a count.
func (*CompletionQueue) EntryBy ¶
func (c *CompletionQueue) EntryBy(userData uint64) (*CompletionEntry, error)
EntryBy (DEPRECATED) returns a CompletionEntry by comparing the user data, this should be called after the ring has been entered.
type FileRegistry ¶
FileRegistry is an interface for registering files to a Ring.
func NewFileRegistry ¶
func NewFileRegistry(ringFd int) FileRegistry
NewFileRegistry creates a FileRegistry for use with a ring.
type Opcode ¶
type Opcode uint8
Opcode is an opcode for the ring.
const ( Nop Opcode = iota Readv Writev Fsync ReadFixed WriteFixed PollAdd PollRemove SyncFileRange SendMsg RecvMsg Timeout TimeoutRemove Accept AsyncCancel LinkTimeout Connect Fallocate OpenAt Close FilesUpdate Statx Read Write Fadvise Madvise Send Recv Openat2 EpollCtl Splice ProvideBuffers RemoveBuffers OpSupported = (1 << 0) )
type Params ¶
type Params struct { SqEntries uint32 CqEntries uint32 Flags uint32 SqThreadCPU uint32 SqThreadIdle uint32 Features uint32 WqFD uint32 Resv [3]uint32 SqOffset SQRingOffset CqOffset CQRingOffset }
Params are used to configured a io uring.
type ReadWriteAtCloser ¶
type ReadWriteAtCloser interface { io.WriterAt io.ReadWriteCloser }
ReadWriteAtCloser supports reading, writing, and closing.
type ReadWriteSeekerCloser ¶
type ReadWriteSeekerCloser interface { io.Reader io.Writer io.Seeker io.Closer ReadAt([]byte, int64) (int, error) WriteAt([]byte, int64) (int, error) }
ReadWriteSeekerCloser is a ReadWriteCloser and ReadWriteSeeker.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring contains an io_uring submit and completion ring.
func New ¶
func New(size uint, p *Params, opts ...RingOption) (*Ring, error)
New is used to create an iouring.Ring.
func (*Ring) CompleteHead ¶
CompleteHead returns the position of the head of the completion queue. This method is safe for calling concurrently.
func (*Ring) CompleteTail ¶
CompleteTail returns the position of the tail of the submit queue. This method is safe for calling concurrently.
func (*Ring) Enter ¶
func (r *Ring) Enter(toSubmit uint, minComplete uint, flags uint, sigset *unix.Sigset_t) (int, error)
Enter is used to enter the ring.
func (*Ring) EventFd ¶
EventFd returns the file descriptor of the eventfd if it is set, otherwise it returns the default value of -1.
func (*Ring) FileReadWriter ¶
func (r *Ring) FileReadWriter(f *os.File) (ReadWriteSeekerCloser, error)
FileReadWriter returns an io.ReadWriter from an os.File that uses the ring. Note that is is not valid to use other operations on the file (Seek/Close) in combination with the reader.
func (*Ring) FileRegistry ¶
func (r *Ring) FileRegistry() FileRegistry
FileRegistry returns the FileRegistry for the Ring.
func (*Ring) ID ¶
ID returns an id for a SQEs, it is a monotonically increasing value (until uint64 wrapping).
func (*Ring) NeedsEnter ¶
NeedsEnter returns if the ring needs to be entered.
func (*Ring) PrepareAccept ¶
func (r *Ring) PrepareAccept( fd int, addr syscall.Sockaddr, socklen uint32, flags int, ) (uint64, error)
PrepareAccept is used to prepare a SQE for an accept(2) call.
func (*Ring) PrepareClose ¶
PrepareClose is used to prepare a close(2) call.
func (*Ring) PrepareConnect ¶
PrepareConnect is used to prepare a SQE for a connect(2) call.
func (*Ring) PrepareFadvise ¶
PrepareFadvise is used to prepare a fadvise call.
func (*Ring) PrepareFallocate ¶
PrepareFallocate is used to prepare a fallocate call.
func (*Ring) PrepareFsync ¶
PrepareFsync is used to prepare a fsync(2) call.
func (*Ring) PrepareNop ¶
PrepareNop is used to prep a nop.
func (*Ring) PreparePollAdd ¶
PreparePollAdd is used to prepare a SQE for adding a poll.
func (*Ring) PrepareRead ¶
PrepareRead is used to prepare a read SQE.
func (*Ring) PrepareReadFixed ¶
PrepareReadFixed is used to prepare a fixed read SQE.
func (*Ring) PrepareReadv ¶
PrepareReadv is used to prepare a readv SQE.
func (*Ring) PrepareRecv ¶
PrepareRecv is used to prepare a Recv SQE.
func (*Ring) PrepareRecvmsg ¶
PrepareRecvmsg is used to prepare a recvmsg SQE.
func (*Ring) PrepareSend ¶
PrepareSend is used to prepare a Send SQE.
func (*Ring) PrepareSplice ¶
func (r *Ring) PrepareSplice( inFd int, inOff *int64, outFd int, outOff *int64, n int, flags int, ) (uint64, error)
PrepareSplice is used to prepare a SQE for a splice(2).
func (*Ring) PrepareStatx ¶
func (r *Ring) PrepareStatx( dirfd int, path string, flags int, mask int, statx *unix.Statx_t, ) (uint64, error)
PrepareStatx is used to prepare a Statx call and will return the request id (SQE UserData) of the SQE. After calling the returned callback function the ring is safe to be entered.
func (*Ring) PrepareTimeout ¶
PrepareTimeout is used to prepare a timeout SQE.
func (*Ring) PrepareTimeoutRemove ¶
PrepareTimeoutRemove is used to prepare a timeout removal.
func (*Ring) PrepareWrite ¶
PrepareWrite is used to prepare a Write SQE.
func (*Ring) PrepareWriteFixed ¶
PrepareWriteFixed is used to prepare a fixed write SQE.
func (*Ring) PrepareWritev ¶
PrepareWritev is used to prepare a writev SQE.
func (*Ring) ShouldFlush ¶
ShouldFlush returns if the ring should flush due to cq being overflown.
func (*Ring) SockoptListener ¶
func (r *Ring) SockoptListener(network, address string, errHandler func(error), sockopts ...int) (net.Listener, error)
SockoptListener returns a net.Listener that is Ring based.
func (*Ring) Splice ¶
func (r *Ring) Splice( inFd int, inOff *int64, outFd int, outOff *int64, n int, flags int, ) (int64, error)
Splice implements splice using a ring.
func (*Ring) Statx ¶
func (r *Ring) Statx( dirfd int, path string, flags int, mask int, statx *unix.Statx_t, ) (err error)
Statx implements statx using a ring.
func (*Ring) SubmitEntry ¶
func (r *Ring) SubmitEntry() (*SubmitEntry, func())
SubmitEntry returns the next available SubmitEntry or nil if the ring is busy. The returned function should be called after SubmitEntry is ready to enter the ring.
func (*Ring) SubmitHead ¶
SubmitHead returns the position of the head of the submit queue. This method is safe for calling concurrently.
func (*Ring) SubmitTail ¶
SubmitTail returns the position of the tail of the submit queue. This method is safe for calling concurrently.
type RingOption ¶
RingOption is an option for configuring a Ring.
func WithDeadline ¶
func WithDeadline(d time.Duration) RingOption
WithDeadline is used to configure the deadline for submitting IO.
func WithDebug ¶
func WithDebug() RingOption
WithDebug is used to print additional debug information.
func WithEnterErrHandler ¶
func WithEnterErrHandler(f func(error)) RingOption
WithEnterErrHandler is used to handle errors on ring enter.
func WithEventFd ¶
func WithEventFd(initval uint, flags int, async bool) RingOption
WithEventFd is used to create an eventfd and register it to the Ring. The event fd can be accessed using the EventFd method.
func WithFileRegistry ¶
func WithFileRegistry() RingOption
WithFileRegistry is used to register a FileRegistry with the Ring. The registery can be accessed with the FileRegistry method on the ring.
func WithID ¶
func WithID(id uint64) RingOption
WithID is used to set the starting id for the monotonically increasing ID method.
type SQRingOffset ¶
type SQRingOffset struct { Head uint32 Tail uint32 RingMask uint32 Entries uint32 Flags uint32 Dropped uint32 Array uint32 Resv1 uint32 Resv2 uint64 }
SQRingOffset describes the various submit queue offsets.
type SubmitEntry ¶
type SubmitEntry struct { Opcode Opcode /* type of operation for this sqe */ Flags uint8 /* IOSQE_ flags */ Ioprio uint16 /* ioprio for the request */ Fd int32 /* file descriptor to do IO on */ Offset uint64 /* offset into file */ Addr uint64 /* pointer to buffer or iovecs */ Len uint32 /* buffer size or number of iovecs */ UFlags int32 UserData uint64 Anon0 [24]byte /* extra padding */ }
SubmitEntry is an IO submission data structure (Submission Queue Entry).
type SubmitQueue ¶
type SubmitQueue struct { Size uint32 Head *uint32 Tail *uint32 Mask *uint32 Flags *uint32 Dropped *uint32 // Array holds entries to be submitted; it must never be resized it is mmap'd. Array []uint32 // Entries must never be resized, it is mmap'd. Entries []SubmitEntry // contains filtered or unexported fields }
SubmitQueue represents the submit queue ring buffer.
func (*SubmitQueue) NeedWakeup ¶
func (s *SubmitQueue) NeedWakeup() bool
NeedWakeup is used to determine whether the submit queue needs awoken.