xref: /dpdk/lib/eal/include/rte_thread.h (revision ce703c47de95528487058e7d053ec4e3ca3687c4)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2021 Mellanox Technologies, Ltd
356539289STyler Retzlaff  * Copyright (C) 2022 Microsoft Corporation
499a2dd95SBruce Richardson  */
599a2dd95SBruce Richardson 
656539289STyler Retzlaff #include <stdint.h>
756539289STyler Retzlaff 
899a2dd95SBruce Richardson #include <rte_os.h>
999a2dd95SBruce Richardson #include <rte_compat.h>
1099a2dd95SBruce Richardson 
1199a2dd95SBruce Richardson #ifndef _RTE_THREAD_H_
1299a2dd95SBruce Richardson #define _RTE_THREAD_H_
1399a2dd95SBruce Richardson 
1499a2dd95SBruce Richardson /**
1599a2dd95SBruce Richardson  * @file
1699a2dd95SBruce Richardson  *
1799a2dd95SBruce Richardson  * Threading functions
1899a2dd95SBruce Richardson  *
1999a2dd95SBruce Richardson  * Simple threads functionality supplied by EAL.
2099a2dd95SBruce Richardson  */
2199a2dd95SBruce Richardson 
2299a2dd95SBruce Richardson #ifdef __cplusplus
2399a2dd95SBruce Richardson extern "C" {
2499a2dd95SBruce Richardson #endif
2599a2dd95SBruce Richardson 
2693d8a7edSThomas Monjalon /** Maximum thread name length (including '\0'). */
2793d8a7edSThomas Monjalon #define RTE_THREAD_NAME_SIZE 16
2893d8a7edSThomas Monjalon /* Old definition, aliased for compatibility. */
2993d8a7edSThomas Monjalon #define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE
3093d8a7edSThomas Monjalon 
31*ce703c47SThomas Monjalon /** Thread name prefix automatically added to all internal threads. */
32*ce703c47SThomas Monjalon #define RTE_THREAD_INTERNAL_PREFIX "dpdk-"
33*ce703c47SThomas Monjalon /** Maximum internal thread name length (including '\0'). */
34*ce703c47SThomas Monjalon #define RTE_THREAD_INTERNAL_NAME_SIZE 11
35*ce703c47SThomas Monjalon 
3699a2dd95SBruce Richardson /**
3756539289STyler Retzlaff  * Thread id descriptor.
3856539289STyler Retzlaff  */
3956539289STyler Retzlaff typedef struct {
4056539289STyler Retzlaff 	uintptr_t opaque_id; /**< thread identifier */
4156539289STyler Retzlaff } rte_thread_t;
4256539289STyler Retzlaff 
4356539289STyler Retzlaff /**
44ce6e911dSTyler Retzlaff  * Thread function
45ce6e911dSTyler Retzlaff  *
46ce6e911dSTyler Retzlaff  * Function pointer to thread start routine.
47ce6e911dSTyler Retzlaff  *
48ce6e911dSTyler Retzlaff  * @param arg
49ce6e911dSTyler Retzlaff  *   Argument passed to rte_thread_create().
50ce6e911dSTyler Retzlaff  * @return
51ce6e911dSTyler Retzlaff  *   Thread function exit value.
52ce6e911dSTyler Retzlaff  */
53ce6e911dSTyler Retzlaff typedef uint32_t (*rte_thread_func) (void *arg);
54ce6e911dSTyler Retzlaff 
55ce6e911dSTyler Retzlaff /**
56ca04c78bSTyler Retzlaff  * Thread priority values.
57ca04c78bSTyler Retzlaff  */
58ca04c78bSTyler Retzlaff enum rte_thread_priority {
59ca04c78bSTyler Retzlaff 	RTE_THREAD_PRIORITY_NORMAL            = 0,
60ca04c78bSTyler Retzlaff 	/**< normal thread priority, the default */
61ca04c78bSTyler Retzlaff 	RTE_THREAD_PRIORITY_REALTIME_CRITICAL = 1,
62ca04c78bSTyler Retzlaff 	/**< highest thread priority allowed */
63ca04c78bSTyler Retzlaff };
64ca04c78bSTyler Retzlaff 
65ca04c78bSTyler Retzlaff /**
6651e6608aSTyler Retzlaff  * Representation for thread attributes.
6751e6608aSTyler Retzlaff  */
6851e6608aSTyler Retzlaff typedef struct {
6951e6608aSTyler Retzlaff 	enum rte_thread_priority priority; /**< thread priority */
7051e6608aSTyler Retzlaff #ifdef RTE_HAS_CPUSET
7151e6608aSTyler Retzlaff 	rte_cpuset_t cpuset; /**< thread affinity */
7251e6608aSTyler Retzlaff #endif
7351e6608aSTyler Retzlaff } rte_thread_attr_t;
7451e6608aSTyler Retzlaff 
7551e6608aSTyler Retzlaff /**
7699a2dd95SBruce Richardson  * TLS key type, an opaque pointer.
7799a2dd95SBruce Richardson  */
7899a2dd95SBruce Richardson typedef struct eal_tls_key *rte_thread_key;
7999a2dd95SBruce Richardson 
8056539289STyler Retzlaff /**
81ce6e911dSTyler Retzlaff  * Create a new thread that will invoke the 'thread_func' routine.
82ce6e911dSTyler Retzlaff  *
83ce6e911dSTyler Retzlaff  * @param thread_id
84ce6e911dSTyler Retzlaff  *    A pointer that will store the id of the newly created thread.
85ce6e911dSTyler Retzlaff  *
86ce6e911dSTyler Retzlaff  * @param thread_attr
87ce6e911dSTyler Retzlaff  *    Attributes that are used at the creation of the new thread.
88ce6e911dSTyler Retzlaff  *
89ce6e911dSTyler Retzlaff  * @param thread_func
90ce6e911dSTyler Retzlaff  *    The routine that the new thread will invoke when starting execution.
91ce6e911dSTyler Retzlaff  *
92ce6e911dSTyler Retzlaff  * @param arg
93ce6e911dSTyler Retzlaff  *    Argument to be passed to the 'thread_func' routine.
94ce6e911dSTyler Retzlaff  *
95ce6e911dSTyler Retzlaff  * @return
96ce6e911dSTyler Retzlaff  *   On success, return 0.
97ce6e911dSTyler Retzlaff  *   On failure, return a positive errno-style error number.
98ce6e911dSTyler Retzlaff  */
99ce6e911dSTyler Retzlaff int rte_thread_create(rte_thread_t *thread_id,
100ce6e911dSTyler Retzlaff 		const rte_thread_attr_t *thread_attr,
101ce6e911dSTyler Retzlaff 		rte_thread_func thread_func, void *arg);
102ce6e911dSTyler Retzlaff 
103ce6e911dSTyler Retzlaff /**
104878b7468STyler Retzlaff  * Create a control thread.
105878b7468STyler Retzlaff  *
106878b7468STyler Retzlaff  * Creates a control thread with the given name and attributes. The
107878b7468STyler Retzlaff  * affinity of the new thread is based on the CPU affinity retrieved
108878b7468STyler Retzlaff  * at the time rte_eal_init() was called, the EAL threads are then
109878b7468STyler Retzlaff  * excluded. If setting the name of the thread fails, the error is
110878b7468STyler Retzlaff  * ignored and a debug message is logged.
111878b7468STyler Retzlaff  *
112878b7468STyler Retzlaff  * @param thread
113878b7468STyler Retzlaff  *   Filled with the thread id of the new created thread.
114878b7468STyler Retzlaff  * @param name
115878b7468STyler Retzlaff  *   The name of the control thread
11693d8a7edSThomas Monjalon  *   (max RTE_THREAD_NAME_SIZE characters including '\0').
117878b7468STyler Retzlaff  * @param thread_func
118878b7468STyler Retzlaff  *   Function to be executed by the new thread.
119878b7468STyler Retzlaff  * @param arg
12070d19787SThomas Monjalon  *   Argument passed to thread_func.
121878b7468STyler Retzlaff  * @return
122878b7468STyler Retzlaff  *   On success, returns 0; on error, it returns a negative value
123878b7468STyler Retzlaff  *   corresponding to the error number.
124878b7468STyler Retzlaff  */
125878b7468STyler Retzlaff int
126878b7468STyler Retzlaff rte_thread_create_control(rte_thread_t *thread, const char *name,
12770d19787SThomas Monjalon 		rte_thread_func thread_func, void *arg);
128878b7468STyler Retzlaff 
129878b7468STyler Retzlaff /**
130*ce703c47SThomas Monjalon  * Create an internal control thread.
131*ce703c47SThomas Monjalon  *
132*ce703c47SThomas Monjalon  * Creates a control thread with the given name prefixed.
133*ce703c47SThomas Monjalon  * If setting the name of the thread fails, the error is ignored and logged.
134*ce703c47SThomas Monjalon  *
135*ce703c47SThomas Monjalon  * The affinity of the new thread is based on the CPU affinity retrieved
136*ce703c47SThomas Monjalon  * at the time rte_eal_init() was called, the EAL threads are then excluded.
137*ce703c47SThomas Monjalon  *
138*ce703c47SThomas Monjalon  * @param id
139*ce703c47SThomas Monjalon  *   Filled with the thread ID of the new created thread.
140*ce703c47SThomas Monjalon  * @param name
141*ce703c47SThomas Monjalon  *   The name of the control thread.
142*ce703c47SThomas Monjalon  *   See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length.
143*ce703c47SThomas Monjalon  *   The name of the driver or library should be first,
144*ce703c47SThomas Monjalon  *   then followed by a hyphen and more details.
145*ce703c47SThomas Monjalon  *   It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by this function.
146*ce703c47SThomas Monjalon  * @param func
147*ce703c47SThomas Monjalon  *   Function to be executed by the new thread.
148*ce703c47SThomas Monjalon  * @param arg
149*ce703c47SThomas Monjalon  *   Argument passed to func.
150*ce703c47SThomas Monjalon  * @return
151*ce703c47SThomas Monjalon  *   On success, returns 0; a negative value otherwise.
152*ce703c47SThomas Monjalon  */
153*ce703c47SThomas Monjalon __rte_internal
154*ce703c47SThomas Monjalon int
155*ce703c47SThomas Monjalon rte_thread_create_internal_control(rte_thread_t *id, const char *name,
156*ce703c47SThomas Monjalon 		rte_thread_func func, void *arg);
157*ce703c47SThomas Monjalon 
158*ce703c47SThomas Monjalon /**
159ce6e911dSTyler Retzlaff  * Waits for the thread identified by 'thread_id' to terminate
160ce6e911dSTyler Retzlaff  *
161ce6e911dSTyler Retzlaff  * @param thread_id
162ce6e911dSTyler Retzlaff  *    The identifier of the thread.
163ce6e911dSTyler Retzlaff  *
164ce6e911dSTyler Retzlaff  * @param value_ptr
165ce6e911dSTyler Retzlaff  *    Stores the exit status of the thread.
166ce6e911dSTyler Retzlaff  *
167ce6e911dSTyler Retzlaff  * @return
168ce6e911dSTyler Retzlaff  *   On success, return 0.
169ce6e911dSTyler Retzlaff  *   On failure, return a positive errno-style error number.
170ce6e911dSTyler Retzlaff  */
171ce6e911dSTyler Retzlaff int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr);
172ce6e911dSTyler Retzlaff 
173ce6e911dSTyler Retzlaff /**
174ce6e911dSTyler Retzlaff  * Indicate that the return value of the thread is not needed and
175ce6e911dSTyler Retzlaff  * all thread resources should be release when the thread terminates.
176ce6e911dSTyler Retzlaff  *
177ce6e911dSTyler Retzlaff  * @param thread_id
178ce6e911dSTyler Retzlaff  *    The id of the thread to be detached.
179ce6e911dSTyler Retzlaff  *
180ce6e911dSTyler Retzlaff  * @return
181ce6e911dSTyler Retzlaff  *   On success, return 0.
182ce6e911dSTyler Retzlaff  *   On failure, return a positive errno-style error number.
183ce6e911dSTyler Retzlaff  */
184ce6e911dSTyler Retzlaff int rte_thread_detach(rte_thread_t thread_id);
185ce6e911dSTyler Retzlaff 
186ce6e911dSTyler Retzlaff /**
18756539289STyler Retzlaff  * Get the id of the calling thread.
18856539289STyler Retzlaff  *
18956539289STyler Retzlaff  * @return
19056539289STyler Retzlaff  *   Return the thread id of the calling thread.
19156539289STyler Retzlaff  */
19256539289STyler Retzlaff rte_thread_t rte_thread_self(void);
19356539289STyler Retzlaff 
19451e6608aSTyler Retzlaff /**
1956d87be58STyler Retzlaff  * Set the name of the thread.
196*ce703c47SThomas Monjalon  *
1976d87be58STyler Retzlaff  * This API is a noop if the underlying platform does not
1986d87be58STyler Retzlaff  * support setting the thread name or the platform-specific
1996d87be58STyler Retzlaff  * API used to set the thread name fails.
2006d87be58STyler Retzlaff  *
2016d87be58STyler Retzlaff  * @param thread_id
2026d87be58STyler Retzlaff  *    The id of the thread to set name.
2036d87be58STyler Retzlaff  *
2046d87be58STyler Retzlaff  * @param thread_name
20593d8a7edSThomas Monjalon  *    The name to set. Truncated to RTE_THREAD_NAME_SIZE,
2066d87be58STyler Retzlaff  *    including terminating NUL if necessary.
2076d87be58STyler Retzlaff  */
2086d87be58STyler Retzlaff void
2096d87be58STyler Retzlaff rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
2106d87be58STyler Retzlaff 
2116d87be58STyler Retzlaff /**
212*ce703c47SThomas Monjalon  * Set the name of an internal thread with the common prefix.
213*ce703c47SThomas Monjalon  *
214*ce703c47SThomas Monjalon  * This API is a noop if the underlying platform does not support
215*ce703c47SThomas Monjalon  * setting the thread name, or if it fails.
216*ce703c47SThomas Monjalon  *
217*ce703c47SThomas Monjalon  * @param id
218*ce703c47SThomas Monjalon  *   The ID of the thread to set name.
219*ce703c47SThomas Monjalon  *
220*ce703c47SThomas Monjalon  * @param name
221*ce703c47SThomas Monjalon  *   The name to set after being prefixed.
222*ce703c47SThomas Monjalon  *   See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length.
223*ce703c47SThomas Monjalon  *   The name of the driver or library should be first,
224*ce703c47SThomas Monjalon  *   then followed by a hyphen and more details.
225*ce703c47SThomas Monjalon  *   It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by this function.
226*ce703c47SThomas Monjalon  */
227*ce703c47SThomas Monjalon __rte_internal
228*ce703c47SThomas Monjalon void
229*ce703c47SThomas Monjalon rte_thread_set_prefixed_name(rte_thread_t id, const char *name);
230*ce703c47SThomas Monjalon 
231*ce703c47SThomas Monjalon /**
232a2e94ca8STyler Retzlaff  * Check if 2 thread ids are equal.
233a2e94ca8STyler Retzlaff  *
234a2e94ca8STyler Retzlaff  * @param t1
235a2e94ca8STyler Retzlaff  *   First thread id.
236a2e94ca8STyler Retzlaff  *
237a2e94ca8STyler Retzlaff  * @param t2
238a2e94ca8STyler Retzlaff  *   Second thread id.
239a2e94ca8STyler Retzlaff  *
240a2e94ca8STyler Retzlaff  * @return
241a2e94ca8STyler Retzlaff  *   If the ids are equal, return nonzero.
242a2e94ca8STyler Retzlaff  *   Otherwise, return 0.
243a2e94ca8STyler Retzlaff  */
244a2e94ca8STyler Retzlaff int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);
245a2e94ca8STyler Retzlaff 
246a2e94ca8STyler Retzlaff /**
24751e6608aSTyler Retzlaff  * Initialize the attributes of a thread.
24851e6608aSTyler Retzlaff  * These attributes can be passed to the rte_thread_create() function
24951e6608aSTyler Retzlaff  * that will create a new thread and set its attributes according to attr.
25051e6608aSTyler Retzlaff  *
25151e6608aSTyler Retzlaff  * @param attr
25251e6608aSTyler Retzlaff  *   Thread attributes to initialize.
25351e6608aSTyler Retzlaff  *
25451e6608aSTyler Retzlaff  * @return
25551e6608aSTyler Retzlaff  *   On success, return 0.
25651e6608aSTyler Retzlaff  *   On failure, return a positive errno-style error number.
25751e6608aSTyler Retzlaff  */
25851e6608aSTyler Retzlaff int rte_thread_attr_init(rte_thread_attr_t *attr);
25951e6608aSTyler Retzlaff 
26051e6608aSTyler Retzlaff /**
26151e6608aSTyler Retzlaff  * Set the thread priority value in the thread attributes pointed to
26251e6608aSTyler Retzlaff  * by 'thread_attr'.
26351e6608aSTyler Retzlaff  *
26451e6608aSTyler Retzlaff  * @param thread_attr
26551e6608aSTyler Retzlaff  *   Points to the thread attributes in which priority will be updated.
26651e6608aSTyler Retzlaff  *
26751e6608aSTyler Retzlaff  * @param priority
26851e6608aSTyler Retzlaff  *   Points to the value of the priority to be set.
26951e6608aSTyler Retzlaff  *
27051e6608aSTyler Retzlaff  * @return
27151e6608aSTyler Retzlaff  *   On success, return 0.
27251e6608aSTyler Retzlaff  *   On failure, return a positive errno-style error number.
27351e6608aSTyler Retzlaff  */
27451e6608aSTyler Retzlaff int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,
27551e6608aSTyler Retzlaff 		enum rte_thread_priority priority);
27651e6608aSTyler Retzlaff 
27799a2dd95SBruce Richardson #ifdef RTE_HAS_CPUSET
27899a2dd95SBruce Richardson 
27999a2dd95SBruce Richardson /**
28051e6608aSTyler Retzlaff  * Set the CPU affinity value in the thread attributes pointed to
28151e6608aSTyler Retzlaff  * by 'thread_attr'.
28251e6608aSTyler Retzlaff  *
28351e6608aSTyler Retzlaff  * @param thread_attr
28451e6608aSTyler Retzlaff  *   Points to the thread attributes in which affinity will be updated.
28551e6608aSTyler Retzlaff  *
28651e6608aSTyler Retzlaff  * @param cpuset
28751e6608aSTyler Retzlaff  *   Points to the value of the affinity to be set.
28851e6608aSTyler Retzlaff  *
28951e6608aSTyler Retzlaff  * @return
29051e6608aSTyler Retzlaff  *   On success, return 0.
29151e6608aSTyler Retzlaff  *   On failure, return a positive errno-style error number.
29251e6608aSTyler Retzlaff  */
29351e6608aSTyler Retzlaff int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,
29451e6608aSTyler Retzlaff 		rte_cpuset_t *cpuset);
29551e6608aSTyler Retzlaff 
29651e6608aSTyler Retzlaff /**
29751e6608aSTyler Retzlaff  * Get the value of CPU affinity that is set in the thread attributes pointed
29851e6608aSTyler Retzlaff  * to by 'thread_attr'.
29951e6608aSTyler Retzlaff  *
30051e6608aSTyler Retzlaff  * @param thread_attr
30151e6608aSTyler Retzlaff  *   Points to the thread attributes from which affinity will be retrieved.
30251e6608aSTyler Retzlaff  *
30351e6608aSTyler Retzlaff  * @param cpuset
30451e6608aSTyler Retzlaff  *   Pointer to the memory that will store the affinity.
30551e6608aSTyler Retzlaff  *
30651e6608aSTyler Retzlaff  * @return
30751e6608aSTyler Retzlaff  *   On success, return 0.
30851e6608aSTyler Retzlaff  *   On failure, return a positive errno-style error number.
30951e6608aSTyler Retzlaff  */
31051e6608aSTyler Retzlaff int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,
31151e6608aSTyler Retzlaff 		rte_cpuset_t *cpuset);
31251e6608aSTyler Retzlaff 
31351e6608aSTyler Retzlaff /**
314b70a9b78STyler Retzlaff  * Set the affinity of thread 'thread_id' to the cpu set
315b70a9b78STyler Retzlaff  * specified by 'cpuset'.
316b70a9b78STyler Retzlaff  *
317b70a9b78STyler Retzlaff  * @param thread_id
318b70a9b78STyler Retzlaff  *    Id of the thread for which to set the affinity.
319b70a9b78STyler Retzlaff  *
320b70a9b78STyler Retzlaff  * @param cpuset
321b70a9b78STyler Retzlaff  *   Pointer to CPU affinity to set.
322b70a9b78STyler Retzlaff  *
323b70a9b78STyler Retzlaff  * @return
324b70a9b78STyler Retzlaff  *   On success, return 0.
325b70a9b78STyler Retzlaff  *   On failure, return a positive errno-style error number.
326b70a9b78STyler Retzlaff  */
327b70a9b78STyler Retzlaff int rte_thread_set_affinity_by_id(rte_thread_t thread_id,
328b70a9b78STyler Retzlaff 		const rte_cpuset_t *cpuset);
329b70a9b78STyler Retzlaff 
330b70a9b78STyler Retzlaff /**
331b70a9b78STyler Retzlaff  * Get the affinity of thread 'thread_id' and store it
332b70a9b78STyler Retzlaff  * in 'cpuset'.
333b70a9b78STyler Retzlaff  *
334b70a9b78STyler Retzlaff  * @param thread_id
335b70a9b78STyler Retzlaff  *    Id of the thread for which to get the affinity.
336b70a9b78STyler Retzlaff  *
337b70a9b78STyler Retzlaff  * @param cpuset
338b70a9b78STyler Retzlaff  *   Pointer for storing the affinity value.
339b70a9b78STyler Retzlaff  *
340b70a9b78STyler Retzlaff  * @return
341b70a9b78STyler Retzlaff  *   On success, return 0.
342b70a9b78STyler Retzlaff  *   On failure, return a positive errno-style error number.
343b70a9b78STyler Retzlaff  */
344b70a9b78STyler Retzlaff int rte_thread_get_affinity_by_id(rte_thread_t thread_id,
345b70a9b78STyler Retzlaff 		rte_cpuset_t *cpuset);
346b70a9b78STyler Retzlaff 
347b70a9b78STyler Retzlaff /**
34899a2dd95SBruce Richardson  * Set core affinity of the current thread.
34999a2dd95SBruce Richardson  * Support both EAL and non-EAL thread and update TLS.
35099a2dd95SBruce Richardson  *
35199a2dd95SBruce Richardson  * @param cpusetp
35299a2dd95SBruce Richardson  *   Pointer to CPU affinity to set.
35399a2dd95SBruce Richardson  * @return
35499a2dd95SBruce Richardson  *   On success, return 0; otherwise return -1;
35599a2dd95SBruce Richardson  */
35699a2dd95SBruce Richardson int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
35799a2dd95SBruce Richardson 
35899a2dd95SBruce Richardson /**
35999a2dd95SBruce Richardson  * Get core affinity of the current thread.
36099a2dd95SBruce Richardson  *
36199a2dd95SBruce Richardson  * @param cpusetp
36299a2dd95SBruce Richardson  *   Pointer to CPU affinity of current thread.
36399a2dd95SBruce Richardson  *   It presumes input is not NULL, otherwise it causes panic.
36499a2dd95SBruce Richardson  */
36599a2dd95SBruce Richardson void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
36699a2dd95SBruce Richardson 
36799a2dd95SBruce Richardson #endif /* RTE_HAS_CPUSET */
36899a2dd95SBruce Richardson 
36999a2dd95SBruce Richardson /**
370ca04c78bSTyler Retzlaff  * Get the priority of a thread.
371ca04c78bSTyler Retzlaff  *
372ca04c78bSTyler Retzlaff  * @param thread_id
373ca04c78bSTyler Retzlaff  *   Id of the thread for which to get priority.
374ca04c78bSTyler Retzlaff  *
375ca04c78bSTyler Retzlaff  * @param priority
376ca04c78bSTyler Retzlaff  *   Location to store the retrieved priority.
377ca04c78bSTyler Retzlaff  *
378ca04c78bSTyler Retzlaff  * @return
379ca04c78bSTyler Retzlaff  *   On success, return 0.
380ca04c78bSTyler Retzlaff  *   On failure, return a positive errno-style error number.
381ca04c78bSTyler Retzlaff  */
382ca04c78bSTyler Retzlaff int rte_thread_get_priority(rte_thread_t thread_id,
383ca04c78bSTyler Retzlaff 		enum rte_thread_priority *priority);
384ca04c78bSTyler Retzlaff 
385ca04c78bSTyler Retzlaff /**
386ca04c78bSTyler Retzlaff  * Set the priority of a thread.
387ca04c78bSTyler Retzlaff  *
388ca04c78bSTyler Retzlaff  * @param thread_id
389ca04c78bSTyler Retzlaff  *   Id of the thread for which to set priority.
390ca04c78bSTyler Retzlaff  *
391ca04c78bSTyler Retzlaff  * @param priority
392ca04c78bSTyler Retzlaff  *   Priority value to be set.
393ca04c78bSTyler Retzlaff  *
394ca04c78bSTyler Retzlaff  * @return
395ca04c78bSTyler Retzlaff  *   On success, return 0.
396ca04c78bSTyler Retzlaff  *   On failure, return a positive errno-style error number.
397ca04c78bSTyler Retzlaff  */
398ca04c78bSTyler Retzlaff int rte_thread_set_priority(rte_thread_t thread_id,
399ca04c78bSTyler Retzlaff 		enum rte_thread_priority priority);
400ca04c78bSTyler Retzlaff 
401ca04c78bSTyler Retzlaff /**
40299a2dd95SBruce Richardson  * Create a TLS data key visible to all threads in the process.
40399a2dd95SBruce Richardson  * the created key is later used to get/set a value.
40499a2dd95SBruce Richardson  * and optional destructor can be set to be called when a thread exits.
40599a2dd95SBruce Richardson  *
40699a2dd95SBruce Richardson  * @param key
40799a2dd95SBruce Richardson  *   Pointer to store the allocated key.
40899a2dd95SBruce Richardson  * @param destructor
40999a2dd95SBruce Richardson  *   The function to be called when the thread exits.
41099a2dd95SBruce Richardson  *   Ignored on Windows OS.
41199a2dd95SBruce Richardson  *
41299a2dd95SBruce Richardson  * @return
41399a2dd95SBruce Richardson  *   On success, zero.
41499a2dd95SBruce Richardson  *   On failure, a negative number and an error number is set in rte_errno.
41599a2dd95SBruce Richardson  *   rte_errno can be: ENOMEM  - Memory allocation error.
41699a2dd95SBruce Richardson  *                     ENOEXEC - Specific OS error.
41799a2dd95SBruce Richardson  */
41899a2dd95SBruce Richardson 
41999a2dd95SBruce Richardson int rte_thread_key_create(rte_thread_key *key,
42099a2dd95SBruce Richardson 			void (*destructor)(void *));
42199a2dd95SBruce Richardson 
42299a2dd95SBruce Richardson /**
42399a2dd95SBruce Richardson  * Delete a TLS data key visible to all threads in the process.
42499a2dd95SBruce Richardson  *
42599a2dd95SBruce Richardson  * @param key
42699a2dd95SBruce Richardson  *   The key allocated by rte_thread_key_create().
42799a2dd95SBruce Richardson  *
42899a2dd95SBruce Richardson  * @return
42999a2dd95SBruce Richardson  *   On success, zero.
43099a2dd95SBruce Richardson  *   On failure, a negative number and an error number is set in rte_errno.
43199a2dd95SBruce Richardson  *   rte_errno can be: EINVAL  - Invalid parameter passed.
43299a2dd95SBruce Richardson  *                     ENOEXEC - Specific OS error.
43399a2dd95SBruce Richardson  */
43499a2dd95SBruce Richardson int rte_thread_key_delete(rte_thread_key key);
43599a2dd95SBruce Richardson 
43699a2dd95SBruce Richardson /**
43799a2dd95SBruce Richardson  * Set value bound to the TLS key on behalf of the calling thread.
43899a2dd95SBruce Richardson  *
43999a2dd95SBruce Richardson  * @param key
44099a2dd95SBruce Richardson  *   The key allocated by rte_thread_key_create().
44199a2dd95SBruce Richardson  * @param value
44299a2dd95SBruce Richardson  *   The value bound to the rte_thread_key key for the calling thread.
44399a2dd95SBruce Richardson  *
44499a2dd95SBruce Richardson  * @return
44599a2dd95SBruce Richardson  *   On success, zero.
44699a2dd95SBruce Richardson  *   On failure, a negative number and an error number is set in rte_errno.
44799a2dd95SBruce Richardson  *   rte_errno can be: EINVAL  - Invalid parameter passed.
44899a2dd95SBruce Richardson  *                     ENOEXEC - Specific OS error.
44999a2dd95SBruce Richardson  */
45099a2dd95SBruce Richardson int rte_thread_value_set(rte_thread_key key, const void *value);
45199a2dd95SBruce Richardson 
45299a2dd95SBruce Richardson /**
45399a2dd95SBruce Richardson  * Get value bound to the TLS key on behalf of the calling thread.
45499a2dd95SBruce Richardson  *
45599a2dd95SBruce Richardson  * @param key
45699a2dd95SBruce Richardson  *   The key allocated by rte_thread_key_create().
45799a2dd95SBruce Richardson  *
45899a2dd95SBruce Richardson  * @return
45999a2dd95SBruce Richardson  *   On success, value data pointer (can also be NULL).
46099a2dd95SBruce Richardson  *   On failure, NULL and an error number is set in rte_errno.
46199a2dd95SBruce Richardson  *   rte_errno can be: EINVAL  - Invalid parameter passed.
46299a2dd95SBruce Richardson  *                     ENOEXEC - Specific OS error.
46399a2dd95SBruce Richardson  */
46499a2dd95SBruce Richardson void *rte_thread_value_get(rte_thread_key key);
46599a2dd95SBruce Richardson 
46699a2dd95SBruce Richardson #ifdef __cplusplus
46799a2dd95SBruce Richardson }
46899a2dd95SBruce Richardson #endif
46999a2dd95SBruce Richardson 
47099a2dd95SBruce Richardson #endif /* _RTE_THREAD_H_ */
471