Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.10: coll/libnbc: fix race condition with multi threaded apps #2443

Merged
merged 2 commits into from
Dec 1, 2016

Conversation

ggouaillardet
Copy link
Contributor

protect the mca_coll_libnbc_component.active_requests list with
the new mca_coll_libnbc_component.lock mutex.

Thanks Jie Hu for the report

Signed-off-by: Gilles Gouaillardet gilles@rist.or.jp

(back-ported from commit 2c94a3a)

@bosilca
Copy link
Member

bosilca commented Nov 21, 2016

@ggouaillardet This code is pretty complicated, and honestly it deserves a comment on why this approach is correct. I haven't had time to dig deep into the code but from a quick look I am not sure about the correctness of this code in a multi-threaded scenario. You added a mutex to protect the modifications of the active request list, but because this list can be modified outside the progress function, your local next (the one protected by the newly added mutex) might become stale. However, if the progress is the only function allowed to remove active requests, then my comment is not holding and the proposed code is correct (but deserves documentation).

@jjhursey
Copy link
Member

We can keep the discussion here (moving my question from PR #2441):

I'm curious why you didn't just reuse mca_coll_libnbc_component.progress_lock? Since the progress function is already protected by that lock then you would not have to grab another lock in there, but instead just protect the opal_list_append.

... Thinking about this a bit more, and let me know if I'm correct here...
The next stage of the collective is started from inside the NBC_Progress call, so the lock would need to be released across that call in order not to deadlock. In that case it would make sense to have a separate lock, but it feels like we might be able to get away with only one lock to reduce the overhead of the progress function. But I'm going to have to think more about that.

@ggouaillardet
Copy link
Contributor Author

@bosilca the MPI layer opal_list_append() and the progress thread opal_list_remove_item(),
so i think the code i correct and it does deserve some documentation as you pointed. will do.

@jjhursey my understanding is that mca_coll_libnbc_component.progress_lock role is to avoid recursivity in the progress thread. i need to double check that, and hopefully get rid of this lock since it looks both inefficient and inelegant.
regardless, mca_coll_libnbc_component.progress_lock is held for "some time" by the progress thread, whereas mca_coll_libnbc_component.lock is only held to access the mca_coll_libnbc_component.active_requests. bottom line using a second lock avoids the MPI layer being slowed down by the progress thread.

@jjhursey
Copy link
Member

@ggouaillardet This commit looks correct to me. It protects the .active_requests list when needed, and I don't see how we could get into a situation where we try to lock twice. Using the separate lock makes sense to me. The progress_lock is, as you mention, meant to prevent recursively calling that progress function. There might be a more elegant way to do this, but that can be a different PR.

@bosilca The progress function is the only place where requests are removed from this structure so I think the locking is safe.

I think that all this PR needs is a comment about what this lock is protecting. Maybe inside the ompi_coll_libnbc_progress function or where it is declared. Then I think this PR is good to merge.

@ggouaillardet
Copy link
Contributor Author

@jjhursey thanks ! wil add comment today, sorry for the delay

protect the mca_coll_libnbc_component.active_requests list with
the new mca_coll_libnbc_component.lock mutex.

Thanks Jie Hu for the report

Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>

(back-ported from commit open-mpi/ompi@2c94a3a)
no code change

Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>

(cherry picked from commit open-mpi/ompi@1509816)
@ggouaillardet
Copy link
Contributor Author

@bosilca i added some comments in 1509816 and updated the PR for the three release branches

Copy link
Member

@bosilca bosilca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely. This looks ready to go !

@rhc54 rhc54 merged commit 0b793b9 into open-mpi:v1.10 Dec 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants