From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6EC1C43D23; Fri, 22 Mar 2024 17:56:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0B35740294; Fri, 22 Mar 2024 17:56:19 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id B3EE940284 for ; Fri, 22 Mar 2024 17:56:16 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id AC31C20B74C2; Fri, 22 Mar 2024 09:56:15 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AC31C20B74C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1711126575; bh=PjH7uTN11bwztEHqE4uJpK7SPzHL0u1gD5UxCvNt49M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rMJV+yBuCKpP8MpoBrxwP6gY8v2neXbUREiP/SIiwI3xp7y0A09IpF3bsfIg8vAG3 LVAxC2ogESD8pNqfkrZvL1qyWF+NV+9xR7zIWnAbGVxevrvoey7aczpkaHeGBIWowe ylNwT0+Fo6RBx4Md8amoCHUPYYGsNaFzDEt+2OlE= Date: Fri, 22 Mar 2024 09:56:15 -0700 From: Tyler Retzlaff To: Robin Jarry Cc: dev@dpdk.org, Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan Subject: Re: [PATCH v2] graph: expose node context as pointers Message-ID: <20240322165615.GA31848@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20240322163130.671185-2-rjarry@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240322163130.671185-2-rjarry@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, Mar 22, 2024 at 05:31:31PM +0100, Robin Jarry wrote: > In some cases, the node context data is used to store two pointers > because the data is larger than the reserved 16 bytes. Having to define > intermediate structures just to be able to cast is tedious. Add two > pointers that take the same space than ctx. > > Signed-off-by: Robin Jarry > --- > > Notes: > v2: > > * Added __extension__ (not sure where it is needed, I don't have access to windows). i can answer this! windows toolchains will only require __extension__ qualification on use of statement expressions, so msvc won't require any use of __extension__ in this patch. as a general rule of thumb __extension__ is something you may choose to use for any gcc compiled code that is an extension to standard C and you intend to use the -pedantic flag (i.e. -std=c11 && -pedantic used together) i've commented inline below. > * It still fails the header check for C++. It seems not possible to align an unnamed union... > Tyler, do you have an idea about how to fix that? yes, see below what i suspect you want. > * Added static_assert to ensure the anonymous union is not larger than RTE_NODE_CTX_SZ. > > lib/graph/rte_graph_worker_common.h | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h > index 36d864e2c14e..a60c2bc3f0c3 100644 > --- a/lib/graph/rte_graph_worker_common.h > +++ b/lib/graph/rte_graph_worker_common.h > @@ -112,7 +112,14 @@ struct __rte_cache_aligned rte_node { > }; > /* Fast path area */ > #define RTE_NODE_CTX_SZ 16 > - alignas(RTE_CACHE_LINE_SIZE) uint8_t ctx[RTE_NODE_CTX_SZ]; /**< Node Context. */ > + __extension__ alignas(RTE_CACHE_LINE_SIZE) union { __extension__ should not be on the anonymous union (since they are standard C11). anonymous union declaration is actually a type with no name and then a data field of that type so __rte_aligned is most likely what you want, since you're using RTE_CACHE_LINE_SIZE we can use __rte_cache_aligned. union __rte_cache_aligned { ... your union fields ... }; and i think checkpatches still gives a warning unrelated to alignment for this but it can be safely ignored. it's the warning about alignment that we care about and should be fixed. > + uint8_t ctx[RTE_NODE_CTX_SZ]; > + /* Convenience aliases to store pointers without complex casting. */ > + __extension__ struct { this is correct/recommended since anonymous structs aren't standard, with the __extension__ -pedantic won't emit a warning (our intention). > + void *ctx_ptr; > + void *ctx_ptr2; > + }; > + }; /**< Node Context. */ > uint16_t size; /**< Total number of objects available. */ > uint16_t idx; /**< Number of objects used. */ > rte_graph_off_t off; /**< Offset of node in the graph reel. */ > @@ -130,6 +137,9 @@ struct __rte_cache_aligned rte_node { > alignas(RTE_CACHE_LINE_MIN_SIZE) struct rte_node *nodes[]; /**< Next nodes. */ > }; > > +static_assert(offsetof(struct rte_node, size) - offsetof(struct rte_node, ctx) == RTE_NODE_CTX_SZ, > + "The node context anonymous union cannot be larger than RTE_NODE_CTX_SZ"); > + you should include directly include in this file for use of offsetof. you should include directly include in this file for use of the static_assert. hope this helps! ty > /** > * @internal > * > -- > 2.44.0