From patchwork Mon Mar 25 10:05:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Jarry X-Patchwork-Id: 138765 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 5BA3543D46; Mon, 25 Mar 2024 11:05:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D1D9C40271; Mon, 25 Mar 2024 11:05:34 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id E5ED040270 for ; Mon, 25 Mar 2024 11:05:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711361132; 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=luFTsUlLiAriW5xVS/XjnUbT0d566VBnVQ+NtfwVy0A=; b=GbxHhsbg0MGGutjgvpl15Vq3CLxM//fDWtSC44C1kPPor87NF1wftSwWgDPeJiZbfhLb0X cjjhvsWsKKlwFkFuQY6HYHGGgJBcF4nj1Fs0rZDTpCEq6gj/S3JimcOqANkWt3UKcPQV13 kCEq+/g7o54cCe6L3m6EnqlezS+euo0= 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-110-n0ZHpa_qOnKhhM1-MkBSwA-1; Mon, 25 Mar 2024 06:05:30 -0400 X-MC-Unique: n0ZHpa_qOnKhhM1-MkBSwA-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 356351C0170D; Mon, 25 Mar 2024 10:05:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.208.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4CE42022EA7; Mon, 25 Mar 2024 10:05:28 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan Cc: Tyler Retzlaff Subject: [PATCH v3] graph: expose node context as pointers Date: Mon, 25 Mar 2024 11:05:01 +0100 Message-ID: <20240325100500.694748-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: v3: * Added __extension__ to the unnamed struct inside the union. * Fixed C++ header checks. * Replaced alignas() with an explicit static_assert. 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 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h index 36d864e2c14e..722e9dac0d36 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 @@ -112,7 +114,19 @@ 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. */ + /* + * alignas(RTE_CACHE_LINE_SIZE) cannot be used for ctx since it is part of an unnamed union. + * The compiler shifts the next field on the next cache line which is not what we want. + * The alignment is enforced via a explcicit static asserts below. + */ + 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 +144,11 @@ struct __rte_cache_aligned rte_node { alignas(RTE_CACHE_LINE_MIN_SIZE) struct rte_node *nodes[]; /**< Next nodes. */ }; +static_assert(offsetof(struct rte_node, ctx) % RTE_CACHE_LINE_SIZE == 0, + "rte_node ctx must be aligned on a cache line"); +static_assert(offsetof(struct rte_node, size) - offsetof(struct rte_node, ctx) == RTE_NODE_CTX_SZ, + "rte_node context union cannot be larger than RTE_NODE_CTX_SZ"); + /** * @internal *