Skip to content

Conversation

@sverker
Copy link
Contributor

@sverker sverker commented Sep 16, 2025

Another step in the quest of purging ERTS from BIFs that block all scheduler threads.

This affects both the new trace:info/3 and the old erlang:trace_info/2 when they are called to collect call_time and/or call_memory counters.

@sverker sverker added this to the OTP-29.0 milestone Sep 16, 2025
@sverker sverker self-assigned this Sep 16, 2025
@sverker sverker added team:VM Assigned to OTP team VM enhancement labels Sep 16, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 16, 2025

CT Test Results

    3 files    135 suites   49m 8s ⏱️
1 654 tests 1 597 ✅ 57 💤 0 ❌
2 292 runs  2 216 ✅ 76 💤 0 ❌

Results for commit 55df6b0.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

Don't spend time and heap memory on items not asked for.
in preparation for block-less trace:info.
Save memory in most cases, but impose extra cpu (time) when tracing.
It should always be erts_active_bp_index ^ 1.
Avoid tiny race when we had to change two atomics.
We only call erts_staging_bp_ix() when we change trace settings.
@sverker sverker force-pushed the sverker/erts/trace-no-block branch from 84b9e53 to 5fee623 Compare September 16, 2025 16:14
@sverker sverker added the testing currently being tested, tag is used by OTP internal CI label Sep 17, 2025
@sverker sverker requested a review from Copilot September 17, 2025 17:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the implementation of trace:info/3 and erlang:trace_info/2 to make them non-blocking when collecting call_time and call_memory counters, addressing the issue of these functions blocking all scheduler threads.

  • Refactored breakpoint data structures to eliminate the erts_staging_bp_index variable
  • Implemented non-blocking trace info collection using code barriers and process suspension/resumption
  • Reorganized hash table structures and functions for call time/memory tracing

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
erts/emulator/test/trace_call_time_SUITE.erl Added new test cases to verify non-blocking behavior and robustness against process termination
erts/emulator/nifs/common/prim_tty_nif.c Fixed assertion to include zero in valid character range
erts/emulator/beam/erl_trace.h Removed staging breakpoint index variable
erts/emulator/beam/erl_trace.c Removed staging breakpoint index variable
erts/emulator/beam/erl_init.c Moved trace initialization after emulator initialization
erts/emulator/beam/erl_bif_trace.c Major refactor to implement non-blocking trace info collection with trapping mechanisms
erts/emulator/beam/beam_bp.h Refactored breakpoint data structures and function signatures
erts/emulator/beam/beam_bp.c Implemented new hash table management and non-blocking collection algorithms
erts/emulator/beam/atom.names Added new atom for trace info finish export

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sverker sverker added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI labels Sep 29, 2025
@sverker sverker force-pushed the sverker/erts/trace-no-block branch 2 times, most recently from baded75 to f41cc8d Compare October 1, 2025 12:07
@sverker sverker requested a review from frazze-jobb October 1, 2025 12:13
@sverker sverker force-pushed the sverker/erts/trace-no-block branch 3 times, most recently from c8cb8dd to 357949a Compare October 1, 2025 13:37
@sverker sverker requested a review from Copilot October 1, 2025 15:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

frazze-jobb
frazze-jobb previously approved these changes Oct 2, 2025
@sverker sverker added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI labels Oct 2, 2025
@sverker sverker force-pushed the sverker/erts/trace-no-block branch 2 times, most recently from b9fa60c to 0824a58 Compare October 9, 2025 14:20
@sverker sverker force-pushed the sverker/erts/trace-no-block branch 2 times, most recently from 109232d to 1501b6d Compare October 9, 2025 17:02
Instead use this strategy

0. Seize code mod permission (as before)
1. Allocate temporary zeroed hashes for any traced calls that may happen
   during the call to trace:info.
2. Thread progress
3. Switch bp index to make the temp hashes active.
4. Thread progress.
5. Collect stats from the real hashes that are now unused and stable.
6. Switch back bp index to make the real hashes active again.
7. Thread progress.
8. Consolidate by collecting stats from the temp hashes into the
   active generation.
9. Deallocate the temp hashes and make the two halves of the breakpoint
   identical again using the same real hashes.
10. Build result from stats collected in step 5
11. Release code mod permission
@sverker sverker force-pushed the sverker/erts/trace-no-block branch 2 times, most recently from afb61ca to dde3b5d Compare October 14, 2025 13:35
frazze-jobb
frazze-jobb previously approved these changes Oct 15, 2025
with some talk about sessions
and call_time and call_memory.
@sverker sverker merged commit 169d1ae into erlang:master Oct 22, 2025
27 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants