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 6908645A66; Mon, 30 Sep 2024 11:28:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E3C9E40299; Mon, 30 Sep 2024 11:28:02 +0200 (CEST) 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 034654027D for ; Mon, 30 Sep 2024 11:28:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727688480; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gWrYYthGtfl1wrPZDlRtALeYNz8JVtHFOeO4p1eM8fs=; b=NnshXnQe09maZmJNcjs+njvCQuX6qtLxL7xISO22u95auCiqTKSKHqOQYfNIlniYx3Gg7U iey3ybioMuEq7iWaBhVoWOO5nB4MufMom87NrN8mnAHLrcdv5V/+Q4+wjKVREAkm/yO41f WXnIXkTOHuqGsQcWZPaXxp+Vn6+FHYc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-307-2RiqLw_5PyCRG7wmKEGTWA-1; Mon, 30 Sep 2024 05:27:57 -0400 X-MC-Unique: 2RiqLw_5PyCRG7wmKEGTWA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6B2E618E6A62; Mon, 30 Sep 2024 09:27:56 +0000 (UTC) Received: from ringo.home (unknown [10.39.208.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 94E9B3003E5F; Mon, 30 Sep 2024 09:27:54 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan Subject: [PATCH dpdk v7] graph: expose node context as pointers Date: Mon, 30 Sep 2024 11:27:51 +0200 Message-ID: <20240930092750.168280-2-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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. And without intermediate structures, casting to opaque pointers is hard without violating strict aliasing rules. Add an unnamed union to allow storing opaque pointers in the node context. Unfortunately, aligning an unnamed union that contains an array produces inconsistent results between C and C++. To preserve ABI/API compatibility in both C and C++, move all fast-path area fields into an unnamed struct which is itself cache aligned. Use __rte_cache_aligned to preserve existing alignment on architectures where cache lines are 128 bytes. Add a static assert to ensure that the fast path area does not grow beyond a 64 bytes cache line. Signed-off-by: Robin Jarry Acked-by: Kiran Kumar Kokkilagadda --- Notes: v7: * rebased on bf0ff8df59c7 ("maintainers: fix prog guide paths") * no change, only to re-trigger ci v6: * Fix ABI breakage on arm64 (and all platforms that have RTE_CACHE_LINE_SIZE=128). * This patch will cause CI failures without libabigail 2.5. See this commit https://sourceware.org/git/?p=libabigail.git;a=commitdiff;h=f821c2be3fff2047ef8fc436f6f02301812d166f for more details. v5: * Helper functions to hide casting proved to be harder than expected. Naive casting may even be impossible without breaking strict aliasing rules. The only other option would be to use explicit memcpy calls. * Unnamed union tentative again. As suggested by Tyler (thank you!), using an intermediate unnamed struct to carry the alignment produces consistent ABI in C and C++. * Also, Tyler (thank you!) suggested that the fast path area alignment size may be incorrect for architectures where the cache line is not 64 bytes. There will be a 64 bytes hole in the structure at the end of the unnamed struct before the zero length next nodes array. Use __rte_cache_min_aligned to preserve existing alignment. lib/graph/rte_graph_worker_common.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h index 36d864e2c14e..8d8956fdddda 100644 --- a/lib/graph/rte_graph_worker_common.h +++ b/lib/graph/rte_graph_worker_common.h @@ -12,7 +12,9 @@ * process, enqueue and move streams of objects to the next nodes. */ +#include #include +#include #include #include @@ -111,14 +113,21 @@ struct __rte_cache_aligned rte_node { } dispatch; }; /* Fast path area */ + __extension__ struct __rte_cache_aligned { #define RTE_NODE_CTX_SZ 16 - alignas(RTE_CACHE_LINE_SIZE) uint8_t ctx[RTE_NODE_CTX_SZ]; /**< 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. */ - uint64_t total_cycles; /**< Cycles spent in this node. */ - uint64_t total_calls; /**< Calls done to this node. */ - uint64_t total_objs; /**< Objects processed by this node. */ + union { + uint8_t ctx[RTE_NODE_CTX_SZ]; + __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. */ + uint64_t total_cycles; /**< Cycles spent in this node. */ + uint64_t total_calls; /**< Calls done to this node. */ + uint64_t total_objs; /**< Objects processed by this node. */ union { void **objs; /**< Array of object pointers. */ uint64_t objs_u64; @@ -127,9 +136,13 @@ struct __rte_cache_aligned rte_node { rte_node_process_t process; /**< Process function. */ uint64_t process_u64; }; - alignas(RTE_CACHE_LINE_MIN_SIZE) struct rte_node *nodes[]; /**< Next nodes. */ + alignas(RTE_CACHE_LINE_MIN_SIZE) struct rte_node *nodes[]; /**< Next nodes. */ + }; }; +static_assert(offsetof(struct rte_node, nodes) - offsetof(struct rte_node, ctx) + == RTE_CACHE_LINE_MIN_SIZE, "rte_node fast path area must fit in 64 bytes"); + /** * @internal * -- 2.46.1