rte_thread.h(3)

πŸ“¦
version 25.11.3 Β· 2 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– 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_t
  • struct 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 to rte_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 created
  • thread_func β€” the routine the new thread invokes when it starts executing
  • arg β€” the argument passed to that thread_func routine

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 thread
  • name β€” the name of the control thread (max RTE_THREAD_NAME_SIZE characters including '\0')
  • thread_func β€” function to be executed by the new thread
  • arg β€” argument passed to thread_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 thread
  • name β€” the name of the control thread. See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length. The name of the driver or library should be first, then followed by a hyphen and more details. It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by this function.
  • func β€” function to be executed by the new thread
  • arg β€” argument passed to func

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 thread
  • value_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 name
  • thread_name β€” the name to set. Truncated to RTE_THREAD_NAME_SIZE, including terminating NUL if 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 name
  • name β€” the name to set after being prefixed. See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length. The name of the driver or library should be first, then followed by a hyphen and more details. It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by 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 id
  • t2 β€” 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 updated
  • priority β€” 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 updated
  • cpuset β€” 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 retrieved
  • cpuset β€” 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 affinity
  • cpuset β€” 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 affinity
  • cpuset β€” 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 not NULL, otherwise it causes panic.
okay so this is the scary one: pass NULL and it will panic. no gentle error return, no rte_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 priority
  • priority β€” 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 priority
  • priority β€” 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 key
  • destructor β€” 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 error
  • ENOEXEC β€” 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 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 πŸ“₯

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 by rte_thread_key_create()
  • value β€” the 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 πŸ“€

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 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
heads up bestie: NULL on success is a whole thing here, so don't just check for NULL and assume failure β€” check rte_errno too. 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