Skip to content

Commit 03ee6bc

Browse files
Allways take cpu time from OSTime on WSL
Signed-off-by: Maciej Plewka <[email protected]>
1 parent 269b49a commit 03ee6bc

File tree

6 files changed

+123
-24
lines changed

6 files changed

+123
-24
lines changed

shared/source/os_interface/windows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
4949
${CMAKE_CURRENT_SOURCE_DIR}/dxgi_wrapper.h
5050
${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion_win.cpp
5151
${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion_win.h
52+
${CMAKE_CURRENT_SOURCE_DIR}/device_time_gpu_cpu_${DRIVER_MODEL}.cpp
5253
${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.cpp
5354
${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.h
5455
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_windows.h
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2017-2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/execution_environment/root_device_environment.h"
9+
#include "shared/source/os_interface/hw_info_config.h"
10+
#include "shared/source/os_interface/os_time.h"
11+
#include "shared/source/os_interface/windows/device_time_wddm.h"
12+
#include "shared/source/os_interface/windows/wddm/wddm.h"
13+
14+
namespace NEO {
15+
bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) {
16+
bool retVal = false;
17+
18+
pGpuCpuTime->CPUTimeinNS = 0;
19+
pGpuCpuTime->GPUTimeStamp = 0;
20+
21+
TimeStampDataHeader escapeInfo = {};
22+
23+
if (runEscape(wddm, escapeInfo)) {
24+
auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily;
25+
auto *hwInfoConfig = HwInfoConfig::get(productFamily);
26+
hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks);
27+
28+
osTime->getCpuTime(&pGpuCpuTime->CPUTimeinNS);
29+
pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks;
30+
retVal = true;
31+
}
32+
33+
return retVal;
34+
}
35+
} // namespace NEO
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2017-2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/execution_environment/root_device_environment.h"
9+
#include "shared/source/os_interface/hw_info_config.h"
10+
#include "shared/source/os_interface/os_time.h"
11+
#include "shared/source/os_interface/windows/device_time_wddm.h"
12+
#include "shared/source/os_interface/windows/wddm/wddm.h"
13+
14+
namespace NEO {
15+
bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) {
16+
bool retVal = false;
17+
18+
pGpuCpuTime->CPUTimeinNS = 0;
19+
pGpuCpuTime->GPUTimeStamp = 0;
20+
21+
TimeStampDataHeader escapeInfo = {};
22+
23+
if (runEscape(wddm, escapeInfo)) {
24+
auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily;
25+
auto *hwInfoConfig = HwInfoConfig::get(productFamily);
26+
hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks);
27+
double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks *
28+
(1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq);
29+
30+
pGpuCpuTime->CPUTimeinNS = (unsigned long long)cpuNanoseconds;
31+
pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks;
32+
retVal = true;
33+
}
34+
35+
return retVal;
36+
}
37+
} // namespace NEO

shared/source/os_interface/windows/device_time_wddm.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace NEO {
2121

22-
bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) {
22+
bool DeviceTimeWddm::runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) {
2323
if (wddm) {
2424
D3DKMT_ESCAPE escapeCommand = {0};
2525

@@ -48,29 +48,6 @@ bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) {
4848
return false;
4949
}
5050

51-
bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) {
52-
bool retVal = false;
53-
54-
pGpuCpuTime->CPUTimeinNS = 0;
55-
pGpuCpuTime->GPUTimeStamp = 0;
56-
57-
TimeStampDataHeader escapeInfo = {};
58-
59-
if (runEscape(wddm, escapeInfo)) {
60-
auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily;
61-
auto *hwInfoConfig = HwInfoConfig::get(productFamily);
62-
hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks);
63-
double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks *
64-
(1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq);
65-
66-
pGpuCpuTime->CPUTimeinNS = (unsigned long long)cpuNanoseconds;
67-
pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks;
68-
retVal = true;
69-
}
70-
71-
return retVal;
72-
}
73-
7451
DeviceTimeWddm::DeviceTimeWddm(Wddm *wddm) {
7552
this->wddm = wddm;
7653
}

