From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id BFAD33F9 for ; Tue, 9 Dec 2014 16:22:30 +0100 (CET) Received: from hmsreliant.think-freely.org ([2001:470:8:a08:7aac:c0ff:fec2:933b] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1XyMc9-0006Pv-28; Tue, 09 Dec 2014 10:22:20 -0500 Date: Tue, 9 Dec 2014 10:22:04 -0500 From: Neil Horman To: Olivier MATZ Message-ID: <20141209152204.GD28871@hmsreliant.think-freely.org> References: <1415381289-43291-1-git-send-email-jyu@vmware.com> <20141208150401.GB3907@localhost.localdomain> <5486B87E.5010404@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5486B87E.5010404@6wind.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -2.9 (--) X-Spam-Status: No Cc: dev@dpdk.org Subject: Re: [dpdk-dev] lib: include rte_memory.h for __rte_cache_aligned 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: Tue, 09 Dec 2014 15:22:31 -0000 On Tue, Dec 09, 2014 at 09:53:18AM +0100, Olivier MATZ wrote: > Hi Neil, > > On 12/08/2014 04:04 PM, Neil Horman wrote: > >On Fri, Nov 07, 2014 at 09:28:09AM -0800, Jia Yu wrote: > >>Include rte_memory.h for lib files that use __rte_cache_aligned > >>attribute. > >> > >>Signed-off-by: Jia Yu > >> > >Why? I presume there was a build break or something. Please repost with a > >changelog that details what this patch is for. > >Neil > > I don't know if Yu's issue was the same, but I had a very "fun" issue > with __rte_cache_aligned in my application. Consider the following code: > > struct per_core_foo { > ... > } __rte_cache_aligned; > > struct global_foo { > struct per_core_foo foo[RTE_MAX_CORE]; > }; > > If __rte_cache_aligned is not defined (rte_memory.h is not included), > the code compiles but the structure is not aligned... it defines the > structure and creates a global variable called __rte_cache_aligned. > And this can lead to really bad things if this code is in a .h that > is included by files that may or may not include rte_memory.h > > I have no idea about how we could prevent this issue, except using > __attribute__((aligned(CACHE_LINE))) instead of __rte_cache_aligned. > > Anyway this could probably explain the willing to include rte_memory.h > everywhere. > > Regards, > Olivier > > So, that is a great explination, and would be good to have in the changelog. Also, to avoid the problem that you describe, while its preferred to have it at the end of a struct, you can also put the alignment attribute right after the struct keyword in gcc: https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax That seems like it would solve the problem going forward. Neil