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