From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 28E56A04E6;
	Fri, 30 Oct 2020 18:49:30 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 765492BFF;
	Fri, 30 Oct 2020 18:45:43 +0100 (CET)
Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com
 [66.111.4.26]) by dpdk.org (Postfix) with ESMTP id 9690A5946
 for <dev@dpdk.org>; Fri, 30 Oct 2020 18:45:16 +0100 (CET)
Received: from compute2.internal (compute2.nyi.internal [10.202.2.42])
 by mailout.nyi.internal (Postfix) with ESMTP id 4A04A5C0226;
 Fri, 30 Oct 2020 13:45:16 -0400 (EDT)
Received: from mailfrontend2 ([10.202.2.163])
 by compute2.internal (MEProxy); Fri, 30 Oct 2020 13:45:16 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h=
 from:to:cc:subject:date:message-id:in-reply-to:references
 :mime-version:content-transfer-encoding; s=fm2; bh=tiaM3Au73WwaT
 RdFqBkQJUsMMBTubovz+d2J0K8CACE=; b=lxWZufSviUJGwmcPsw+XXyOkHx7bB
 k5sYEol8Nn8O5LxFij0PzfaZ6d3dIjUi34XZtLZXvjVAvRpYekPlCh4mSMmgQH7w
 bY9DeSGA/1dQx879QyB8gXJGqt9MTWvwwGGWcafBEIZBNSnRi4WSwzYHqWiN5ik4
 SP0YJNchqxtK+jvkaenzyxoJkMJZo6c3JcGdzF4tS79IPfTX+NOXZ5//oj778pyM
 RGWPvoBi5L5zcS/1Rkjae0PgJa/74P41FfHtqS0N43FQd6r4DKC4ohqAc928QNn1
 HR7UN3Qw2nRVT1VvJkjapMHaqhFyeG7A7C4zh/WTsQodwHOD18e8yjDHQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:date:from
 :in-reply-to:message-id:mime-version:references:subject:to
 :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
 fm1; bh=tiaM3Au73WwaTRdFqBkQJUsMMBTubovz+d2J0K8CACE=; b=WnEmioXz
 ecg9US1oloFHZdS66HL94r3kY1K8EWUn34vt54kg6/01dues7iG0/3q9hrBGqeps
 S9AwucatAyJz1M4QnvjnESCiV6psHiH1KXXt+ek/nPD/2P3CYOPykuKQal4rEQLa
 lSBqZpMiNzssq+bwPccfWFbpKtt9p8qpQShvuXru42gg2zdoMLzqTrizj4asIh3d
 WwnIj/+2rwe91WY2faXznUlh0u9teoqD4EAnb59URdfQ6UL5N+e3hD3ZjTwNWzjW
 RQROls3KsrE15awzgelDaIlbBN39aIawWYVPkgVpnDzqqcjb2u5wt5MDbVPX5kNa
 bKTA9I4WzhIPvA==
X-ME-Sender: <xms:LFGcX7_IDn97-oObEmuqV80NF14Ie6WdoO413BqxXkKkUXZCjHUXfQ>
 <xme:LFGcX3svsVtric6UHkM8Gvt5T9DvAwAt9B7OHIMmPcPzQNQ3OCJTTmsfpY-00yZB7
 QiM2E1y_CRA349b2Q>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleehgdellecutefuodetggdotefrodftvf
 curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
 uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc
 fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghs
 ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucggtf
 frrghtthgvrhhnpedvhefgiedvjeegtdevheefhfetleefgfeivefgffevfeejgedtgfeu
 tdehtdegveenucfkphepjeejrddufeegrddvtdefrddukeegnecuvehluhhsthgvrhfuih
 iivgepleenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhho
 nhdrnhgvth
X-ME-Proxy: <xmx:LFGcX5AR3qGVyR1ukNVUCEHhQy_cofuTBMpBN0e96rIcZBrBVVV_YQ>
 <xmx:LFGcX3dG-MQhJjxlFIZnz77jZ0jXjihT7fAe1Y8oyVIq9aJtvIzCsQ>
 <xmx:LFGcXwOv_FByjH3BfslwDgClhczQdAkJPyakQmnNeUbU--DeP895Jw>
 <xmx:LFGcX8DbS6JqsLv_xebKemNJAwRb-UWa6z83fC5dfaW87L8ALKcurw>
Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184])
 by mail.messagingengine.com (Postfix) with ESMTPA id 39FF43064674;
 Fri, 30 Oct 2020 13:45:15 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, david.marchand@redhat.com,
 bruce.richardson@intel.com, olivier.matz@6wind.com,
 andrew.rybchenko@oktetlabs.ru, akhil.goyal@nxp.com, jerinj@marvell.com,
 John McNamara <john.mcnamara@intel.com>
