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

Move emscripten_atomic_wait_async to atomic.h and add core testing #20404

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Oct 5, 2023

This API was orininally added for wasm workers but is not wasm worker specific.

As part of making this API compatible with pthreads I added support for
runtimeKeepalivePush/Pop and callUserCallback which means that this PR
subsumes #20306.

Followup to #20381.

@sbc100 sbc100 force-pushed the move_wait_async branch 9 times, most recently from acbdf92 to 1fe2c44 Compare October 11, 2023 19:11
src/library_atomic.js Outdated Show resolved Hide resolved
$polyfillWaitAsync: () => {
// nop, used for its postset to ensure waitAsync() polyfill is included
// exaclyt once.
// Any function using Atomics.waitAsync should depend on this.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I suppose you are looking to fix a situation where only JS code would ever be doing Atomics.waitAsync()s, and Wasm code is doing all the wakes, hence the polyfill would never be emitted?

This situation looks like something that would be good to go in the Atomics related documentation?

Copy link
Collaborator

@juj juj Oct 16, 2023

Choose a reason for hiding this comment

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

Reviewing this PR for these functional changes is a bit tricky, given the code move. Are there other functional differences?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I suppose you are looking to fix a situation where only JS code would ever be doing Atomics.waitAsync()s, and Wasm code is doing all the wakes, hence the polyfill would never be emitted?

This situation looks like something that would be good to go in the Atomics related documentation?

I'm not quite sure I understand. Atomics.waitAsync can only ever be performed by JS code, since its JS only function, right? There is no wasm version of it.

This dependency just means the polyfill is only ever included when the library functions that call it are included. Isn't that desirable? Or would you rather the polyfill always be included?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reviewing this PR for these functional changes is a bit tricky, given the code move. Are there other functional differences?

I'm pretty sure I didn't change anything functionally on the JS library side, just moved stuff around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I suppose you are looking to fix a situation where only JS code would ever be doing Atomics.waitAsync()s, and Wasm code is doing all the wakes, hence the polyfill would never be emitted?

This situation looks like something that would be good to go in the Atomics related documentation?

I can split out the __deps fix and land that first to make it more obvious what is going on here ..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is one change to the JS code here, in order to support running emscripten_atomic_wait_async under node: I added runtimeKeepalivePush/runtimeKeepalivePop and callUserCallback to emscripten_atomic_wait_async. This means that the runtime will not exit will async waits are running, but will exit cleanly once the last one is done.

sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 17, 2023
Split out from emscripten-core#20404.

Rather than adding artificial dependencies on
`emscripten_atomic_wait_async` we can use the same technique used by
`$polyfillSetImmediate` in `library_eventloop.js`.
sbc100 added a commit that referenced this pull request Oct 19, 2023
Split out from #20404.

Rather than adding artificial dependencies on
`emscripten_atomic_wait_async` we can use the same technique used by
`$polyfillSetImmediate` in `library_eventloop.js`.
@sbc100
Copy link
Collaborator Author

sbc100 commented Oct 19, 2023

Rebased on top of #20474

@sbc100 sbc100 requested review from juj and kripken October 19, 2023 16:48
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Reviewing the changes since my last lgtm, all the changed files lgtm aside from src/library_atomic.js which has changes and is very large. Any chance you have a diff compared to my last review?

I think adding commits on top of an existing PR is really better for this workflow, as I've said in the past. For small stuff it doesn't matter, but there's 150 lines of code in that file here.

@sbc100
Copy link
Collaborator Author

sbc100 commented Oct 19, 2023

Reviewing the changes since my last lgtm, all the changed files lgtm aside from src/library_atomic.js which has changes and is very large. Any chance you have a diff compared to my last review?

I think adding commits on top of an existing PR is really better for this workflow, as I've said in the past. For small stuff it doesn't matter, but there's 150 lines of code in that file here.

Nothing should have changed here since that last review, just rebased on top of #20474

@sbc100
Copy link
Collaborator Author

sbc100 commented Oct 19, 2023

I think adding commits on top of an existing PR is really better for this workflow, as I've said in the past. For small stuff it doesn't matter, but there's 150 lines of code in that file here.

The reason that is hard for me to do that since my workflow is basically a rebase one. I use git rebase-update to rebase all my active branches (normally > 30 at any given time). I suppose could have a list of branches that I opt out of the rebase flow and use a merge flow instead for them but I fear it would add a fair amount of overhead, and I'm not sure I how I would decide for a given PR if i use switch to the merge flow (which I am less familiar with).

How about this: The next time you see a PR from me that you think you would rather see review in a merge workflow can you comment there and I will give it a try.

@kripken
Copy link
Member

kripken commented Oct 19, 2023

Rebasing sgtm - it's the squashing that is the issue for me, iiuc.

That is, if this PR had one commit, then you realized the need for a fix so you added another commit, and then you rebased them both on main, that would be fine: I'd review the second commit in detail (I'd still need to look at the first commit, so it's not as good as a merge-based workflow, but I can live with that).

Is adding more commits as you go tricky for some reason? Does the rebase workflow always squash them for you for some reason?

@sbc100
Copy link
Collaborator Author

sbc100 commented Oct 19, 2023

Rebasing sgtm - it's the squashing that is the issue for me, iiuc.

That is, if this PR had one commit, then you realized the need for a fix so you added another commit, and then you rebased them both on main, that would be fine: I'd review the second commit in detail (I'd still need to look at the first commit, so it's not as good as a merge-based workflow, but I can live with that).

Is adding more commits as you go tricky for some reason? Does the rebase workflow always squash them for you for some reason?

Ah no, you are right, its the rebasing that is kind of key to my workflow, not the constant squashing. I could avoid that in some cases.

However, IIRC github still gets confused about incremental reviewing when rebasing happens, even if squashing doesn't happen. You can still review each commit if you like, but githubs "show be whats changed since I last looked" feature I think doesn't work.

@kripken
Copy link
Member

kripken commented Oct 19, 2023

At least in this PR "show me what changed" seems to have worked. Some files were marked as unchanged and some were marked as changed. (I didn't have a way to verify that it was the right ones, though.)

This API was orininally added for wasm workers but is not wasm worker
specific.

Followup to emscripten-core#20381.
@sbc100 sbc100 enabled auto-merge (squash) October 23, 2023 23:46
@sbc100 sbc100 merged commit a0a3f24 into emscripten-core:main Oct 24, 2023
2 checks passed
@sbc100 sbc100 deleted the move_wait_async branch October 24, 2023 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants