DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shahaf Shuler <shahafs@mellanox.com>
To: Slava Ovsiienko <viacheslavo@mellanox.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH 4/4] net/mlx5: add mutex for shared DV/DR structures
Date: Tue, 2 Apr 2019 19:09:57 +0000	[thread overview]
Message-ID: <AM0PR0502MB3795DA569663C99BC486FB5EC3560@AM0PR0502MB3795.eurprd05.prod.outlook.com> (raw)
Message-ID: <20190402190957.BmFfd9xsNvYGxwALzDAysbtvfZqZSrYmQ5fxNx5yids@z> (raw)
In-Reply-To: <1554186157-29455-5-git-send-email-viacheslavo@mellanox.com>

Tuesday, April 2, 2019 9:23 AM, Viacheslav Ovsiienko:
> Subject: [PATCH 4/4] net/mlx5: add mutex for shared DV/DR structures

Same comment about title. 

> 
> This patch introduces the mutex for shared DV/DR structures.
> Application may have multiple threads (but single dedicated thread per port).
> Due to sharing the IB context in the multiport IB device configurations we
> should synchronize access to the shared DV/DR flow structures.
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> ---
>  drivers/net/mlx5/mlx5.c         |   6 +++
>  drivers/net/mlx5/mlx5.h         |   1 +
>  drivers/net/mlx5/mlx5_flow_dv.c | 103
> ++++++++++++++++++++++++++++++++++++++--
>  3 files changed, 106 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index
> 369b698..96ad4c6 100644
> --- a/drivers/net/mlx5/mlx5.c
> +++ b/drivers/net/mlx5/mlx5.c
> @@ -312,6 +312,7 @@ struct mlx5_dev_spawn_data {
> mlx5_alloc_shared_dv(struct mlx5_priv *priv)  {
>  	struct mlx5_ibv_shared *sh = priv->sh;
> +	pthread_mutexattr_t mattr;
>  	int err = 0;
>  	void *ns;
> 
> @@ -336,6 +337,10 @@ struct mlx5_dev_spawn_data {
>  		err = errno;
>  		goto error;
>  	}
> +	pthread_mutexattr_init(&mattr);
> +	pthread_mutexattr_settype(&mattr,
> PTHREAD_MUTEX_RECURSIVE);

Please add inline comment about why you use this type of mutex (so that you can use a single mutex for the entire flow engine logic). 

> +	pthread_mutex_init(&sh->dv_mutex, &mattr);
> +	pthread_mutexattr_destroy(&mattr);
>  	sh->tx_ns = ns;
>  	sh->dv_refcnt++;
>  	priv->dv_shared = 1;
> @@ -381,6 +386,7 @@ struct mlx5_dev_spawn_data {
>  		mlx5dv_dr_destroy_ns(sh->tx_ns);
>  		sh->tx_ns = NULL;
>  	}
> +	pthread_mutex_destroy(&sh->dv_mutex);
>  }
>  #endif
> 
> diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index
> e67227f..4f6c1b7 100644
> --- a/drivers/net/mlx5/mlx5.h
> +++ b/drivers/net/mlx5/mlx5.h
> @@ -223,6 +223,7 @@ struct mlx5_ibv_shared {
>  	char ibdev_path[IBV_SYSFS_PATH_MAX]; /* IB device path for
> secondary */
>  	struct ibv_device_attr_ex device_attr; /* Device properties. */
>  	/* Shared DV/DR flow data section. */
> +	pthread_mutex_t dv_mutex; /* DV context mutex. */
>  	uint32_t dv_refcnt; /* DV/DR data reference counter. */
>  	void *rx_ns; /* RX Direct Rules name space handle. */
>  	struct mlx5_flow_tbl_resource rx_tbl[MLX5_MAX_TABLES]; diff --git
> a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
> index 4912fc8..737011a 100644
> --- a/drivers/net/mlx5/mlx5_flow_dv.c
> +++ b/drivers/net/mlx5/mlx5_flow_dv.c
> @@ -125,6 +125,45 @@ struct field_modify_info modify_tcp[] = {  };
> 
>  /**
> + * Acquire the synchronizing object to protect multithreaded access
> + * to shared dv context. Lock occurs only if context is actually
> + * shared, i.e. we have multiport IB device and representors are
> + * created.
> + *
> + * @param[in] dev
> + *   Pointer to the rte_eth_dev structure.
> + */
> +static void
> +flow_d_shared_lock(struct rte_eth_dev *dev) {
> +	struct mlx5_priv *priv = dev->data->dev_private;
> +	struct mlx5_ibv_shared *sh = priv->sh;
> +
> +	if (sh->dv_refcnt > 1) {
> +		int ret;
> +
> +		ret = pthread_mutex_lock(&sh->dv_mutex);
> +		assert(!ret);
> +		(void)ret;
> +	}
> +}
> +
> +static void
> +flow_d_shared_unlock(struct rte_eth_dev *dev) {
> +	struct mlx5_priv *priv = dev->data->dev_private;
> +	struct mlx5_ibv_shared *sh = priv->sh;
> +
> +	if (sh->dv_refcnt > 1) {
> +		int ret;
> +
> +		ret = pthread_mutex_unlock(&sh->dv_mutex);
> +		assert(!ret);
> +		(void)ret;
> +	}
> +}
> +
> +/**
>   * Convert modify-header action to DV specification.
>   *
>   * @param[in] item
> @@ -3958,14 +3997,70 @@ struct field_modify_info modify_tcp[] = {
>  	return ret;
>  }
> 
> +/*
> + * Mutex-protected thunk to flow_dv_translate().
> + */
> +static int
> +flow_d_translate(struct rte_eth_dev *dev,
> +		 struct mlx5_flow *dev_flow,
> +		 const struct rte_flow_attr *attr,
> +		 const struct rte_flow_item items[],
> +		 const struct rte_flow_action actions[],
> +		 struct rte_flow_error *error)
> +{
> +	int ret;
> +
> +	flow_d_shared_lock(dev);
> +	ret = flow_dv_translate(dev, dev_flow, attr, items, actions, error);
> +	flow_d_shared_unlock(dev);
> +	return ret;
> +}
> +
> +/*
> + * Mutex-protected thunk to flow_dv_apply().
> + */
> +static int
> +flow_d_apply(struct rte_eth_dev *dev,
> +	     struct rte_flow *flow,
> +	     struct rte_flow_error *error)
> +{
> +	int ret;
> +
> +	flow_d_shared_lock(dev);
> +	ret = flow_dv_apply(dev, flow, error);
> +	flow_d_shared_unlock(dev);
> +	return ret;
> +}
> +
> +/*
> + * Mutex-protected thunk to flow_dv_remove().
> + */
> +static void
> +flow_d_remove(struct rte_eth_dev *dev, struct rte_flow *flow) {
> +	flow_d_shared_lock(dev);
> +	flow_dv_remove(dev, flow);
> +	flow_d_shared_unlock(dev);
> +}
> +
> +/*
> + * Mutex-protected thunk to flow_dv_destroy().
> + */
> +static void
> +flow_d_destroy(struct rte_eth_dev *dev, struct rte_flow *flow) {
> +	flow_d_shared_lock(dev);
> +	flow_dv_destroy(dev, flow);
> +	flow_d_shared_unlock(dev);
> +}
> 
>  const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
>  	.validate = flow_dv_validate,
>  	.prepare = flow_dv_prepare,
> -	.translate = flow_dv_translate,
> -	.apply = flow_dv_apply,
> -	.remove = flow_dv_remove,
> -	.destroy = flow_dv_destroy,
> +	.translate = flow_d_translate,
> +	.apply = flow_d_apply,
> +	.remove = flow_d_remove,
> +	.destroy = flow_d_destroy,
>  	.query = flow_dv_query,
>  };
> 
> --
> 1.8.3.1


  parent reply	other threads:[~2019-04-02 19:10 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02  6:22 [dpdk-dev] [PATCH 0/4] support DR/DV flows over shared IB context Viacheslav Ovsiienko
2019-04-02  6:22 ` Viacheslav Ovsiienko
2019-04-02  6:22 ` [dpdk-dev] [PATCH 1/4] net/mlx5: add DV/DR flow data alloc/free routines Viacheslav Ovsiienko
2019-04-02  6:22   ` Viacheslav Ovsiienko
2019-04-02 19:09   ` Shahaf Shuler
2019-04-02 19:09     ` Shahaf Shuler
2019-04-02  6:22 ` [dpdk-dev] [PATCH 2/4] net/mlx5: add reference counter for DV/DR structures Viacheslav Ovsiienko
2019-04-02  6:22   ` Viacheslav Ovsiienko
2019-04-02 19:09   ` Shahaf Shuler
2019-04-02 19:09     ` Shahaf Shuler
2019-04-03 13:27     ` Slava Ovsiienko
2019-04-03 13:27       ` Slava Ovsiienko
2019-04-02  6:22 ` [dpdk-dev] [PATCH 3/4] net/mlx5: share DV/DR flow related structures Viacheslav Ovsiienko
2019-04-02  6:22   ` Viacheslav Ovsiienko
2019-04-02 19:09   ` Shahaf Shuler
2019-04-02 19:09     ` Shahaf Shuler
2019-04-02  6:22 ` [dpdk-dev] [PATCH 4/4] net/mlx5: add mutex for shared DV/DR structures Viacheslav Ovsiienko
2019-04-02  6:22   ` Viacheslav Ovsiienko
2019-04-02 19:09   ` Shahaf Shuler [this message]
2019-04-02 19:09     ` Shahaf Shuler
2019-04-04 13:04 ` [dpdk-dev] [PATCH v2 0/2] support Direct Rules flows over shared IB context Viacheslav Ovsiienko
2019-04-04 13:04   ` Viacheslav Ovsiienko
2019-04-04 13:04   ` [dpdk-dev] [PATCH v2 1/2] net/mlx5: add Direct Rules flow data alloc/free routines Viacheslav Ovsiienko
2019-04-04 13:04     ` Viacheslav Ovsiienko
2019-04-04 13:04   ` [dpdk-dev] [PATCH v2 2/2] net/mlx5: share Direct Rules/Verbs flow related structures Viacheslav Ovsiienko
2019-04-04 13:04     ` Viacheslav Ovsiienko
2019-04-04 18:57   ` [dpdk-dev] [PATCH v2 0/2] support Direct Rules flows over shared IB context Shahaf Shuler
2019-04-04 18:57     ` Shahaf Shuler

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=AM0PR0502MB3795DA569663C99BC486FB5EC3560@AM0PR0502MB3795.eurprd05.prod.outlook.com \
    --to=shahafs@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=viacheslavo@mellanox.com \
    /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).