[v2,2/3] mlx5: Implement support for read_clock

Message ID 20190327061935.19572-3-barbette@kth.se
State Superseded, archived
Delegated to: Ferruh Yigit
Headers show
Series
  • Add rte_eth_read_clock API
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Tom Barbette March 27, 2019, 6:19 a.m.
Signed-off-by: Tom Barbette <barbette@kth.se>
---
 drivers/net/mlx5/mlx5.c        |  1 +
 drivers/net/mlx5/mlx5.h        |  1 +
 drivers/net/mlx5/mlx5_ethdev.c | 29 +++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_glue.c   |  8 ++++++++
 drivers/net/mlx5/mlx5_glue.h   |  2 ++
 5 files changed, 41 insertions(+)

Comments

Ferruh Yigit April 2, 2019, 5:47 p.m. | #1
On 3/27/2019 6:19 AM, Tom Barbette wrote:
> Signed-off-by: Tom Barbette <barbette@kth.se>


Hi Shahaf,

Reminder of this patch waiting for review.
Ferruh Yigit April 2, 2019, 6:26 p.m. | #2
On 3/27/2019 6:19 AM, Tom Barbette wrote:
> +int
> +mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
> +{
> + struct mlx5_priv *priv = dev->data->dev_private;
> + struct ibv_values_ex values;
> + int err = 0;
> +
> + values.comp_mask = IBV_VALUES_MASK_RAW_CLOCK;
> + err = mlx5_glue->query_rt_values_ex(priv->ctx, &values);

error: no member named 'ctx' in 'struct mlx5_priv'
Tom Barbette April 2, 2019, 7:05 p.m. | #3
Le 02/04/2019 à 20:26, Ferruh Yigit a écrit :
> 
> error: no member named 'ctx' in 'struct mlx5_priv'
> 

Yes indeed, master changed since my last rebase. This is fixed in v3 
(I'll address other comments in related patches before sending v3).

I already addressed Shahaf's comments for this patch in prior discussions.

Thanks,

Tom
Shahaf Shuler April 3, 2019, 5:28 a.m. | #4
Wednesday, March 27, 2019 8:20 AM, Tom Barbette:
> Subject: [PATCH v2 2/3] mlx5: Implement support for read_clock
> 
> Signed-off-by: Tom Barbette <barbette@kth.se>

Apart from the compilation issue I am OK w/ this patch.

You can add my acked-by on v3.

> ---
>  drivers/net/mlx5/mlx5.c        |  1 +
>  drivers/net/mlx5/mlx5.h        |  1 +
>  drivers/net/mlx5/mlx5_ethdev.c | 29 +++++++++++++++++++++++++++++
>  drivers/net/mlx5/mlx5_glue.c   |  8 ++++++++
>  drivers/net/mlx5/mlx5_glue.h   |  2 ++
>  5 files changed, 41 insertions(+)
> 
> diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index
> ae4b71695..7091ff4bb 100644
> --- a/drivers/net/mlx5/mlx5.c
> +++ b/drivers/net/mlx5/mlx5.c
> @@ -376,6 +376,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,
> +	.read_clock = mlx5_read_clock,
>  	.dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
>  	.vlan_filter_set = mlx5_vlan_filter_set,
>  	.rx_queue_setup = mlx5_rx_queue_setup, diff --git
> a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index
> 538445367..88394f391 100644
> --- a/drivers/net/mlx5/mlx5.h
> +++ b/drivers/net/mlx5/mlx5.h
> @@ -275,6 +275,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);  void
> mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info
> *info);
> +int mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *time);
>  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);  int mlx5_link_update(struct rte_eth_dev *dev, int
> wait_to_complete); diff --git a/drivers/net/mlx5/mlx5_ethdev.c
> b/drivers/net/mlx5/mlx5_ethdev.c index f84f7cf69..52262ee44 100644
> --- a/drivers/net/mlx5/mlx5_ethdev.c
> +++ b/drivers/net/mlx5/mlx5_ethdev.c
> @@ -557,6 +557,35 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev,
> struct rte_eth_dev_info *info)
>  	}
>  }
> 
> +/**
> + * Get device current raw clock counter
> + *
> + * @param dev
> + *   Pointer to Ethernet device structure.
> + * @param[out] time
> + *   Current raw clock counter of the device.
> + *
> + * @return
> + *   0 if the clock has correctly been read
> + *   The value of errno in case of error
> + */
> +int
> +mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock) {
> +	struct mlx5_priv *priv = dev->data->dev_private;
> +	struct ibv_values_ex values;
> +	int err = 0;
> +
> +	values.comp_mask = IBV_VALUES_MASK_RAW_CLOCK;
> +	err = mlx5_glue->query_rt_values_ex(priv->ctx, &values);
> +	if (err != 0) {
> +		DRV_LOG(WARNING, "Could not query the clock !");
> +		return err;
> +	}
> +	*clock = values.raw_clock.tv_nsec;
> +	return 0;
> +}
> +
>  /**
>   * Get firmware version of a device.
>   *
> diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c
> index c817d86c5..c1786c5e9 100644
> --- a/drivers/net/mlx5/mlx5_glue.c
> +++ b/drivers/net/mlx5/mlx5_glue.c
> @@ -86,6 +86,13 @@ mlx5_glue_query_device_ex(struct ibv_context
> *context,
>  	return ibv_query_device_ex(context, input, attr);  }
> 
> +static int
> +mlx5_glue_query_rt_values_ex(struct ibv_context *context,
> +			  struct ibv_values_ex *values)
> +{
> +	return ibv_query_rt_values_ex(context, values); }
> +
>  static int
>  mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
>  		     struct ibv_port_attr *port_attr) @@ -603,6 +610,7 @@
> const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
>  	.close_device = mlx5_glue_close_device,
>  	.query_device = mlx5_glue_query_device,
>  	.query_device_ex = mlx5_glue_query_device_ex,
> +	.query_rt_values_ex = mlx5_glue_query_rt_values_ex,
>  	.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/net/mlx5/mlx5_glue.h b/drivers/net/mlx5/mlx5_glue.h index
> b11896062..fd651cc03 100644
> --- a/drivers/net/mlx5/mlx5_glue.h
> +++ b/drivers/net/mlx5/mlx5_glue.h
> @@ -74,6 +74,8 @@ struct mlx5_glue {
>  	int (*query_device_ex)(struct ibv_context *context,
>  			       const struct ibv_query_device_ex_input *input,
>  			       struct ibv_device_attr_ex *attr);
> +	int (*query_rt_values_ex)(struct ibv_context *context,
> +			       struct ibv_values_ex *values);
>  	int (*query_port)(struct ibv_context *context, uint8_t port_num,
>  			  struct ibv_port_attr *port_attr);
>  	struct ibv_comp_channel *(*create_comp_channel)
> --
> 2.17.1

Patch

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index ae4b71695..7091ff4bb 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -376,6 +376,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,
+	.read_clock = mlx5_read_clock,
 	.dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
 	.vlan_filter_set = mlx5_vlan_filter_set,
 	.rx_queue_setup = mlx5_rx_queue_setup,
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 538445367..88394f391 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -275,6 +275,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);
 void mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info);
+int mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *time);
 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);
 int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index f84f7cf69..52262ee44 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -557,6 +557,35 @@  mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	}
 }
 
+/**
+ * Get device current raw clock counter
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param[out] time
+ *   Current raw clock counter of the device.
+ *
+ * @return
+ *   0 if the clock has correctly been read
+ *   The value of errno in case of error
+ */
+int
+mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct ibv_values_ex values;
+	int err = 0;
+
+	values.comp_mask = IBV_VALUES_MASK_RAW_CLOCK;
+	err = mlx5_glue->query_rt_values_ex(priv->ctx, &values);
+	if (err != 0) {
+		DRV_LOG(WARNING, "Could not query the clock !");
+		return err;
+	}
+	*clock = values.raw_clock.tv_nsec;
+	return 0;
+}
+
 /**
  * Get firmware version of a device.
  *
diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c
index c817d86c5..c1786c5e9 100644
--- a/drivers/net/mlx5/mlx5_glue.c
+++ b/drivers/net/mlx5/mlx5_glue.c
@@ -86,6 +86,13 @@  mlx5_glue_query_device_ex(struct ibv_context *context,
 	return ibv_query_device_ex(context, input, attr);
 }
 
+static int
+mlx5_glue_query_rt_values_ex(struct ibv_context *context,
+			  struct ibv_values_ex *values)
+{
+	return ibv_query_rt_values_ex(context, values);
+}
+
 static int
 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
 		     struct ibv_port_attr *port_attr)
@@ -603,6 +610,7 @@  const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
 	.close_device = mlx5_glue_close_device,
 	.query_device = mlx5_glue_query_device,
 	.query_device_ex = mlx5_glue_query_device_ex,
+	.query_rt_values_ex = mlx5_glue_query_rt_values_ex,
 	.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/net/mlx5/mlx5_glue.h b/drivers/net/mlx5/mlx5_glue.h
index b11896062..fd651cc03 100644
--- a/drivers/net/mlx5/mlx5_glue.h
+++ b/drivers/net/mlx5/mlx5_glue.h
@@ -74,6 +74,8 @@  struct mlx5_glue {
 	int (*query_device_ex)(struct ibv_context *context,
 			       const struct ibv_query_device_ex_input *input,
 			       struct ibv_device_attr_ex *attr);
+	int (*query_rt_values_ex)(struct ibv_context *context,
+			       struct ibv_values_ex *values);
 	int (*query_port)(struct ibv_context *context, uint8_t port_num,
 			  struct ibv_port_attr *port_attr);
 	struct ibv_comp_channel *(*create_comp_channel)