uring

package
v0.0.0-...-69611e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SqeFixedFileFlag    uint8 = 1 << 0
	SqeIODrainFlag      uint8 = 1 << 1
	SqeIOLinkFlag       uint8 = 1 << 2
	SqeIOHardLinkFlag   uint8 = 1 << 3
	SqeAsyncFlag        uint8 = 1 << 4
	SqeBufferSelectFlag uint8 = 1 << 5
)

SQE flags

View Source
const MaxEntries uint32 = 1 << 15
View Source
const OpSupportedFlag uint16 = 1 << 0

Variables

View Source
var ErrRingSetup = errors.New("ring setup")
View Source
var ErrSQOverflow = errors.New("sq ring overflow")

Functions

func CreateMany

func CreateMany(count int, entries uint32, wpCount int, opts ...SetupOption) ([]*Ring, Defer, error)

CreateMany create multiple io_uring instances. Entries - size of SQ and CQ buffers. count - the number of io_uring instances. wpCount - the number of worker pools, this value must be a multiple of the entries. If workerCount < count worker pool will be shared with setupAttachWQ flag.

func ReadOnceUint32

func ReadOnceUint32(p *uint32) uint32

func SmpLoadAcquireUint32

func SmpLoadAcquireUint32(p *uint32) uint32

func SmpStoreReleaseUint32

func SmpStoreReleaseUint32(p *uint32, v uint32)

Types

type AcceptOp

type AcceptOp struct {
	// contains filtered or unexported fields
}

AcceptOp accept command.

func Accept

func Accept(fd uintptr, flags uint32) *AcceptOp

Accept - accept operation.

func (*AcceptOp) Addr

func (op *AcceptOp) Addr() (net.Addr, error)

func (*AcceptOp) AddrLen

func (op *AcceptOp) AddrLen() uint32

func (*AcceptOp) Code

func (op *AcceptOp) Code() OpCode

func (*AcceptOp) Fd

func (op *AcceptOp) Fd() int

func (*AcceptOp) PrepSQE

func (op *AcceptOp) PrepSQE(sqe *SQEntry)

type CQEvent

type CQEvent struct {
	UserData uint64
	Res      int32
	Flags    uint32
}

func (*CQEvent) Error

func (cqe *CQEvent) Error() error

type CancelOp

type CancelOp struct {
	// contains filtered or unexported fields
}

CancelOp attempt to cancel an already issued request.

func Cancel

func Cancel(targetUserData uint64, flags uint32) *CancelOp

Cancel create CancelOp. Put in targetUserData value of user_data field of the request that should be cancelled.

func (*CancelOp) Code

func (op *CancelOp) Code() OpCode

func (*CancelOp) PrepSQE

func (op *CancelOp) PrepSQE(sqe *SQEntry)

func (*CancelOp) SetTargetUserData

func (op *CancelOp) SetTargetUserData(ud uint64)

type CloseOp

type CloseOp struct {
	// contains filtered or unexported fields
}

CloseOp closes a file descriptor, equivalent of a close(2) system call.

func Close

func Close(fd uintptr) *CloseOp

Close closes a file descriptor, equivalent of a close(2) system call.

func (*CloseOp) Code

func (op *CloseOp) Code() OpCode

func (*CloseOp) PrepSQE

func (op *CloseOp) PrepSQE(sqe *SQEntry)

type ConnectOp

type ConnectOp struct {
	// contains filtered or unexported fields
}

ConnectOp connect operation, equivalent of a connect(2) system call.

func Connect

func Connect(fd uintptr, addr *net.TCPAddr) *ConnectOp

Connect operation, equivalent of a connect(2) system call.

func (*ConnectOp) Code

func (op *ConnectOp) Code() OpCode

func (*ConnectOp) PrepSQE

func (op *ConnectOp) PrepSQE(sqe *SQEntry)

type Defer

type Defer func() error

type LinkTimeoutOp

type LinkTimeoutOp struct {
	// contains filtered or unexported fields
}

LinkTimeoutOp IORING_OP_LINK_TIMEOUT command.

func LinkTimeout

func LinkTimeout(duration time.Duration) *LinkTimeoutOp

LinkTimeout - timeout operation for linked command. Note: previous queued SQE must be queued with flag SqeIOLinkFlag.

func (*LinkTimeoutOp) Code

func (op *LinkTimeoutOp) Code() OpCode

func (*LinkTimeoutOp) PrepSQE

func (op *LinkTimeoutOp) PrepSQE(sqe *SQEntry)

type NopOp

type NopOp struct {
}

NopOp - do not perform any I/O. This is useful for testing the performance of the io_uring implementation itself.

func Nop

func Nop() *NopOp

func (*NopOp) Code

func (op *NopOp) Code() OpCode

