diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 21:49:53 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 21:49:53 -0500 |
| commit | 8d686309b0617e1a561c0404b8b79e6176385664 (patch) | |
| tree | 439d4a796034028a0951e6d469dbd695eacf69bb /runtime/src/thread_stacks.cpp | |
| parent | 6c8a89dea7e0521714834383a847e36dcf437036 (diff) | |
| parent | 7f3d0095a2d51892bc7048f24505c37168f25c34 (diff) | |
Merge main into integration/boot-combined (RT-BOOT-COMBINED)
Conflict in runtime/shims/d3d12_xs_device.cpp, proxy_copy_descriptors_simple:
keep this branch's copy_null_rtv_marks call and main's fsdraw::enabled()
gate for the descriptor-copy diagnostic.
tools/rdna2spirv.py merged without a textual conflict, but #1662 on main
calls restore_dot4_inline_sel in the exact re-anchoring path, which this
branch had deleted. The merge puts main's function back so that call
resolves; the next commits reconcile it with the dot4 op_sel rule.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/thread_stacks.cpp')
| -rw-r--r-- | runtime/src/thread_stacks.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/runtime/src/thread_stacks.cpp b/runtime/src/thread_stacks.cpp index 67188d908..38d7cc2a4 100644 --- a/runtime/src/thread_stacks.cpp +++ b/runtime/src/thread_stacks.cpp | |||
| @@ -121,10 +121,10 @@ struct ThreadTrace { | |||
| 121 | size_t count = 0; | 121 | size_t count = 0; |
| 122 | }; | 122 | }; |
| 123 | 123 | ||
| 124 | void print_traces(unsigned at, const std::vector<ThreadTrace>& traces) { | 124 | void print_traces(const std::string& tag, const std::vector<ThreadTrace>& traces) { |
| 125 | std::string out = "[rt] stacks t=" + std::to_string(at) + ": " + std::to_string(traces.size()) + " threads\n"; | 125 | std::string out = "[rt] stacks " + tag + ": " + std::to_string(traces.size()) + " threads\n"; |
| 126 | for (auto it = traces.begin(); it != traces.end(); ++it) { | 126 | for (auto it = traces.begin(); it != traces.end(); ++it) { |
| 127 | out += "[rt] stacks t=" + std::to_string(at) + " thread " + std::to_string(it->tid) + " (" + it->label + "):\n"; | 127 | out += "[rt] stacks " + tag + " thread " + std::to_string(it->tid) + " (" + it->label + "):\n"; |
| 128 | const auto same = std::find_if(traces.begin(), it, [&](const ThreadTrace& earlier) { | 128 | const auto same = std::find_if(traces.begin(), it, [&](const ThreadTrace& earlier) { |
| 129 | return it->count && it->count == earlier.count && | 129 | return it->count && it->count == earlier.count && |
| 130 | std::equal(it->frames.begin(), it->frames.begin() + it->count, earlier.frames.begin()); | 130 | std::equal(it->frames.begin(), it->frames.begin() + it->count, earlier.frames.begin()); |
| @@ -142,10 +142,11 @@ void print_traces(unsigned at, const std::vector<ThreadTrace>& traces) { | |||
| 142 | std::fflush(stderr); | 142 | std::fflush(stderr); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describe, QueryThread query) { | 145 | void snapshot_threads(const std::string& tag, StackSampler& sampler, GetDescription describe, QueryThread query, |
| 146 | DWORD only = 0) { | ||
| 146 | const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); | 147 | const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); |
| 147 | if (snapshot == INVALID_HANDLE_VALUE) { | 148 | if (snapshot == INVALID_HANDLE_VALUE) { |
| 148 | std::fprintf(stderr, "[rt] stacks t=%u: thread list failed (error %lu)\n", at, GetLastError()); | 149 | std::fprintf(stderr, "[rt] stacks %s: thread list failed (error %lu)\n", tag.c_str(), GetLastError()); |
| 149 | return; | 150 | return; |
| 150 | } | 151 | } |
| 151 | std::vector<ThreadTrace> traces; | 152 | std::vector<ThreadTrace> traces; |
| @@ -157,6 +158,7 @@ void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describ | |||
| 157 | for (BOOL ok = Thread32First(snapshot, &entry); ok; ok = Thread32Next(snapshot, &entry)) { | 158 | for (BOOL ok = Thread32First(snapshot, &entry); ok; ok = Thread32Next(snapshot, &entry)) { |
| 158 | entry.dwSize = sizeof(entry); | 159 | entry.dwSize = sizeof(entry); |
| 159 | if (entry.th32OwnerProcessID != pid || entry.th32ThreadID == self) continue; | 160 | if (entry.th32OwnerProcessID != pid || entry.th32ThreadID == self) continue; |
| 161 | if (only && entry.th32ThreadID != only) continue; | ||
| 160 | const HANDLE thread = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, | 162 | const HANDLE thread = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, |
| 161 | FALSE, entry.th32ThreadID); | 163 | FALSE, entry.th32ThreadID); |
| 162 | if (!thread) continue; | 164 | if (!thread) continue; |
| @@ -169,7 +171,7 @@ void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describ | |||
| 169 | CloseHandle(thread); | 171 | CloseHandle(thread); |
| 170 | } | 172 | } |
| 171 | CloseHandle(snapshot); | 173 | CloseHandle(snapshot); |
| 172 | print_traces(at, traces); | 174 | print_traces(tag, traces); |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | } // namespace | 177 | } // namespace |
| @@ -207,6 +209,20 @@ bool parse_stack_times(std::string_view text, std::vector<unsigned>& seconds) { | |||
| 207 | return true; | 209 | return true; |
| 208 | } | 210 | } |
| 209 | 211 | ||
| 212 | void print_thread_stacks_now(std::uint32_t tid, const char* why) noexcept { | ||
| 213 | static std::mutex mutex; | ||
| 214 | try { | ||
| 215 | std::lock_guard lock(mutex); | ||
| 216 | static StackSampler sampler; | ||
| 217 | const auto describe = reinterpret_cast<GetDescription>(reinterpret_cast<void*>( | ||
| 218 | GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetThreadDescription"))); | ||
| 219 | const auto query = reinterpret_cast<QueryThread>(reinterpret_cast<void*>( | ||
| 220 | GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtQueryInformationThread"))); | ||
| 221 | snapshot_threads(why ? why : "now", sampler, describe, query, tid); | ||
| 222 | } catch (...) { | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 210 | std::jthread start_thread_stacks() { | 226 | std::jthread start_thread_stacks() { |
| 211 | const auto start = Clock::now(); | 227 | const auto start = Clock::now(); |
| 212 | char spec[1024]; | 228 | char spec[1024]; |
| @@ -229,7 +245,7 @@ std::jthread start_thread_stacks() { | |||
| 229 | for (const unsigned at : times) { | 245 | for (const unsigned at : times) { |
| 230 | wake.wait_until(lock, stop, start + std::chrono::seconds(at), [] { return false; }); | 246 | wake.wait_until(lock, stop, start + std::chrono::seconds(at), [] { return false; }); |
| 231 | if (stop.stop_requested()) break; | 247 | if (stop.stop_requested()) break; |
| 232 | snapshot_threads(at, sampler, describe, query); | 248 | snapshot_threads("t=" + std::to_string(at), sampler, describe, query); |
| 233 | } | 249 | } |
| 234 | }); | 250 | }); |
| 235 | } | 251 | } |