diff --git a/runtime/helpers/kmd_notify_properties.cpp b/runtime/helpers/kmd_notify_properties.cpp index 5dbbee82eb..99dc781883 100644 --- a/runtime/helpers/kmd_notify_properties.cpp +++ b/runtime/helpers/kmd_notify_properties.cpp @@ -42,7 +42,7 @@ bool KmdNotifyHelper::obtainTimeoutParams(int64_t &timeoutValueOutput, } else if (quickKmdSleepRequest && properties->enableQuickKmdSleep) { timeoutValueOutput = properties->delayQuickKmdSleepMicroseconds; } else { - timeoutValueOutput = properties->delayKmdNotifyMicroseconds * multiplier; + timeoutValueOutput = getBaseTimeout(multiplier); } return flushStampToWait != 0 && (properties->enableKmdNotify || !acLineConnected); diff --git a/runtime/helpers/kmd_notify_properties.h b/runtime/helpers/kmd_notify_properties.h index 98800433d9..8a2573831b 100644 --- a/runtime/helpers/kmd_notify_properties.h +++ b/runtime/helpers/kmd_notify_properties.h @@ -64,6 +64,7 @@ class KmdNotifyHelper { protected: bool applyQuickKmdSleepForSporadicWait() const; + int64_t getBaseTimeout(const int64_t &multiplier) const; const KmdNotifyProperties *properties = nullptr; std::chrono::high_resolution_clock::time_point lastWaitForCompletionTimestamp; diff --git a/runtime/helpers/linux/kmd_notify_properties_linux.cpp b/runtime/helpers/linux/kmd_notify_properties_linux.cpp index ccdb21f235..1a7ed9579c 100644 --- a/runtime/helpers/linux/kmd_notify_properties_linux.cpp +++ b/runtime/helpers/linux/kmd_notify_properties_linux.cpp @@ -22,4 +22,10 @@ #include "runtime/helpers/kmd_notify_properties.h" -void OCLRT::KmdNotifyHelper::updateAcLineStatus() {} +using namespace OCLRT; + +void KmdNotifyHelper::updateAcLineStatus() {} + +int64_t KmdNotifyHelper::getBaseTimeout(const int64_t &multiplier) const { + return properties->delayKmdNotifyMicroseconds * multiplier; +} diff --git a/runtime/helpers/windows/kmd_notify_properties_windows.cpp b/runtime/helpers/windows/kmd_notify_properties_windows.cpp index eae99fb117..9e476b4113 100644 --- a/runtime/helpers/windows/kmd_notify_properties_windows.cpp +++ b/runtime/helpers/windows/kmd_notify_properties_windows.cpp @@ -23,10 +23,16 @@ #include "runtime/helpers/kmd_notify_properties.h" #include "runtime/os_interface/windows/sys_calls.h" -void OCLRT::KmdNotifyHelper::updateAcLineStatus() { +using namespace OCLRT; + +void KmdNotifyHelper::updateAcLineStatus() { SYSTEM_POWER_STATUS systemPowerStatus = {}; auto powerStatusRetValue = SysCalls::getSystemPowerStatus(&systemPowerStatus); if (powerStatusRetValue == 1) { acLineConnected = (systemPowerStatus.ACLineStatus == 1); } } + +int64_t KmdNotifyHelper::getBaseTimeout(const int64_t &multiplier) const { + return properties->delayKmdNotifyMicroseconds; +} diff --git a/unit_tests/helpers/CMakeLists.txt b/unit_tests/helpers/CMakeLists.txt index 56163bf917..dca977a6b2 100644 --- a/unit_tests/helpers/CMakeLists.txt +++ b/unit_tests/helpers/CMakeLists.txt @@ -59,8 +59,15 @@ set(IGDRCL_SRCS_tests_helpers_windows ${CMAKE_CURRENT_SOURCE_DIR}/windows/kmd_notify_windows_tests.cpp ) +set(IGDRCL_SRCS_tests_helpers_linux + ${CMAKE_CURRENT_SOURCE_DIR}/linux/kmd_notify_linux_tests.cpp +) + if(WIN32) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_helpers_windows}) -endif() + else() + target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_helpers_linux}) + endif() target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_helpers}) +set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_helpers_linux ${IGDRCL_SRCS_tests_helpers_linux}) diff --git a/unit_tests/helpers/kmd_notify_tests.cpp b/unit_tests/helpers/kmd_notify_tests.cpp index 39fac8e573..c682335d4d 100644 --- a/unit_tests/helpers/kmd_notify_tests.cpp +++ b/unit_tests/helpers/kmd_notify_tests.cpp @@ -221,25 +221,6 @@ HWTEST_F(KmdNotifyTests, givenQuickSleepRequestWhenItsSporadicWaitOptimizationIs csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, true); } -HWTEST_F(KmdNotifyTests, givenComputeTimeoutMultiplierWhenWaitCalledThenUseNewTimeout) { - auto csr = createMockCsr(); - - *device->getTagAddress() = taskCountToWait; - taskCountToWait += 5; - - auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds * - (taskCountToWait - *device->getTagAddress()); - - auto updateHwTag = [&](bool, int64_t, uint32_t) { - *device->getTagAddress() = taskCountToWait; - return true; - }; - - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, ::testing::_)).Times(1).WillOnce(::testing::Invoke(updateHwTag)); - - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false); -} - HWTEST_F(KmdNotifyTests, givenTaskCountEqualToHwTagWhenWaitCalledThenDontMultiplyTimeout) { auto csr = createMockCsr(); *device->getTagAddress() = taskCountToWait; diff --git a/unit_tests/helpers/linux/kmd_notify_linux_tests.cpp b/unit_tests/helpers/linux/kmd_notify_linux_tests.cpp new file mode 100644 index 0000000000..9aa3d7c2d7 --- /dev/null +++ b/unit_tests/helpers/linux/kmd_notify_linux_tests.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/helpers/kmd_notify_properties.h" +#include "runtime/helpers/options.h" + +#include "test.h" + +namespace OCLRT { + +class MockKmdNotifyHelper : public KmdNotifyHelper { + public: + using KmdNotifyHelper::getBaseTimeout; + + MockKmdNotifyHelper(const KmdNotifyProperties *newProperties) : KmdNotifyHelper(newProperties){}; +}; + +TEST(KmdNotifyLinuxTests, givenTaskCountDiffGreaterThanOneWhenBaseTimeoutRequestedThenMultiply) { + auto localProperties = (platformDevices[0]->capabilityTable.kmdNotifyProperties); + localProperties.delayKmdNotifyMicroseconds = 10; + const int64_t multiplier = 10; + + MockKmdNotifyHelper helper(&localProperties); + EXPECT_EQ(localProperties.delayKmdNotifyMicroseconds * multiplier, helper.getBaseTimeout(multiplier)); +} +} // namespace OCLRT diff --git a/unit_tests/helpers/windows/kmd_notify_windows_tests.cpp b/unit_tests/helpers/windows/kmd_notify_windows_tests.cpp index 853e3d4899..f14e04647a 100644 --- a/unit_tests/helpers/windows/kmd_notify_windows_tests.cpp +++ b/unit_tests/helpers/windows/kmd_notify_windows_tests.cpp @@ -37,6 +37,7 @@ extern BYTE systemPowerStatusACLineStatusOverride; class MockKmdNotifyHelper : public KmdNotifyHelper { public: using KmdNotifyHelper::acLineConnected; + using KmdNotifyHelper::getBaseTimeout; using KmdNotifyHelper::updateAcLineStatus; MockKmdNotifyHelper(const KmdNotifyProperties *newProperties) : KmdNotifyHelper(newProperties){}; @@ -74,4 +75,14 @@ TEST(KmdNotifyWindowsTests, whenGetSystemPowerStatusReturnErrorThenDontUpdateAcL helper.updateAcLineStatus(); EXPECT_TRUE(helper.acLineConnected); } + +TEST(KmdNotifyWindowsTests, givenTaskCountDiffGreaterThanOneWhenBaseTimeoutRequestedThenDontMultiply) { + auto localProperties = (platformDevices[0]->capabilityTable.kmdNotifyProperties); + localProperties.delayKmdNotifyMicroseconds = 10; + const int64_t multiplier = 10; + + MockKmdNotifyHelper helper(&localProperties); + EXPECT_EQ(localProperties.delayKmdNotifyMicroseconds, helper.getBaseTimeout(multiplier)); +} + } // namespace OCLRT