Documentation ¶
Overview ¶
Package lcore allows to control execution of user-supplied functions on specified logical CPU core.
This may have some advantages such as: reduce context switches, allows to use non-preemptible algorithms etc.
Please note that thread function is entirely specified by user. It is up to user to define how this function would exit.
Index ¶
Examples ¶
Constants ¶
const (
NumaNodeAny = -1
)
Default NUMA node value.
Variables ¶
var (
MaxLcoreID = loadCPUMap()
)
Maximum number of logical CPU cores on the system.
Functions ¶
Types ¶
type Thread ¶
type Thread chan<- func()
Thread is a channel which jobs can be sent to.
func NewLockedThread ¶
func NewLockedThread(ch chan func()) Thread
NewLockedThread creates new Thread with user specified channel.
Example ¶
package main import ( "fmt" "sync" "github.com/pkoukk/go-dpdk/lcore" ) func main() { // create a thread with new channel thd := lcore.NewLockedThread(make(chan func())) defer thd.Close() // Set affinity to lcore 0 err := thd.SetAffinity(0) if err != nil { fmt.Println(err) return } var wg sync.WaitGroup wg.Add(1) var a int thd.Exec(false, func() { defer wg.Done() a = 1 }) wg.Wait() fmt.Println(a) }
Output: 1
func (Thread) Exec ¶
Exec sends new job to the Thread. If wait is true this function blocks until job finishes execution.
Example ¶
package main import ( "fmt" "github.com/pkoukk/go-dpdk/lcore" ) func main() { // create a thread with new channel thd := lcore.NewLockedThread(make(chan func())) defer thd.Close() var a int thd.Exec(true, func() { a = 1 }) fmt.Println(a) }
Output: 1
func (Thread) GetAffinity ¶
GetAffinity retrieves CPU affinity of the Thread.
func (Thread) SetAffinity ¶
SetAffinity pins the thread to specified CPU core id.