Date: Fri, 30 Oct 2020 18:44:40 +0100
Message-Id: <20201030174441.1076264-15-thomas@monjalon.net>
X-Mailer: git-send-email 2.28.0
In-Reply-To: <20201030174441.1076264-1-thomas@monjalon.net>
References: <20201026052105.1561859-1-thomas@monjalon.net>
 <20201030174441.1076264-1-thomas@monjalon.net>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v6 14/15] examples/rxtx_callbacks: switch TSC to
	dynamic field
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

The example used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 doc/guides/sample_app_ug/rxtx_callbacks.rst |  4 ++--
 examples/rxtx_callbacks/main.c              | 24 +++++++++++++++++++--
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/doc/guides/sample_app_ug/rxtx_callbacks.rst b/doc/guides/sample_app_ug/rxtx_callbacks.rst
index 62d1f39d7e..344446290b 100644
--- a/doc/guides/sample_app_ug/rxtx_callbacks.rst
+++ b/doc/guides/sample_app_ug/rxtx_callbacks.rst
@@ -152,7 +152,7 @@ all packets received:
         uint64_t now = rte_rdtsc();
 
         for (i = 0; i < nb_pkts; i++)
-            pkts[i]->udata64 = now;
+            *tsc_field(pkts[i]) = now;
 
         return nb_pkts;
     }
@@ -179,7 +179,7 @@ packets prior to transmission:
         unsigned i;
 
         for (i = 0; i < nb_pkts; i++)
-            cycles += now - pkts[i]->udata64;
+            cycles += now - *tsc_field(pkts[i]);
 
         latency_numbers.total_cycles += cycles;
         latency_numbers.total_pkts   += nb_pkts;
diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c
index 6fe39546dd..1a8e7d47d9 100644
--- a/examples/rxtx_callbacks/main.c
+++ b/examples/rxtx_callbacks/main.c
@@ -10,6 +10,7 @@
 #include <rte_cycles.h>
 #include <rte_lcore.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 #define RX_RING_SIZE 1024
 #define TX_RING_SIZE 1024
@@ -18,6 +19,15 @@
 #define MBUF_CACHE_SIZE 250
 #define BURST_SIZE 32
 
+typedef uint64_t tsc_t;
+static int tsc_dynfield_offset = -1;
+
+static inline tsc_t *
+tsc_field(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf, tsc_dynfield_offset, tsc_t *);
+}
+
 static const char usage[] =
 	"%s EAL_ARGS -- [-t]\n";
 
@@ -47,7 +57,7 @@ add_timestamps(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
 	uint64_t now = rte_rdtsc();
 
 	for (i = 0; i < nb_pkts; i++)
-		pkts[i]->udata64 = now;
+		*tsc_field(pkts[i]) = now;
 	return nb_pkts;
 }
 
@@ -65,7 +75,7 @@ calc_latency(uint16_t port, uint16_t qidx __rte_unused,
 		rte_eth_read_clock(port, &ticks);
 
 	for (i = 0; i < nb_pkts; i++) {
-		cycles += now - pkts[i]->udata64;
+		cycles += now - *tsc_field(pkts[i]);
 		if (hw_timestamping)
 			queue_ticks += ticks - pkts[i]->timestamp;
 	}
@@ -261,6 +271,11 @@ main(int argc, char *argv[])
 	};
 	int opt, option_index;
 
+	static const struct rte_mbuf_dynfield tsc_dynfield_desc = {
+		.name = "example_bbdev_dynfield_tsc",
+		.size = sizeof(tsc_t),
+		.align = __alignof__(tsc_t),
+	};
 
 	/* init EAL */
 	int ret = rte_eal_init(argc, argv);
@@ -292,6 +307,11 @@ main(int argc, char *argv[])
 	if (mbuf_pool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
 
+	tsc_dynfield_offset =
+		rte_mbuf_dynfield_register(&tsc_dynfield_desc);
+	if (tsc_dynfield_offset < 0)
+		rte_exit(EXIT_FAILURE, "Cannot register mbuf field\n");
+
 	/* initialize all ports */
 	RTE_ETH_FOREACH_DEV(portid)
 		if (port_init(portid, mbuf_pool) != 0)
-- 
2.28.0