DPDK patches and discussions
 help / color / mirror / Atom feed
From: Wenjing Qiao <wenjing.qiao@intel.com>
To: jingjing.wu@intel.com, beilei.xing@intel.com, qi.z.zhang@intel.com
Cc: dev@dpdk.org, mingxia.liu@intel.com,
	Wenjing Qiao <wenjing.qiao@intel.com>,
	stable@dpdk.org
Subject: [PATCH v3 4/7] common/idpf: enhance timestamp offload feature for ACC
Date: Mon, 24 Apr 2023 05:17:04 -0400	[thread overview]
Message-ID: <20230424091707.488045-5-wenjing.qiao@intel.com> (raw)
In-Reply-To: <20230424091707.488045-1-wenjing.qiao@intel.com>

For ACC, getting main time from MTS registers by shared memory.

Notice: it is a workaround, and it will be removed after generic
solution are provided.

Fixes: 8c6098afa075 ("common/idpf: add Rx/Tx data path")
Cc: stable@dpdk.org

Signed-off-by: Wenjing Qiao <wenjing.qiao@intel.com>
---
 config/meson.build                     |  3 ++
 drivers/common/idpf/base/idpf_osdep.h  | 48 ++++++++++++++++++++++++++
 drivers/common/idpf/idpf_common_rxtx.c | 30 +++++++++++++---
 meson_options.txt                      |  2 ++
 4 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/config/meson.build b/config/meson.build
index fa730a1b14..8d74f301b4 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -316,6 +316,9 @@ endif
 if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)
 endif
+if get_option('enable_acc_timestamp')
+    dpdk_conf.set('IDPF_ACC_TIMESTAMP', true)
+endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
 
 compile_time_cpuflags = []
diff --git a/drivers/common/idpf/base/idpf_osdep.h b/drivers/common/idpf/base/idpf_osdep.h
index 99ae9cf60a..e634939a51 100644
--- a/drivers/common/idpf/base/idpf_osdep.h
+++ b/drivers/common/idpf/base/idpf_osdep.h
@@ -24,6 +24,13 @@
 #include <rte_random.h>
 #include <rte_io.h>
 
+#ifdef IDPF_ACC_TIMESTAMP
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#endif /* IDPF_ACC_TIMESTAMP */
+
 #define INLINE inline
 #define STATIC static
 
@@ -361,4 +368,45 @@ idpf_hweight32(u32 num)
 
 #endif
 
+#ifdef IDPF_ACC_TIMESTAMP
+#define IDPF_ACC_TIMESYNC_BASE_ADDR 0x480D500000
+#define IDPF_ACC_GLTSYN_TIME_H (IDPF_ACC_TIMESYNC_BASE_ADDR + 0x1C)
+#define IDPF_ACC_GLTSYN_TIME_L (IDPF_ACC_TIMESYNC_BASE_ADDR + 0x10)
+
+inline uint32_t
+idpf_mmap_r32(uint64_t pa)
+{
+	int fd;
+	void *bp, *vp;
+	uint32_t rval = 0xdeadbeef;
+	uint32_t ps, ml, of;
+
+	fd = open("/dev/mem", (O_RDWR | O_SYNC));
+	if (fd == -1) {
+		perror("/dev/mem");
+		return -1;
+	}
+	ml = ps = getpagesize();
+	of = (uint32_t)pa & (ps - 1);
+	if (of + (sizeof(uint32_t) * 4) > ps)
+		ml *= 2;
+	bp = mmap(NULL, ml, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, pa & ~(uint64_t)(ps - 1));
+	if (bp == MAP_FAILED) {
+		perror("mmap");
+		goto done;
+	}
+
+	vp = (char *)bp + of;
+
+	rval = *(volatile uint32_t *)vp;
+	if (munmap(bp, ml) == -1)
+		perror("munmap");
+done:
+	close(fd);
+
+	return rval;
+}
+
+#endif /* IDPF_ACC_TIMESTAMP */
+
 #endif /* _IDPF_OSDEP_H_ */
