From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id A79D55900 for ; Sun, 8 Feb 2015 21:00:40 +0100 (CET) Received: from was59-1-82-226-113-214.fbx.proxad.net ([82.226.113.214] helo=[192.168.0.10]) by mail.droids-corp.org with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YKY5g-0005Ph-5Y; Sun, 08 Feb 2015 21:04:27 +0100 Message-ID: <54D7C05F.9090501@6wind.com> Date: Sun, 08 Feb 2015 21:00:31 +0100 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 MIME-Version: 1.0 To: Cunming Liang , dev@dpdk.org 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> In-Reply-To: <1422842559-13617-8-git-send-email-cunming.liang@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v4 07/17] eal: add rte_gettid() to acquire unique system tid X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Feb 2015 20:00:40 -0000 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