mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:18:38 +00:00
tests: raise kHeavyTurns in vk_gpu_profile_test and synchronize lock_timed holder in submit_frame_test
This commit is contained in:
@ -62,20 +62,39 @@ int scripted() {
|
||||
std::chrono::steady_clock::now() - call_start).count());
|
||||
const std::uint64_t fences = load(f.part_ns[sp::part_fences]);
|
||||
EXPECT(fences > 1 * ms && double(fences) <= call_ns - 1e6);
|
||||
// Helper: holds a real std::mutex until lock_timed() has failed try_lock(), recorded its start timestamp, and
|
||||
// entered its blocking lock() path, then holds for 4 ms so VM scheduling delays (e.g. macOS runners) never
|
||||
// cause the holder to unlock before the waiter starts timing.
|
||||
struct TrackedLock {
|
||||
std::unique_lock<std::mutex> inner;
|
||||
std::atomic<bool>& blocking;
|
||||
bool try_lock() { return inner.try_lock(); }
|
||||
void lock() {
|
||||
blocking.store(true, std::memory_order_release);
|
||||
inner.lock();
|
||||
}
|
||||
};
|
||||
const auto run_contended_lock = [](std::mutex& m, auto&& waiter_fn) {
|
||||
std::atomic<bool> taken{false};
|
||||
std::atomic<bool> blocking{false};
|
||||
std::thread holder([&] { // takes the lock and lets it go on its own thread, as a mutex must be
|
||||
const std::lock_guard held(m);
|
||||
taken.store(true, std::memory_order_release);
|
||||
while (!blocking.load(std::memory_order_acquire)) std::this_thread::yield();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
||||
});
|
||||
while (!taken.load(std::memory_order_acquire)) std::this_thread::yield();
|
||||
waiter_fn(blocking);
|
||||
holder.join();
|
||||
};
|
||||
// A lock another thread holds for 4 ms: counted as a lock wait, inside the other parts (not in the frame's sum).
|
||||
std::mutex m;
|
||||
std::atomic<bool> taken{false};
|
||||
std::thread holder([&] { // takes the lock and lets it go on its own thread, as a mutex must be
|
||||
const std::lock_guard held(m);
|
||||
taken.store(true);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
||||
});
|
||||
while (!taken.load()) std::this_thread::yield();
|
||||
{
|
||||
std::unique_lock lock(m, std::defer_lock);
|
||||
sp::lock_timed(lock);
|
||||
std::mutex m;
|
||||
run_contended_lock(m, [&](std::atomic<bool>& blocking) {
|
||||
TrackedLock lock{std::unique_lock(m, std::defer_lock), blocking};
|
||||
sp::lock_timed(lock);
|
||||
});
|
||||
}
|
||||
holder.join();
|
||||
EXPECT(load(f.part_ns[sp::part_lock_wait]) >= 2 * ms);
|
||||
const std::uint64_t frame1 = 3 * ms + 1 * ms + fences; // heaps, replay, replay in the call, fences
|
||||
EXPECT(load(f.current_ns) == frame1);
|
||||
@ -111,18 +130,10 @@ int scripted() {
|
||||
const sp::TitleCall call(sp::part_lists);
|
||||
const sp::Scope shadows_scope(sp::shadows);
|
||||
std::mutex mirror_m;
|
||||
std::atomic<bool> held_flag{false};
|
||||
std::thread holder([&] {
|
||||
const std::lock_guard held(mirror_m);
|
||||
held_flag.store(true);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
||||
});
|
||||
while (!held_flag.load()) std::this_thread::yield();
|
||||
{
|
||||
std::unique_lock lock(mirror_m, std::defer_lock);
|
||||
run_contended_lock(mirror_m, [&](std::atomic<bool>& blocking) {
|
||||
TrackedLock lock{std::unique_lock(mirror_m, std::defer_lock), blocking};
|
||||
sp::lock_timed(lock);
|
||||
}
|
||||
holder.join();
|
||||
});
|
||||
}
|
||||
EXPECT(load(f.phase_ns[sp::shadows]) >= 2 * ms);
|
||||
EXPECT(load(f.part_ns[sp::part_lock_wait]) >= 2 * ms);
|
||||
@ -131,20 +142,14 @@ int scripted() {
|
||||
{
|
||||
const std::uint64_t title_waits_before = load(f.part_ns[sp::part_lock_wait]);
|
||||
std::mutex worker_m;
|
||||
std::atomic<bool> held_flag{false};
|
||||
std::thread holder([&] {
|
||||
const std::lock_guard held(worker_m);
|
||||
held_flag.store(true, std::memory_order_release);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
||||
run_contended_lock(worker_m, [&](std::atomic<bool>& blocking) {
|
||||
std::thread worker([&] {
|
||||
const sp::WorkerScope busy(sp::worker_submit);
|
||||
TrackedLock lock{std::unique_lock(worker_m, std::defer_lock), blocking};
|
||||
sp::lock_timed(lock);
|
||||
});
|
||||
worker.join();
|
||||
});
|
||||
while (!held_flag.load(std::memory_order_acquire)) std::this_thread::yield();
|
||||
std::thread worker([&] {
|
||||
const sp::WorkerScope busy(sp::worker_submit);
|
||||
std::unique_lock lock(worker_m, std::defer_lock);
|
||||
sp::lock_timed(lock);
|
||||
});
|
||||
worker.join();
|
||||
holder.join();
|
||||
EXPECT(load(f.worker_lock_wait_ns) >= 2 * ms);
|
||||
EXPECT(load(f.part_ns[sp::part_lock_wait]) == title_waits_before);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ using namespace leonida;
|
||||
using Kind = VulkanQueue::QueueKind;
|
||||
|
||||
constexpr std::uint32_t kGroups = 64; // 64 x 64 invocations a dispatch
|
||||
constexpr std::uint32_t kHeavyTurns = 20000, kLightTurns = 300, kVertexTurns = 4000;
|
||||
constexpr std::uint32_t kHeavyTurns = 40000, kLightTurns = 300, kVertexTurns = 4000;
|
||||
constexpr std::uint32_t kVertices = 3 * 2048;
|
||||
constexpr std::uintptr_t kHeavy = 0x1001, kLight = 0x1002, kDraw = 0x2001;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user