eal

package
v0.0.0-...-1e60831 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: NIST-PD-fallback Imports: 20 Imported by: 2

Documentation

Overview

Package eal contains bindings of DPDK Environment Abstraction Layer.

Index

Constants

View Source
const MaxLCoreID = C.RTE_MAX_LCORE

MaxLCoreID is the (exclusive) maximum LCore ID.

Variables

View Source
var (
	// MainLCore is the main lcore.
	MainLCore LCore
	// Workers are worker lcores.
	Workers LCores
	// Sockets are NUMA sockets of worker lcores.
	Sockets []NumaSocket

	// MainThread is a PollThread running on the initial lcore.
	MainThread PollThread
	// MainReadSide is an RCU read-side object of the MainThread.
	MainReadSide *urcu.ReadSide
)

EAL variables, available after ealinit.Init().

View Source
var (
	// TscHz is TSC time units in one second.
	TscHz uint64
	// TscGHz is TSC time units in one nanosecond.
	TscGHz float64
	// TscSeconds is seconds in one TSC time unit.
	TscSeconds float64
	// TscNanos is nanoseconds in one TSC time unit.
	TscNanos float64
)
View Source
var GqlWithNumaSocket = &graphql.Field{
	Type:        graphql.Int,
	Name:        "numaSocket",
	Description: "NUMA socket.",
	Resolve: func(p graphql.ResolveParams) (any, error) {
		socket := p.Source.(WithNumaSocket).NumaSocket()
		if socket.IsAny() {
			return nil, nil
		}
		return socket.ID(), nil
	},
}

GqlWithNumaSocket is a GraphQL field for source object that implements WithNumaSocket.

View Source
var Version string

Version is DPDK version. This is assigned during package ealinit initialization.

Functions

func AllocObjectID

func AllocObjectID(dbgtype string) string

AllocObjectID allocates an identifier/name for DPDK objects.

func CallMain

func CallMain(f any) any

CallMain runs a function on the main thread and waits for its completion. f must be a function with zero parameters and zero or one return values. Returns f's return value, or nil if f does not have a return value.

func ClassifyByNumaSocket

func ClassifyByNumaSocket[T WithNumaSocket, S ~[]T](s S, r RewriteAnyNumaSocket) (m map[NumaSocket]S)

ClassifyByNumaSocket classifies items by NUMA socket.

T: type that satisfies WithNumaSocket interface
s: source []T

Returns map[eal.NumaSocket][]T

func Free

func Free[T any](ptr *T)

Free deallocates memory from Zmalloc.

func FromTscDuration

func FromTscDuration(d int64) time.Duration

FromTscDuration converts TSC duration to time.Duration.

func InitTscUnit

func InitTscUnit()

InitTscUnit saves TSC time unit. This is called by ealinit package.

func JoinDevArgs

func JoinDevArgs(m map[string]any) string

JoinDevArgs converts device argument key-value pairs to a string. nil values are skipped. As a special case, if the map has a "" key, its value would override all other arguments.

func MakeErrno

func MakeErrno[I constraints.Signed](v I) error

MakeErrno creates Errno from non-zero number or returns nil for zero.

func PostMain

func PostMain(fn cptr.Function)

PostMain asynchronously posts a function to be run on the main thread.

func ProbePCI

func ProbePCI(addr pciaddr.PCIAddress, args map[string]any) error

ProbePCI requests to probe a PCI device.

func ToTscDuration

func ToTscDuration(d time.Duration) int64

ToTscDuration converts time.Duration to TSC duration.

func UpdateLCoreSockets

func UpdateLCoreSockets(lcoreSockets map[int]int, mainLCoreID int) (undo func())

UpdateLCoreSockets saves LCores and Sockets information. Returns an undo function that reverts the changes, useful for mocking in unit tests.

func Zmalloc

func Zmalloc[T any, S constraints.Integer](dbgtype string, size S, socket NumaSocket) *T

Zmalloc allocates zero'ed memory on specified NumaSocket. Panics if out of memory.

func ZmallocAligned

func ZmallocAligned[T any, S constraints.Integer](dbgtype string, size S, align int, socket NumaSocket) *T

ZmallocAligned allocates zero'ed memory on specified NumaSocket. Panics if out of memory. align specifies alignment requirement in cachelines (must be power of 2), or 0 to indicate no requirement.

Types

type Errno

type Errno syscall.Errno

Errno represents a DPDK error.

func GetErrno

func GetErrno() Errno

GetErrno returns the current DPDK error.

func (Errno) Error

func (e Errno) Error() string

type LCore

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

LCore represents a logical core. Zero LCore is invalid.

func CurrentLCore

func CurrentLCore() LCore

CurrentLCore returns the current lcore.

func LCoreFromID

func LCoreFromID(id int) (lc LCore)

LCoreFromID converts lcore ID to LCore.

func (LCore) ID

func (lc LCore) ID() int

ID returns lcore ID.

func (LCore) IsBusy

func (lc LCore) IsBusy() bool

IsBusy returns true if this lcore is running a function.

func (LCore) MarshalJSON

func (lc LCore) MarshalJSON() ([]byte, error)

MarshalJSON encodes lcore as number. Invalid lcore is encoded as null.

func (LCore) NumaSocket

func (lc LCore) NumaSocket() (socket NumaSocket)

NumaSocket returns the NUMA socket where this lcore is located.

func (LCore) RemoteLaunch

func (lc LCore) RemoteLaunch(fn cptr.Function)

RemoteLaunch asynchronously launches a function on this lcore. Errors are fatal.

func (LCore) String

func (lc LCore) String() string

func (LCore) Valid

