upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/queue_proxy_test.cpp
diff options
context:
space:
mode:
authorDominik <55330408+Dom-in@users.noreply.github.com>2026-11-22 13:28:40 +0000
committerDominik <55330408+Dom-in@users.noreply.github.com>2026-11-22 13:28:40 +0000
commita80614d7de5e5f3f7d6572f9d185c68af29ad092 (patch)
tree71c1639878da8c276c2076d907cd66e47cfdb8d3 /runtime/test/queue_proxy_test.cpp
parenta0acd33d77babe67a28e398b2936a9f735a50f5d (diff)
queue_proxy_test: run the differential children side by side (TEST-242)
Each differential case starts two child processes (real object, proxy), and each child pays its own device start-up: ~5 s on an AMD RDNA2 iGPU, 97 s per ctest run. The children now run differential_jobs() at a time (half the logical processors, 1..8; LEONIDA_QUEUE_PROXY_JOBS overrides, 1 = serial) and are judged afterwards in case order, so the report is unchanged. Starting children from several threads needs the pipe's write end to be inheritable only for its own CreateProcessW: both ends are now created uninheritable and the write end is made inheritable under a start lock, so a sibling started meanwhile can't inherit it and hold the pipe open. RX 9070 (WARP + hardware + Vulkan backends): 44 s -> 20 s, same output; 5 runs at 16 jobs clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/queue_proxy_test.cpp')
-rw-r--r--runtime/test/queue_proxy_test.cpp74
1 files changed, 59 insertions, 15 deletions
diff --git a/runtime/test/queue_proxy_test.cpp b/runtime/test/queue_proxy_test.cpp
index 23a550685..69c1c26bd 100644
--- a/runtime/test/queue_proxy_test.cpp
+++ b/runtime/test/queue_proxy_test.cpp
@@ -33,6 +33,7 @@
33#include <cstring> 33#include <cstring>
34#include <cwchar> 34#include <cwchar>
35#include <iterator> 35#include <iterator>
36#include <mutex>
36#include <string> 37#include <string>
37#include <system_error> 38#include <system_error>
38#include <thread> 39#include <thread>
@@ -822,29 +823,37 @@ ChildRun run_process(const wchar_t* exe, const wchar_t* arguments, DWORD limit_m
822 RunnerFault fault = RunnerFault::none) { 823 RunnerFault fault = RunnerFault::none) {
823 ChildRun run; 824 ChildRun run;
824 std::wstring command = L"\"" + std::wstring(exe) + L"\" " + arguments; 825 std::wstring command = L"\"" + std::wstring(exe) + L"\" " + arguments;
825 SECURITY_ATTRIBUTES inherit{sizeof(inherit), nullptr, TRUE}; 826 // Both ends are made uninheritable. The write end becomes inheritable only while the start lock is held, just for
827 // its own child's CreateProcessW: children are started from several threads at once (check_differential), and a
828 // write end inheritable at any other time would also go to a sibling started meanwhile, which would then keep this
829 // pipe open after this child ended.
826 HANDLE read_end = nullptr, write_end = nullptr; 830 HANDLE read_end = nullptr, write_end = nullptr;
827 if (fault == RunnerFault::pipe) SetLastError(ERROR_NOT_ENOUGH_MEMORY); 831 if (fault == RunnerFault::pipe) SetLastError(ERROR_NOT_ENOUGH_MEMORY);
828 if (fault == RunnerFault::pipe || !CreatePipe(&read_end, &write_end, &inherit, 0)) { 832 if (fault == RunnerFault::pipe || !CreatePipe(&read_end, &write_end, nullptr, 0)) {
829 report_runner_error("CreatePipe"); 833 report_runner_error("CreatePipe");
830 return run; 834 return run;
831 } 835 }
832 if (!SetHandleInformation(read_end, HANDLE_FLAG_INHERIT, 0)) {
833 report_runner_error("SetHandleInformation");
834 CloseHandle(read_end);
835 CloseHandle(write_end);
836 return run;
837 }
838 STARTUPINFOW startup{sizeof(startup)}; 836 STARTUPINFOW startup{sizeof(startup)};
839 startup.dwFlags = STARTF_USESTDHANDLES; 837 startup.dwFlags = STARTF_USESTDHANDLES;
840 startup.hStdOutput = write_end; 838 startup.hStdOutput = write_end;
841 startup.hStdError = GetStdHandle(STD_ERROR_HANDLE); 839 startup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
842 startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE); 840 startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
843 PROCESS_INFORMATION process{}; 841 PROCESS_INFORMATION process{};
844 const BOOL started = 842 BOOL started = FALSE;
845 CreateProcessW(exe, command.data(), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &startup, &process); 843 DWORD start_error = 0;
846 const DWORD start_error = GetLastError(); 844 {
847 CloseHandle(write_end); // the child holds the only write end now: the reader sees the pipe end when it is gone 845 static std::mutex start_lock;
846 const std::lock_guard<std::mutex> hold(start_lock);
847 if (!SetHandleInformation(write_end, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
848 report_runner_error("SetHandleInformation");
849 CloseHandle(read_end);
850 CloseHandle(write_end);
851 return run;
852 }
853 started = CreateProcessW(exe, command.data(), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &startup, &process);
854 start_error = GetLastError();
855 CloseHandle(write_end); // the child holds the only write end now: the reader sees the pipe end when it is gone
856 }
848 if (!started) { 857 if (!started) {
849 std::fprintf(stderr, "child runner: CreateProcessW \"%ls\" failed (error %lu)\n", exe, start_error); 858 std::fprintf(stderr, "child runner: CreateProcessW \"%ls\" failed (error %lu)\n", exe, start_error);
850 CloseHandle(read_end); 859 CloseHandle(read_end);
@@ -1044,14 +1053,49 @@ int check_child_runner() {
1044 return 0; 1053 return 0;
1045} 1054}
1046 1055
1056// How many differential children run at once: LEONIDA_QUEUE_PROXY_JOBS when set (1 = one after another, as before),
1057// else half the logical processors, from 1 to 8. Each child pays its own device start-up (about 5 s each on an AMD
1058// RDNA2 iGPU, TEST-242), and that waiting is what running them side by side hides.
1059unsigned differential_jobs() {
1060 char value[16] = {};
1061 const DWORD length = GetEnvironmentVariableA("LEONIDA_QUEUE_PROXY_JOBS", value, sizeof(value));
1062 if (length > 0 && length < sizeof(value)) { // set, and short enough to be a number
1063 const unsigned long jobs = std::strtoul(value, nullptr, 10);
1064 if (jobs >= 1 && jobs <= 64) return static_cast<unsigned>(jobs);
1065 }
1066 const unsigned half = std::thread::hardware_concurrency() / 2;
1067 return half < 1 ? 1 : half > 8 ? 8 : half;
1068}
1069
1047// Each case, in a child process for the real object and in another for the proxy: the same HRESULT, the device 1070// Each case, in a child process for the real object and in another for the proxy: the same HRESULT, the device
1048// removed (or not) alike, and no validation errors. A case the real runtime faults on is reported, not compared. 1071// removed (or not) alike, and no validation errors. A case the real runtime faults on is reported, not compared.
1072// The children run differential_jobs() at a time; the results are judged afterwards in case order, so the report is
1073// the same as one child after another would give (a proxy child whose real one faulted is run but not judged).
1049int check_differential(const Backend& b) { 1074int check_differential(const Backend& b) {
1050 const char* label = b.label; 1075 const char* label = b.label;
1051 int compared = 0, faulting = 0; 1076 int compared = 0, faulting = 0;
1052 for (int i = 0; i < static_cast<int>(std::size(kDiffCases)); ++i) { 1077 constexpr int kCases = static_cast<int>(std::size(kDiffCases));
1078 std::vector<ChildResult> results(2 * kCases); // [2 * case] real, [2 * case + 1] proxy
1079 {
1080 std::atomic<int> next{0};
1081 const auto work = [&] {
1082 for (int job; (job = next.fetch_add(1)) < 2 * kCases;)
1083 results[job] = run_child(b.kind, job / 2, job % 2 == 1);
1084 };
1085 const unsigned jobs = differential_jobs();
1086 std::vector<std::thread> pool;
1087 try {
1088 for (unsigned t = 1; t < jobs; ++t) pool.emplace_back(work);
1089 } catch (const std::system_error& e) { // fewer helpers; this thread still runs every job left
1090 std::fprintf(stderr, "%s: %zu of %u differential runner threads (%s)\n", label, pool.size() + 1, jobs,
1091 e.what());
1092 }
1093 work();
1094 for (std::thread& t : pool) t.join();
1095 }
1096 for (int i = 0; i < kCases; ++i) {
1053 const char* name = kDiffCases[i].name; 1097 const char* name = kDiffCases[i].name;
1054 const ChildResult want = run_child(b.kind, i, false); 1098 const ChildResult& want = results[2 * i];
1055 if (!want.ok) { 1099 if (!want.ok) {
1056 std::fprintf(stderr, "%s: %s: the real-object child did not report\n", label, name); 1100 std::fprintf(stderr, "%s: %s: the real-object child did not report\n", label, name);
1057 return 1; 1101 return 1;
@@ -1061,7 +1105,7 @@ int check_differential(const Backend& b) {
1061 ++faulting; 1105 ++faulting;
1062 continue; 1106 continue;
1063 } 1107 }
1064 const ChildResult got = run_child(b.kind, i, true); 1108 const ChildResult& got = results[2 * i + 1];
1065 if (!got.ok || !got.ran || got.hr != want.hr || got.removed != want.removed || got.validation || 1109 if (!got.ok || !got.ran || got.hr != want.hr || got.removed != want.removed || got.validation ||
1066 want.validation) { 1110 want.validation) {
1067 std::fprintf(stderr, 1111 std::fprintf(stderr,