ring

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package ring wraps RTE ring library.

Please refer to DPDK Programmer's Guide for reference and caveats.

Index

Constants

View Source
const (
	// SingleConsumer specifies that default dequeue operation will
	// exhibit 'single-consumer' behaviour.
	SingleConsumer uint = C.RING_F_SC_DEQ
	// SingleProducer specifies that default enqueue operation will
	// exhibit 'single-producer' behaviour.
	SingleProducer = C.RING_F_SP_ENQ
	// ExactSize specifies how to handle ring size during Create/Init.
	// Ring is to hold exactly requested number of entries. Without
	// this flag set, the ring size requested must be a power of 2,
	// and the usable space will be that size - 1. With the flag, the
	// requested size will be rounded up to the next power of two, but
	// the usable space will be exactly that requested. Worst case, if
	// a power-of-2 size is requested, half the ring space will be
	// wasted.
	ExactSize = C.RING_F_EXACT_SZ
)

Variables

Shortcuts for ring creation flags.

Functions

func GetMemSize

func GetMemSize(count uint) (int, error)

GetMemSize calculates the memory size needed for a ring.

This function returns the number of bytes needed for a ring, given the number of elements in it. This value is the sum of the size of the structure rte_ring and the size of the memory needed by the objects pointers. The value is aligned to a cache line size.

count should be power of 2. If that is not the case, EINVAL error will be returned.

func TelemetryInit added in v0.0.12

func TelemetryInit(prefix string)

TelemetryInit initializes telemetry callbacks for rings. Specify prefix for cmd path to avoid conflicts in the future. "/ring" is the good candidate for a prefix.

Types

type Option

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

Option alters ring behaviour.

func OptAlign added in v0.0.7

func OptAlign(align uint) Option

OptAlign specifies the alignment requirement for allocation using malloc. Not used in Create.

func OptFlag

func OptFlag(flag uint) Option

OptFlag add one of permitted flags for the ring creation.

func OptSocket

func OptSocket(socket uint) Option

OptSocket specifies the socket id where the memzone would be created in Create.

type Ring

type Ring C.struct_rte_ring

Ring is a fixed-size queue, implemented as a table of pointers. Head and tail pointers are modified atomically, allowing concurrent access to it. It has the following features:

* FIFO (First In First Out)

* Maximum size is fixed; the pointers are stored in a table.

* Lockless implementation.

* Multi- or single-consumer dequeue.

* Multi- or single-producer enqueue.

* Bulk dequeue.

* Bulk enqueue. Note: the ring implementation is not preemptible. Refer to Programmer's guide/Environment Abstraction Layer/Multiple pthread/Known Issues/rte_ring for more information.

func Create

func Create(name string, count uint, opts ...Option) (*Ring, error)

Create creates new ring named name in memory.

This function uses rte_memzone_reserve() to allocate memory. Then it calls rte_ring_init() to initialize an empty ring.

The new ring size is set to count, which must be a power of two. Water marking is disabled by default. The real usable ring size is count-1 instead of count to differentiate a free ring from an empty ring.

The ring is added in RTE_TAILQ_RING list.

func Lookup

func Lookup(name string) (*Ring, error)

Lookup searches a ring from its name in RTE_TAILQ_RING, i.e. among those created with Create.

func New

func New(name string, count uint, opts ...Option) (*Ring, error)

New allocates and initializes Ring in Go memory. It allocates a slice of bytes with enough length to hold a Ring with requested parameters. Then slice is casted to Ring and initialized with Init.

Please note that OptSocket is irrelevant in this case and is unused if specified.

func NewEAL added in v0.0.7

func NewEAL(name string, count uint, opts ...Option) (*Ring, error)

NewEAL allocates and initializes Ring in EAL memory. It allocates a memory with rte_zmalloc_socket with enough length to hold a Ring with requested parameters. Then this pointer is casted to Ring and initialized with Init.

func (*Ring) Cap

func (r *Ring) Cap() uint

Cap returns the number of elements which can be stored in the ring.

func (*Ring) Count

func (r *Ring) Count() uint

Count returns the number of entries in a ring.

func (*Ring) Dequeue

func (r *Ring) Dequeue() (unsafe.Pointer, bool)

Dequeue dequeues single object from Ring.

func (*Ring) DequeueBulk

func (r *Ring) DequeueBulk(obj []unsafe.Pointer) (n, avail uint32)

DequeueBulk dequeues objects into given slice of pointers. Returns number of dequeued objects (either 0 or len(obj)) and amount of remaining ring entries in the ring after the enqueue operation has finished.

func (*Ring) DequeueBurst

func (r *Ring) DequeueBurst(obj []unsafe.Pointer) (n, avail uint32)

DequeueBurst dequeues objects into given slice of pointers. Returns number of dequeued objects and amount of remaining ring entries in the ring after the enqueue operation has finished. after the enqueue operation has finished.

func (*Ring) Enqueue

func (r *Ring) Enqueue(obj unsafe.Pointer) bool

Enqueue enqueues an object into given Ring.

func (*Ring) EnqueueBulk

