Allways take cpu time from OSTime on WSL

Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka 2021-09-08 14:38:15 +00:00 committed by Compute-Runtime-Automation
parent 269b49a0d4
commit 03ee6bc2dd
6 changed files with 123 additions and 24 deletions

View File

@ -49,6 +49,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
${CMAKE_CURRENT_SOURCE_DIR}/dxgi_wrapper.h
${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion_win.cpp
${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion_win.h
${CMAKE_CURRENT_SOURCE_DIR}/device_time_gpu_cpu_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.h
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_windows.h

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/os_time.h"
#include "shared/source/os_interface/windows/device_time_wddm.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
namespace NEO {
bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) {
bool retVal = false;
pGpuCpuTime->CPUTimeinNS = 0;
pGpuCpuTime->GPUTimeStamp = 0;
TimeStampDataHeader escapeInfo = {};
if (runEscape(wddm, escapeInfo)) {
auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily;
auto *hwInfoConfig = HwInfoConfig::get(productFamily);
hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks);
osTime->getCpuTime(&pGpuCpuTime->CPUTimeinNS);
pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks;
retVal = true;
}
return retVal;
}
} // namespace NEO

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/os_time.h"
#include "shared/source/os_interface/windows/device_time_wddm.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
namespace NEO {
bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) {
bool retVal = false;
pGpuCpuTime->CPUTimeinNS = 0;
pGpuCpuTime->GPUTimeStamp = 0;
TimeStampDataHeader escapeInfo = {};
if (runEscape(wddm, escapeInfo)) {
auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily;
auto *hwInfoConfig = HwInfoConfig::get(productFamily);
hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks);
double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks *
(1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq);
pGpuCpuTime->CPUTimeinNS = (unsigned long long)cpuNanoseconds;
pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks;
retVal = true;
}
return retVal;
}
} // namespace NEO

View File

@ -19,7 +19,7 @@
namespace NEO {
bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) {
bool DeviceTimeWddm::runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) {
if (wddm) {
D3DKMT_ESCAPE escapeCommand = {0};
@ -48,29 +48,6 @@ bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) {
return false;
}
bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) {
bool retVal = false;
pGpuCpuTime->CPUTimeinNS = 0;
pGpuCpuTime->GPUTimeStamp = 0;
TimeStampDataHeader escapeInfo = {};
if (runEscape(wddm, escapeInfo)) {
auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily;
auto *hwInfoConfig = HwInfoConfig::get(productFamily);
hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks);
double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks *
(1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq);
pGpuCpuTime->CPUTimeinNS = (unsigned long long)cpuNanoseconds;
pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks;
retVal = true;
}
return retVal;
}
DeviceTimeWddm::DeviceTimeWddm(Wddm *wddm) {
this->wddm = wddm;
}

View File

@ -13,6 +13,7 @@
namespace NEO {
class Wddm;
struct TimeStampDataHeader;
class DeviceTimeWddm : public DeviceTime {
public:
@ -22,6 +23,7 @@ class DeviceTimeWddm : public DeviceTime {
uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override;
protected:
MOCKABLE_VIRTUAL bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo);
Wddm *wddm = nullptr;
};

View File

@ -6,6 +6,10 @@
*/
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/os_interface/linux/os_time_linux.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/os_interface/os_time.h"
#include "shared/source/os_interface/windows/device_time_wddm.h"
#include "shared/source/os_interface/windows/gdi_interface.h"
#include "shared/source/os_interface/windows/os_environment_win.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
@ -203,3 +207,46 @@ TEST(WddmLinux, givenRequestFor32bitAllocationWithoutPreexistingHostPtrWhenAlloc
EXPECT_EQ(0U, receivedMapGpuVirtualAddressArgs.BaseAddress);
EXPECT_EQ(mockAllocationHandle, receivedLock2Args.hAllocation);
}
class MockOsTimeLinux : public NEO::OSTimeLinux {
public:
MockOsTimeLinux(NEO::OSInterface *osInterface, std::unique_ptr<NEO::DeviceTime> deviceTime) : NEO::OSTimeLinux(osInterface, std::move(deviceTime)) {}
bool getCpuTime(uint64_t *timeStamp) override {
osTimeGetCpuTimeWasCalled = true;
*timeStamp = 0x1234;
return true;
}
bool osTimeGetCpuTimeWasCalled = false;
};
class MockDeviceTimeWddm : public NEO::DeviceTimeWddm {
public:
MockDeviceTimeWddm(NEO::Wddm *wddm) : NEO::DeviceTimeWddm(wddm) {}
bool runEscape(NEO::Wddm *wddm, NEO::TimeStampDataHeader &escapeInfo) override {
return true;
}
};
TEST(OSTimeWinLinuxTests, givenOSInterfaceWhenGetCpuGpuTimeThenGetCpuTimeFromOsTimeWasCalled) {
NEO::TimeStampData CPUGPUTime01 = {0};
std::unique_ptr<NEO::HwDeviceIdWddm> hwDeviceIdIn;
auto osEnvironment = std::make_unique<NEO::OsEnvironmentWin>();
osEnvironment->gdi->closeAdapter = closeAdapterMock;
osEnvironment->gdi->reserveGpuVirtualAddress = reserveDeviceAddressSpaceMock;
NEO::MockExecutionEnvironment mockExecEnv;
NEO::MockRootDeviceEnvironment mockRootDeviceEnvironment{mockExecEnv};
hwDeviceIdIn.reset(new NEO::HwDeviceIdWddm(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique<NEO::UmKmDataTranslator>()));
std::unique_ptr<NEO::OSInterface> osInterface(new NEO::OSInterface());
std::unique_ptr<MockWddmLinux> wddm = std::make_unique<MockWddmLinux>(std::move(hwDeviceIdIn), mockRootDeviceEnvironment);
*wddm->gfxPlatform = NEO::defaultHwInfo->platform;
mockRootDeviceEnvironment.setHwInfo(NEO::defaultHwInfo.get());
auto mockDeviceTimeWddm = std::make_unique<MockDeviceTimeWddm>(wddm.get());
osInterface->setDriverModel(std::move(wddm));
std::unique_ptr<NEO::DeviceTime> deviceTime = std::unique_ptr<NEO::DeviceTime>(mockDeviceTimeWddm.release());
auto osTime = std::unique_ptr<MockOsTimeLinux>(new MockOsTimeLinux(osInterface.get(), std::move(deviceTime)));
osTime->getCpuGpuTime(&CPUGPUTime01);
EXPECT_TRUE(osTime->osTimeGetCpuTimeWasCalled);
}