From adc40934aecc3298352024bec262df225d90f125 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Thu, 8 May 2025 08:46:47 +0000 Subject: [PATCH] test: ensure thread safety when capturing input params for wait function Signed-off-by: Mateusz Jablonski --- .../core/test/unit_tests/sources/device/test_l0_device.cpp | 2 ++ shared/test/common/libult/ult_command_stream_receiver.h | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index cb941aed7b..76c82a269c 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -6805,6 +6805,7 @@ HWTEST_F(DeviceSimpleTests, givenNoGpuHangWhenSynchronizingDeviceThenCallWaitFor csr->latestFlushedTaskCount = 0u; csr->taskCount = taskCountToWait++; csr->flushStamp->setStamp(flushStampToWait++); + csr->captureWaitForTaskCountWithKmdNotifyInputParams = true; csr->waitForTaskCountWithKmdNotifyFallbackReturnValue = WaitStatus::ready; } @@ -6815,6 +6816,7 @@ HWTEST_F(DeviceSimpleTests, givenNoGpuHangWhenSynchronizingDeviceThenCallWaitFor csr->latestFlushedTaskCount = 0u; csr->taskCount = taskCountToWait++; csr->flushStamp->setStamp(flushStampToWait++); + csr->captureWaitForTaskCountWithKmdNotifyInputParams = true; csr->waitForTaskCountWithKmdNotifyFallbackReturnValue = WaitStatus::ready; } diff --git a/shared/test/common/libult/ult_command_stream_receiver.h b/shared/test/common/libult/ult_command_stream_receiver.h index 6da63b9ad2..0eafd78cb3 100644 --- a/shared/test/common/libult/ult_command_stream_receiver.h +++ b/shared/test/common/libult/ult_command_stream_receiver.h @@ -330,7 +330,11 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { } WaitStatus waitForTaskCountWithKmdNotifyFallback(TaskCountType taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, QueueThrottle throttle) override { - waitForTaskCountWithKmdNotifyInputParams.push_back({taskCountToWait, flushStampToWait, useQuickKmdSleep, throttle}); + if (captureWaitForTaskCountWithKmdNotifyInputParams) { + static std::mutex waitForTaskCountWithKmdNotifyInputParamsMtx; + std::unique_lock lock(waitForTaskCountWithKmdNotifyInputParamsMtx); + waitForTaskCountWithKmdNotifyInputParams.push_back({taskCountToWait, flushStampToWait, useQuickKmdSleep, throttle}); + } if (waitForTaskCountWithKmdNotifyFallbackReturnValue.has_value()) { return *waitForTaskCountWithKmdNotifyFallbackReturnValue; } @@ -667,6 +671,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { bool isUserFenceWaitSupported = false; bool isAnyDirectSubmissionEnabledCallBase = true; bool isAnyDirectSubmissionEnabledResult = true; + std::atomic_bool captureWaitForTaskCountWithKmdNotifyInputParams = false; }; } // namespace NEO