2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2024-11-28 05:28:50 +08:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/windows/os_time_win.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-10-18 16:00:43 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2021-05-21 01:49:44 +08:00
|
|
|
#include "shared/source/os_interface/windows/device_time_wddm.h"
|
2021-05-21 07:17:57 +08:00
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#undef WIN32_NO_STATUS
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
bool OSTimeWin::getCpuTime(uint64_t *timeStamp) {
|
|
|
|
uint64_t time;
|
2018-02-19 22:04:03 +08:00
|
|
|
this->QueryPerfomanceCounterFnc((LARGE_INTEGER *)&time);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-19 22:04:03 +08:00
|
|
|
*timeStamp = static_cast<uint64_t>((static_cast<double>(time) * NSEC_PER_SEC / frequency.QuadPart));
|
2017-12-21 07:45:38 +08:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2024-11-28 05:28:50 +08:00
|
|
|
bool OSTime::getCpuTimeHost(uint64_t *timeStamp) {
|
|
|
|
uint64_t time;
|
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&time);
|
|
|
|
|
|
|
|
LARGE_INTEGER frequency;
|
|
|
|
QueryPerformanceFrequency(&frequency);
|
|
|
|
*timeStamp = static_cast<uint64_t>((static_cast<double>(time) * NSEC_PER_SEC / frequency.QuadPart));
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2023-10-18 16:00:43 +08:00
|
|
|
std::unique_ptr<OSTime> OSTimeWin::create(OSInterface &osInterface) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return std::unique_ptr<OSTime>(new OSTimeWin(osInterface));
|
|
|
|
}
|
|
|
|
|
2023-10-18 16:00:43 +08:00
|
|
|
OSTimeWin::OSTimeWin(OSInterface &osInterface) {
|
|
|
|
this->osInterface = &osInterface;
|
|
|
|
Wddm *wddm = osInterface.getDriverModel()->as<Wddm>();
|
|
|
|
auto hwInfo = wddm->getHardwareInfo();
|
|
|
|
if (hwInfo->capabilityTable.timestampValidBits < 64) {
|
|
|
|
maxGpuTimeStamp = 1ull << hwInfo->capabilityTable.timestampValidBits;
|
|
|
|
}
|
2021-05-21 01:49:44 +08:00
|
|
|
this->deviceTime = std::make_unique<DeviceTimeWddm>(wddm);
|
2017-12-21 07:45:38 +08:00
|
|
|
QueryPerformanceFrequency(&frequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
double OSTimeWin::getHostTimerResolution() const {
|
|
|
|
double retValue = 0;
|
|
|
|
if (frequency.QuadPart) {
|
|
|
|
retValue = 1e9 / frequency.QuadPart;
|
|
|
|
}
|
|
|
|
return retValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t OSTimeWin::getCpuRawTimestamp() {
|
|
|
|
LARGE_INTEGER cpuRawTimestamp = {};
|
2018-02-19 22:04:03 +08:00
|
|
|
this->QueryPerfomanceCounterFnc(&cpuRawTimestamp);
|
2017-12-21 07:45:38 +08:00
|
|
|
return cpuRawTimestamp.QuadPart;
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|