rte_thread.h(3)
π rte_thread.h β Library Functions Manual (section 3) π
okay so bestie, welcome to rte_thread.h, straight out of the Library Functions Manual, section 3 π this is the threading header that EAL hands you, and we're gonna go through every single thing in it together. grab a snack. it's a lot. but we're doing it. π
β¨ NAME β¨
rte_thread.h
like. that's the name. it's the header. she's iconic, she contains the threading functions, that's the whole vibe π¦
β¨ SYNOPSIS β¨
first thing, you gotta pull in the headers, no cap:
#include <pthread.h>
#include <stdint.h>
#include <rte_os.h>
#include <rte_compat.h>
πΈ Data Structures
struct rte_thread_tstruct rte_thread_attr_t
πΈ Macros
#define RTE_THREAD_NAME_SIZE 16
#define RTE_THREAD_INTERNAL_PREFIX 'dpdk-'
#define RTE_THREAD_INTERNAL_NAME_SIZE 11
πΈ 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
here's the whole roster, every single one, no skipping, we don't do that here π
int rte_thread_create (rte_thread_t *thread_id, const rte_thread_attr_t
*thread_attr, rte_thread_func thread_func, void *arg)
int rte_thread_create_control (rte_thread_t *thread, const char *name,
rte_thread_func thread_func, void *arg)
__rte_internal int rte_thread_create_internal_control (rte_thread_t *id,
const char *name, rte_thread_func func, void *arg)
int rte_thread_join (rte_thread_t thread_id, uint32_t *value_ptr)
int rte_thread_detach (rte_thread_t thread_id)
rte_thread_t rte_thread_self (void)
void rte_thread_set_name (rte_thread_t thread_id, const char
*thread_name)
__rte_internal void rte_thread_set_prefixed_name (rte_thread_t id, const
char *name)
int rte_thread_equal (rte_thread_t t1, rte_thread_t t2)
int rte_thread_attr_init (rte_thread_attr_t *attr)
int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, enum
rte_thread_priority priority)
int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr,
rte_cpuset_t *cpuset)
int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr,
rte_cpuset_t *cpuset)
int rte_thread_set_affinity_by_id (rte_thread_t thread_id, const
rte_cpuset_t *cpuset)
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)
int rte_thread_get_priority (rte_thread_t thread_id, enum
rte_thread_priority *priority)
int rte_thread_set_priority (rte_thread_t thread_id, enum
rte_thread_priority priority)
int rte_thread_key_create (rte_thread_key *key, void(*destructor)(void
*))
int rte_thread_key_delete (rte_thread_key key)
int rte_thread_value_set (rte_thread_key key, const void *value)
void * rte_thread_value_get (rte_thread_key key)
__rte_internal void rte_thread_mutex_init_shared (pthread_mutex_t
*mutex)
look at that list. she's booked and busy π
β¨ Detailed Description β¨
Threading functions π§΅β¨
it's simple threads functionality, supplied by EAL. that's the whole deal, bestie.
Definition in file rte_thread.h.
β¨ Macro Definition Documentation β¨
π #define RTE_THREAD_NAME_SIZE 16
maximum thread name length, and yes that count includes the '\0' bestie, so don't get cute with it π
Definition at line 28 of file rte_thread.h.
π #define RTE_THREAD_INTERNAL_PREFIX 'dpdk-'
the thread name prefix that gets automatically added to all the internal threads. so if you ever see names starting with that, that's why. iykyk π
Definition at line 33 of file rte_thread.h.
π #define RTE_THREAD_INTERNAL_NAME_SIZE 11
maximum internal thread name length β and again, '\0' is counted in there, so it's 11 total, not 11 plus a null. lowkey important β¨
Definition at line 35 of file rte_thread.h.
β¨ Typedef Documentation β¨
π¦ typedef uint32_t(* rte_thread_func) (void *arg)
Thread function π
it's a function pointer to your thread start routine. the thing the thread runs. main character of the thread, fr fr.
Parameters
argβ the argument that gets passed torte_thread_create().
Returns
- the thread function's exit value.
Definition at line 54 of file rte_thread.h.
π¦ typedef struct eal_tls_key* rte_thread_key
TLS key type β and she's an opaque pointer, so no peeking inside, bestie π
Definition at line 79 of file rte_thread.h.
β¨ Enumeration Type Documentation β¨
π enum rte_thread_priority
Thread priority values. pick your vibe.
Enumerator
RTE_THREAD_PRIORITY_NORMALβ normal thread priority, and it's the default, so if you don't say anything this is what you get πRTE_THREAD_PRIORITY_REALTIME_CRITICALβ the highest thread priority allowed. like, the ceiling. the most. use with intention π
Definition at line 59 of file rte_thread.h.
that's part 1 bestie, keep scrolling, we are not done yet π
rte_thread_create π
int rte_thread_create (rte_thread_t * thread_id, const rte_thread_attr_t * thread_attr, rte_thread_func thread_func, void * arg)
okay so this is THE one bestie β it makes you a brand new thread that's gonna go run the thread_func routine. main character energy fr.
Parameters β¨
thread_idβ a pointer that will store the id of the newly created thread π«Άthread_attrβ the attributes that get used when the new thread is createdthread_funcβ the routine the new thread invokes when it starts executingargβ the argument passed to thatthread_funcroutine
Returns π
On success, return 0. On failure, return a positive errno-style error number.
rte_thread_create_control π
int rte_thread_create_control (rte_thread_t * thread, const char * name, rte_thread_func thread_func, void * arg)
Creates a control thread. Like, a control thread with the given name and attributes, periodt.
The affinity of the new thread is based on the CPU affinity retrieved at the time rte_eal_init() was called, and the EAL threads are then excluded. And if setting the name of the thread fails? The error is ignored and a debug message is logged. slay, no drama.
Parameters πΈ
threadβ filled with the thread id of the new created threadnameβ the name of the control thread (maxRTE_THREAD_NAME_SIZEcharacters including'\0')thread_funcβ function to be executed by the new threadargβ argument passed tothread_func
Returns β
On success, returns 0; on error, it returns a negative value corresponding to the error number.
rte_thread_create_internal_control π₯
__rte_internal int rte_thread_create_internal_control (rte_thread_t * id, const char * name, rte_thread_func func, void * arg)
This one is marked __rte_internal β that's internal API territory, bestie, not your everyday public call.
Creates an internal control thread. It creates a control thread with the given name prefixed. If setting the name of the thread fails, the error is ignored and logged. π
The affinity of the new thread is based on the CPU affinity retrieved at the time rte_eal_init() was called, and the EAL threads are then excluded.
Parameters π¦
idβ filled with the thread ID of the new created threadnameβ the name of the control thread. SeeRTE_THREAD_INTERNAL_NAME_SIZEfor maximum length. The name of the driver or library should be first, then followed by a hyphen and more details. It will be prefixed withRTE_THREAD_INTERNAL_PREFIXby this function.funcβ function to be executed by the new threadargβ argument passed tofunc
Returns β¨
On success, returns 0; a negative value otherwise.
rte_thread_join π«Ά
int rte_thread_join (rte_thread_t thread_id, uint32_t * value_ptr)
Waits for the thread identified by thread_id to terminate. no cap, it just sits there and waits for the vibe to end.
Parameters π
thread_idβ the identifier of the threadvalue_ptrβ stores the exit status of the thread
Returns π
On success, return 0. On failure, return a positive errno-style error number.
rte_thread_detach π§
int rte_thread_detach (rte_thread_t thread_id)
Indicate that the return value of the thread is not needed and that all thread resources should be release[d] when the thread terminates. it's giving "we're done here, clean up after yourself" π
Parameters π
thread_idβ the 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_thread_t rte_thread_self (void )
Get the id of the calling thread. literally just "who am i" but for threads. main character identification moment β¨
Returns π
Return the thread id of the calling thread.
rte_thread_set_name π·οΈ
void rte_thread_set_name (rte_thread_t thread_id, const char * thread_name)
Set the name of the thread.
This API is a noop if the underlying platform does not support setting the thread name, or if the platform-specific API used to set the thread name fails. so like, it might just be out here doing nothing and that's fine, it says nothing about it π€· not a failure, just a vibe.
Parameters π
thread_idβ the id of the thread to set namethread_nameβ the name to set. Truncated toRTE_THREAD_NAME_SIZE, including terminatingNULif necessary.
rte_thread_set_prefixed_name π
__rte_internal void rte_thread_set_prefixed_name (rte_thread_t id, const char * name)
__rte_internal again β internal-only, bestie, don't go wild with this one.
Set the name of an internal thread with the common prefix.
This API is a noop if the underlying platform does not support setting the thread name, or if it fails. same energy as above fr fr.
Parameters π¦
idβ the ID of the thread to set namenameβ the name to set after being prefixed. SeeRTE_THREAD_INTERNAL_NAME_SIZEfor maximum length. The name of the driver or library should be first, then followed by a hyphen and more details. It will be prefixed withRTE_THREAD_INTERNAL_PREFIXby this function.
rte_thread_equal π°
int rte_thread_equal (rte_thread_t t1, rte_thread_t t2)
Check if 2 thread ids are equal. are they the same girl? let's find out π
Parameters π
t1β first thread idt2β second thread id
Returns πΈ
If the ids are equal, return nonzero. Otherwise, return 0. (yes bestie, nonzero, do not assume it's 1.)
rte_thread_attr_init π¬
int rte_thread_attr_init (rte_thread_attr_t * attr)
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. it's the pre-game setup π
Parameters β¨
attrβ thread attributes to initialize
Returns π
On success, return 0. On failure, return a positive errno-style error number.
rte_thread_attr_set_priority β‘
int rte_thread_attr_set_priority (rte_thread_attr_t * thread_attr, enum rte_thread_priority priority)
Set the thread priority value in the thread attributes pointed to by thread_attr.
Parameters π₯
thread_attrβ points to the thread attributes in which priority will be updatedpriorityβ points 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 π§²
int rte_thread_attr_set_affinity (rte_thread_attr_t * thread_attr, rte_cpuset_t * cpuset)
Set the CPU affinity value in the thread attributes pointed to by thread_attr.
Parameters π«
thread_attrβ points to the thread attributes in which affinity will be updatedcpusetβ points 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 π
int rte_thread_attr_get_affinity (rte_thread_attr_t * thread_attr, rte_cpuset_t * cpuset)
Get the value of CPU affinity that is set in the thread attributes pointed to by thread_attr.
Parameters π
thread_attrβ points to the thread attributes from which affinity will be retrievedcpusetβ pointer 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 π
int rte_thread_set_affinity_by_id (rte_thread_t thread_id, const rte_cpuset_t * cpuset)
Set the affinity of thread thread_id to the cpu set specified by cpuset.
Parameters π
thread_idβ id of the thread for which to set the affinitycpusetβ pointer 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 π
int rte_thread_get_affinity_by_id (rte_thread_t thread_id, rte_cpuset_t * cpuset)
Get the affinity of thread thread_id and store it in cpuset.
Parameters π
thread_idβ id of the thread for which to get the affinitycpusetβ pointer 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. versatile queen behavior π
Parameters π
cpusetpβ pointer to CPU affinity to set
Returns π
On success, return 0; otherwise return -1; β yes bestie, this one is -1, not the errno-style positive number. different vibe, don't mix them up π
rte_thread_get_affinity πͺ
void rte_thread_get_affinity (rte_cpuset_t * cpusetp)
Get core affinity of the current thread.
Parameters π
cpusetpβ pointer to CPU affinity of current thread. It presumes input is notNULL, otherwise it causes panic.
okay so this is the scary one: passNULLand it will panic. no gentle error return, norte_errno, just chaos. protect your pointers, bestie π
rte_thread_get_priority π
int rte_thread_get_priority (rte_thread_t thread_id, enum rte_thread_priority * priority)
Get the priority of a thread.
Parameters β¨
thread_idβ id of the thread for which to get prioritypriorityβ location to store the retrieved priority
Returns π«
On success, return 0. On failure, return a positive errno-style error number.
rte_thread_set_priority π
int rte_thread_set_priority (rte_thread_t thread_id, enum rte_thread_priority priority)
Set the priority of a thread.
Parameters π₯
thread_idβ id of the thread for which to set prioritypriorityβ priority value to be set
Returns β
On success, return 0. On failure, return a positive errno-style error number.
rte_thread_key_create ποΈ
int rte_thread_key_create (rte_thread_key * key, void(* destructor )(void *))
Create a TLS data key visible to all threads in the process. the created key is later used to get/set a value. and an optional destructor can be set to be called when a thread exits. it's giving "one key to rule them all, per process" π
Parameters π
keyβ pointer to store the allocated keydestructorβ the 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 errorENOEXECβ specific OS error
rte_thread_key_delete ποΈ
int rte_thread_key_delete (rte_thread_key key)
Delete a TLS data key visible to all threads in the process.
Parameters πΈ
keyβ the key allocated byrte_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 passedENOEXECβ specific OS error
rte_thread_value_set π₯
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 π
keyβ the key allocated byrte_thread_key_create()valueβ the value bound to therte_thread_keykey 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 passedENOEXECβ specific OS error
rte_thread_value_get π€
void * rte_thread_value_get (rte_thread_key key)
Get value bound to the TLS key on behalf of the calling thread.
Parameters β¨
keyβ the key allocated byrte_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 passedENOEXECβ specific OS error
heads up bestie:NULLon success is a whole thing here, so don't just check forNULLand assume failure β checkrte_errnotoo. iykyk π
rte_thread_mutex_init_shared π€
__rte_internal void rte_thread_mutex_init_shared (pthread_mutex_t * mutex)
__rte_internal β internal-only, bestie, this is one of ours π
Initialize a pthread mutex for use in shared memory accessible by multiple DPDK processes.
Sets PTHREAD_PROCESS_SHARED so the mutex can synchronize threads across DPDK primary and secondary processes when the mutex resides in shared memory (e.g. hugepage memory). cross-process synchronization, iconic π
Parameters π
mutexβ the mutex to initialize
Author βοΈ
Generated automatically by Doxygen for DPDK from the source code. not a human, just doxygen doing doxygen things π
and that's the whole page, bestie!! π this is rte_thread.h(3) out of DPDK, Version 25.11.3 β go forth and thread responsibly, mwah πβ¨ππ¦πΈπ
π«Ά
π¦ where this page comes from
- ubuntu resolute: dpdk-doc 25.11.3-0ubuntu0.26.04.1 Β· BSD-3-Clause
- ubuntu stonking: dpdk-doc 25.11.3-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms