From c7eeef568ce5a3714b89689160ec85c017527364 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 6 Dec 2019 00:39:16 +0100 Subject: [PATCH] cli: add `--trace-atomics-wait` flag Adds a flag that helps with debugging deadlocks due to incorrectly implemented `Atomics.wait()` calls. PR-URL: https://github.com/nodejs/node/pull/33292 Reviewed-By: Gus Caplan Reviewed-By: David Carlier Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- benchmark/worker/atomics-wait.js | 15 +++++ doc/api/cli.md | 30 +++++++++ doc/node.1 | 4 ++ src/node.cc | 45 ++++++++++++++ src/node_options.cc | 4 ++ src/node_options.h | 1 + test/parallel/test-trace-atomics-wait.js | 79 ++++++++++++++++++++++++ 7 files changed, 178 insertions(+) create mode 100644 benchmark/worker/atomics-wait.js create mode 100644 test/parallel/test-trace-atomics-wait.js diff --git a/benchmark/worker/atomics-wait.js b/benchmark/worker/atomics-wait.js new file mode 100644 index 00000000000000..a771b1813731ed --- /dev/null +++ b/benchmark/worker/atomics-wait.js @@ -0,0 +1,15 @@ +'use strict'; +/* global SharedArrayBuffer */ + +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + n: [1e7] +}); + +function main({ n }) { + const i32arr = new Int32Array(new SharedArrayBuffer(4)); + bench.start(); + for (let i = 0; i < n; i++) + Atomics.wait(i32arr, 0, 1); // Will return immediately. + bench.end(n); +} diff --git a/doc/api/cli.md b/doc/api/cli.md index e6310b279f424c..82e2f674a8a9ac 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -816,6 +816,33 @@ added: v12.0.0 Set default [`tls.DEFAULT_MIN_VERSION`][] to 'TLSv1.3'. Use to disable support for TLSv1.2, which is not as secure as TLSv1.3. +### `--trace-atomics-wait` + + +Print short summaries of calls to [`Atomics.wait()`][] to stderr. +The output could look like this: + +```text +(node:15701) [Thread 0] Atomics.wait(
+ 0, 1, inf) started +(node:15701) [Thread 0] Atomics.wait(
+ 0, 1, inf) did not wait because the values mismatched +(node:15701) [Thread 0] Atomics.wait(
+ 0, 0, 10) started +(node:15701) [Thread 0] Atomics.wait(
+ 0, 0, 10) timed out +(node:15701) [Thread 0] Atomics.wait(
+ 4, 0, inf) started +(node:15701) [Thread 1] Atomics.wait(
+ 4, -1, inf) started +(node:15701) [Thread 0] Atomics.wait(
+ 4, 0, inf) was woken up by another thread +(node:15701) [Thread 1] Atomics.wait(
+ 4, -1, inf) was woken up by another thread +``` + +The fields here correspond to: + +* The thread id as given by [`worker_threads.threadId`][] +* The base address of the `SharedArrayBuffer` in question, as well as the + byte offset corresponding to the index passed to `Atomics.wait()` +* The expected value that was passed to `Atomics.wait()` +* The timeout passed to `Atomics.wait` + ### `--trace-deprecation`