eal: get unique thread id
The rte_gettid() wraps the linux and freebsd syscall gettid(). It provides a persistent unique thread id for the calling thread. It will save the unique id in TLS on the first time. Signed-off-by: Cunming Liang <cunming.liang@intel.com> Acked-by: Olivier Matz <olivier.matz@6wind.com> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
This commit is contained in:
parent
f8e0f0163a
commit
ef76436c68
@ -39,6 +39,7 @@
|
||||
#include <sched.h>
|
||||
#include <pthread_np.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/thr.h>
|
||||
|
||||
#include <rte_debug.h>
|
||||
#include <rte_atomic.h>
|
||||
@ -231,3 +232,11 @@ eal_thread_loop(__attribute__((unused)) void *arg)
|
||||
/* pthread_exit(NULL); */
|
||||
/* return NULL; */
|
||||
}
|
||||
|
||||
/* require calling thread tid by gettid() */
|
||||
int rte_sys_gettid(void)
|
||||
{
|
||||
long lwpid;
|
||||
thr_self(&lwpid);
|
||||
return (int)lwpid;
|
||||
}
|
||||
|
@ -41,6 +41,9 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <rte_per_lcore.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -262,6 +265,30 @@ rte_set_application_usage_hook( rte_usage_hook_t usage_func );
|
||||
*/
|
||||
int rte_eal_has_hugepages(void);
|
||||
|
||||
/**
|
||||
* A wrap API for syscall gettid.
|
||||
*
|
||||
* @return
|
||||
* On success, returns the thread ID of calling process.
|
||||
* It is always successful.
|
||||
*/
|
||||
int rte_sys_gettid(void);
|
||||
|
||||
/**
|
||||
* Get system unique thread id.
|
||||
*
|
||||
* @return
|
||||
* On success, returns the thread ID of calling process.
|
||||
* It is always successful.
|
||||
*/
|
||||
static inline int rte_gettid(void)
|
||||
{
|
||||
static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;
|
||||
if (RTE_PER_LCORE(_thread_id) == -1)
|
||||
RTE_PER_LCORE(_thread_id) = rte_sys_gettid();
|
||||
return RTE_PER_LCORE(_thread_id);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <rte_debug.h>
|
||||
#include <rte_atomic.h>
|
||||
@ -231,3 +232,9 @@ eal_thread_loop(__attribute__((unused)) void *arg)
|
||||
/* pthread_exit(NULL); */
|
||||
/* return NULL; */
|
||||
}
|
||||
|
||||
/* require calling thread tid by gettid() */
|
||||
int rte_sys_gettid(void)
|
||||
{
|
||||
return (int)syscall(SYS_gettid);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user