2018-05-08 19:19:26 +08:00
|
|
|
/*
|
|
|
|
* 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/command_stream/preemption.h"
|
|
|
|
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
|
|
|
#include "unit_tests/os_interface/windows/wddm_fixture.h"
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
using namespace OCLRT;
|
|
|
|
|
|
|
|
class WddmPreemptionTests : public Test<WddmFixtureWithMockGdiDll> {
|
|
|
|
public:
|
|
|
|
void SetUp() override {
|
|
|
|
WddmFixtureWithMockGdiDll::SetUp();
|
|
|
|
const HardwareInfo hwInfo = *platformDevices[0];
|
|
|
|
memcpy(&hwInfoTest, &hwInfo, sizeof(hwInfoTest));
|
|
|
|
dbgRestorer = new DebugManagerStateRestore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
delete dbgRestorer;
|
|
|
|
WddmFixtureWithMockGdiDll::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void createAndInitWddm(unsigned int forceReturnPreemptionRegKeyValue) {
|
2018-08-27 21:48:29 +08:00
|
|
|
wddm = static_cast<WddmMock *>(Wddm::createWddm());
|
|
|
|
osInterface = std::make_unique<OSInterface>();
|
|
|
|
osInterface->get()->setWddm(wddm);
|
2018-05-08 19:19:26 +08:00
|
|
|
auto regReader = new RegistryReaderMock();
|
|
|
|
wddm->registryReader.reset(regReader);
|
|
|
|
regReader->forceRetValue = forceReturnPreemptionRegKeyValue;
|
|
|
|
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest);
|
|
|
|
wddm->setPreemptionMode(preemptionMode);
|
2018-08-23 17:29:39 +08:00
|
|
|
wddm->init();
|
2018-09-12 13:47:55 +08:00
|
|
|
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
|
2018-08-27 21:48:29 +08:00
|
|
|
osContextWin = osContext->get();
|
2018-05-08 19:19:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DebugManagerStateRestore *dbgRestorer = nullptr;
|
|
|
|
HardwareInfo hwInfoTest;
|
|
|
|
};
|
|
|
|
|
2018-08-23 17:29:39 +08:00
|
|
|
TEST_F(WddmPreemptionTests, givenDevicePreemptionEnabledDebugFlagDontForceWhenPreemptionRegKeySetThenSetGpuTimeoutFlagOn) {
|
2018-05-08 19:19:26 +08:00
|
|
|
DebugManager.flags.ForcePreemptionMode.set(-1); // dont force
|
|
|
|
hwInfoTest.capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread;
|
|
|
|
unsigned int expectedVal = 1u;
|
2018-08-23 17:29:39 +08:00
|
|
|
createAndInitWddm(1u);
|
2018-05-08 19:19:26 +08:00
|
|
|
EXPECT_EQ(expectedVal, getMockCreateDeviceParamsFcn().Flags.DisableGpuTimeout);
|
|
|
|
EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout);
|
|
|
|
}
|
|
|
|
|
2018-08-23 17:29:39 +08:00
|
|
|
TEST_F(WddmPreemptionTests, givenDevicePreemptionDisabledDebugFlagDontForceWhenPreemptionRegKeySetThenSetGpuTimeoutFlagOff) {
|
2018-05-08 19:19:26 +08:00
|
|
|
DebugManager.flags.ForcePreemptionMode.set(-1); // dont force
|
|
|
|
hwInfoTest.capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled;
|
|
|
|
unsigned int expectedVal = 0u;
|
2018-08-23 17:29:39 +08:00
|
|
|
createAndInitWddm(1u);
|
2018-05-08 19:19:26 +08:00
|
|
|
EXPECT_EQ(expectedVal, getMockCreateDeviceParamsFcn().Flags.DisableGpuTimeout);
|
|
|
|
EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout);
|
|
|
|
}
|
|
|
|
|
2018-08-23 17:29:39 +08:00
|
|
|
TEST_F(WddmPreemptionTests, givenDevicePreemptionEnabledDebugFlagDontForceWhenPreemptionRegKeyNotSetThenSetGpuTimeoutFlagOff) {
|
2018-05-08 19:19:26 +08:00
|
|
|
DebugManager.flags.ForcePreemptionMode.set(-1); // dont force
|
|
|
|
hwInfoTest.capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread;
|
|
|
|
unsigned int expectedVal = 0u;
|
2018-08-23 17:29:39 +08:00
|
|
|
createAndInitWddm(0u);
|
2018-05-08 19:19:26 +08:00
|
|
|
EXPECT_EQ(expectedVal, getMockCreateDeviceParamsFcn().Flags.DisableGpuTimeout);
|
|
|
|
EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout);
|
|
|
|
}
|
|
|
|
|
2018-08-23 17:29:39 +08:00
|
|
|
TEST_F(WddmPreemptionTests, givenDevicePreemptionDisabledDebugFlagDontForceWhenPreemptionRegKeyNotSetThenSetGpuTimeoutFlagOff) {
|
2018-05-08 19:19:26 +08:00
|
|
|
DebugManager.flags.ForcePreemptionMode.set(-1); // dont force
|
|
|
|
hwInfoTest.capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled;
|
|
|
|
unsigned int expectedVal = 0u;
|
2018-08-23 17:29:39 +08:00
|
|
|
createAndInitWddm(0u);
|
2018-05-08 19:19:26 +08:00
|
|
|
EXPECT_EQ(expectedVal, getMockCreateDeviceParamsFcn().Flags.DisableGpuTimeout);
|
|
|
|
EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout);
|
|
|
|
}
|
|
|
|
|
2018-08-23 17:29:39 +08:00
|
|
|
TEST_F(WddmPreemptionTests, givenDevicePreemptionDisabledDebugFlagForcePreemptionWhenPreemptionRegKeySetThenSetGpuTimeoutFlagOn) {
|
2018-05-08 19:19:26 +08:00
|
|
|
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::MidThread)); // force preemption
|
|
|
|
hwInfoTest.capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled;
|
|
|
|
unsigned int expectedVal = 1u;
|
2018-08-23 17:29:39 +08:00
|
|
|
createAndInitWddm(1u);
|
2018-05-08 19:19:26 +08:00
|
|
|
EXPECT_EQ(expectedVal, getMockCreateDeviceParamsFcn().Flags.DisableGpuTimeout);
|
|
|
|
EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout);
|
|
|
|
}
|
|
|
|
|
2018-08-23 17:29:39 +08:00
|
|
|
TEST_F(WddmPreemptionTests, givenDevicePreemptionDisabledDebugFlagForcePreemptionWhenPreemptionRegKeyNotSetThenSetGpuTimeoutFlagOff) {
|
2018-05-08 19:19:26 +08:00
|
|
|
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::MidThread)); // force preemption
|
|
|
|
hwInfoTest.capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled;
|
|
|
|
unsigned int expectedVal = 0u;
|
2018-08-23 17:29:39 +08:00
|
|
|
createAndInitWddm(0u);
|
2018-05-08 19:19:26 +08:00
|
|
|
EXPECT_EQ(expectedVal, getMockCreateDeviceParamsFcn().Flags.DisableGpuTimeout);
|
|
|
|
EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout);
|
|
|
|
}
|