From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 12D73A04FE; Tue, 9 Jun 2020 16:18:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 087F31BEB7; Tue, 9 Jun 2020 16:17:57 +0200 (CEST) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by dpdk.org (Postfix) with ESMTP id BF9C21BEB0 for ; Tue, 9 Jun 2020 16:17:54 +0200 (CEST) Received: by mail-qk1-f196.google.com with SMTP id c185so20896060qke.7 for ; Tue, 09 Jun 2020 07:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=radio-canada-ca.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VE80sA5gxLM6CWwHUxg8d9OMsp1RcZrQu7BQ1sVsykE=; b=t4unuq+PxCWfVb3KfAz2aLBUdpdhp7dXQl/Tq/03bjfs0yQN2xdqhyNslYM/BERtlk St7tuuxfiO05aDg+IvryM9btQsB6XBVEUyjJZv1bf9W8PpKti0ZZquQE/mYryy4lBkp2 UPczd0EMxwAEZjduen5DoU22AuNEXmOWOf9QG2IFYipfgpYH9vodlmSGZDVYegpLh2w2 WocCyM06C6CySuQMeLoGdAdpqhDLzE3PJ6JJWIUKM3VM7VWNWcheIeFYPUd/GLF7qFgw 2BZxl2i4Rz3CT5vQvwDEt3rvDh30/QsmlOaC+SNJzezsSiplELbFvH++s1ktfA1DQ0Th 520g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VE80sA5gxLM6CWwHUxg8d9OMsp1RcZrQu7BQ1sVsykE=; b=jTx8uOnLHpTAoP3enS9MUh2x3KPd6NnRdmmgh68ty6dDBpt8e63zWDon6/Usesx9hi df/pTcgDhN7axWUnppE5hynTAZ44Acbgvv1wSNVNYBHaj8q4zeKyTchkDTzIE2M8viqn vCSylaKSbz7lGNnSHalA+CMKL8w6Ky5yZyH1N9ARPE16duOfferNCUzF2bIaU+Z2HLUS F/1eMuyI1VwXnlD86VobAhFbgb7zWk5eS2CvT6Tg2eoQKeolKu3st6f2MdjbQJD9qdhf v+lKZa1agoTur+msAUu7/+wmdFfKc0oXI7henN6+e/qEXyZB+PHw/XWOC8JTplNlp2en 7OvA== X-Gm-Message-State: AOAM532xycDBcGQ6HXgCEtivNCWAVus5aZGH35Pc7l4YFm1jcpbzumwM IceIBcPE20nIhBdmsw2HgbPOMaW4jgGiyA== X-Google-Smtp-Source: ABdhPJwjZlbe8YwFNcX6seXnZqDYE8/VBjCSjxTjgXs/vaXJmsmIug8ftcHh/aY2WS8u/gTtwJ0bGQ== X-Received: by 2002:a37:6385:: with SMTP id x127mr27658975qkb.307.1591712273356; Tue, 09 Jun 2020 07:17:53 -0700 (PDT) Received: from localhost.localdomain (104-163-142-249.qc.dsl.ebox.net. [104.163.142.249]) by smtp.gmail.com with ESMTPSA id a82sm10287148qkb.29.2020.06.09.07.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 07:17:53 -0700 (PDT) From: Patrick Keroulas To: dev@dpdk.org Cc: Patrick Keroulas Date: Tue, 9 Jun 2020 10:17:12 -0400 Message-Id: <20200609141713.11614-3-patrick.keroulas@radio-canada.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141713.11614-1-patrick.keroulas@radio-canada.ca> References: <20200609141713.11614-1-patrick.keroulas@radio-canada.ca> Subject: [dpdk-dev] [RFC] [PATCH v1 2/3] ethdev: add API to convert raw timestamps to nsec X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 usefull in a pdump application. A new API is required because the conversion is derived from dev clock info. Signed-off-by: Patrick Keroulas --- 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 | 15 ++++++++++++++- 6 files changed, 52 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 b9a59c879..7f51f9157 100644 --- a/lib/librte_mbuf/rte_mbuf_core.h +++ b/lib/librte_mbuf/rte_mbuf_core.h @@ -592,7 +592,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..bc80ed0c6 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -100,12 +100,25 @@ 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 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.17.1