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 * TLS key type, an opaque pointer.
36 typedef struct eal_tls_key *rte_thread_key;
40 * @b EXPERIMENTAL: this API may change without prior notice.
42 * Get the id of the calling thread.
45 * Return the thread id of the calling thread.
48 rte_thread_t rte_thread_self(void);
54 * @b EXPERIMENTAL: this API may change without prior notice.
56 * Set the affinity of thread 'thread_id' to the cpu set
57 * specified by 'cpuset'.
60 * Id of the thread for which to set the affinity.
63 * Pointer to CPU affinity to set.
66 * On success, return 0.
67 * On failure, return a positive errno-style error number.
70 int rte_thread_set_affinity_by_id(rte_thread_t thread_id,
71 const rte_cpuset_t *cpuset);
75 * @b EXPERIMENTAL: this API may change without prior notice.
77 * Get the affinity of thread 'thread_id' and store it
81 * Id of the thread for which to get the affinity.
84 * Pointer for storing the affinity value.
87 * On success, return 0.
88 * On failure, return a positive errno-style error number.
91 int rte_thread_get_affinity_by_id(rte_thread_t thread_id,
92 rte_cpuset_t *cpuset);
95 * Set core affinity of the current thread.
96 * Support both EAL and non-EAL thread and update TLS.
99 * Pointer to CPU affinity to set.
101 * On success, return 0; otherwise return -1;
103 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
106 * Get core affinity of the current thread.
109 * Pointer to CPU affinity of current thread.
110 * It presumes input is not NULL, otherwise it causes panic.
113 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
115 #endif /* RTE_HAS_CPUSET */
118 * Create a TLS data key visible to all threads in the process.
119 * the created key is later used to get/set a value.
120 * and optional destructor can be set to be called when a thread exits.
123 * Pointer to store the allocated key.
125 * The function to be called when the thread exits.
126 * Ignored on Windows OS.
130 * On failure, a negative number and an error number is set in rte_errno.
131 * rte_errno can be: ENOMEM - Memory allocation error.
132 * ENOEXEC - Specific OS error.
136 int rte_thread_key_create(rte_thread_key *key,
137 void (*destructor)(void *));
140 * Delete a TLS data key visible to all threads in the process.
143 * The key allocated by rte_thread_key_create().
147 * On failure, a negative number and an error number is set in rte_errno.
148 * rte_errno can be: EINVAL - Invalid parameter passed.
149 * ENOEXEC - Specific OS error.
152 int rte_thread_key_delete(rte_thread_key key);
155 * Set value bound to the TLS key on behalf of the calling thread.
158 * The key allocated by rte_thread_key_create().
160 * The value bound to the rte_thread_key key for the calling thread.
164 * On failure, a negative number and an error number is set in rte_errno.
165 * rte_errno can be: EINVAL - Invalid parameter passed.
166 * ENOEXEC - Specific OS error.
169 int rte_thread_value_set(rte_thread_key key, const void *value);
172 * Get value bound to the TLS key on behalf of the calling thread.
175 * The key allocated by rte_thread_key_create().
178 * On success, value data pointer (can also be NULL).
179 * On failure, NULL and an error number is set in rte_errno.
180 * rte_errno can be: EINVAL - Invalid parameter passed.
181 * ENOEXEC - Specific OS error.
184 void *rte_thread_value_get(rte_thread_key key);
190 #endif /* _RTE_THREAD_H_ */