lcore

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

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

View Source
const (
	NumaNodeAny = -1
)

Default NUMA node value.

Variables

View Source
var (
	MaxLcoreID = loadCPUMap()
)

Maximum number of logical CPU cores on the system.

Functions

func NumaNode

func NumaNode(id uint) int

NumaNode returns id of the NUMA node for specified logical CPU core id. if core id is invalid, NumaNodeAny is returned.

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) Close

func (t Thread) Close()

Close sends a signal to Thread to finish.

func (Thread) Exec

func (t Thread) Exec(wait bool, fn func())

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

func (t Thread) GetAffinity() (s unix.CPUSet, err error)

GetAffinity retrieves CPU affinity of the Thread.

func (Thread) Gettid

func (t Thread) Gettid() (tid int)

Gettid returns Thread id.

func (Thread) SetAffinity

func (t Thread) SetAffinity(id uint) error

SetAffinity pins the thread to specified CPU core id.

Jump to

Keyboard shortcuts

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