diff --git a/drivers/common/idpf/idpf_common_rxtx.c b/drivers/common/idpf/idpf_common_rxtx.c
index 19bcb94077..9c58f3fb11 100644
--- a/drivers/common/idpf/idpf_common_rxtx.c
+++ b/drivers/common/idpf/idpf_common_rxtx.c
@@ -1582,12 +1582,36 @@ idpf_qc_splitq_rx_vec_setup(struct idpf_rx_queue *rxq)
 void
 idpf_dev_read_time_hw(void *cb_arg)
 {
-#ifdef RTE_ARCH_X86_64
 	struct idpf_adapter *ad = (struct idpf_adapter *)cb_arg;
 	uint32_t hi, lo, lo2;
 	int rc = 0;
+#ifndef IDPF_ACC_TIMESTAMP
 	struct idpf_hw *hw = &ad->hw;
+#endif /*  !IDPF_ACC_TIMESTAMP */
 
+#ifdef IDPF_ACC_TIMESTAMP
+
+	lo = idpf_mmap_r32(IDPF_ACC_GLTSYN_TIME_L);
+	hi = idpf_mmap_r32(IDPF_ACC_GLTSYN_TIME_H);
+	DRV_LOG(DEBUG, "lo : %X,", lo);
+	DRV_LOG(DEBUG, "hi : %X,", hi);
+	/*
+	 * On typical system, the delta between lo and lo2 is ~1000ns,
+	 * so 10000 seems a large-enough but not overly-big guard band.
+	 */
+	if (lo > (UINT32_MAX - IDPF_TIMESYNC_REG_WRAP_GUARD_BAND))
+		lo2 = idpf_mmap_r32(IDPF_ACC_GLTSYN_TIME_L);
+	else
+		lo2 = lo;
+
+	if (lo2 < lo) {
+		lo = idpf_mmap_r32(IDPF_ACC_GLTSYN_TIME_L);
+		hi = idpf_mmap_r32(IDPF_ACC_GLTSYN_TIME_H);
+	}
+
+	ad->time_hw = ((uint64_t)hi << 32) | lo;
+
+#else  /* !IDPF_ACC_TIMESTAMP */
 	IDPF_WRITE_REG(hw, GLTSYN_CMD_SYNC_0_0, PF_GLTSYN_CMD_SYNC_SHTIME_EN_M);
 	IDPF_WRITE_REG(hw, GLTSYN_CMD_SYNC_0_0,
 		       PF_GLTSYN_CMD_SYNC_EXEC_CMD_M | PF_GLTSYN_CMD_SYNC_SHTIME_EN_M);
@@ -1608,9 +1632,7 @@ idpf_dev_read_time_hw(void *cb_arg)
 	}
 
 	ad->time_hw = ((uint64_t)hi << 32) | lo;
-#else  /* !RTE_ARCH_X86_64 */
-	ad->time_hw = 0;
-#endif /* RTE_ARCH_X86_64 */
+#endif /* IDPF_ACC_TIMESTAMP */
 
 	/* re-alarm watchdog */
 	rc = rte_eal_alarm_set(1000 * 1000, &idpf_dev_read_time_hw, cb_arg);
diff --git a/meson_options.txt b/meson_options.txt
index 82c8297065..31fc634aa0 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -52,3 +52,5 @@ option('tests', type: 'boolean', value: true, description:
        'build unit tests')
 option('use_hpet', type: 'boolean', value: false, description:
        'use HPET timer in EAL')
