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

Cleaning up coroutine implementation #3126

Merged
merged 1 commit into from Feb 1, 2018
Merged

Cleaning up coroutine implementation #3126

merged 1 commit into from Feb 1, 2018

Conversation

sithhell
Copy link
Member

Proposed Changes

  • Removing dynamic memory allocation
  • Removing intrusive ptr
  • Removing unused functions
  • Simplifying thread functions to be nullary
  • Using thread_data directly to get/set the state_ex value

Any background context you want to provide?

This patch both simplifies and cleans up current code. This patch gives a rough speedup of about 1.5x for small grain sizes leading to heavy contention in the thread scheduler.

There is a potential breaking change for third party code using thread functions directly. I think this code is minimal and should be mostly under our control.

@hkaiser
Copy link
Member

hkaiser commented Jan 26, 2018

As said on IRC, I'm slightly worried that this PR removes the previously existing symmetry between the functionality provided by yielding a thread and terminating a thread. While yielding still does allow for specifying another thread-id to the scheduler, instructing it to run the given thread first, this is not possible for terminating threads anymore (i.e. terminating threads do not allow to specify a continuation thread anymore).

@sithhell
Copy link
Member Author

sithhell commented Jan 29, 2018

I've put the thread function returns back in.

@@ -517,7 +516,7 @@ namespace hpx { namespace threads
coroutine_type::result_type operator()()
{
HPX_ASSERT(this == coroutine_.get_thread_id().get());
return coroutine_(set_state_ex(wait_signaled));
return coroutine_();
Copy link
Member

@hkaiser hkaiser Jan 29, 2018

Choose a reason for hiding this comment

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

Shouldn't set_state_ex(wait_signaled) still be called here anyways (before the call to the coroutine)?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are currently 3 state transitions:

I don't see a reason to reset the state_ex at each coroutine invocation.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, makes sense. Thanks for the explanations.

}
catch (boost::exception const&) {
status = super_type::ctx_exited_abnormally;
tinfo = std::current_exception();
this->reset();
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest adding an assert here making sure the returned state == terminated.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@@ -94,7 +92,7 @@ struct hpx_driver : htts2::driver
using hpx::util::placeholders::_1;
Copy link
Member

Choose a reason for hiding this comment

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

The using declaration could be removed now.

 - Removing dynamic memory allocation
 - Removing intrusive ptr
 - Removing unused functions
 - Simplifying thread functions
 - Using thread_data directly to get/set the state_ex value
Copy link
Member

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@msimberg (release) please note that this is a high risk change. Please merge only if you believe it does not cause undue problems for the release..

@msimberg
Copy link
Contributor

msimberg commented Feb 1, 2018

@hkaiser Thanks for the heads up. I'll go ahead and merge this since this would be a very nice improvement to have in the release, but I'll revert if there are any signs of trouble. Please don't merge other PRs while this is being tested on buildbot.

@msimberg msimberg merged commit 4df531c into master Feb 1, 2018
@hkaiser hkaiser deleted the coroutine_cleanup branch February 1, 2018 23:34
sithhell pushed a commit that referenced this pull request Feb 2, 2018
This patch reverts the changes related to the thread state_ex changes as they
seem to lead to overall problems.
sithhell pushed a commit that referenced this pull request Feb 2, 2018
This patch reverts the changes related to the thread state_ex changes as they
seem to lead to overall problems.
sithhell pushed a commit that referenced this pull request Feb 2, 2018
This patch reverts the changes related to the thread state_ex changes as they
seem to lead to overall problems.
hkaiser added a commit that referenced this pull request Feb 3, 2018
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.

None yet

3 participants