Skip to content

add support for async backtraces of Tasks on any thread#51430

Merged
vtjnash merged 2 commits intomasterfrom
jn/async-stacktrace
Sep 25, 2023
Merged

add support for async backtraces of Tasks on any thread#51430
vtjnash merged 2 commits intomasterfrom
jn/async-stacktrace

Conversation

@vtjnash
Copy link
Copy Markdown
Member

@vtjnash vtjnash commented Sep 22, 2023

No description provided.

@vtjnash vtjnash added multithreading Base.Threads and related functionality feature Indicates new feature / enhancement requests labels Sep 22, 2023
@vtjnash vtjnash force-pushed the jn/async-stacktrace branch from 63f43ba to f662a2e Compare September 24, 2023 13:46
The jl_live_tasks API now reports all threads, instead of only Tasks
first started by the current thread. There is a new abstraction called
mtarraylist with adds functionality to small_arraylist (it is
layout-compatible). In particular, it makes it safe for another thread
to observe the content of the list concurrently with any mutations.
@vtjnash vtjnash force-pushed the jn/async-stacktrace branch from f662a2e to f7d8bfb Compare September 24, 2023 17:29
@vtjnash vtjnash merged commit e5c6340 into master Sep 25, 2023
@vtjnash vtjnash deleted the jn/async-stacktrace branch September 25, 2023 11:20
kpamnany pushed a commit to RelationalAI/julia that referenced this pull request Sep 25, 2023
@kpamnany
Copy link
Copy Markdown
Member

What this PR does (for future reference):

Previously, the C/C++ part of the runtime had only arraylist_t and small_arraylist_t for lists of things, neither of which are inherently thread-safe and need an external lock.

This PR adds small_mtarraylist_t which is basically a small_arraylist_t with atomics that allows multiple threads to safely read pushes and adds (which have implicit resizes when necessary) concurrently with a single writer thread.

Three lists in ptls->heap are converted to small_mtarraylist_ts -- weak_refs, live_tasks and free_stacks and the code that touches these has been updated to use the new thread-safe accessors.

Then, jl_live_tasks() is also updated and, it looks like, hardened somewhat to handle foreign threads and GC threads correctly.

There are some changes to the signal_listener and jl_thread_suspend_and_get_state and jl_thread_resume that I think are used by the profiling mechanism but I'm not very clear on what's going on there.

All that essentially enables: jl_rec_backtrace() is improved to not simply skip over sticky tasks or tasks running on other threads; it now uses jl_thread_suspend_and_get_state to stop the thread and get its state (which includes the backtrace). And jl_print_task_backtraces() is updated to use the correct (small_mtarraylist_t) calls to access live_tasks.

@oscardssmith
Copy link
Copy Markdown
Member

what's the difference between an arraylist_t and a Julia Vector (which we can also use from the C side?

@vtjnash
Copy link
Copy Markdown
Member Author

vtjnash commented Sep 26, 2023

An arraylist_t is not a safepoint, and as such, cannot hold GC references and cannot be reclaimed by the GC. In most cases, Vector{Int} is the preferable thing to use, if the GC is available and initialized on that thread.

kpamnany pushed a commit to RelationalAI/julia that referenced this pull request Sep 26, 2023
kpamnany pushed a commit to RelationalAI/julia that referenced this pull request Sep 26, 2023
vtjnash pushed a commit that referenced this pull request Sep 27, 2023
In `jl_print_task_backtraces()`. Follow-on to
#51430.
kpamnany pushed a commit to RelationalAI/julia that referenced this pull request Sep 27, 2023
kpamnany added a commit to RelationalAI/julia that referenced this pull request Sep 27, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
kpamnany pushed a commit to RelationalAI/julia that referenced this pull request Sep 27, 2023
kpamnany added a commit to RelationalAI/julia that referenced this pull request Sep 27, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
@kpamnany
Copy link
Copy Markdown
Member

The previous implementation of this capability was insufficiently safe and segfaults on occasion, so this is actually a bugfix. Can we backport it to 1.10 @vtjnash and @KristofferC?

@kpamnany
Copy link
Copy Markdown
Member

If so, #51471 should be backported also.

kpamnany pushed a commit to RelationalAI/julia that referenced this pull request Oct 19, 2023
kpamnany added a commit to RelationalAI/julia that referenced this pull request Oct 19, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
@kpamnany kpamnany added the backport 1.10 Change should be backported to the 1.10 release label Oct 20, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Oct 20, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Oct 31, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Oct 31, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 1, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 1, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 1, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 1, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 2, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 2, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
@KristofferC KristofferC mentioned this pull request Nov 6, 2023
39 tasks
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 7, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 7, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 10, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 10, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 10, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 10, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 10, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 10, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 14, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 14, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 14, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 14, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 15, 2023
DelveCI pushed a commit to RelationalAI/julia that referenced this pull request Nov 15, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
kpamnany pushed a commit to RelationalAI/julia that referenced this pull request Nov 16, 2023
kpamnany added a commit to RelationalAI/julia that referenced this pull request Nov 16, 2023
In `jl_print_task_backtraces()`. Follow-on to
JuliaLang#51430.
KristofferC pushed a commit that referenced this pull request Nov 27, 2023
KristofferC pushed a commit that referenced this pull request Nov 27, 2023
In `jl_print_task_backtraces()`. Follow-on to
#51430.

(cherry picked from commit cde964f)
@KristofferC KristofferC mentioned this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Indicates new feature / enhancement requests multithreading Base.Threads and related functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants