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 D36D6A0350; Tue, 30 Jun 2020 09:32:56 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A98521BED2; Tue, 30 Jun 2020 09:32:32 +0200 (CEST) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by dpdk.org (Postfix) with ESMTP id 676973B5 for ; Thu, 25 Jun 2020 21:01:29 +0200 (CEST) Received: by mail-qk1-f193.google.com with SMTP id q198so6472716qka.2 for ; Thu, 25 Jun 2020 12:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=55g/mvmHJ0l/KM3Ims9yy+nq4bRxnNhDnYTRmvmPZTo=; b=pnrkK4tiKo/Jm+nEeuYUXIyIPVwnUaxXLDTccudg6ijCGVDU5dPTwd1TeWddpGLI6z l0b/j5b1LH0ht8C4aRlmuACs5Ve3FwCYQjeD1p34DSoVhih5/9mHWHXFnQ/mzN80yNfa Om4zBHS0oIx6GIdyRia7zJlURgMA/Tol7tquAaGmJa256jOS9GhIVsqqsTJlNdnM97Cx looFCkhxsk97xQjrsYTOXITARZ4TZoN7VayspJoJIcYEfRpD1DcPENFowrh6q2xL7rKS 7wL0WN3SQqJ5hmRxAInKJe/aOFP+qZnLaPwKz8+rd38RnvlLqcZgOXYRHKI2Ck69WyRW O0Kw== 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:mime-version:content-transfer-encoding; bh=55g/mvmHJ0l/KM3Ims9yy+nq4bRxnNhDnYTRmvmPZTo=; b=AZihZ9OyOG2ZseAOWP14eBJE6rJYzsdV7PREFFIAjY0R5EFpuCRlhXohMvJW77+gXK DvUmvAJ0xeBKa6Eap096LJVFf3ujCo2NlANgmh23BPVS2wJpY8mXfRJ0HowIcJAVSJXo d46VFbsg3P97D4tXN1WVJ1MAgpa9pA9mJdY+cpTPVmgFc3cNPEiRrbnwy6p2fhhW+NWQ sx2FZy7dPQb5wTHY+o7+88IeR3Xq8w9GK67fPcj8G6umyP1FxDr1bz4kts7GIs1U8J5M 7jfGCnspq4XAmkJuZGqEs8h6mZNtcglJ1Dtc5TzR5DAuBge9TSBPPQNOS1UDjOwUy0P3 Dj7g== X-Gm-Message-State: AOAM5304GaZ5iBd80UNHgMPgnBSEWZ+waw6x7C46JAwTqbdMRpXFQSS3 xGVBKglGyi6ORnJOVFq5RVNHkA8+ X-Google-Smtp-Source: ABdhPJwQXRER90786QHcyilGuKNM8CWLa7JhJ+d5SLUEbpfH6+gYRVVY64SoRa1D6tWFNvyU4ONdPQ== X-Received: by 2002:a37:6589:: with SMTP id z131mr24336727qkb.235.1593111688410; Thu, 25 Jun 2020 12:01:28 -0700 (PDT) Received: from localhost (modemcable249.105-163-184.mc.videotron.ca. [184.163.105.249]) by smtp.gmail.com with ESMTPSA id w65sm6930640qtd.86.2020.06.25.12.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 12:01:27 -0700 (PDT) From: Vivien Didelot To: dev@dpdk.org Cc: Patrick Keroulas , Olivier Matz , Ferruh Yigit Date: Thu, 25 Jun 2020 15:01:17 -0400 Message-Id: <20200625190119.265739-2-vivien.didelot@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200625190119.265739-1-vivien.didelot@gmail.com> References: <20200625190119.265739-1-vivien.didelot@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 30 Jun 2020 09:32:26 +0200 Subject: [dpdk-dev] [RFC PATCH 1/3] net/mlx5: add timestamp-to-ns converter from libibverbs 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" From: Patrick Keroulas While some devices update their own clock info to provide current time, mlx5dv part of libibverbs already handles this and also converts any raw counter cycle to nanoseconds. Signed-off-by: Patrick Keroulas --- drivers/common/mlx5/linux/mlx5_glue.c | 16 +++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 4 ++++ drivers/net/mlx5/linux/mlx5_ethdev_os.c | 30 +++++++++++++++++++++++++ drivers/net/mlx5/linux/mlx5_os.c | 1 + drivers/net/mlx5/mlx5.h | 1 + 5 files changed, 52 insertions(+) diff --git a/drivers/common/mlx5/linux/mlx5_glue.c b/drivers/common/mlx5/linux/mlx5_glue.c index c91ee33bb..cac24015b 100644 --- a/drivers/common/mlx5/linux/mlx5_glue.c +++ b/drivers/common/mlx5/linux/mlx5_glue.c @@ -80,6 +80,20 @@ mlx5_glue_query_rt_values_ex(struct ibv_context *context, return ibv_query_rt_values_ex(context, values); } +static int +mlx5_glue_get_clock_info(struct ibv_context *context, + struct mlx5dv_clock_info *clock_info) +{ + return mlx5dv_get_clock_info(context, clock_info); +} + +static uint64_t +mlx5_glue_mlx5dv_ts_to_ns(struct mlx5dv_clock_info *clock_info, + uint64_t device_timestamp) +{ + return mlx5dv_ts_to_ns(clock_info, device_timestamp); +} + static int mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num, struct ibv_port_attr *port_attr) @@ -1207,6 +1221,8 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) { .query_device = mlx5_glue_query_device, .query_device_ex = mlx5_glue_query_device_ex, .query_rt_values_ex = mlx5_glue_query_rt_values_ex, + .get_clock_info = mlx5_glue_get_clock_info, + .convert_ts_to_ns = mlx5_glue_mlx5dv_ts_to_ns, .query_port = mlx5_glue_query_port, .create_comp_channel = mlx5_glue_create_comp_channel, .destroy_comp_channel = mlx5_glue_destroy_comp_channel, diff --git a/drivers/common/mlx5/linux/mlx5_glue.h b/drivers/common/mlx5/linux/mlx5_glue.h index 5d238a40a..8d05e7398 100644 --- a/drivers/common/mlx5/linux/mlx5_glue.h +++ b/drivers/common/mlx5/linux/mlx5_glue.h @@ -123,6 +123,10 @@ struct mlx5_glue { struct ibv_port_attr *port_attr); struct ibv_comp_channel *(*create_comp_channel) (struct ibv_context *context); + int (*get_clock_info)(struct ibv_context *context, + struct mlx5dv_clock_info *clock_info); + uint64_t (*convert_ts_to_ns)(struct mlx5dv_clock_info *clock_info, + uint64_t device_timestamp); int (*destroy_comp_channel)(struct ibv_comp_channel *channel); struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe, void *cq_context, diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c index ab47cb531..86bec111b 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -355,6 +355,36 @@ mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags) return mlx5_ifreq(dev, SIOCSIFFLAGS, &request); } +/** + * Convert raw clock counter to nanoseconds + * + * @param dev + * Pointer to Ethernet device structure. + * @param[in&out] timestamp + * Pointer to the timestamp to be converted. + * + * @return + * 0 if the clock has correctly been read + * The value of errno in case of error + */ +int +mlx5_convert_ts_to_ns(struct rte_eth_dev *dev, uint64_t *timestamp) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct ibv_context *ctx = priv->sh->ctx; + struct mlx5dv_clock_info clock_info; + + int err = mlx5_glue->get_clock_info(ctx, &clock_info); + if (err != 0) { + DRV_LOG(WARNING, "Could not get the clock info!"); + return err; + } + + *timestamp = mlx5_glue->convert_ts_to_ns(&clock_info, *timestamp); + + return err; +} + /** * Get device current raw clock counter * diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 3792371c3..914e58f52 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -2408,6 +2408,7 @@ const struct eth_dev_ops mlx5_os_dev_sec_ops = { .xstats_get_names = mlx5_xstats_get_names, .fw_version_get = mlx5_fw_version_get, .dev_infos_get = mlx5_dev_infos_get, + .convert_ts_to_ns = mlx5_convert_ts_to_ns, .rx_descriptor_status = mlx5_rx_descriptor_status, .tx_descriptor_status = mlx5_tx_descriptor_status, .rxq_info_get = mlx5_rxq_info_get, diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 5bd5acd9d..dc469f7d9 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -738,6 +738,7 @@ int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu); int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags); int mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu); +int mlx5_convert_ts_to_ns(struct rte_eth_dev *dev, uint64_t *timestamp); int mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock); int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete); int mlx5_force_link_status_change(struct rte_eth_dev *dev, int status); -- 2.27.0