func (*NopOp) PrepSQE

func (op *NopOp) PrepSQE(sqe *SQEntry)

type OpCode

type OpCode uint8
const (
	NopCode OpCode = iota
	ReadVCode
	WriteVCode

	TimeoutCode

	AcceptCode
	AsyncCancelCode
	LinkTimeoutCode
	ConnectCode

	CloseCode

	ReadCode
	WriteCode

	SendCode
	RecvCode

	ProvideBuffersCode
)

type Operation

type Operation interface {
	PrepSQE(*SQEntry)
	Code() OpCode
}

type Probe

type Probe struct {
	// contains filtered or unexported fields
}

func (*Probe) GetOP

func (p *Probe) GetOP(code int) *probeOp

GetOP return info for operation by code.

type ProvideBuffersOp

type ProvideBuffersOp struct {
	// contains filtered or unexported fields
}

ProvideBuffersOp .

func ProvideBuffers

func ProvideBuffers(buff []byte, bufferId uint64, groupId uint16) *ProvideBuffersOp

ProvideBuffers .

func (*ProvideBuffersOp) Code

func (op *ProvideBuffersOp) Code() OpCode

func (*ProvideBuffersOp) PrepSQE

func (op *ProvideBuffersOp) PrepSQE(sqe *SQEntry)

type ReadOp

type ReadOp struct {
	// contains filtered or unexported fields
}

ReadOp read operation, equivalent of a pread(2) system call.

func Read

func Read(fd uintptr, buff []byte, offset uint64) *ReadOp

Read - create read operation, equivalent of a pread(2) system call.

func (*ReadOp) Code

func (op *ReadOp) Code() OpCode

func (*ReadOp) PrepSQE

func (op *ReadOp) PrepSQE(sqe *SQEntry)

type ReadVOp

type ReadVOp struct {
	FD     uintptr
	Size   int64
	Offset uint64
	IOVecs []syscall.Iovec
}

ReadVOp vectored read operation, similar to preadv2(2).

func ReadV

func ReadV(file *os.File, vectors [][]byte, offset uint64) *ReadVOp

ReadV vectored read operation, similar to preadv2(2).

func (*ReadVOp) Code

func (op *ReadVOp) Code() OpCode

func (*ReadVOp) PrepSQE

func (op *ReadVOp) PrepSQE(sqe *SQEntry)

type RecvOp

type RecvOp struct {
	// contains filtered or unexported fields
}

RecvOp receive a message from a socket operation.

func Recv

func Recv(socketFd uintptr, buff []byte, msgFlags uint32) *RecvOp

Recv receive a message from a socket.

func (*RecvOp) Code

func (op *RecvOp) Code() OpCode

func (*RecvOp) Fd

func (op *RecvOp) Fd() int

func (*RecvOp) PrepSQE

func (op *RecvOp) PrepSQE(sqe *SQEntry)

func (*RecvOp) SetBuffer

func (op *RecvOp) SetBuffer(buff []byte)

type Ring

type Ring struct {
	Params *ringParams
	// contains filtered or unexported fields
}

Ring io_uring instance.

func New

func New(entries uint32, opts ...SetupOption) (*Ring, error)

New create new io_uring instance with. Entries - size of SQ and CQ buffers.

func (*Ring) AdvanceCQ

func (r *Ring) AdvanceCQ(n uint32)

AdvanceCQ dequeue CQ on n entry.

func (*Ring) Close

func (r *Ring) Close() error

func (*Ring) Fd

func (r *Ring) Fd() int

Fd io_uring file descriptor.

func (*Ring) NextSQE

func (r *Ring) NextSQE() (entry *SQEntry, err error)

NextSQE return pointer of the next available SQE in SQ queue.

func (*Ring) PeekCQE

func (r *Ring) PeekCQE() (*CQEvent, error)

PeekCQE return first available CQE from CQ.

func (*Ring) PeekCQEventBatch

func (r *Ring) PeekCQEventBatch(buff []*CQEvent) int

PeekCQEventBatch fill buffer by available CQEs. Return count of filled CQEs.

func (*Ring) Probe

func (r *Ring) Probe() (*Probe, error)

Probe return io_uring probe.

func (*Ring) QueueSQE

func (r *Ring) QueueSQE(op Operation, flags uint8, userData uint64) error

QueueSQE adds an operation to the queue SQ.

func (*Ring) RegisterBuffers

func (r *Ring) RegisterBuffers(buffers []syscall.Iovec) error

RegisterBuffers register shared buffers.

func (*Ring) RegisterFiles

func (r *Ring) RegisterFiles(descriptors []int) error

RegisterFiles register shared files.

func (*Ring) SeenCQE

func (r *Ring) SeenCQE(cqe *CQEvent)

