From 71856ec2397af7b86af3a4565a73aeb6bc6b6ea3 Mon Sep 17 00:00:00 2001 From: Shadi Dashmiz <94885391+shadidashmiz@users.noreply.github.com> Date: Mon, 26 Jan 2026 16:54:07 -0500 Subject: [PATCH] SWDEV-465366 : Deadlock during stream wait opeartion (#2652) Signed-off-by: sdashmiz --- projects/clr/rocclr/device/pal/palvirtual.cpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/projects/clr/rocclr/device/pal/palvirtual.cpp b/projects/clr/rocclr/device/pal/palvirtual.cpp index 3946d5b729..d66883adc3 100644 --- a/projects/clr/rocclr/device/pal/palvirtual.cpp +++ b/projects/clr/rocclr/device/pal/palvirtual.cpp @@ -3380,12 +3380,29 @@ bool VirtualGPU::waitAllEngines(CommandBatch* cb) { } void VirtualGPU::waitEventLock(CommandBatch* cb) { - bool earlyDone = false; + bool earlyDone = true; + GpuEvent eventsCopy[AllEngines]; + { - // Make sure VirtualGPU has an exclusive access to the resources amd::ScopedLock lock(execution()); - earlyDone = waitAllEngines(cb); + + GpuEvent* events = (cb == nullptr) ? events_ : cb->events_; + + // The first loop is to flush all engines and/or check if + // engines are idle already + for (uint i = 0; i < AllEngines; ++i) { + eventsCopy[i] = events[i]; + earlyDone &= isDone(&events[i]); + } + + // Release all pinned memory + releasePinnedMem(); } + + for (uint i = 0; i < AllEngines; ++i) { + waitForEvent(&eventsCopy[i]); + } + // Get timestamp, incase readjustTimeGPU_ needs to be updated uint64_t endTimeStampCPU = amd::Os::timeNanos();