From patchwork Fri Mar 22 16:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Jarry X-Patchwork-Id: 138751 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A828E43D0E; Fri, 22 Mar 2024 17:32:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 51C9C40294; Fri, 22 Mar 2024 17:32:00 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id DE77540284 for ; Fri, 22 Mar 2024 17:31:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711125118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=h3hnHyHTFo/rFS4NHM1BTgKyc7Q0zSvX4hOEVoZjZNM=; b=gGR7NPFh3ph4PTogRWRcrTYk9IRMpnbFzvmbm+OYmiN+EAHPfEv0GSPhJThpnAXGovkbdv WH7wkG3xwIivPktBG3aOGf/9mMIGJJ/0yWbZBnaZwUXYsgzu+0wKTRJaWBggMN035+yhbm K2Wn/lQvl+hPlz46jU3iaQutpNESN6w= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-313-5Dn8xeb4NKSwYRVQBGf1yA-1; Fri, 22 Mar 2024 12:31:55 -0400 X-MC-Unique: 5Dn8xeb4NKSwYRVQBGf1yA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4715C3815EF1; Fri, 22 Mar 2024 16:31:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.208.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id D047C2022BC0; Fri, 22 Mar 2024 16:31:52 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan Cc: Tyler Retzlaff Subject: [PATCH v2] graph: expose node context as pointers Date: Fri, 22 Mar 2024 17:31:31 +0100 Message-ID: <20240322163130.671185-2-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 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). * 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? * 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 { + uint8_t ctx[RTE_NODE_CTX_SZ]; + /* Convenience aliases to store pointers without complex casting. */ + __extension__ struct { + 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"); + /** * @internal *