SeenCQE dequeue CQ on 1 entry.

func (*Ring) SetIOWQMaxWorkers

func (r *Ring) SetIOWQMaxWorkers(count int) error

SetIOWQMaxWorkers provides a way to change worker count per ring.

func (*Ring) Submit

func (r *Ring) Submit() (uint, error)

Submit new SQEs. Return count of submitted SQEs.

func (*Ring) SubmitAndWaitCQEvents

func (r *Ring) SubmitAndWaitCQEvents(cnt uint32) (cqe *CQEvent, err error)

SubmitAndWaitCQEvents submit new SQEs in SQE and wait cnt CQEs in CQ. Return first available CQE.

func (*Ring) UnRegisterBuffers

func (r *Ring) UnRegisterBuffers() error

UnRegisterBuffers .

func (*Ring) UnRegisterFiles

func (r *Ring) UnRegisterFiles() error

UnRegisterFiles .

func (*Ring) WaitCQEvents

func (r *Ring) WaitCQEvents(cnt uint32) (cqe *CQEvent, err error)

WaitCQEvents wait cnt CQEs in CQ.

func (*Ring) WaitCQEventsWithTimeout

func (r *Ring) WaitCQEventsWithTimeout(cnt uint32, timeout time.Duration) (cqe *CQEvent, err error)

WaitCQEventsWithTimeout wait cnt CQEs in CQ. Timeout will be exceeded if no new CQEs in queue.

type SQEntry

type SQEntry struct {
	OpCode      uint8
	Flags       uint8
	IoPrio      uint16
	Fd          int32
	Off         uint64
	Addr        uint64
	Len         uint32
	OpcodeFlags uint32
	UserData    uint64

	BufIG       uint16
	Personality uint16
	SpliceFdIn  int32
	// contains filtered or unexported fields
}

type SendOp

type SendOp struct {
	// contains filtered or unexported fields
}

SendOp send a message to a socket operation.

func Send

func Send(socketFd uintptr, buff []byte, msgFlags uint32) *SendOp

Send send a message to a socket.

func (*SendOp) Code

func (op *SendOp) Code() OpCode

func (*SendOp) Fd

func (op *SendOp) Fd() int

func (*SendOp) PrepSQE

func (op *SendOp) PrepSQE(sqe *SQEntry)

func (*SendOp) SetBuffer

func (op *SendOp) SetBuffer(buff []byte)

type SetupOption

type SetupOption func(params *ringParams)

func WithAttachedWQ

func WithAttachedWQ(fd int) SetupOption

WithAttachedWQ use worker pool from another io_uring instance.

func WithCQSize

func WithCQSize(sz uint32) SetupOption

WithCQSize set CQ max entries count.

func WithIOPoll

func WithIOPoll() SetupOption

WithIOPoll enable IOPOLL option.

func WithSQPoll

func WithSQPoll(threadIdle time.Duration) SetupOption

WithSQPoll add IORING_SETUP_SQPOLL flag. Note, that process must started with root privileges or the user should have the CAP_SYS_NICE capability (for kernel version >= 5.11).

func WithSQThreadCPU

func WithSQThreadCPU(cpu uint32) SetupOption

WithSQThreadCPU bound poll thread to the cpu.

type TimeoutOp

type TimeoutOp struct {
	// contains filtered or unexported fields
}

TimeoutOp timeout command.

func Timeout

func Timeout(duration time.Duration) *TimeoutOp

Timeout - timeout operation.

func (*TimeoutOp) Code

func (op *TimeoutOp) Code() OpCode

func (*TimeoutOp) PrepSQE

func (op *TimeoutOp) PrepSQE(sqe *SQEntry)

type WriteOp

type WriteOp struct {
	// contains filtered or unexported fields
}

WriteOp write operation, equivalent of a pwrite(2) system call.

func Write

func Write(fd uintptr, buff []byte, offset uint64) *WriteOp

Write - create write operation, equivalent of a pwrite(2) system call.

func (*WriteOp) Code

func (op *WriteOp) Code() OpCode

func (*WriteOp) PrepSQE

func (op *WriteOp) PrepSQE(sqe *SQEntry)

type WriteVOp

type WriteVOp struct {
	FD     uintptr
	IOVecs []syscall.Iovec
	Offset uint64
}

WriteVOp vectored write operation, similar to pwritev2(2).

func WriteV

func WriteV(file *os.File, bytes [][]byte, offset uint64) *WriteVOp

WriteV vectored writes bytes to file. Write starts from offset. If the file is not seekable, offset must be set to zero.

func (*WriteVOp) Code

func (op *WriteVOp) Code() OpCode

func (*WriteVOp) PrepSQE

func (op *WriteVOp) PrepSQE(sqe *SQEntry)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL