From patchwork Thu Jun 11 15:16:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Keroulas X-Patchwork-Id: 71278 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 41191A0093; Thu, 11 Jun 2020 17:16:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5C4332C02; Thu, 11 Jun 2020 17:16:26 +0200 (CEST) Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by dpdk.org (Postfix) with ESMTP id D3B211D9E for ; Thu, 11 Jun 2020 17:16:24 +0200 (CEST) Received: by mail-qv1-f65.google.com with SMTP id cv17so2760544qvb.13 for ; Thu, 11 Jun 2020 08:16:24 -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=Yl+hqdmDSWH9JtqCwOV3WJU08COpubb+7rdyHhP38BQ=; b=dGTA6w9Ji99IRJ7OCDrFP/fodbmJnV0AgrR9H3BQR4NRTeXYi6Pe7Dm2vh3BxOraNh koA6nZA/OVW1NW1q7CX0HF7mCWrRF7sk/bE5miModefg6vCVAU7yz1zDi6Ghn13FPREc RgjgaKNN/Xxbk6LhI1vTCoUO/jZm7ESSMEmIfgKv5w7HbsqJId3hnHvMqF7EhEAov2aM 5OOmwaFSB/I2+kUd+8W6Yot+OdvYVP9DvffXLsoJSriRW9C8HpC/PuludXA9DD5Mhd5a 6NQw+5RrhQFgnKZWpGZyB3kxsuV0Src7dDwFDeInPRHsVIawhEpiejBPcvMe7jIgZUgO 8Ptw== 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=Yl+hqdmDSWH9JtqCwOV3WJU08COpubb+7rdyHhP38BQ=; b=jB4Lnn681F7tZsmQs2umWQg2trHY9617hpWTGPnfS7HCDLP2UELVPPmqYXX7ac5G0C W01oA9wfLkKBKTX1dJYhirwoc3Vl8bu3hnvtdJ/ZnucGdWwYyVb0TsORSR3bPFR/0bmh zhUR34qSP5EGE70pRW/GqFZTdlsUxTogTfdOVvNhIzQOKugp9BWI73w7CxXGIbo7gUu1 rzqpGFFsuHLe5gNJx37ycpSwdDNNnZBKzSDstdCEVSEtmPffg3Eavo50B/RSSAV5+uYU t2d5cHebsXQPUioE3mDzL1gxW9vP7wNP5EfEXY0dFbOnQwJqnvB5czGQMrj3q9QRhVjl ERtQ== X-Gm-Message-State: AOAM530esg+jnN9I1so0J/6GGqIVberqDB0GaGZOWqiZEtemJ3HAb4N1 5NuC0367qluPriAZ6ThHvFju8luXRjbJ4Q== X-Google-Smtp-Source: ABdhPJzrJWL3h/0rdbAI+t0XN1hzMvC7H2MkporeyWDwXeQEQB0knXhIP+uSdND3tV7Yi3KXHBhL0g== X-Received: by 2002:ad4:4a6e:: with SMTP id cn14mr7934428qvb.79.1591888583911; Thu, 11 Jun 2020 08:16:23 -0700 (PDT) Received: from localhost.localdomain (modemcable246.10-73-45.static.videotron.ca. [45.73.10.246]) by smtp.gmail.com with ESMTPSA id h77sm2524379qke.37.2020.06.11.08.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 08:16:23 -0700 (PDT) From: Patrick Keroulas To: dev@dpdk.org Cc: Patrick Keroulas Date: Thu, 11 Jun 2020 11:16:08 -0400 Message-Id: <20200611151610.32409-2-patrick.keroulas@radio-canada.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200611151610.32409-1-patrick.keroulas@radio-canada.ca> References: <20200611151610.32409-1-patrick.keroulas@radio-canada.ca> Subject: [dpdk-dev] [RFC][PATCH v2 1/3] net/mlx5: add counter-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" 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/mlx5.c | 1 + drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 30 +++++++++++++++++++++++++++ 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/mlx5.c b/drivers/net/mlx5/mlx5.c index 7c5e23d9f..c14117f5b 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1241,6 +1241,7 @@ const struct eth_dev_ops mlx5_dev_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, .read_clock = mlx5_read_clock, .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get, .vlan_filter_set = mlx5_vlan_filter_set, diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 8c4b234e5..f4906a54e 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -720,6 +720,7 @@ int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags); int mlx5_dev_configure(struct rte_eth_dev *dev); int mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info); +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_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size); const uint32_t *mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev); diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 6b8b30322..374c9a226 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -690,6 +690,36 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) return 0; } +/** + * 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 *