DPDK 22.11.6
Data Structures | Typedefs | Enumerations | Functions
rte_thread.h File Reference
#include <stdint.h>
#include <rte_os.h>
#include <rte_compat.h>

Go to the source code of this file.

Data Structures

struct  rte_thread_t
 
struct  rte_thread_attr_t
 

Typedefs

typedef uint32_t(* rte_thread_func) (void *arg)
 
typedef struct eal_tls_key * rte_thread_key
 

Enumerations

enum  rte_thread_priority { RTE_THREAD_PRIORITY_NORMAL = 0 , RTE_THREAD_PRIORITY_REALTIME_CRITICAL = 1 }
 

Functions

__rte_experimental int rte_thread_create (rte_thread_t *thread_id, const rte_thread_attr_t *thread_attr, rte_thread_func thread_func, void *arg)
 
__rte_experimental int rte_thread_join (rte_thread_t thread_id, uint32_t *value_ptr)
 
__rte_experimental int rte_thread_detach (rte_thread_t thread_id)
 
__rte_experimental rte_thread_t rte_thread_self (void)
 
__rte_experimental int rte_thread_equal (rte_thread_t t1, rte_thread_t t2)
 
__rte_experimental int rte_thread_attr_init (rte_thread_attr_t *attr)
 
__rte_experimental int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, enum rte_thread_priority priority)
 
__rte_experimental int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset)
 
__rte_experimental int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset)
 
__rte_experimental int rte_thread_set_affinity_by_id (rte_thread_t thread_id, const rte_cpuset_t *cpuset)
 
__rte_experimental int rte_thread_get_affinity_by_id (rte_thread_t thread_id, rte_cpuset_t *cpuset)
 
int rte_thread_set_affinity (rte_cpuset_t *cpusetp)
 
void rte_thread_get_affinity (rte_cpuset_t *cpusetp)
 
__rte_experimental int rte_thread_get_priority (rte_thread_t thread_id, enum rte_thread_priority *priority)
 
__rte_experimental int rte_thread_set_priority (rte_thread_t thread_id, enum rte_thread_priority priority)
 
__rte_experimental int rte_thread_key_create (rte_thread_key *key, void(*destructor)(void *))
 
__rte_experimental int rte_thread_key_delete (rte_thread_key key)
 
__rte_experimental int rte_thread_value_set (rte_thread_key key, const void *value)
 
__rte_experimental void * rte_thread_value_get (rte_thread_key key)
 

Detailed Description

Threading functions

Simple threads functionality supplied by EAL.

Definition in file rte_thread.h.

Typedef Documentation

◆ rte_thread_func

typedef uint32_t(* rte_thread_func) (void *arg)

Thread function

Function pointer to thread start routine.

Parameters
argArgument passed to rte_thread_create().
Returns
Thread function exit value.

Definition at line 43 of file rte_thread.h.

◆ rte_thread_key

typedef struct eal_tls_key* rte_thread_key

TLS key type, an opaque pointer.

Definition at line 68 of file rte_thread.h.

Enumeration Type Documentation

◆ rte_thread_priority

Thread priority values.

Enumerator
RTE_THREAD_PRIORITY_NORMAL 

normal thread priority, the default

RTE_THREAD_PRIORITY_REALTIME_CRITICAL 

highest thread priority allowed

Definition at line 48 of file rte_thread.h.

Function Documentation

◆ rte_thread_create()

