2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2024-04-16 08:50:16 +00:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2019-03-26 11:59:46 +01:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
#include <memory>
|
2023-10-18 10:00:43 +02:00
|
|
|
#include <optional>
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
#define NSEC_PER_SEC (1000000000ULL)
|
2024-04-30 10:59:04 +00:00
|
|
|
#define NSEC_PER_MSEC (NSEC_PER_SEC / 1000)
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
class OSInterface;
|
|
|
|
|
struct HardwareInfo;
|
|
|
|
|
|
|
|
|
|
struct TimeStampData {
|
2023-04-27 09:50:55 +00:00
|
|
|
uint64_t gpuTimeStamp; // GPU time in counter ticks
|
|
|
|
|
uint64_t cpuTimeinNS; // CPU time in ns
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
2021-05-20 19:49:44 +02:00
|
|
|
class OSTime;
|
|
|
|
|
|
|
|
|
|
class DeviceTime {
|
|
|
|
|
public:
|
2024-05-25 07:39:33 +02:00
|
|
|
DeviceTime();
|
2021-05-20 19:49:44 +02:00
|
|
|
virtual ~DeviceTime() = default;
|
2024-04-30 10:59:04 +00:00
|
|
|
bool getGpuCpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime, bool forceKmdCall);
|
2023-10-18 10:00:43 +02:00
|
|
|
virtual bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime);
|
2023-02-01 17:26:39 +00:00
|
|
|
virtual double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const;
|
|
|
|
|
virtual uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const;
|
2024-04-30 10:59:04 +00:00
|
|
|
bool getGpuCpuTimestamps(TimeStampData *timeStamp, OSTime *osTime, bool forceKmdCall);
|
|
|
|
|
void setDeviceTimerResolution(HardwareInfo const &hwInfo);
|
|
|
|
|
void setRefreshTimestampsFlag() {
|
|
|
|
|
refreshTimestamps = true;
|
|
|
|
|
}
|
|
|
|
|
uint64_t getTimestampRefreshTimeout() const {
|
|
|
|
|
return timestampRefreshTimeoutNS;
|
|
|
|
|
};
|
2023-10-18 10:00:43 +02:00
|
|
|
|
|
|
|
|
std::optional<uint64_t> initialGpuTimeStamp{};
|
|
|
|
|
bool waitingForGpuTimeStampOverflow = false;
|
|
|
|
|
uint64_t gpuTimeStampOverflowCounter = 0;
|
2024-04-30 10:59:04 +00:00
|
|
|
|
|
|
|
|
double deviceTimerResolution = 0;
|
|
|
|
|
const uint64_t timestampRefreshMinTimeoutNS = NSEC_PER_MSEC; // 1ms
|
|
|
|
|
const uint64_t timestampRefreshMaxTimeoutNS = NSEC_PER_SEC; // 1s
|
2024-05-25 07:39:33 +02:00
|
|
|
uint64_t timestampRefreshTimeoutNS = 0;
|
2024-04-30 10:59:04 +00:00
|
|
|
bool refreshTimestamps = true;
|
2024-05-25 07:39:33 +02:00
|
|
|
bool reusingTimestampsEnabled = false;
|
2024-04-30 10:59:04 +00:00
|
|
|
TimeStampData fetchedTimestamps{};
|
2021-05-20 19:49:44 +02:00
|
|
|
};
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
class OSTime {
|
|
|
|
|
public:
|
|
|
|
|
static std::unique_ptr<OSTime> create(OSInterface *osInterface);
|
2023-02-01 17:26:39 +00:00
|
|
|
OSTime(std::unique_ptr<DeviceTime> deviceTime);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
virtual ~OSTime() = default;
|
2023-02-01 17:26:39 +00:00
|
|
|
virtual bool getCpuTime(uint64_t *timeStamp);
|
|
|
|
|
virtual double getHostTimerResolution() const;
|
|
|
|
|
virtual uint64_t getCpuRawTimestamp();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
static double getDeviceTimerResolution(HardwareInfo const &hwInfo);
|
2024-04-30 10:59:04 +00:00
|
|
|
|
|
|
|
|
bool getGpuCpuTime(TimeStampData *gpuCpuTime, bool forceKmdCall) {
|
|
|
|
|
return deviceTime->getGpuCpuTime(gpuCpuTime, this, forceKmdCall);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-18 10:00:43 +02:00
|
|
|
bool getGpuCpuTime(TimeStampData *gpuCpuTime) {
|
2024-04-30 10:59:04 +00:00
|
|
|
return deviceTime->getGpuCpuTime(gpuCpuTime, this, false);
|
2021-05-20 19:49:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const {
|
|
|
|
|
return deviceTime->getDynamicDeviceTimerResolution(hwInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const {
|
|
|
|
|
return deviceTime->getDynamicDeviceTimerClock(hwInfo);
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2023-10-18 10:00:43 +02:00
|
|
|
uint64_t getMaxGpuTimeStamp() const { return maxGpuTimeStamp; }
|
|
|
|
|
|
2024-04-30 10:59:04 +00:00
|
|
|
void setDeviceTimerResolution(HardwareInfo const &hwInfo) const {
|
|
|
|
|
deviceTime->setDeviceTimerResolution(hwInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setRefreshTimestampsFlag() const {
|
|
|
|
|
deviceTime->setRefreshTimestampsFlag();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t getTimestampRefreshTimeout() const {
|
|
|
|
|
return deviceTime->getTimestampRefreshTimeout();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
2023-02-01 17:26:39 +00:00
|
|
|
OSTime() = default;
|
2017-12-21 00:45:38 +01:00
|
|
|
OSInterface *osInterface = nullptr;
|
2021-05-20 19:49:44 +02:00
|
|
|
std::unique_ptr<DeviceTime> deviceTime;
|
2023-10-18 10:00:43 +02:00
|
|
|
uint64_t maxGpuTimeStamp = 0;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|