Documentation ¶
Overview ¶
Package ealthread provides a thread abstraction bound to an DPDK LCore.
Index ¶
- Constants
- Variables
- func AllocClear()
- func AllocConfig(c Config) (m map[string]eal.LCores, e error)
- func AllocFree(lcores ...eal.LCore)
- func AllocLaunch(th ThreadWithRole) error
- func AllocRequest(requests ...AllocReq) (list []eal.LCore, e error)
- func AllocThread(threads ...ThreadWithRole) error
- func GqlWithWorker(get func(p graphql.ResolveParams) Thread) *graphql.Field
- func Launch(thread Thread)
- type AllocReq
- type Config
- type Ctrl
- type LoadStat
- type RoleConfig
- type StopChan
- type Stopper
- type Thread
- type ThreadWithCtrl
- type ThreadWithLoadStat
- type ThreadWithRole
Constants ¶
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 ¶
GraphQL types.
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 ¶
AllocConfig allocates lcores according to configuration.
func AllocLaunch ¶
func AllocLaunch(th ThreadWithRole) error
AllocLaunch allocates lcore to a thread from DefaultAllocator, and launches the thread.
func AllocRequest ¶
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.
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.
type Ctrl ¶
type Ctrl struct {
// contains filtered or unexported fields
}
Ctrl controls a C thread.
func (*Ctrl) ThreadLoadStat ¶
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.
type RoleConfig ¶
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 (StopChan) Continue ¶
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.
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 ¶
ThreadWithLoadStat is an object that tracks thread load statistics.
type ThreadWithRole ¶
ThreadWithRole is a thread that identifies itself with a role.