From 7a67eb90e2d75518c1e2dea569b73caad3ad9014 Mon Sep 17 00:00:00 2001 From: Flora Cui Date: Thu, 26 Sep 2024 17:23:03 +0800 Subject: [PATCH] wsl/hsakmt: add lock for sdma packet processing Suggested-by: Shane Xiao Signed-off-by: Flora Cui Reviewed-by: Shane Xiao Reviewed-by: Shi.Leslie Part-of: --- inc/wddm/queue.h | 1 + wddm/queue.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/inc/wddm/queue.h b/inc/wddm/queue.h index 7317d87fc8..d08e654b09 100644 --- a/inc/wddm/queue.h +++ b/inc/wddm/queue.h @@ -285,6 +285,7 @@ private: uint64_t rptr_next; uint64_t doorbell_; std::queue> wptr_queue_; + std::mutex wptr_queue_lock_; uint64_t ib_size; uint64_t ib_start_addr; diff --git a/wddm/queue.cpp b/wddm/queue.cpp index bd622003f7..4e3f02c805 100644 --- a/wddm/queue.cpp +++ b/wddm/queue.cpp @@ -989,9 +989,11 @@ void SDMAQueue::SdmaThread(SDMAQueue *queue) { while (true) { if (!queue->wptr_queue_.empty()) { + std::unique_lock lock(queue->wptr_queue_lock_); uint64_t start = queue->wptr_queue_.front().first; uint64_t end = queue->wptr_queue_.front().second; queue->wptr_queue_.pop(); + lock.unlock(); debug_print("SDMA: wptr %lx %lx\n", start, end); SDMA_PKT_POLL_REGMEM* poll_pkt = reinterpret_cast(queue->cmdbuf_addr + queue->WrapIntoRocrRing(start)); @@ -1081,7 +1083,10 @@ SDMAQueue::~SDMAQueue() { void SDMAQueue::RingDoorbell() { debug_print("SDMA: ringdoorbell %#llx %#llx\n", wptr_pre_, wptr_next_); - wptr_queue_.emplace(wptr_pre_, wptr_next_); + { + std::lock_guard lock(wptr_queue_lock_); + wptr_queue_.emplace(wptr_pre_, wptr_next_); + } thread_cond_.notify_one(); wptr_pre_ = wptr_next_; }