From c8b9257c0bf32405d4f590b719f774a13b3d0f84 Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Fri, 19 Mar 2021 14:47:08 -0700 Subject: [PATCH] SWDEV-277847 - Move event lock_ to the beginning For addMarker, assume T1 comes in first and enqueues a command C1. Before T1 grabs the event_::lock_ it gets preempted. At this time, T2 comes in, enqueues C2 and grabs the lock_ and updates event_. Now T1 wakes up and updates a older command C1 for the event. Change-Id: Ia423782b23026302c40976385623cfdede32d70b --- rocclr/hip_event.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rocclr/hip_event.cpp b/rocclr/hip_event.cpp index 6633f5fe79..1a1d242804 100755 --- a/rocclr/hip_event.cpp +++ b/rocclr/hip_event.cpp @@ -148,6 +148,9 @@ hipError_t Event::streamWait(amd::HostQueue* hostQueue, uint flags) { } void Event::addMarker(amd::HostQueue* queue, amd::Command* command, bool record) { + // Keep the lock always at the beginning of this to avoid a race. SWDEV-277847 + amd::ScopedLock lock(lock_); + if (command == nullptr) { command = queue->getLastQueuedCommand(true); @@ -171,7 +174,6 @@ void Event::addMarker(amd::HostQueue* queue, amd::Command* command, bool record) command->enqueue(); } } - amd::ScopedLock lock(lock_); if (event_ == &command->event()) return;