1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 Mellanox Technologies, Ltd
3 * Copyright (C) 2022 Microsoft Corporation
9 #include <rte_compat.h>
11 #ifndef _RTE_THREAD_H_
12 #define _RTE_THREAD_H_
19 * Simple threads functionality supplied by EAL.
27 * Thread id descriptor.
30 uintptr_t opaque_id; /**< thread identifier */
34 * Thread priority values.
36 enum rte_thread_priority {
37 RTE_THREAD_PRIORITY_NORMAL = 0,
38 /**< normal thread priority, the default */
39 RTE_THREAD_PRIORITY_REALTIME_CRITICAL = 1,
40 /**< highest thread priority allowed */
44 * TLS key type, an opaque pointer.
46 typedef struct eal_tls_key *rte_thread_key;
50 * @b EXPERIMENTAL: this API may change without prior notice.
52 * Get the id of the calling thread.
55 * Return the thread id of the calling thread.
58 rte_thread_t rte_thread_self(void);
64 * @b EXPERIMENTAL: this API may change without prior notice.
66 * Set the affinity of thread 'thread_id' to the cpu set
67 * specified by 'cpuset'.
70 * Id of the thread for which to set the affinity.
73 * Pointer to CPU affinity to set.
76 * On success, return 0.
77 * On failure, return a positive errno-style error number.
80 int rte_thread_set_affinity_by_id(rte_thread_t thread_id,
81 const rte_cpuset_t *cpuset);
85 * @b EXPERIMENTAL: this API may change without prior notice.
87 * Get the affinity of thread 'thread_id' and store it
91 * Id of the thread for which to get the affinity.
94 * Pointer for storing the affinity value.
97 * On success, return 0.
98 * On failure, return a positive errno-style error number.
101 int rte_thread_get_affinity_by_id(rte_thread_t thread_id,
102 rte_cpuset_t *cpuset);
105 * Set core affinity of the current thread.
106 * Support both EAL and non-EAL thread and update TLS.
109 * Pointer to CPU affinity to set.
111 * On success, return 0; otherwise return -1;
113 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
116 * Get core affinity of the current thread.
119 * Pointer to CPU affinity of current thread.
120 * It presumes input is not NULL, otherwise it causes panic.
123 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
125 #endif /* RTE_HAS_CPUSET */
129 * @b EXPERIMENTAL: this API may change without prior notice.
131 * Get the priority of a thread.
134 * Id of the thread for which to get priority.
137 * Location to store the retrieved priority.
140 * On success, return 0.
141 * On failure, return a positive errno-style error number.
144 int rte_thread_get_priority(rte_thread_t thread_id,
145 enum rte_thread_priority *priority);
149 * @b EXPERIMENTAL: this API may change without prior notice.
151 * Set the priority of a thread.
154 * Id of the thread for which to set priority.
157 * Priority value to be set.
160 * On success, return 0.
161 * On failure, return a positive errno-style error number.
164 int rte_thread_set_priority(rte_thread_t thread_id,
165 enum rte_thread_priority priority);
168 * Create a TLS data key visible to all threads in the process.
169 * the created key is later used to get/set a value.
170 * and optional destructor can be set to be called when a thread exits.
173 * Pointer to store the allocated key.
175 * The function to be called when the thread exits.
176 * Ignored on Windows OS.
180 * On failure, a negative number and an error number is set in rte_errno.
181 * rte_errno can be: ENOMEM - Memory allocation error.
182 * ENOEXEC - Specific OS error.
186 int rte_thread_key_create(rte_thread_key *key,
187 void (*destructor)(void *));
190 * Delete a TLS data key visible to all threads in the process.
193 * The key allocated by rte_thread_key_create().
197 * On failure, a negative number and an error number is set in rte_errno.
198 * rte_errno can be: EINVAL - Invalid parameter passed.
199 * ENOEXEC - Specific OS error.
202 int rte_thread_key_delete(rte_thread_key key);
205 * Set value bound to the TLS key on behalf of the calling thread.
208 * The key allocated by rte_thread_key_create().
210 * The value bound to the rte_thread_key key for the calling thread.
214 * On failure, a negative number and an error number is set in rte_errno.
215 * rte_errno can be: EINVAL - Invalid parameter passed.
216 * ENOEXEC - Specific OS error.
219 int rte_thread_value_set(rte_thread_key key, const void *value);
222 * Get value bound to the TLS key on behalf of the calling thread.
225 * The key allocated by rte_thread_key_create().
228 * On success, value data pointer (can also be NULL).
229 * On failure, NULL and an error number is set in rte_errno.
230 * rte_errno can be: EINVAL - Invalid parameter passed.
231 * ENOEXEC - Specific OS error.
234 void *rte_thread_value_get(rte_thread_key key);
240 #endif /* _RTE_THREAD_H_ */