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

threads: log every wait and notify #7220

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Oct 11, 2023

When troubleshooting deadlocks in WebAssembly modules, it is important to understand which wait instructions are still pending a notify. It would be nice to have some kind of --warn-deadlock-after=1s flag available that would poll the parking lot for waits hanging past the time limit, but I realized the real value would be to tie the wait instruction (through CLIF) to the original source code, if debug information were available. This did not seem to be entirely feasible, since CLIF loses the original Wasm source context (is this true?) and I was not confident that we would be able to use addr2line to map from Wasm instructions to source (e.g., see @cfallin's issue).

Instead, this change simply logs each valid wait and notify execution, leaving it to the user to figure out which one is hanging (should not be too difficult) and how to map this back to their source code (more difficult).

When troubleshooting deadlocks in WebAssembly modules, it is important
to understand which `wait` instructions are still pending a `notify`.
It would be nice to have some kind of `--warn-deadlock-after=1s` flag
available that would poll the parking lot for `wait`s hanging past the
time limit, but I realized the real value would be to tie the `wait`
instruction (through CLIF) to the original source code, if debug
information were available. This did not seem to be entirely feasible,
since CLIF loses the original Wasm source context (is this true?) and I
was not confident that we would be able to use `addr2line` to map from
Wasm instructions to source (e.g., see @cfallin's
[issue](gimli-rs/addr2line#265)).

Instead, this change simply logs each valid `wait` and `notify`
execution, leaving it to the user to figure out which one is hanging
(should not be too difficult) and how to map this back to their source
code (more difficult).
@abrown abrown marked this pull request as ready for review October 11, 2023 18:47
@abrown abrown requested a review from a team as a code owner October 11, 2023 18:47
@abrown abrown requested review from pchickey and removed request for a team October 11, 2023 18:47
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

lgtm, modulo a style change across all of these traces

@@ -565,6 +565,7 @@ impl SharedMemory {
/// Implementation of `memory.atomic.notify` for this shared memory.
pub fn atomic_notify(&self, addr_index: u64, count: u32) -> Result<u32, Trap> {
validate_atomic_addr(&self.0.def.0, addr_index, 4, 4)?;
log::trace!("memory.atomic.notify(addr={addr_index}, count={count})");
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of using the format string, use log::trace!("memory.atomic.notify", addr=addr_index, count=count); to provide structured values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that but it complains: I think to use the key-value syntax we need to set target: ..., up front and still provide a string at the end (see log::log!)?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, my bad. I just realized this is log and the key value syntax only works with the tracing crate, and I forgot we use log in wasmtime-runtime in order to keep the dependencies as small as possible, but tracing in wasmtime-wit-bindgen, wasi, etc.

So, your PR is good to go as is. I don't think we need should using log vs tracing down in the runtime now, unless someone really wants to.

@abrown abrown added this pull request to the merge queue Oct 11, 2023
Merged via the queue into bytecodealliance:main with commit d038a43 Oct 11, 2023
@abrown abrown deleted the log-wait-notify branch October 11, 2023 23:24
abrown added a commit to abrown/wasmtime that referenced this pull request Oct 13, 2023
In bytecodealliance#7220, we began logging the arguments of WebAssembly `wait` and
`notify` as these instructions are executed. This change prints the
addresses using hexadecimal, which is simply more convenient when
dealing with addressing.
github-merge-queue bot pushed a commit that referenced this pull request Oct 14, 2023
In #7220, we began logging the arguments of WebAssembly `wait` and
`notify` as these instructions are executed. This change prints the
addresses using hexadecimal, which is simply more convenient when
dealing with addressing.
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.

2 participants