From: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
To: Binoy Jayan <binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
Hal Rosenstock
<hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v3 8/9] IB/mlx5: Add helper mlx5_ib_post_send_wait
Date: Wed, 26 Oct 2016 10:48:26 +0200 [thread overview]
Message-ID: <12933685.Se3eQHi9An@wuerfel> (raw)
In-Reply-To: <1477468874-16328-9-git-send-email-binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
On Wednesday, October 26, 2016 1:31:13 PM CEST Binoy Jayan wrote:
> +static inline int mlx5_ib_post_send_wait(struct mlx5_ib_dev *dev,
> + struct mlx5_umr_wr *umrwr)
> +{
> + struct umr_common *umrc = &dev->umrc;
> + struct ib_send_wr *bad;
> + int err;
> + struct mlx5_ib_umr_context umr_context;
> +
> + mlx5_ib_init_umr_context(&umr_context);
> + umrwr->wr.wr_cqe = &umr_context.cqe;
> +
> + down(&umrc->sem);
> + err = ib_post_send(umrc->qp, &umrwr->wr, &bad);
> + if (err) {
> + mlx5_ib_warn(dev, "UMR post send failed, err %d\n", err);
> + } else {
> + wait_for_completion(&umr_context.done);
> + if (umr_context.status != IB_WC_SUCCESS) {
> + mlx5_ib_warn(dev, "reg umr failed (%u)\n",
> + umr_context.status);
> + err = -EFAULT;
> + }
> + }
> + up(&umrc->sem);
> + return err;
> +}
>
Looks nice!
Now that this has become the only use of the semaphore (and the
last one in infiniband I guess), I wonder if we can agree on a way
to get rid of that one too. How about
/* limit number of concurrent ib_post_send() on qp */
wait_event(&umrc->wq, atomic_add_unless(&umrc->users, 1, MAX_UMR_WR);
...
atomic_dec(&umrc->users);
wake_up(&umrc->wq);
That would be a fairly simple conversion and document better
what we actually do here: the down() looks like a simple mutex,
which it isn't.
In terms of efficiency, the wait_event() is actually better
here for the common case that the semaphore is not contented
as it only needs a single atomic operation and a branch
instead of an external function call and a spinlock in down().
However, the wake_up() is slightly better than atomic_dec()+up()
as it avoids the additional atomic.
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Arnd Bergmann <arnd@arndb.de>
To: Binoy Jayan <binoy.jayan@linaro.org>
Cc: Doug Ledford <dledford@redhat.com>,
Sean Hefty <sean.hefty@intel.com>,
Hal Rosenstock <hal.rosenstock@gmail.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 8/9] IB/mlx5: Add helper mlx5_ib_post_send_wait
Date: Wed, 26 Oct 2016 10:48:26 +0200 [thread overview]
Message-ID: <12933685.Se3eQHi9An@wuerfel> (raw)
In-Reply-To: <1477468874-16328-9-git-send-email-binoy.jayan@linaro.org>
On Wednesday, October 26, 2016 1:31:13 PM CEST Binoy Jayan wrote:
> +static inline int mlx5_ib_post_send_wait(struct mlx5_ib_dev *dev,
> + struct mlx5_umr_wr *umrwr)
> +{
> + struct umr_common *umrc = &dev->umrc;
> + struct ib_send_wr *bad;
> + int err;
> + struct mlx5_ib_umr_context umr_context;
> +
> + mlx5_ib_init_umr_context(&umr_context);
> + umrwr->wr.wr_cqe = &umr_context.cqe;
> +
> + down(&umrc->sem);
> + err = ib_post_send(umrc->qp, &umrwr->wr, &bad);
> + if (err) {
> + mlx5_ib_warn(dev, "UMR post send failed, err %d\n", err);
> + } else {
> + wait_for_completion(&umr_context.done);
> + if (umr_context.status != IB_WC_SUCCESS) {
> + mlx5_ib_warn(dev, "reg umr failed (%u)\n",
> + umr_context.status);
> + err = -EFAULT;
> + }
> + }
> + up(&umrc->sem);
> + return err;
> +}
>
Looks nice!
Now that this has become the only use of the semaphore (and the
last one in infiniband I guess), I wonder if we can agree on a way
to get rid of that one too. How about
/* limit number of concurrent ib_post_send() on qp */
wait_event(&umrc->wq, atomic_add_unless(&umrc->users, 1, MAX_UMR_WR);
...
atomic_dec(&umrc->users);
wake_up(&umrc->wq);
That would be a fairly simple conversion and document better
what we actually do here: the down() looks like a simple mutex,
which it isn't.
In terms of efficiency, the wait_event() is actually better
here for the common case that the semaphore is not contented
as it only needs a single atomic operation and a branch
instead of an external function call and a spinlock in down().
However, the wake_up() is slightly better than atomic_dec()+up()
as it avoids the additional atomic.
Arnd
next prev parent reply other threads:[~2016-10-26 8:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-26 8:01 [PATCH v3 0/9] infiniband: Remove semaphores Binoy Jayan
2016-10-26 8:01 ` Binoy Jayan
[not found] ` <1477468874-16328-1-git-send-email-binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-10-26 8:01 ` [PATCH v3 1/9] IB/core: iwpm_nlmsg_request: Replace semaphore with completion Binoy Jayan
2016-10-26 8:01 ` Binoy Jayan
2016-10-26 8:01 ` [PATCH v3 5/9] IB/isert: Replace semaphore sem " Binoy Jayan
2016-10-26 8:01 ` Binoy Jayan
2016-10-26 8:01 ` [PATCH v3 8/9] IB/mlx5: Add helper mlx5_ib_post_send_wait Binoy Jayan
2016-10-26 8:01 ` Binoy Jayan
[not found] ` <1477468874-16328-9-git-send-email-binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-10-26 8:48 ` Arnd Bergmann [this message]
2016-10-26 8:48 ` Arnd Bergmann
2016-10-27 6:09 ` Leon Romanovsky
2016-10-27 6:09 ` Leon Romanovsky
2016-10-26 8:01 ` [PATCH v3 9/9] IB/mlx5: Simplify completion into a wait_event Binoy Jayan
2016-10-26 8:01 ` Binoy Jayan
2016-10-26 8:01 ` [PATCH v3 2/9] IB/core: Replace semaphore sm_sem with an atomic wait Binoy Jayan
2016-10-26 8:01 ` [PATCH v3 3/9] IB/hns: Replace semaphore poll_sem with mutex Binoy Jayan
2016-10-26 8:01 ` [PATCH v3 4/9] IB/mthca: " Binoy Jayan
2016-10-26 8:01 ` [PATCH v3 6/9] IB/hns: Replace counting semaphore event_sem with wait_event Binoy Jayan
2016-10-26 8:01 ` [PATCH v3 7/9] IB/mthca: " Binoy Jayan
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=12933685.Se3eQHi9An@wuerfel \
--to=arnd-r2ngtmty4d4@public.gmane.org \
--cc=binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.