From: Vivien Didelot <vivien.didelot@gmail.com>
To: dev@dpdk.org
Cc: Patrick Keroulas <patrick.keroulas@radio-canada.ca>,
Olivier Matz <olivier.matz@6wind.com>,
Ferruh Yigit <ferruh.yigit@intel.com>
Subject: [dpdk-dev] [RFC PATCH 2/3] ethdev: add API to convert raw timestamps to nsec
Date: Thu, 25 Jun 2020 15:01:18 -0400 [thread overview]
Message-ID: <20200625190119.265739-3-vivien.didelot@gmail.com> (raw)
In-Reply-To: <20200625190119.265739-1-vivien.didelot@gmail.com>
From: Patrick Keroulas <patrick.keroulas@radio-canada.ca>
Existing ethdev functions can read/write time from/to device but
they're all related to timesync and none of them can translate a raw
counter in real time unit which is useful in a pdump application.
A new API is required because the conversion is derived from dev
clock info.
Signed-off-by: Patrick Keroulas <patrick.keroulas@radio-canada.ca>
---
lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++
lib/librte_ethdev/rte_ethdev.h | 17 +++++++++++++++++
lib/librte_ethdev/rte_ethdev_core.h | 5 +++++
lib/librte_ethdev/rte_ethdev_version.map | 2 ++
lib/librte_mbuf/rte_mbuf_core.h | 3 ++-
lib/librte_pdump/rte_pdump.c | 14 +++++++++++++-
6 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 8e10a6fc3..822fa6d5a 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -4810,6 +4810,18 @@ rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
timestamp));
}
+int
+rte_eth_convert_ts_to_ns(uint16_t port_id, uint64_t *timestamp)
+{
+ struct rte_eth_dev *dev;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ dev = &rte_eth_devices[port_id];
+
+ RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->convert_ts_to_ns, -ENOTSUP);
+ return eth_err(port_id, (*dev->dev_ops->convert_ts_to_ns)(dev, timestamp));
+}
+
int
rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
{
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index a49242bcd..2d4d0bc7d 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -4103,6 +4103,23 @@ int rte_eth_timesync_read_time(uint16_t port_id, struct timespec *time);
*/
int rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *time);
+/**
+ * Convert a raw clock counter to nanoseconds from device clock
+ *
+ * @param port_id
+ * The port identifier of the Ethernet device.
+ * @param[in&out] timestamp
+ * Pointer to the timestamp to be converted.
+ *
+ * @return
+ * - 0: Success.
+ * - -ENODEV: The port ID is invalid.
+ * - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+__rte_experimental
+int
+rte_eth_convert_ts_to_ns(uint16_t port_id, uint64_t *timestamp);
+
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 32407dd41..255b41b67 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -464,6 +464,10 @@ typedef int (*eth_timesync_write_time)(struct rte_eth_dev *dev,
const struct timespec *timestamp);
/**< @internal Function used to get time from the device clock */
+typedef int (*eth_convert_ts_to_ns)(struct rte_eth_dev *dev,
+ uint64_t *timestamp);
+/**< @internal Function used to convert timestamp from device clock */
+
typedef int (*eth_read_clock)(struct rte_eth_dev *dev,
uint64_t *timestamp);
/**< @internal Function used to get the current value of the device clock. */
@@ -730,6 +734,7 @@ struct eth_dev_ops {
eth_timesync_read_time timesync_read_time; /** Get the device clock time. */
eth_timesync_write_time timesync_write_time; /** Set the device clock time. */
+ eth_convert_ts_to_ns convert_ts_to_ns;
eth_read_clock read_clock;
eth_xstats_get_by_id_t xstats_get_by_id;
diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map
index 715505604..754c05630 100644
--- a/lib/librte_ethdev/rte_ethdev_version.map
+++ b/lib/librte_ethdev/rte_ethdev_version.map
@@ -241,4 +241,6 @@ EXPERIMENTAL {
__rte_ethdev_trace_rx_burst;
__rte_ethdev_trace_tx_burst;
rte_flow_get_aged_flows;
+
+ rte_eth_convert_ts_to_ns;
};
diff --git a/lib/librte_mbuf/rte_mbuf_core.h b/lib/librte_mbuf/rte_mbuf_core.h
index 16600f171..470616fb2 100644
--- a/lib/librte_mbuf/rte_mbuf_core.h
+++ b/lib/librte_mbuf/rte_mbuf_core.h
@@ -595,7 +595,8 @@ struct rte_mbuf {
/** Valid if PKT_RX_TIMESTAMP is set. The unit and time reference
* are not normalized but are always the same for a given port.
* Some devices allow to query rte_eth_read_clock that will return the
- * current device timestamp.
+ * current device timestamp or rte_eth_ts_to_ns that will convert raw
+ * counter to nanoseconds.
*/
uint64_t timestamp;
diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c
index f96709f95..03d9ba484 100644
--- a/lib/librte_pdump/rte_pdump.c
+++ b/lib/librte_pdump/rte_pdump.c
@@ -100,12 +100,24 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
}
}
+static inline void
+pdump_ts_to_ns(uint16_t port_id, struct rte_mbuf **pkts, uint16_t nb_pkts)
+{
+ unsigned int i;
+
+ for (i = 0; i < nb_pkts; i++) {
+ if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP)
+ rte_eth_convert_ts_to_ns(port_id, &pkts[i]->timestamp);
+ }
+}
+
static uint16_t
-pdump_rx(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
+pdump_rx(uint16_t port_id, uint16_t qidx __rte_unused,
struct rte_mbuf **pkts, uint16_t nb_pkts,
uint16_t max_pkts __rte_unused,
void *user_params)
{
+ pdump_ts_to_ns(port_id, pkts, nb_pkts);
pdump_copy(pkts, nb_pkts, user_params);
return nb_pkts;
}
--
2.27.0
next prev parent reply other threads:[~2020-06-30 7:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 19:01 [dpdk-dev] [RFC PATCH 0/3] mlx5 to PCAP capture with hardware timestamps Vivien Didelot
2020-06-25 19:01 ` [dpdk-dev] [RFC PATCH 1/3] net/mlx5: add timestamp-to-ns converter from libibverbs Vivien Didelot
2020-06-26 6:41 ` Olivier Matz
2020-07-07 15:23 ` PATRICK KEROULAS
2020-06-25 19:01 ` Vivien Didelot [this message]
2020-06-25 19:01 ` [dpdk-dev] [RFC PATCH 3/3] net/pcap: support hardware Tx timestamps Vivien Didelot
2020-06-26 6:48 ` Olivier Matz
2020-07-06 18:36 ` PATRICK KEROULAS
2020-07-07 14:47 ` Olivier Matz
2020-07-10 19:23 ` PATRICK KEROULAS
2020-06-30 14:59 ` Stephen Hemminger
2020-07-08 14:34 ` [dpdk-dev] [RFC PATCH 0/3] mlx5 to PCAP capture with hardwaretimestamps Morten Brørup
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=20200625190119.265739-3-vivien.didelot@gmail.com \
--to=vivien.didelot@gmail.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=olivier.matz@6wind.com \
--cc=patrick.keroulas@radio-canada.ca \
/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).