upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-29 16:17:10 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-29 16:17:10 -0500
commiteade9562c1919e39efe3ea2ce719e4b96d59c837 (patch)
treeb5fc81180358c3031259b27c88c0267245f74303
parent1d0867c4a76184fce5eccc51b64c92a7400adb03 (diff)
tests: raise kHeavyTurns in vk_gpu_profile_test and synchronize lock_timed holder in submit_frame_test
-rw-r--r--runtime/test/submit_frame_test.cpp75
-rw-r--r--runtime/test/vk_gpu_profile_test.cpp2
2 files changed, 41 insertions, 36 deletions
diff --git a/runtime/test/submit_frame_test.cpp b/runtime/test/submit_frame_test.cpp
index 4b54931b2..b79b7f3f7 100644
--- a/runtime/test/submit_frame_test.cpp
+++ b/runtime/test/submit_frame_test.cpp
@@ -62,20 +62,39 @@ int scripted() {
62 std::chrono::steady_clock::now() - call_start).count()); 62 std::chrono::steady_clock::now() - call_start).count());
63 const std::uint64_t fences = load(f.part_ns[sp::part_fences]); 63 const std::uint64_t fences = load(f.part_ns[sp::part_fences]);
64 EXPECT(fences > 1 * ms && double(fences) <= call_ns - 1e6); 64 EXPECT(fences > 1 * ms && double(fences) <= call_ns - 1e6);
65 // Helper: holds a real std::mutex until lock_timed() has failed try_lock(), recorded its start timestamp, and
66 // entered its blocking lock() path, then holds for 4 ms so VM scheduling delays (e.g. macOS runners) never
67 // cause the holder to unlock before the waiter starts timing.
68 struct TrackedLock {
69 std::unique_lock<std::mutex> inner;
70 std::atomic<bool>& blocking;
71 bool try_lock() { return inner.try_lock(); }
72 void lock() {
73 blocking.store(true, std::memory_order_release);
74 inner.lock();
75 }
76 };
77 const auto run_contended_lock = [](std::mutex& m, auto&& waiter_fn) {
78 std::atomic<bool> taken{false};
79 std::atomic<bool> blocking{false};
80 std::thread holder([&] { // takes the lock and lets it go on its own thread, as a mutex must be
81 const std::lock_guard held(m);
82 taken.store(true, std::memory_order_release);
83 while (!blocking.load(std::memory_order_acquire)) std::this_thread::yield();
84 std::this_thread::sleep_for(std::chrono::milliseconds(4));
85 });
86 while (!taken.load(std::memory_order_acquire)) std::this_thread::yield();
87 waiter_fn(blocking);
88 holder.join();
89 };
65 // A lock another thread holds for 4 ms: counted as a lock wait, inside the other parts (not in the frame's sum). 90 // A lock another thread holds for 4 ms: counted as a lock wait, inside the other parts (not in the frame's sum).
66 std::mutex m;
67 std::atomic<bool> taken{false};
68 std::thread holder([&] { // takes the lock and lets it go on its own thread, as a mutex must be
69 const std::lock_guard held(m);
70 taken.store(true);
71 std::this_thread::sleep_for(std::chrono::milliseconds(4));
72 });
73 while (!taken.load()) std::this_thread::yield();
74 { 91 {
75 std::unique_lock lock(m, std::defer_lock); 92 std::mutex m;
76 sp::lock_timed(lock); 93 run_contended_lock(m, [&](std::atomic<bool>& blocking) {
94 TrackedLock lock{std::unique_lock(m, std::defer_lock), blocking};
95 sp::lock_timed(lock);
96 });
77 } 97 }
78 holder.join();
79 EXPECT(load(f.part_ns[sp::part_lock_wait]) >= 2 * ms); 98 EXPECT(load(f.part_ns[sp::part_lock_wait]) >= 2 * ms);
80 const std::uint64_t frame1 = 3 * ms + 1 * ms + fences; // heaps, replay, replay in the call, fences 99 const std::uint64_t frame1 = 3 * ms + 1 * ms + fences; // heaps, replay, replay in the call, fences
81 EXPECT(load(f.current_ns) == frame1); 100 EXPECT(load(f.current_ns) == frame1);
@@ -111,18 +130,10 @@ int scripted() {
111 const sp::TitleCall call(sp::part_lists); 130 const sp::TitleCall call(sp::part_lists);
112 const sp::Scope shadows_scope(sp::shadows); 131 const sp::Scope shadows_scope(sp::shadows);
113 std::mutex mirror_m; 132 std::mutex mirror_m;
114 std::atomic<bool> held_flag{false}; 133 run_contended_lock(mirror_m, [&](std::atomic<bool>& blocking) {
115 std::thread holder([&] { 134 TrackedLock lock{std::unique_lock(mirror_m, std::defer_lock), blocking};
116 const std::lock_guard held(mirror_m);
117 held_flag.store(true);
118 std::this_thread::sleep_for(std::chrono::milliseconds(4));
119 });
120 while (!held_flag.load()) std::this_thread::yield();
121 {
122 std::unique_lock lock(mirror_m, std::defer_lock);
123 sp::lock_timed(lock); 135 sp::lock_timed(lock);
124 } 136 });
125 holder.join();
126 } 137 }
127 EXPECT(load(f.phase_ns[sp::shadows]) >= 2 * ms); 138 EXPECT(load(f.phase_ns[sp::shadows]) >= 2 * ms);
128 EXPECT(load(f.part_ns[sp::part_lock_wait]) >= 2 * ms); 139 EXPECT(load(f.part_ns[sp::part_lock_wait]) >= 2 * ms);
@@ -131,20 +142,14 @@ int scripted() {
131 { 142 {
132 const std::uint64_t title_waits_before = load(f.part_ns[sp::part_lock_wait]); 143 const std::uint64_t title_waits_before = load(f.part_ns[sp::part_lock_wait]);
133 std::mutex worker_m; 144 std::mutex worker_m;
134 std::atomic<bool> held_flag{false}; 145 run_contended_lock(worker_m, [&](std::atomic<bool>& blocking) {
135 std::thread holder([&] { 146 std::thread worker([&] {
136 const std::lock_guard held(worker_m); 147 const sp::WorkerScope busy(sp::worker_submit);
137 held_flag.store(true, std::memory_order_release); 148 TrackedLock lock{std::unique_lock(worker_m, std::defer_lock), blocking};
138 std::this_thread::sleep_for(std::chrono::milliseconds(4)); 149 sp::lock_timed(lock);
139 }); 150 });
140 while (!held_flag.load(std::memory_order_acquire)) std::this_thread::yield(); 151 worker.join();
141 std::thread worker([&] {
142 const sp::WorkerScope busy(sp::worker_submit);
143 std::unique_lock lock(worker_m, std::defer_lock);
144 sp::lock_timed(lock);
145 }); 152 });
146 worker.join();
147 holder.join();
148 EXPECT(load(f.worker_lock_wait_ns) >= 2 * ms); 153 EXPECT(load(f.worker_lock_wait_ns) >= 2 * ms);
149 EXPECT(load(f.part_ns[sp::part_lock_wait]) == title_waits_before); 154 EXPECT(load(f.part_ns[sp::part_lock_wait]) == title_waits_before);
150 } 155 }
diff --git a/runtime/test/vk_gpu_profile_test.cpp b/runtime/test/vk_gpu_profile_test.cpp
index 332df584e..ac0c9e2c7 100644
--- a/runtime/test/vk_gpu_profile_test.cpp
+++ b/runtime/test/vk_gpu_profile_test.cpp
@@ -26,7 +26,7 @@ using namespace leonida;
26using Kind = VulkanQueue::QueueKind; 26using Kind = VulkanQueue::QueueKind;
27 27
28constexpr std::uint32_t kGroups = 64; // 64 x 64 invocations a dispatch 28constexpr std::uint32_t kGroups = 64; // 64 x 64 invocations a dispatch
29constexpr std::uint32_t kHeavyTurns = 20000, kLightTurns = 300, kVertexTurns = 4000; 29constexpr std::uint32_t kHeavyTurns = 40000, kLightTurns = 300, kVertexTurns = 4000;
30constexpr std::uint32_t kVertices = 3 * 2048; 30constexpr std::uint32_t kVertices = 3 * 2048;
31constexpr std::uintptr_t kHeavy = 0x1001, kLight = 0x1002, kDraw = 0x2001; 31constexpr std::uintptr_t kHeavy = 0x1001, kLight = 0x1002, kDraw = 0x2001;
32 32