DPDK patches and discussions
 help / color / mirror / Atom feed
From: Simei Su <simei.su@intel.com>
To: qi.z.zhang@intel.com, qiming.yang@intel.com
Cc: dev@dpdk.org, wenjun1.wu@intel.com
Subject: [PATCH v1 3/3] net/iavf: improve performance of Rx timestamp offload
Date: Fri,  8 Apr 2022 10:13:07 +0800	[thread overview]
Message-ID: <20220408021307.272746-4-simei.su@intel.com> (raw)
In-Reply-To: <20220408021307.272746-1-simei.su@intel.com>

From: Wenjun Wu <wenjun1.wu@intel.com>

In this patch, We use CPU ticks instead of HW register
to determin whether low 32 bits timestamp has turned
over. It can avoid requesting register value frequently
and improve receving performance.

Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
---
 drivers/net/iavf/iavf.h        |  1 +
 drivers/net/iavf/iavf_ethdev.c |  8 +++++++
 drivers/net/iavf/iavf_rxtx.c   | 50 +++++++++++++++++++++++++++---------------
 drivers/net/iavf/iavf_rxtx.h   |  1 -
 4 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h
index 2838b5e..ad5c0d4 100644
--- a/drivers/net/iavf/iavf.h
+++ b/drivers/net/iavf/iavf.h
@@ -303,6 +303,7 @@ struct iavf_adapter {
 	uint16_t fdir_ref_cnt;
 	struct iavf_devargs devargs;
 	uint64_t phc_time;
+	uint64_t hw_time_update;
 };
 
 /* IAVF_DEV_PRIVATE_TO */
diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
index 704c174..ffdc368 100644
--- a/drivers/net/iavf/iavf_ethdev.c
+++ b/drivers/net/iavf/iavf_ethdev.c
@@ -1014,6 +1014,14 @@ iavf_dev_start(struct rte_eth_dev *dev)
 		goto err_mac;
 	}
 
+	if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		if (iavf_get_phc_time(adapter)) {
+			PMD_DRV_LOG(ERR, "get physical time failed");
+			goto err_mac;
+		}
+		adapter->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+	}
+
 	return 0;
 
 err_mac:
diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c
index ab5b3de..02ee279 100644
--- a/drivers/net/iavf/iavf_rxtx.c
+++ b/drivers/net/iavf/iavf_rxtx.c
@@ -1432,8 +1432,14 @@ iavf_recv_pkts_flex_rxd(void *rx_queue,
 	struct iavf_adapter *ad = rxq->vsi->adapter;
 	uint64_t ts_ns;
 
-	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
-		rxq->hw_register_set = 1;
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+		if (sw_cur_time - ad->hw_time_update > 4) {
+			if (iavf_get_phc_time(ad))
+				PMD_DRV_LOG(ERR, "get physical time failed");
+			ad->hw_time_update = sw_cur_time;
+		}
+	}
 
 	while (nb_rx < nb_pkts) {
 		rxdp = (volatile union iavf_rx_flex_desc *)&rx_ring[rx_id];
@@ -1498,13 +1504,12 @@ iavf_recv_pkts_flex_rxd(void *rx_queue,
 		pkt_flags = iavf_flex_rxd_error_to_pkt_flags(rx_stat_err0);
 
 		if (iavf_timestamp_dynflag > 0) {
-			if (rxq->hw_register_set)
-				iavf_get_phc_time(ad);
-
-			rxq->hw_register_set = 0;
 			ts_ns = iavf_tstamp_convert_32b_64b(ad->phc_time,
 				rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high));
 
+			ad->phc_time = ts_ns;
+			ad->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+
 			*RTE_MBUF_DYNFIELD(rxm,
 				iavf_timestamp_dynfield_offset,
 				rte_mbuf_timestamp_t *) = ts_ns;
@@ -1546,8 +1551,14 @@ iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts,
 	volatile union iavf_rx_flex_desc *rxdp;
 	const uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
-	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
-		rxq->hw_register_set = 1;
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+		if (sw_cur_time - ad->hw_time_update > 4) {
+			if (iavf_get_phc_time(ad))
+				PMD_DRV_LOG(ERR, "get physical time failed");
+			ad->hw_time_update = sw_cur_time;
+		}
+	}
 
 	while (nb_rx < nb_pkts) {
 		rxdp = (volatile union iavf_rx_flex_desc *)&rx_ring[rx_id];
@@ -1662,13 +1673,12 @@ iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts,
 		pkt_flags = iavf_flex_rxd_error_to_pkt_flags(rx_stat_err0);
 
 		if (iavf_timestamp_dynflag > 0) {
-			if (rxq->hw_register_set)
-				iavf_get_phc_time(ad);
-
-			rxq->hw_register_set = 0;
 			ts_ns = iavf_tstamp_convert_32b_64b(ad->phc_time,
 				rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high));
 
+			ad->phc_time = ts_ns;
+			ad->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+
 			*RTE_MBUF_DYNFIELD(first_seg,
 				iavf_timestamp_dynfield_offset,
 				rte_mbuf_timestamp_t *) = ts_ns;
@@ -1879,8 +1889,14 @@ iavf_rx_scan_hw_ring_flex_rxd(struct iavf_rx_queue *rxq)
 	if (!(stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_DD_S)))
 		return 0;
 
-	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
-		rxq->hw_register_set = 1;
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+		if (sw_cur_time - ad->hw_time_update > 4) {
+			if (iavf_get_phc_time(ad))
+				PMD_DRV_LOG(ERR, "get physical time failed");
+			ad->hw_time_update = sw_cur_time;
+		}
+	}
 
 	/* Scan LOOK_AHEAD descriptors at a time to determine which
 	 * descriptors reference packets that are ready to be received.
@@ -1941,12 +1957,10 @@ iavf_rx_scan_hw_ring_flex_rxd(struct iavf_rx_queue *rxq)
 			pkt_flags = iavf_flex_rxd_error_to_pkt_flags(stat_err0);
 
 			if (iavf_timestamp_dynflag > 0) {
-				if (rxq->hw_register_set)
-					iavf_get_phc_time(ad);
-
-				rxq->hw_register_set = 0;
 				ts_ns = iavf_tstamp_convert_32b_64b(ad->phc_time,
 					rte_le_to_cpu_32(rxdp[j].wb.flex_ts.ts_high));
+				ad->phc_time = ts_ns;
+				ad->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
 
 				*RTE_MBUF_DYNFIELD(mb,
 					iavf_timestamp_dynfield_offset,
diff --git a/drivers/net/iavf/iavf_rxtx.h b/drivers/net/iavf/iavf_rxtx.h
index 37453c4..642b9a7 100644
--- a/drivers/net/iavf/iavf_rxtx.h
+++ b/drivers/net/iavf/iavf_rxtx.h
@@ -222,7 +222,6 @@ struct iavf_rx_queue {
 		/* flexible descriptor metadata extraction offload flag */
 	struct iavf_rx_queue_stats stats;
 	uint64_t offloads;
-	uint32_t hw_register_set;
 };
 
 struct iavf_tx_entry {
-- 
2.9.5


  parent reply	other threads:[~2022-04-08  2:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08  2:13 [PATCH v1 0/3] net/iavf: support Rx timestamp on flex descriptor Simei Su
2022-04-08  2:13 ` [PATCH v1 1/3] common/iavf: support Rx timestamp in virtual channel Simei Su
2022-04-08  2:13 ` [PATCH v1 2/3] net/iavf: enable Rx timestamp on Flex Descriptor Simei Su
2022-04-08  2:13 ` Simei Su [this message]
2022-04-24  7:08 ` [PATCH v2 0/3] net/iavf: support Rx timestamp on flex descriptor Simei Su
2022-04-24  7:08   ` [PATCH v2 1/3] common/iavf: support Rx timestamp in virtual channel Simei Su
2022-04-24  7:08   ` [PATCH v2 2/3] net/iavf: enable Rx timestamp on Flex Descriptor Simei Su
2022-04-24  7:08   ` [PATCH v2 3/3] net/iavf: improve performance of Rx timestamp offload Simei Su
2022-04-28  8:13   ` [PATCH v3 0/3] net/iavf: support Rx timestamp on flex descriptor Simei Su
2022-04-28  8:13     ` [PATCH v3 1/3] common/iavf: support Rx timestamp in virtual channel Simei Su
2022-04-28  8:13     ` [PATCH v3 2/3] net/iavf: enable Rx timestamp on Flex Descriptor Simei Su
2022-04-28  8:13     ` [PATCH v3 3/3] net/iavf: improve performance of Rx timestamp offload Simei Su
2022-05-10 16:00       ` Thomas Monjalon
2022-04-29  2:56     ` [PATCH v3 0/3] net/iavf: support Rx timestamp on flex descriptor Zhang, Qi Z

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220408021307.272746-4-simei.su@intel.com \
    --to=simei.su@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=wenjun1.wu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).