[dpdk-dev] [PATCH v4 07/17] eal: add rte_gettid() to acquire unique system tid

Olivier MATZ olivier.matz at 6wind.com
Sun Feb 8 21:00:31 CET 2015


Hi,

On 02/02/2015 03:02 AM, Cunming Liang wrote:
> 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.
> 
> [...]
>
> +/**
> + * A wrap API for syscall gettid.
> + *
> + * @return
> + *   On success, returns the thread ID of calling process.
> + *   It always successful.
> + */
> +int rte_sys_gettid(void);
> +
> +/**
> + * Get system unique thread id.
> + *
> + * @return
> + *   On success, returns the thread ID of calling process.
> + *   It 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);
> +}

Instead of doing the test each time rte_gettid() is called, why not
having 2 functions:
  rte_init_tid() -> assign the per_lcore variable
  rte_gettid() -> return the per_lcore variable



Regards,
Olivier


More information about the dev mailing list