+option('enable_acc_timestamp', type: 'boolean', value: false, description:
+       'enable timestamp on ACC.')
-- 
2.25.1


  parent reply	other threads:[~2023-04-24  9:23 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20  9:19 [PATCH 0/7] update idpf and cpfl timestamp Wenjing Qiao
2023-04-20  9:19 ` [PATCH 1/7] common/idpf: fix 64b timestamp roll over issue Wenjing Qiao
2023-04-21  7:15   ` [PATCH v2 0/7] update idpf and cpfl timestamp Wenjing Qiao
2023-04-21  7:15     ` [PATCH v2 1/7] common/idpf: fix 64b timestamp roll over issue Wenjing Qiao
2023-04-24  9:17       ` [PATCH v3 0/7] fix and enhance idpf and cpfl timestamp Wenjing Qiao
2023-04-24  9:17         ` [PATCH v3 1/7] common/idpf: fix 64b timestamp roll over issue Wenjing Qiao
2023-05-19  8:31           ` [PATCH v4 0/7] fix idpf and cpfl timestamp Wenjing Qiao
2023-05-19  8:31             ` [PATCH v4 1/7] common/idpf: fix 64b timestamp roll over issue Wenjing Qiao
2023-05-24  8:36               ` Liu, Mingxia
2023-05-19  8:31             ` [PATCH v4 2/7] net/idpf: save main time by alarm Wenjing Qiao
2023-05-19  8:31             ` [PATCH v4 3/7] net/cpfl: " Wenjing Qiao
2023-05-19  8:31             ` [PATCH v4 4/7] common/idpf: enhance timestamp offload feature for ACC Wenjing Qiao
2023-05-19  8:31             ` [PATCH v4 5/7] common/idpf: add timestamp enable flag for rxq Wenjing Qiao
2023-05-19  8:31             ` [PATCH v4 6/7] net/cpfl: adjust timestamp mbuf register Wenjing Qiao
2023-05-19  8:31             ` [PATCH v4 7/7] net/idpf: " Wenjing Qiao
2023-04-24  9:17         ` [PATCH v3 2/7] net/idpf: save main time by alarm Wenjing Qiao
2023-04-24  9:17         ` [PATCH v3 3/7] net/cpfl: " Wenjing Qiao
2023-04-24  9:17         ` Wenjing Qiao [this message]
2023-04-24  9:17         ` [PATCH v3 5/7] common/idpf: add timestamp enable flag for rxq Wenjing Qiao
2023-04-24  9:17         ` [PATCH v3 6/7] net/cpfl: register timestamp mbuf when starting dev Wenjing Qiao
2023-04-28  3:24           ` Zhang, Qi Z
2023-04-24  9:17         ` [PATCH v3 7/7] net/idpf: " Wenjing Qiao
2023-04-21  7:15     ` [PATCH v2 2/7] net/idpf: save main time by alarm Wenjing Qiao
2023-04-28  2:46       ` Zhang, Qi Z
2023-04-21  7:15     ` [PATCH v2 3/7] net/cpfl: " Wenjing Qiao
2023-04-21  7:16     ` [PATCH v2 4/7] common/idpf: support timestamp offload feature for ACC Wenjing Qiao
2023-04-21  7:16     ` [PATCH v2 5/7] common/idpf: add timestamp enable flag for rxq Wenjing Qiao
2023-04-21  7:16     ` [PATCH v2 6/7] net/cpfl: register timestamp mbuf when starting dev Wenjing Qiao
2023-04-21  7:16     ` [PATCH v2 7/7] net/idpf: " Wenjing Qiao
2023-04-20  9:19 ` [PATCH 2/7] net/idpf: save master time by alarm Wenjing Qiao
2023-04-20  9:19 ` [PATCH 3/7] net/cpfl: " Wenjing Qiao
2023-04-20  9:19 ` [PATCH 4/7] common/idpf: support timestamp offload feature for ACC Wenjing Qiao
2023-04-20  9:19 ` [PATCH 5/7] common/idpf: add timestamp enable flag for rxq Wenjing Qiao
2023-04-20  9:19 ` [PATCH 6/7] net/cpfl: register timestamp mbuf when starting dev Wenjing Qiao
2023-04-20  9:19 ` [PATCH 7/7] net/idpf: " Wenjing Qiao

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=20230424091707.488045-5-wenjing.qiao@intel.com \
    --to=wenjing.qiao@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=mingxia.liu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=stable@dpdk.org \
    /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).