2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-02-02 01:26:39 +08:00
|
|
|
* Copyright (C) 2018-2023 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>
|
|
|
|
|
|
|
|
#define NSEC_PER_SEC (1000000000ULL)
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class OSInterface;
|
|
|
|
struct HardwareInfo;
|
|
|
|
|
|
|
|
struct TimeStampData {
|
2021-06-22 21:16:27 +08:00
|
|
|
uint64_t GPUTimeStamp; // GPU time in counter ticks
|
2017-12-21 07:45:38 +08:00
|
|
|
uint64_t CPUTimeinNS; // CPU time in ns
|
|
|
|
};
|
|
|
|
|
2021-05-21 01:49:44 +08:00
|
|
|
class OSTime;
|
|
|
|
|
|
|
|
class DeviceTime {
|
|
|
|
public:
|
|
|
|
virtual ~DeviceTime() = default;
|
2023-02-02 01:26:39 +08:00
|
|
|
virtual bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime);
|
|
|
|
virtual double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const;
|
|
|
|
virtual uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const;
|
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);
|
|
|
|
virtual double getHostTimerResolution() const;
|
|
|
|
virtual uint64_t getCpuRawTimestamp();
|
2017-12-21 07:45:38 +08:00
|
|
|
OSInterface *getOSInterface() const {
|
|
|
|
return osInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double getDeviceTimerResolution(HardwareInfo const &hwInfo);
|
2021-05-21 01:49:44 +08:00
|
|
|
bool getCpuGpuTime(TimeStampData *gpuCpuTime) {
|
|
|
|
return deviceTime->getCpuGpuTime(gpuCpuTime, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const {
|
|
|
|
return deviceTime->getDynamicDeviceTimerResolution(hwInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const {
|
|
|
|
return deviceTime->getDynamicDeviceTimerClock(hwInfo);
|
|
|
|
}
|
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;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|