shared/source/os_interface/windows/device_time_wddm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace NEO {
1515
class Wddm;
16+
struct TimeStampDataHeader;
1617

1718
class DeviceTimeWddm : public DeviceTime {
1819
public:
@@ -22,6 +23,7 @@ class DeviceTimeWddm : public DeviceTime {
2223
uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override;
2324

2425
protected:
26+
MOCKABLE_VIRTUAL bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo);
2527
Wddm *wddm = nullptr;
2628
};
2729

shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
*/
77

88
#include "shared/source/gmm_helper/gmm_helper.h"
9+
#include "shared/source/os_interface/linux/os_time_linux.h"
10+
#include "shared/source/os_interface/os_interface.h"
11+
#include "shared/source/os_interface/os_time.h"
12+
#include "shared/source/os_interface/windows/device_time_wddm.h"
913
#include "shared/source/os_interface/windows/gdi_interface.h"
1014
#include "shared/source/os_interface/windows/os_environment_win.h"
1115
#include "shared/source/os_interface/windows/wddm/wddm.h"
@@ -203,3 +207,46 @@ TEST(WddmLinux, givenRequestFor32bitAllocationWithoutPreexistingHostPtrWhenAlloc
203207
EXPECT_EQ(0U, receivedMapGpuVirtualAddressArgs.BaseAddress);
204208
EXPECT_EQ(mockAllocationHandle, receivedLock2Args.hAllocation);
205209
}
210+
class MockOsTimeLinux : public NEO::OSTimeLinux {
211+
public:
212+
MockOsTimeLinux(NEO::OSInterface *osInterface, std::unique_ptr<NEO::DeviceTime> deviceTime) : NEO::OSTimeLinux(osInterface, std::move(deviceTime)) {}
213+
bool getCpuTime(uint64_t *timeStamp) override {
214+
osTimeGetCpuTimeWasCalled = true;
215+
*timeStamp = 0x1234;
216+
return true;
217+
}
218+
bool osTimeGetCpuTimeWasCalled = false;
219+
};
220+
221+
class MockDeviceTimeWddm : public NEO::DeviceTimeWddm {
222+
public:
223+
MockDeviceTimeWddm(NEO::Wddm *wddm) : NEO::DeviceTimeWddm(wddm) {}
224+
bool runEscape(NEO::Wddm *wddm, NEO::TimeStampDataHeader &escapeInfo) override {
225+
return true;
226+
}
227+
};
228+
229+
TEST(OSTimeWinLinuxTests, givenOSInterfaceWhenGetCpuGpuTimeThenGetCpuTimeFromOsTimeWasCalled) {
230+
231+
NEO::TimeStampData CPUGPUTime01 = {0};
232+
233+
std::unique_ptr<NEO::HwDeviceIdWddm> hwDeviceIdIn;
234+
auto osEnvironment = std::make_unique<NEO::OsEnvironmentWin>();
235+
osEnvironment->gdi->closeAdapter = closeAdapterMock;
236+
osEnvironment->gdi->reserveGpuVirtualAddress = reserveDeviceAddressSpaceMock;
237+
NEO::MockExecutionEnvironment mockExecEnv;
238+
NEO::MockRootDeviceEnvironment mockRootDeviceEnvironment{mockExecEnv};
239+
hwDeviceIdIn.reset(new NEO::HwDeviceIdWddm(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique<NEO::UmKmDataTranslator>()));
240+
241+
std::unique_ptr<NEO::OSInterface> osInterface(new NEO::OSInterface());
242+
243+
std::unique_ptr<MockWddmLinux> wddm = std::make_unique<MockWddmLinux>(std::move(hwDeviceIdIn), mockRootDeviceEnvironment);
244+
*wddm->gfxPlatform = NEO::defaultHwInfo->platform;
245+
mockRootDeviceEnvironment.setHwInfo(NEO::defaultHwInfo.get());
246+
auto mockDeviceTimeWddm = std::make_unique<MockDeviceTimeWddm>(wddm.get());
247+
osInterface->setDriverModel(std::move(wddm));
248+
std::unique_ptr<NEO::DeviceTime> deviceTime = std::unique_ptr<NEO::DeviceTime>(mockDeviceTimeWddm.release());
249+
auto osTime = std::unique_ptr<MockOsTimeLinux>(new MockOsTimeLinux(osInterface.get(), std::move(deviceTime)));
250+
osTime->getCpuGpuTime(&CPUGPUTime01);
251+
EXPECT_TRUE(osTime->osTimeGetCpuTimeWasCalled);
252+
}

0 commit comments

Comments
 (0)