ealthread

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: 15 Imported by: 4

Documentation

Overview

Package ealthread provides a thread abstraction bound to an DPDK LCore.

Index

Constants

View Source
const (
	SleepMin         = 1
	SleepMax         = 100000
	SleepAdjustEvery = 1 << 10
	SleepMultiply    = 11
	SleepDivide      = 10
	SleepAdd         = 0
)

ThreadSleep constants. These are effective only if NDNDPDK_MK_THREADSLEEP=1 is set during compilation. If a C thread had an empty poll, i.e. processed zero packets or work items during an iteration, it sleeps for a short duration to reduce CPU utilization.

Initially, the sleep duration is SleepMin. Once every SleepAdjustEvery consecutive empty polls, the sleep duration is adjusted as:

d = MIN(SleepMax, d * SleepMultiply / SleepDivide + SleepAdd)

After a valid poll, i.e. processed non-zero packets, the sleep duration is reset to SleepMin.

All durations are in nanoseconds unit.

Variables

View Source
var (
	GqlWorkerType   *gqlserver.NodeType[eal.LCore]
	GqlLoadStatType *graphql.Object
)

GraphQL types.

View Source
var ErrRunning = errors.New("operation not permitted when thread is running")

ErrRunning indicates an error condition when a function expects the thread to be stopped.

Functions

func AllocClear

func AllocClear()

AllocClear deletes all allocations.

When this is used together with eal.UpdateLCoreSockets mock in a test case, the cleanup statement should be ordered as:

defer eal.UpdateLCoreSockets(...)()
defer ealthread.AllocClear()

This ensures AllocClear() clears allocations for mocked workers instead of real workers.

func AllocConfig

func AllocConfig(c Config) (m map[string]eal.LCores, e error)

AllocConfig allocates lcores according to configuration.

func AllocFree

func AllocFree(lcores ...eal.LCore)

AllocFree deallocates an lcore.

func AllocLaunch

func AllocLaunch(th ThreadWithRole) error

AllocLaunch allocates lcore to a thread from DefaultAllocator, and launches the thread.

func AllocRequest

func AllocRequest(requests ...AllocReq) (list []eal.LCore, e error)

AllocRequest allocates lcores to requests. Any request with Role=="" is skipped.

func AllocThread

func AllocThread(threads ...ThreadWithRole) error

AllocThread allocates lcores to threads. If thread already has an allocated lcore, it remains unchanged. If thread type implements eal.WithNumaSocket, the lcore comes from the preferred NUMA socket.

func GqlWithWorker

func GqlWithWorker(get func(p graphql.ResolveParams) Thread) *graphql.Field

GqlWithWorker is a GraphQL field for source object that implements Thread. get is a function that returns a Thread; if nil, p.Source must implement Thread.

func Launch

func Launch(thread Thread)

Launch launches the thread.

Types

type AllocReq

type AllocReq struct {
	Role   string         // role name, must not be empty
	Socket eal.NumaSocket // preferred NUMA socket
}

AllocReq represents a request to the allocator.

type Config

type Config map[string]RoleConfig

Config contains lcore allocation config.

All roles needed by the application must be specified.

func (Config) Extract

func (c Config) Extract(roles map[string]int) (p Config, e error)

Extract moves specified roles to another Config, and validates their minimums.

func (Config) ValidateRoles

func (c Config) ValidateRoles(roles map[string]int) error

ValidateRoles ensures the configured roles match application roles and minimums.

type Ctrl

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

Ctrl controls a C thread.

func InitCtrl

func InitCtrl(ptr unsafe.Pointer) (ctrl *Ctrl)

InitCtrl initializes Ctrl from *C.ThreadCtrl pointer.

func (*Ctrl) Stopper

func (ctrl *Ctrl) Stopper() Stopper

Stopper returns a Stopper via C.ThreadCtrl.

func (*Ctrl) ThreadLoadStat

func (ctrl *Ctrl) ThreadLoadStat() (s LoadStat)

ThreadLoadStat reads LoadStat counters.

type LoadStat

type LoadStat struct {
	// EmptyPolls is number of polls that processed zero item.
	EmptyPolls uint64 `json:"emptyPolls" gqldesc:"Polls that processed zero item."`

	// ValidPolls is number of polls that processed non-zero items.
	ValidPolls uint64 `json:"validPolls" gqldesc:"Polls that processed non-zero items."`

	// Items is count of processed items.
	Items uint64 `json:"items" gqldesc:"Count of processed items."`

	// ItemsPerPoll is average count of processed items per valid poll.
	// This is only available from Sub() return value.
	ItemsPerPoll float64 `json:"itemsPerPoll,omitempty" gqldesc:"Average count of processed items per valid poll."`
}

LoadStat contains polling thread workload statistics.

func (LoadStat) Sub

func (s LoadStat) Sub(prev LoadStat) (diff LoadStat)

Sub computes the difference.

type RoleConfig

type RoleConfig struct {
	LCores  []int
	PerNuma map[int]int
}

RoleConfig contains lcore allocation config for a role.

In JSON, it should be either:

  • a list of lcore IDs, which cannot overlap with other roles.
  • an object, where each key is a NUMA socket and each value is the number of lcores on this socket.

func (RoleConfig) Count

func (c RoleConfig) Count() (sum int)

Count returns the number of lcores configured.

func (RoleConfig) MarshalJSON

func (c RoleConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*RoleConfig) UnmarshalJSON

func (c *RoleConfig) UnmarshalJSON(j []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

type StopChan

type StopChan chan bool

StopChan stops a thread by sending to a channel.

func NewStopChan

func NewStopChan() (stop StopChan)

NewStopChan constructs a StopChan.

func (StopChan) AfterWait

func (stop StopChan) AfterWait()

AfterWait completes a stop request.

func (StopChan) BeforeWait

func (stop StopChan) BeforeWait()

BeforeWait requests a stop.

func (StopChan) Continue

func (stop StopChan) Continue() bool

Continue returns true if the thread should continue. This should be invoked within the running thread.

func (StopChan) RequestStop

func (stop StopChan) RequestStop()

RequestStop requests a stop. This may be used independent from Thread.

type Stopper

type Stopper interface {
	// BeforeWait is invoked before lcore.Wait().
	BeforeWait()

	// AfterWait is invoked after lcore.Wait().
	AfterWait()
}

Stopper abstracts how to tell a thread to stop.

type Thread

type Thread interface {
	// LCore returns allocated lcore.
	LCore() eal.LCore

	// SetLCore assigns an lcore.
	// This can only be used when the thread is stopped.
	SetLCore(lc eal.LCore)

	// IsRunning indicates whether the thread is running.
	IsRunning() bool

	// Stop stops the thread.
	Stop() error
	// contains filtered or unexported methods
}

Thread represents a procedure running on an LCore.

func New

func New(main cptr.Function, stop Stopper) Thread

New creates a Thread.

type ThreadWithCtrl

type ThreadWithCtrl interface {
	ThreadWithLoadStat
	ThreadCtrl() *Ctrl
}

ThreadWithCtrl is a Thread with *Ctrl object.

func NewThreadWithCtrl

func NewThreadWithCtrl(main cptr.Function, ctrl unsafe.Pointer) ThreadWithCtrl

NewThreadWithCtrl creates a ThreadWithCtrl.

type ThreadWithLoadStat

type ThreadWithLoadStat interface {
	Thread
	ThreadLoadStat() LoadStat
}

ThreadWithLoadStat is an object that tracks thread load statistics.

type ThreadWithRole

type ThreadWithRole interface {
	Thread
	ThreadRole() string
}

ThreadWithRole is a thread that identifies itself with a role.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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