__rte_experimental int rte_thread_create ( rte_thread_t thread_id,
const rte_thread_attr_t thread_attr,
rte_thread_func  thread_func,
void *  arg 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Create a new thread that will invoke the 'thread_func' routine.

Parameters
thread_idA pointer that will store the id of the newly created thread.
thread_attrAttributes that are used at the creation of the new thread.
thread_funcThe routine that the new thread will invoke when starting execution.
argArgument to be passed to the 'thread_func' routine.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_join()

__rte_experimental int rte_thread_join ( rte_thread_t  thread_id,
uint32_t *  value_ptr 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Waits for the thread identified by 'thread_id' to terminate

Parameters
thread_idThe identifier of the thread.
value_ptrStores the exit status of the thread.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_detach()

__rte_experimental int rte_thread_detach ( rte_thread_t  thread_id)
Warning
EXPERIMENTAL: this API may change without prior notice.

Indicate that the return value of the thread is not needed and all thread resources should be release when the thread terminates.

Parameters
thread_idThe id of the thread to be detached.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_self()

__rte_experimental rte_thread_t rte_thread_self ( void  )
Warning
EXPERIMENTAL: this API may change without prior notice.

Get the id of the calling thread.

Returns
Return the thread id of the calling thread.

◆ rte_thread_equal()

__rte_experimental int rte_thread_equal ( rte_thread_t  t1,
rte_thread_t  t2 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Check if 2 thread ids are equal.

Parameters
t1First thread id.
t2Second thread id.
Returns
If the ids are equal, return nonzero. Otherwise, return 0.

◆ rte_thread_attr_init()

__rte_experimental int rte_thread_attr_init ( rte_thread_attr_t attr)
Warning
EXPERIMENTAL: this API may change without prior notice.

Initialize the attributes of a thread. These attributes can be passed to the rte_thread_create() function that will create a new thread and set its attributes according to attr.

Parameters
attrThread attributes to initialize.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_attr_set_priority()

__rte_experimental int rte_thread_attr_set_priority ( rte_thread_attr_t thread_attr,
enum rte_thread_priority  priority 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Set the thread priority value in the thread attributes pointed to by 'thread_attr'.

Parameters
thread_attrPoints to the thread attributes in which priority will be updated.
priorityPoints to the value of the priority to be set.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_attr_set_affinity()

__rte_experimental int rte_thread_attr_set_affinity ( rte_thread_attr_t thread_attr,
rte_cpuset_t *  cpuset 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Set the CPU affinity value in the thread attributes pointed to by 'thread_attr'.

Parameters
thread_attrPoints to the thread attributes in which affinity will be updated.
cpusetPoints to the value of the affinity to be set.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_attr_get_affinity()

__rte_experimental int rte_thread_attr_get_affinity ( rte_thread_attr_t thread_attr,
rte_cpuset_t *  cpuset 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Get the value of CPU affinity that is set in the thread attributes pointed to by 'thread_attr'.

Parameters
thread_attrPoints to the thread attributes from which affinity will be retrieved.
cpusetPointer to the memory that will store the affinity.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_set_affinity_by_id()

__rte_experimental int rte_thread_set_affinity_by_id ( rte_thread_t  thread_id,
const rte_cpuset_t *  cpuset 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Set the affinity of thread 'thread_id' to the cpu set specified by 'cpuset'.

Parameters
thread_idId of the thread for which to set the affinity.
cpusetPointer to CPU affinity to set.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_get_affinity_by_id()

__rte_experimental int rte_thread_get_affinity_by_id ( rte_thread_t  thread_id,
rte_cpuset_t *  cpuset 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Get the affinity of thread 'thread_id' and store it in 'cpuset'.

Parameters
thread_idId of the thread for which to get the affinity.
cpusetPointer for storing the affinity value.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_set_affinity()

int rte_thread_set_affinity ( rte_cpuset_t *  cpusetp)

Set core affinity of the current thread. Support both EAL and non-EAL thread and update TLS.

Parameters
cpusetpPointer to CPU affinity to set.
Returns
On success, return 0; otherwise return -1;

◆ rte_thread_get_affinity()

void rte_thread_get_affinity ( rte_cpuset_t *  cpusetp)

Get core affinity of the current thread.

Parameters
cpusetpPointer to CPU affinity of current thread. It presumes input is not NULL, otherwise it causes panic.

◆ rte_thread_get_priority()

__rte_experimental int rte_thread_get_priority ( rte_thread_t  thread_id,
enum rte_thread_priority priority 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Get the priority of a thread.

Parameters
thread_idId of the thread for which to get priority.
priorityLocation to store the retrieved priority.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_set_priority()

__rte_experimental int rte_thread_set_priority ( rte_thread_t  thread_id,
enum rte_thread_priority  priority 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Set the priority of a thread.

Parameters
thread_idId of the thread for which to set priority.
priorityPriority value to be set.
Returns
On success, return 0. On failure, return a positive errno-style error number.

◆ rte_thread_key_create()

__rte_experimental int rte_thread_key_create ( rte_thread_key key,
void(*)(void *)  destructor 
)

Create a TLS data key visible to all threads in the process. the created key is later used to get/set a value. and optional destructor can be set to be called when a thread exits.

Parameters
keyPointer to store the allocated key.
destructorThe function to be called when the thread exits. Ignored on Windows OS.
Returns
On success, zero. On failure, a negative number and an error number is set in rte_errno. rte_errno can be: ENOMEM - Memory allocation error. ENOEXEC - Specific OS error.

◆ rte_thread_key_delete()

__rte_experimental int rte_thread_key_delete ( rte_thread_key  key)

Delete a TLS data key visible to all threads in the process.

Parameters
keyThe key allocated by rte_thread_key_create().
Returns
On success, zero. On failure, a negative number and an error number is set in rte_errno. rte_errno can be: EINVAL - Invalid parameter passed. ENOEXEC - Specific OS error.

◆ rte_thread_value_set()

__rte_experimental int rte_thread_value_set ( rte_thread_key  key,
const void *  value 
)

Set value bound to the TLS key on behalf of the calling thread.

Parameters
keyThe key allocated by rte_thread_key_create().
valueThe value bound to the rte_thread_key key for the calling thread.
Returns
On success, zero. On failure, a negative number and an error number is set in rte_errno. rte_errno can be: EINVAL - Invalid parameter passed. ENOEXEC - Specific OS error.

◆ rte_thread_value_get()

__rte_experimental void * rte_thread_value_get ( rte_thread_key  key)

Get value bound to the TLS key on behalf of the calling thread.

Parameters
keyThe key allocated by rte_thread_key_create().
Returns
On success, value data pointer (can also be NULL). On failure, NULL and an error number is set in rte_errno. rte_errno can be: EINVAL - Invalid parameter passed. ENOEXEC - Specific OS error.