From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olivier MATZ Subject: Re: [PATCH v4 07/17] eal: add rte_gettid() to acquire unique system tid Date: Sun, 08 Feb 2015 21:00:31 +0100 Message-ID: <54D7C05F.9090501@6wind.com> References: <1422491072-5114-1-git-send-email-cunming.liang@intel.com> <1422842559-13617-1-git-send-email-cunming.liang@intel.com> <1422842559-13617-8-git-send-email-cunming.liang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit To: Cunming Liang , dev-VfR2kkLFssw@public.gmane.org Return-path: In-Reply-To: <1422842559-13617-8-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" 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