2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-05-10 01:40:30 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_time.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-10-23 21:38:35 +08:00
|
|
|
static int PerfTicks = 0;
|
2021-05-21 01:49:44 +08:00
|
|
|
class MockDeviceTime : public DeviceTime {
|
|
|
|
bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override {
|
2017-12-21 07:45:38 +08:00
|
|
|
pGpuCpuTime->GPUTimeStamp = ++PerfTicks;
|
2022-11-10 12:53:45 +08:00
|
|
|
pGpuCpuTime->CPUTimeinNS = PerfTicks;
|
2017-12-21 07:45:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
2021-05-21 01:49:44 +08:00
|
|
|
|
|
|
|
double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override {
|
|
|
|
return OSTime::getDeviceTimerResolution(hwInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override {
|
|
|
|
return static_cast<uint64_t>(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MockOSTime : public OSTime {
|
|
|
|
public:
|
|
|
|
MockOSTime() {
|
|
|
|
this->deviceTime = std::make_unique<MockDeviceTime>();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool getCpuTime(uint64_t *timeStamp) override {
|
2022-11-10 12:53:45 +08:00
|
|
|
*timeStamp = ++PerfTicks;
|
2017-12-21 07:45:38 +08:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
double getHostTimerResolution() const override {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-21 01:49:44 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
uint64_t getCpuRawTimestamp() override {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static std::unique_ptr<OSTime> create() {
|
|
|
|
return std::unique_ptr<OSTime>(new MockOSTime());
|
|
|
|
}
|
|
|
|
};
|
2021-06-22 21:16:27 +08:00
|
|
|
|
|
|
|
class MockDeviceTimeWithConstTimestamp : public DeviceTime {
|
|
|
|
public:
|
2022-11-10 12:53:45 +08:00
|
|
|
static constexpr uint64_t CPU_TIME_IN_NS = 1u; // NOLINT(readability-identifier-naming)
|
|
|
|
static constexpr uint64_t GPU_TIMESTAMP = 2u; // NOLINT(readability-identifier-naming)
|
2021-06-22 21:16:27 +08:00
|
|
|
|
|
|
|
bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override {
|
2022-11-10 12:53:45 +08:00
|
|
|
pGpuCpuTime->GPUTimeStamp = GPU_TIMESTAMP;
|
|
|
|
pGpuCpuTime->CPUTimeinNS = CPU_TIME_IN_NS;
|
2021-06-22 21:16:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override {
|
|
|
|
return static_cast<uint64_t>(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MockOSTimeWithConstTimestamp : public OSTime {
|
|
|
|
public:
|
|
|
|
MockOSTimeWithConstTimestamp() {
|
|
|
|
this->deviceTime = std::make_unique<MockDeviceTimeWithConstTimestamp>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getCpuTime(uint64_t *timeStamp) override {
|
2022-11-10 12:53:45 +08:00
|
|
|
*timeStamp = MockDeviceTimeWithConstTimestamp::CPU_TIME_IN_NS;
|
2021-06-22 21:16:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double getHostTimerResolution() const override {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getCpuRawTimestamp() override {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|