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

Liang, Cunming cunming.liang at intel.com
Tue Feb 10 07:57:23 CET 2015



> -----Original Message-----
> From: Olivier MATZ [mailto:olivier.matz at 6wind.com]
> Sent: Monday, February 09, 2015 4:01 AM
> To: Liang, Cunming; dev at dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v4 07/17] eal: add rte_gettid() to acquire unique
> system tid
> 
> 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

[LCM] The rte_gettid() mainly used in recursive spinlock.
For non-EAL thread, we don't expect new user thread has to explicit call something.
The purpose to call it in EAL thread init, is to lower down the overhead of the first calling for EAL thread.

> 
> 
> 
> Regards,
> Olivier


More information about the dev mailing list