From: Arnd Bergmann <arnd@arndb.de>
To: Binoy Jayan <binoy.jayan@linaro.org>
Cc: Sagi Grimberg <sagi@grimberg.me>,
Doug Ledford <dledford@redhat.com>,
Sean Hefty <sean.hefty@intel.com>,
Hal Rosenstock <hal.rosenstock@gmail.com>,
linux-rdma@vger.kernel.org,
Linux kernel mailing list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 05/10] IB/isert: Replace semaphore sem with completion
Date: Fri, 18 Nov 2016 09:58:15 +0100 [thread overview]
Message-ID: <3477625.cZS9dUaHfE@wuerfel> (raw)
In-Reply-To: <CAHv-k__HHRzK7+AZ912GVw9ToxZWMw3OccPqgGt_NBf6+RXdzA@mail.gmail.com>
On Friday, November 18, 2016 12:27:32 PM CET Binoy Jayan wrote:
> Hi Sagi,
>
> On 31 October 2016 at 02:42, Sagi Grimberg <sagi@grimberg.me> wrote:
> >> The semaphore 'sem' in isert_device is used as completion, so convert
> >> it to struct completion. Semaphores are going away in the future.
> >
> >
> > Umm, this is 100% *not* true. np->sem is designed as a counting to
> > sync the iscsi login thread with the connect requests coming from the
> > initiators. So this is actually a reliable bug insertion :(
> >
> > NAK from me...
>
> Sorry for the late reply as I was held up in other activities.
>
> I converted this to a wait_event() implementation but as I was doing it,
> I was wondering how it would have been different if it was a completion
> and not a semaphore.
>
> File: drivers/infiniband/ulp/isert/ib_isert.c
>
> If isert_connected_handler() is called multiple times, adding an entry to the
> list, and if that happens while we use completion, 'done' (part of struct
> completion) would be incremented by 1 each time 'complete' is called from
> isert_connected_handler. After 'n' iterations, done will be equal to 'n'. If we
> call wait_for_completion now from isert_accept_np, it would just decrement
> 'done' by one and continue without blocking, consuming one node at a time
> from the list 'isert_np->pending'.
>
> Alternatively if "done" becomes zero, and the next time wait_for_completion is
> called, the API would add a node at the end of the wait queue 'wait' in 'struct
> completion' and block until "done" is nonzero. (Ref: do_wait_for_common)
> It exists the wait when a call to 'complete' turns 'done' back to 1.
> But if there
> are multiple waits called before calling complete, all the tasks
> calling the wait
> gets queued up and they will all would see "done" set to zero. When complete
> is called now, done turns 1 again and the first task in the queue is woken up
> as it is serialized as FIFO. Now the first wait returns and the done is
> decremented by 1 just before the return.
>
> Am I missing something here?
I think you are right. This is behavior is actuallly documented in
Documentation/scheduler/completion.txt:
If complete() is called multiple times then this will allow for that number
of waiters to continue - each call to complete() will simply increment the
done element. Calling complete_all() multiple times is a bug though. Both
complete() and complete_all() can be called in hard-irq/atomic context
safely.
However, this is fairly unusual behavior and I wasn't immediately aware
of it either when I read Sagi's reply. While your patch looks correct,
it's probably a good idea to point out the counting behavior of this
completion as explicitly as possible, in the changelog text of the patch
as well as in a code comment and perhaps in the naming of the completion.
Arnd
next prev parent reply other threads:[~2016-11-18 8:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-27 6:59 [PATCH v4 00/10] infiniband: Remove semaphores Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 01/10] IB/core: iwpm_nlmsg_request: Replace semaphore with completion Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 03/10] IB/hns: Replace semaphore poll_sem with mutex Binoy Jayan
[not found] ` <1477551554-30349-1-git-send-email-binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-10-27 6:59 ` [PATCH v4 02/10] IB/core: Replace semaphore sm_sem with an atomic wait Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 04/10] IB/mthca: Replace semaphore poll_sem with mutex Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 05/10] IB/isert: Replace semaphore sem with completion Binoy Jayan
[not found] ` <1477551554-30349-6-git-send-email-binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-10-30 21:12 ` Sagi Grimberg
[not found] ` <a267cc5e-4d4f-368e-a159-3eecc2187969-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
2016-11-18 6:57 ` Binoy Jayan
2016-11-18 8:58 ` Arnd Bergmann [this message]
2016-11-18 9:10 ` Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 08/10] IB/mlx5: Add helper mlx5_ib_post_send_wait Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 09/10] IB/mlx5: Replace semaphore umr_common:sem with wait_event Binoy Jayan
2016-10-27 7:13 ` [PATCH v4 00/10] infiniband: Remove semaphores Leon Romanovsky
2016-10-27 6:59 ` [PATCH v4 06/10] IB/hns: Replace counting semaphore event_sem with wait_event Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 07/10] IB/mthca: " Binoy Jayan
2016-10-27 6:59 ` [PATCH v4 10/10] IB/mlx5: Simplify completion into a wait_event Binoy Jayan
[not found] ` <1477551554-30349-11-git-send-email-binoy.jayan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-10-30 21:17 ` Sagi Grimberg
[not found] ` <8ceb7dbf-d242-1427-199a-b6ec82876f23-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
2016-11-02 15:59 ` Leon Romanovsky
2016-11-03 6:03 ` Binoy Jayan
2016-11-03 15:37 ` Linus Torvalds
2016-11-07 5:51 ` 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=3477625.cZS9dUaHfE@wuerfel \
--to=arnd@arndb.de \
--cc=binoy.jayan@linaro.org \
--cc=dledford@redhat.com \
--cc=hal.rosenstock@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=sagi@grimberg.me \
--cc=sean.hefty@intel.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