func (lc LCore) Valid() bool

Valid returns true if this is a valid lcore (not zero value).

func (LCore) Wait

func (lc LCore) Wait() (exitCode int)

Wait blocks until this lcore finishes running, and returns lcore function's return value. If this lcore is not running, returns 0 immediately.

func (LCore) ZapField

func (lc LCore) ZapField(key string) zap.Field

ZapField returns a zap.Field for logging.

type LCorePredicate

type LCorePredicate func(lc LCore) bool

LCorePredicate is a predicate function on LCore.

func LCoreOnNumaSocket

func LCoreOnNumaSocket(socket NumaSocket) LCorePredicate

LCoreOnNumaSocket creates a predicate that accepts lcores on a particular NUMA socket. If socket==any, it accepts any NUMA socket.

func (LCorePredicate) Negate

func (pred LCorePredicate) Negate() LCorePredicate

Negate returns the negated predicate.

type LCores

type LCores []LCore

LCores is a slice of LCore.

func (LCores) ByNumaSocket

func (lcores LCores) ByNumaSocket() map[NumaSocket]LCores

ByNumaSocket classifies lcores by NUMA socket.

func (LCores) Filter

func (lcores LCores) Filter(pred ...LCorePredicate) (filtered LCores)

Filter returns lcores that satisfy zero or more predicates.

func (LCores) MarshalLogArray

func (lcores LCores) MarshalLogArray(enc zapcore.ArrayEncoder) error

MarshalLogArray implements zapcore.ArrayMarshaler interface.

type NumaSocket

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

NumaSocket represents a NUMA socket. Zero value is SOCKET_ID_ANY.

func NumaSocketFromID

func NumaSocketFromID(id int) (socket NumaSocket)

NumaSocketFromID converts socket ID to NumaSocket.

func RandomSocket

func RandomSocket() (socket NumaSocket)

RandomSocket returns a random NumaSocket that has at least one worker lcore.

func (NumaSocket) ID

func (socket NumaSocket) ID() int

ID returns NUMA socket ID.

func (NumaSocket) IsAny

func (socket NumaSocket) IsAny() bool

IsAny returns true if this represents SOCKET_ID_ANY.

func (NumaSocket) MarshalJSON

func (socket NumaSocket) MarshalJSON() ([]byte, error)

MarshalJSON encodes NUMA socket as number. Any is encoded as null.

func (NumaSocket) Match

func (socket NumaSocket) Match(other NumaSocket) bool

Match returns true if either NumaSocket is SOCKET_ID_ANY, or both are the same NumaSocket.

func (NumaSocket) NumaSocket

func (socket NumaSocket) NumaSocket() NumaSocket

NumaSocket implements WithNumaSocket.

func (NumaSocket) String

func (socket NumaSocket) String() string

func (*NumaSocket) UnmarshalJSON

func (socket *NumaSocket) UnmarshalJSON(p []byte) error

UnmarshalJSON decodes NUMA socket as number. null is interpreted as Any.

func (NumaSocket) ZapField

func (socket NumaSocket) ZapField(key string) zap.Field

ZapField returns a zap.Field for logging.

type PollThread

type PollThread interface {
	Post(fn cptr.Function)
}

PollThread represents a thread that can accept and run posted functions.

type RewriteAnyNumaSocket

type RewriteAnyNumaSocket int

RewriteAnyNumaSocket provides a function to change "any NUMA socket" to a concrete NUMA socket.

const (
	// KeepAnyNumaSocket keeps "any NUMA socket" unchanged.
	KeepAnyNumaSocket RewriteAnyNumaSocket = -2 - iota
	// RewriteAnyNumaSocketFirst rewrites "any NUMA socket" to eal.Sockets[0].
	RewriteAnyNumaSocketFirst
	// RewriteAnyNumaSocketRandom rewrites "any NUMA socket" to eal.RandomSocket().
	RewriteAnyNumaSocketRandom
)

func RewriteAnyNumaSocketTo

func RewriteAnyNumaSocketTo(socket NumaSocket) (r RewriteAnyNumaSocket)

RewriteAnyNumaSocketTo rewrites "any NUMA socket" to the specified NUMA socket.

func (RewriteAnyNumaSocket) Rewrite

func (r RewriteAnyNumaSocket) Rewrite(socket NumaSocket) NumaSocket

Rewrite rewrites the input if it is "any NUMA socket", otherwise keeps it unchanged.

type TscTime

type TscTime uint64

TscTime represents a time point on TSC clock.

func TscNow

func TscNow() TscTime

TscNow returns current TscTime.

func (TscTime) Add

func (t TscTime) Add(d time.Duration) TscTime

Add returns t+d.

func (TscTime) Sub

func (t TscTime) Sub(t0 TscTime) time.Duration

Sub returns t-t0.

func (TscTime) ToTime

func (t TscTime) ToTime() time.Time

ToTime converts to time.Time.

type VDev

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

VDev represents a DPDK virtual device.

func NewVDev

func NewVDev(name string, args map[string]any, socket NumaSocket) (vdev *VDev, e error)

NewVDev creates a virtual device.

func (*VDev) Close

func (vdev *VDev) Close() error

Close destroys the virtual device.

func (VDev) Name

func (vdev VDev) Name() string

Name returns the device name.

func (VDev) NumaSocket

func (vdev VDev) NumaSocket() NumaSocket

NumaSocket returns the NUMA socket of this device, if known.

type WithNumaSocket

type WithNumaSocket interface {
	NumaSocket() NumaSocket
}

WithNumaSocket interface is implemented by types that have an associated or preferred NUMA socket.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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