From 2dc5db8c07d0b9dcaa54bbb83b3339b1933da6c9 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 7b7fbc83524522..3aef574f3ed538 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -814,6 +814,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`