func (r *Ring) EnqueueBulk(obj []unsafe.Pointer) (n, free uint32)

EnqueueBulk enqueues given objects from slice into Ring. Returns number of enqueued objects (either 0 or len(obj)) and amount of space in the ring after the enqueue operation has finished.

func (*Ring) EnqueueBurst

func (r *Ring) EnqueueBurst(obj []unsafe.Pointer) (n, free uint32)

EnqueueBurst enqueues given objects from slice into Ring. Returns number of enqueued objects and amount of space in the ring after the enqueue operation has finished.

func (*Ring) Free

func (r *Ring) Free()

Free deallocates all memory used by the ring.

This function must be called only if r was created with Create or NewEAL.

func (*Ring) FreeCount

func (r *Ring) FreeCount() uint

FreeCount returns the number of free entries in a ring.

func (*Ring) Init

func (r *Ring) Init(name string, count uint, opts ...Option) error

Init initializes a ring structure in memory. The size of the memory area must be large enough to store the ring structure and the object table. It is advised to use GetMemSize() to get the appropriate size.

The ring size is set to count, which must be a power of two. Water marking is disabled by default. The real usable ring size is count-1 instead of count to differentiate a free ring from an empty ring.

The ring is not added in RTE_TAILQ_RING global list. Indeed, the memory given by the caller may not be shareable among dpdk processes.

func (*Ring) IsEmpty

func (r *Ring) IsEmpty() bool

IsEmpty tests if the ring is empty.

func (*Ring) IsFull

func (r *Ring) IsFull() bool

IsFull tests if the ring is full.

func (*Ring) McDequeue

func (r *Ring) McDequeue() (unsafe.Pointer, bool)

McDequeue dequeues single object from Ring.

func (*Ring) McDequeueBulk

func (r *Ring) McDequeueBulk(obj []unsafe.Pointer) (n, avail uint32)

McDequeueBulk dequeues objects into given slice of pointers. Returns number of dequeued objects (either 0 or len(obj)) and amount of remaining ring entries in the ring after the enqueue operation has finished.

func (*Ring) McDequeueBurst

func (r *Ring) McDequeueBurst(obj []unsafe.Pointer) (n, avail uint32)

McDequeueBurst dequeues objects into given slice of pointers. Returns number of dequeued objects and amount of remaining ring entries in the ring after the enqueue operation has finished. after the enqueue operation has finished.

func (*Ring) MpEnqueue

func (r *Ring) MpEnqueue(obj unsafe.Pointer) bool

MpEnqueue enqueues an object into given Ring.

func (*Ring) MpEnqueueBulk

func (r *Ring) MpEnqueueBulk(obj []unsafe.Pointer) (n, free uint32)

MpEnqueueBulk enqueues given objects from slice into Ring. Returns number of enqueued objects (either 0 or len(obj)) and amount of space in the ring after the enqueue operation has finished.

func (*Ring) MpEnqueueBurst

func (r *Ring) MpEnqueueBurst(obj []unsafe.Pointer) (n, free uint32)

MpEnqueueBurst enqueues given objects from slice into Ring. Returns number of enqueued objects and amount of space in the ring after the enqueue operation has finished.

func (*Ring) Name

func (r *Ring) Name() string

Name returns ring's name stored when creating.

func (*Ring) ScDequeue

func (r *Ring) ScDequeue() (unsafe.Pointer, bool)

ScDequeue dequeues single object from Ring.

func (*Ring) ScDequeueBulk

func (r *Ring) ScDequeueBulk(obj []unsafe.Pointer) (n, avail uint32)

ScDequeueBulk dequeues objects into given slice of pointers. Returns number of dequeued objects (either 0 or len(obj)) and amount of remaining ring entries in the ring after the enqueue operation has finished.

func (*Ring) ScDequeueBurst

func (r *Ring) ScDequeueBurst(obj []unsafe.Pointer) (n, avail uint32)

ScDequeueBurst dequeues objects into given slice of pointers. Returns number of dequeued objects and amount of remaining ring entries in the ring after the enqueue operation has finished. after the enqueue operation has finished.

func (*Ring) Size

func (r *Ring) Size() uint

Size returns the size of the ring.

NOTE: this is not the same as the usable space in the ring. To query that use Cap().

func (*Ring) SpEnqueue

func (r *Ring) SpEnqueue(obj unsafe.Pointer) bool

SpEnqueue enqueues an object into given Ring.

func (*Ring) SpEnqueueBulk

func (r *Ring) SpEnqueueBulk(obj []unsafe.Pointer) (n, free uint32)

SpEnqueueBulk enqueues given objects from slice into Ring. Returns number of enqueued objects (either 0 or len(obj)) and amount of space in the ring after the enqueue operation has finished.

func (*Ring) SpEnqueueBurst

func (r *Ring) SpEnqueueBurst(obj []unsafe.Pointer) (n, free uint32)

SpEnqueueBurst enqueues given objects from slice into Ring. Returns number of enqueued objects and amount of space in the ring after the enqueue operation has finished.

Jump to

Keyboard shortcuts

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