diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 9fb5e3ad06..1821897267 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -935,7 +935,7 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties) ze_result_t DeviceImp::getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp) { NEO::TimeStampData queueTimeStamp; - bool retVal = this->neoDevice->getOSTime()->getCpuGpuTime(&queueTimeStamp); + bool retVal = this->neoDevice->getOSTime()->getGpuCpuTime(&queueTimeStamp); if (!retVal) return ZE_RESULT_ERROR_DEVICE_LOST; diff --git a/level_zero/core/source/event/event.cpp b/level_zero/core/source/event/event.cpp index a9f6c8e5d5..a355ef3a17 100644 --- a/level_zero/core/source/event/event.cpp +++ b/level_zero/core/source/event/event.cpp @@ -415,7 +415,7 @@ void Event::setReferenceTs(uint64_t currentCpuTimeStamp) { const auto recalculate = (currentCpuTimeStamp - referenceTs.cpuTimeinNS) > timestampRefreshIntervalInNanoSec; if (referenceTs.cpuTimeinNS == 0 || recalculate) { - device->getNEODevice()->getOSTime()->getCpuGpuTime(&referenceTs); + device->getNEODevice()->getOSTime()->getGpuCpuTime(&referenceTs); } } diff --git a/level_zero/core/test/unit_tests/fixtures/device_fixture.h b/level_zero/core/test/unit_tests/fixtures/device_fixture.h index 17f05a62db..d3e489aac0 100644 --- a/level_zero/core/test/unit_tests/fixtures/device_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/device_fixture.h @@ -186,9 +186,9 @@ struct SingleRootMultiSubDeviceFixtureWithImplicitScaling : public SingleRootMul SingleRootMultiSubDeviceFixtureWithImplicitScaling() : SingleRootMultiSubDeviceFixtureWithImplicitScalingImpl(copyEngineCount, implicitScalingArg){}; }; -class FalseCpuGpuDeviceTime : public NEO::DeviceTime { +class FalseGpuCpuDeviceTime : public NEO::DeviceTime { public: - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override { return false; } double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override { @@ -199,10 +199,10 @@ class FalseCpuGpuDeviceTime : public NEO::DeviceTime { } }; -class FalseCpuGpuTime : public NEO::OSTime { +class FalseGpuCpuTime : public NEO::OSTime { public: - FalseCpuGpuTime() { - this->deviceTime = std::make_unique(); + FalseGpuCpuTime() { + this->deviceTime = std::make_unique(); } bool getCpuTime(uint64_t *timeStamp) override { @@ -215,7 +215,7 @@ class FalseCpuGpuTime : public NEO::OSTime { return 0; } static std::unique_ptr create() { - return std::unique_ptr(new FalseCpuGpuTime()); + return std::unique_ptr(new FalseGpuCpuTime()); } }; diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index 29b2e90b97..443e722b4f 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -1533,11 +1533,11 @@ struct GlobalTimestampTest : public ::testing::Test { const uint32_t numRootDevices = 2u; }; -TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetCpuGpuTimeIsFalseReturnError) { +TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetGpuCpuTimeIsFalseReturnError) { uint64_t hostTs = 0u; uint64_t deviceTs = 0u; - neoDevice->setOSTime(new FalseCpuGpuTime()); + neoDevice->setOSTime(new FalseGpuCpuTime()); NEO::DeviceVector devices; devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique>(); @@ -1549,7 +1549,7 @@ TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetCpuGpuTimeIsFalseR } TEST_F(GlobalTimestampTest, whenGetProfilingTimerClockandProfilingTimerResolutionThenVerifyRelation) { - neoDevice->setOSTime(new FalseCpuGpuTime()); + neoDevice->setOSTime(new FalseGpuCpuTime()); NEO::DeviceVector devices; devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique>(); @@ -1563,7 +1563,7 @@ TEST_F(GlobalTimestampTest, whenGetProfilingTimerClockandProfilingTimerResolutio } TEST_F(GlobalTimestampTest, whenQueryingForTimerResolutionWithLegacyDevicePropertiesStructThenDefaultTimerResolutionInNanoSecondsIsReturned) { - neoDevice->setOSTime(new FalseCpuGpuTime()); + neoDevice->setOSTime(new FalseGpuCpuTime()); NEO::DeviceVector devices; devices.push_back(std::unique_ptr(neoDevice)); std::unique_ptr driverHandle = std::make_unique(); @@ -1579,7 +1579,7 @@ TEST_F(GlobalTimestampTest, whenQueryingForTimerResolutionWithLegacyDeviceProper } TEST_F(GlobalTimestampTest, whenQueryingForTimerResolutionWithDeviceProperties_1_2_StructThenDefaultTimerResolutionInCyclesPerSecondsIsReturned) { - neoDevice->setOSTime(new FalseCpuGpuTime()); + neoDevice->setOSTime(new FalseGpuCpuTime()); NEO::DeviceVector devices; devices.push_back(std::unique_ptr(neoDevice)); std::unique_ptr driverHandle = std::make_unique(); @@ -1598,7 +1598,7 @@ TEST_F(GlobalTimestampTest, whenQueryingForTimerResolutionWithUseCyclesPerSecond DebugManagerStateRestore restorer; DebugManager.flags.UseCyclesPerSecondTimer.set(1u); - neoDevice->setOSTime(new FalseCpuGpuTime()); + neoDevice->setOSTime(new FalseGpuCpuTime()); NEO::DeviceVector devices; devices.push_back(std::unique_ptr(neoDevice)); std::unique_ptr driverHandle = std::make_unique(); @@ -1615,7 +1615,7 @@ TEST_F(GlobalTimestampTest, whenQueryingForTimerResolutionWithUseCyclesPerSecond class FalseCpuDeviceTime : public NEO::DeviceTime { public: - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, NEO::OSTime *) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, NEO::OSTime *) override { pGpuCpuTime->cpuTimeinNS = mockCpuTimeInNs; pGpuCpuTime->gpuTimeStamp = mockGpuTimeInNs; return true; diff --git a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp index 0c3df6204b..402666f0f4 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp +++ b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp @@ -6,6 +6,7 @@ */ #include "shared/test/common/mocks/mock_driver_info.h" +#include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/test_macros/test.h" #include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h" @@ -312,22 +313,6 @@ TEST_F(SysmanMultiDeviceFixture, GivenValidEffectiveUserIdCheckWhetherPermission } } -class UnknownDriverModel : public DriverModel { - public: - UnknownDriverModel() : DriverModel(DriverModelType::UNKNOWN) {} - void setGmmInputArgs(void *args) override {} - uint32_t getDeviceHandle() const override { return 0u; } - PhysicalDevicePciBusInfo getPciBusInfo() const override { - PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::invalidValue, PhysicalDevicePciBusInfo::invalidValue, PhysicalDevicePciBusInfo::invalidValue, PhysicalDevicePciBusInfo::invalidValue); - return pciBusInfo; - } - PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override { return {}; } - - bool isGpuHangDetected(OsContext &osContext) override { - return false; - } -}; - TEST(SysmanUnknownDriverModelTest, GivenDriverModelTypeIsNotDrmWhenExecutingSysmanOnLinuxThenErrorIsReturned) { NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); hwInfo.capabilityTable.levelZeroSupported = true; @@ -335,7 +320,7 @@ TEST(SysmanUnknownDriverModelTest, GivenDriverModelTypeIsNotDrmWhenExecutingSysm execEnv->prepareRootDeviceEnvironments(1); execEnv->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(NEO::defaultHwInfo.get()); execEnv->rootDeviceEnvironments[0]->osInterface = std::make_unique(); - execEnv->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); + execEnv->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); auto pSysmanDeviceImp = std::make_unique(execEnv, 0); auto pLinuxSysmanImp = static_cast(pSysmanDeviceImp->pOsSysman); diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp index eb14266ea0..3caef2aeb6 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp @@ -299,11 +299,11 @@ TEST_F(MetricIpSamplingTimestampTest, GivenEnumerationIsSuccessfulWhenReadingMet EXPECT_NE(metricTimestamp, 0UL); } -TEST_F(MetricIpSamplingTimestampTest, GivenGetCpuGpuTimeIsFalseWhenReadingMetricsFrequencyThenValuesAreZero) { +TEST_F(MetricIpSamplingTimestampTest, GivenGetGpuCpuTimeIsFalseWhenReadingMetricsFrequencyThenValuesAreZero) { EXPECT_EQ(ZE_RESULT_SUCCESS, device->getMetricDeviceContext().enableMetricApi()); - neoDevice->setOSTime(new FalseCpuGpuTime()); + neoDevice->setOSTime(new FalseGpuCpuTime()); ze_device_properties_t deviceProps = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2, nullptr}; device->getProperties(&deviceProps); diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp index a8c962e791..a1ab0222cb 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp @@ -786,7 +786,7 @@ TEST_F(MetricEnumerationTest, GivenEnumerationIsSuccessfulWhenFailingToReadMetri globalTimestamp = 1; metricTimestamp = 1; - neoDevice->setOSTime(new FalseCpuGpuTime()); + neoDevice->setOSTime(new FalseGpuCpuTime()); EXPECT_EQ(L0::zetMetricGroupGetGlobalTimestampsExp(metricGroupHandle, synchronizedWithHost, &globalTimestamp, &metricTimestamp), ZE_RESULT_ERROR_DEVICE_LOST); EXPECT_EQ(globalTimestamp, 0UL); EXPECT_EQ(metricTimestamp, 0UL); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp index 50b48fe786..8f27f5c65e 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp @@ -6,6 +6,7 @@ */ #include "shared/test/common/mocks/mock_driver_info.h" +#include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h" #include "shared/test/common/test_macros/test.h" @@ -800,27 +801,11 @@ TEST_F(SysmanMultiDeviceFixture, GivenSysmanEnvironmentVariableSetWhenCreateL0De EXPECT_EQ(device->getSysmanHandle(), nullptr); } -class UnknownDriverModel : public DriverModel { - public: - UnknownDriverModel() : DriverModel(DriverModelType::UNKNOWN) {} - void setGmmInputArgs(void *args) override {} - uint32_t getDeviceHandle() const override { return 0u; } - PhysicalDevicePciBusInfo getPciBusInfo() const override { - PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::invalidValue, PhysicalDevicePciBusInfo::invalidValue, PhysicalDevicePciBusInfo::invalidValue, PhysicalDevicePciBusInfo::invalidValue); - return pciBusInfo; - } - PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override { return {}; } - - bool isGpuHangDetected(OsContext &osContext) override { - return false; - } -}; - using SysmanUnknownDriverModelTest = Test; TEST_F(SysmanUnknownDriverModelTest, GivenDriverModelTypeIsNotDrmWhenExecutingSysmanOnLinuxThenErrorIsReturned) { neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->osInterface = std::make_unique(); auto &osInterface = device->getOsInterface(); - osInterface.setDriverModel(std::make_unique()); + osInterface.setDriverModel(std::make_unique()); auto pSysmanDeviceImp = std::make_unique(device->toHandle()); auto pLinuxSysmanImp = static_cast(pSysmanDeviceImp->pOsSysman); EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxSysmanImp->init()); diff --git a/opencl/source/command_queue/command_queue_hw_base.inl b/opencl/source/command_queue/command_queue_hw_base.inl index ec4599588b..b47a49a9a8 100644 --- a/opencl/source/command_queue/command_queue_hw_base.inl +++ b/opencl/source/command_queue/command_queue_hw_base.inl @@ -227,7 +227,7 @@ void CommandQueueHw::setupEvent(EventBuilder &eventBuilder, cl_event *ou if (eventObj->isProfilingEnabled()) { TimeStampData queueTimeStamp; - getDevice().getOSTime()->getCpuGpuTime(&queueTimeStamp); + getDevice().getOSTime()->getGpuCpuTime(&queueTimeStamp); eventObj->setQueueTimeStamp(queueTimeStamp); if (isCommandWithoutKernel(cmdType) && cmdType != CL_COMMAND_MARKER) { diff --git a/opencl/source/command_queue/cpu_data_transfer_handler.cpp b/opencl/source/command_queue/cpu_data_transfer_handler.cpp index d90c59c474..5536a7d1a2 100644 --- a/opencl/source/command_queue/cpu_data_transfer_handler.cpp +++ b/opencl/source/command_queue/cpu_data_transfer_handler.cpp @@ -61,7 +61,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie eventBuilder.create(this, transferProperties.cmdType, CompletionStamp::notReady, CompletionStamp::notReady); outEventObj = eventBuilder.getEvent(); TimeStampData queueTimeStamp; - getDevice().getOSTime()->getCpuGpuTime(&queueTimeStamp); + getDevice().getOSTime()->getGpuCpuTime(&queueTimeStamp); outEventObj->setQueueTimeStamp(queueTimeStamp); outEventObj->setCPUProfilingPath(true); *eventsRequest.outEvent = outEventObj; @@ -99,7 +99,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie if (outEventObj) { TimeStampData submitTimeStamp; - getDevice().getOSTime()->getCpuGpuTime(&submitTimeStamp); + getDevice().getOSTime()->getGpuCpuTime(&submitTimeStamp); outEventObj->setSubmitTimeStamp(submitTimeStamp); } // wait for the completness of previous commands diff --git a/opencl/source/command_queue/enqueue_common.h b/opencl/source/command_queue/enqueue_common.h index ef8900afcb..0308447eb0 100644 --- a/opencl/source/command_queue/enqueue_common.h +++ b/opencl/source/command_queue/enqueue_common.h @@ -421,7 +421,7 @@ cl_int CommandQueueHw::enqueueHandler(Surface **surfacesForResidency, if (eventBuilder.getEvent() && isProfilingEnabled()) { TimeStampData submitTimeStamp; - getDevice().getOSTime()->getCpuGpuTime(&submitTimeStamp); + getDevice().getOSTime()->getGpuCpuTime(&submitTimeStamp); eventBuilder.getEvent()->setSubmitTimeStamp(submitTimeStamp); eventBuilder.getEvent()->setStartTimeStamp(); } @@ -851,7 +851,7 @@ CompletionStamp CommandQueueHw::enqueueNonBlocked( if (isProfilingEnabled() && eventBuilder.getEvent()) { TimeStampData submitTimeStamp; - getDevice().getOSTime()->getCpuGpuTime(&submitTimeStamp); + getDevice().getOSTime()->getGpuCpuTime(&submitTimeStamp); eventBuilder.getEvent()->setSubmitTimeStamp(submitTimeStamp); auto hwTimestampNode = eventBuilder.getEvent()->getHwTimeStampNode(); @@ -1118,7 +1118,7 @@ CompletionStamp CommandQueueHw::enqueueCommandWithoutKernel( if (eventBuilder.getEvent() && isProfilingEnabled()) { TimeStampData submitTimeStamp; - getDevice().getOSTime()->getCpuGpuTime(&submitTimeStamp); + getDevice().getOSTime()->getGpuCpuTime(&submitTimeStamp); eventBuilder.getEvent()->setSubmitTimeStamp(submitTimeStamp); eventBuilder.getEvent()->setStartTimeStamp(); } diff --git a/opencl/source/event/event.cpp b/opencl/source/event/event.cpp index 87b3d0a3cf..759d1cdc3a 100644 --- a/opencl/source/event/event.cpp +++ b/opencl/source/event/event.cpp @@ -374,7 +374,7 @@ void Event::calculateProfilingDataInternal(uint64_t contextStartTS, uint64_t con if (DebugManager.flags.EnableDeviceBasedTimestamps.get()) { startTimeStamp = static_cast(globalStartTS * frequency); - if (startTimeStamp < gpuQueueTimeStamp) { + while (startTimeStamp < gpuQueueTimeStamp) { startTimeStamp += static_cast((1ULL << gfxCoreHelper.getGlobalTimeStampBits()) * frequency); } } else { @@ -612,7 +612,7 @@ void Event::submitCommand(bool abortTasks) { this->cmdQueue->getGpgpuCommandStreamReceiver().makeResident(*timeStampNode->getBaseGraphicsAllocation()); cmdToProcess->timestamp = timeStampNode; } - this->cmdQueue->getDevice().getOSTime()->getCpuGpuTime(&submitTimeStamp); + this->cmdQueue->getDevice().getOSTime()->getGpuCpuTime(&submitTimeStamp); if (profilingCpuPath) { setStartTimeStamp(); } else { diff --git a/opencl/test/unit_test/api/cl_get_device_and_host_timer.inl b/opencl/test/unit_test/api/cl_get_device_and_host_timer.inl index 90ec841fc6..84503ee9cd 100644 --- a/opencl/test/unit_test/api/cl_get_device_and_host_timer.inl +++ b/opencl/test/unit_test/api/cl_get_device_and_host_timer.inl @@ -14,7 +14,7 @@ using namespace NEO; struct FailDeviceTime : public MockDeviceTime { - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *) override { return false; } }; diff --git a/opencl/test/unit_test/device/device_timers_tests.cpp b/opencl/test/unit_test/device/device_timers_tests.cpp index 1024ff0d93..9972be3791 100644 --- a/opencl/test/unit_test/device/device_timers_tests.cpp +++ b/opencl/test/unit_test/device/device_timers_tests.cpp @@ -164,7 +164,7 @@ class FailingMockOSTime : public OSTime { class FailingMockDeviceTime : public DeviceTime { public: - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override { return false; } diff --git a/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl b/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl index 10d7ab0901..06b21b0161 100644 --- a/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl +++ b/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl @@ -93,7 +93,7 @@ class MyDeviceTime : public DeviceTime { EXPECT_FALSE(true); return 0; } - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *) override { EXPECT_FALSE(true); return false; } diff --git a/opencl/test/unit_test/os_interface/linux/mock_performance_counters_linux.cpp b/opencl/test/unit_test/os_interface/linux/mock_performance_counters_linux.cpp index 3e328f3862..89eeb716ee 100644 --- a/opencl/test/unit_test/os_interface/linux/mock_performance_counters_linux.cpp +++ b/opencl/test/unit_test/os_interface/linux/mock_performance_counters_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -42,9 +42,11 @@ void PerformanceCountersFixture::setUp() { device = std::make_unique(new MockDevice()); context = std::make_unique(device.get()); queue = std::make_unique(context.get(), device.get(), &queueProperties, false); - osInterface = std::unique_ptr(new OSInterface()); - osInterface->setDriverModel(std::unique_ptr(new DrmMock(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]))); - device->setOSTime(new MockOSTimeLinux(osInterface.get())); + auto &rootDeviceEnvironment = *device->getExecutionEnvironment()->rootDeviceEnvironments[0]; + rootDeviceEnvironment.osInterface = std::make_unique(); + rootDeviceEnvironment.osInterface->setDriverModel(std::unique_ptr(new DrmMock(rootDeviceEnvironment))); + + device->setOSTime(new MockOSTimeLinux(*rootDeviceEnvironment.osInterface)); } ////////////////////////////////////////////////////// diff --git a/opencl/test/unit_test/os_interface/linux/performance_counters_linux_tests.cpp b/opencl/test/unit_test/os_interface/linux/performance_counters_linux_tests.cpp index 2867433a5e..8dc0d43322 100644 --- a/opencl/test/unit_test/os_interface/linux/performance_counters_linux_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/performance_counters_linux_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -36,5 +36,5 @@ TEST_F(PerformanceCountersLinuxTest, WhenCreatingPerformanceCountersThenDrmFileD auto performanceCountersLinux = static_cast(performanceCounters.get()); EXPECT_EQ(LinuxAdapterType::DrmFileDescriptor, performanceCountersLinux->adapter.Type); - EXPECT_EQ(osInterface->getDriverModel()->as()->getFileDescriptor(), performanceCountersLinux->adapter.DrmFileDescriptor); + EXPECT_EQ(device->getRootDeviceEnvironment().osInterface->getDriverModel()->as()->getFileDescriptor(), performanceCountersLinux->adapter.DrmFileDescriptor); } diff --git a/opencl/test/unit_test/os_interface/mock_performance_counters.cpp b/opencl/test/unit_test/os_interface/mock_performance_counters.cpp index 93fd014ff4..5c0bcaa301 100644 --- a/opencl/test/unit_test/os_interface/mock_performance_counters.cpp +++ b/opencl/test/unit_test/os_interface/mock_performance_counters.cpp @@ -361,8 +361,6 @@ void PerformanceCountersMetricsLibraryFixture::tearDown() { ////////////////////////////////////////////////////// PerformanceCountersFixture::PerformanceCountersFixture() { executionEnvironment = std::make_unique(); - rootDeviceEnvironment = std::make_unique(*executionEnvironment); - rootDeviceEnvironment->setHwInfoAndInitHelpers(defaultHwInfo.get()); } ////////////////////////////////////////////////////// diff --git a/opencl/test/unit_test/os_interface/mock_performance_counters.h b/opencl/test/unit_test/os_interface/mock_performance_counters.h index ec5cfb8f08..8a9f129e98 100644 --- a/opencl/test/unit_test/os_interface/mock_performance_counters.h +++ b/opencl/test/unit_test/os_interface/mock_performance_counters.h @@ -226,8 +226,6 @@ struct PerformanceCountersFixture { std::unique_ptr context; std::unique_ptr queue; std::unique_ptr executionEnvironment; - std::unique_ptr rootDeviceEnvironment; - std::unique_ptr osInterface; }; ////////////////////////////////////////////////////// diff --git a/opencl/test/unit_test/os_interface/performance_counters_tests.cpp b/opencl/test/unit_test/os_interface/performance_counters_tests.cpp index eb75c3b246..2ac119ab99 100644 --- a/opencl/test/unit_test/os_interface/performance_counters_tests.cpp +++ b/opencl/test/unit_test/os_interface/performance_counters_tests.cpp @@ -215,9 +215,10 @@ struct PerformanceCountersMetricsLibraryTest : public PerformanceCountersMetrics public: void SetUp() override { PerformanceCountersMetricsLibraryFixture::setUp(); - auto hwInfo = rootDeviceEnvironment->getHardwareInfo(); - auto &gfxCoreHelper = rootDeviceEnvironment->getHelper(); - osContext = std::make_unique(0, EngineDescriptorHelper::getDefaultDescriptor(gfxCoreHelper.getGpgpuEngineInstances(*rootDeviceEnvironment)[0], + auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0]; + auto hwInfo = rootDeviceEnvironment.getHardwareInfo(); + auto &gfxCoreHelper = rootDeviceEnvironment.getHelper(); + osContext = std::make_unique(0, EngineDescriptorHelper::getDefaultDescriptor(gfxCoreHelper.getGpgpuEngineInstances(rootDeviceEnvironment)[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo))); queue->getGpgpuCommandStreamReceiver().setupContext(*osContext); } diff --git a/opencl/test/unit_test/os_interface/windows/mock_performance_counters_win.cpp b/opencl/test/unit_test/os_interface/windows/mock_performance_counters_win.cpp index f34e0a5a5b..8d5c1f7047 100644 --- a/opencl/test/unit_test/os_interface/windows/mock_performance_counters_win.cpp +++ b/opencl/test/unit_test/os_interface/windows/mock_performance_counters_win.cpp @@ -42,9 +42,10 @@ void PerformanceCountersFixture::setUp() { device = std::make_unique(new MockDevice()); context = std::make_unique(device.get()); queue = std::make_unique(context.get(), device.get(), &queueProperties, false); - osInterface = std::unique_ptr(new OSInterface()); - osInterface->setDriverModel(std::unique_ptr(new WddmMock(*rootDeviceEnvironment))); - device->setOSTime(new MockOSTimeWin(osInterface.get())); + auto &rootDeviceEnvironment = *device->getExecutionEnvironment()->rootDeviceEnvironments[0]; + rootDeviceEnvironment.osInterface = std::make_unique(); + rootDeviceEnvironment.osInterface->setDriverModel(std::unique_ptr(new WddmMock(rootDeviceEnvironment))); + device->setOSTime(new MockOSTimeWin(*rootDeviceEnvironment.osInterface)); } ////////////////////////////////////////////////////// diff --git a/opencl/test/unit_test/profiling/profiling_tests.cpp b/opencl/test/unit_test/profiling/profiling_tests.cpp index b305cc8fa1..6780211a95 100644 --- a/opencl/test/unit_test/profiling/profiling_tests.cpp +++ b/opencl/test/unit_test/profiling/profiling_tests.cpp @@ -505,7 +505,7 @@ class MyOSDeviceTime : public DeviceTime { EXPECT_FALSE(true); return 0; } - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *) override { EXPECT_FALSE(true); return false; } diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 84ded01d74..14766080a7 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -248,7 +248,7 @@ bool Device::createDeviceImpl() { initializeCaps(); - if (getOSTime()->getOSInterface()) { + if (getRootDeviceEnvironment().osInterface) { if (hwInfo.capabilityTable.instrumentationEnabled) { performanceCounters = createPerformanceCountersFunc(this); } @@ -512,7 +512,7 @@ EngineControl &Device::getEngine(uint32_t index) { bool Device::getDeviceAndHostTimer(uint64_t *deviceTimestamp, uint64_t *hostTimestamp) const { TimeStampData timeStamp; - auto retVal = getOSTime()->getCpuGpuTime(&timeStamp); + auto retVal = getOSTime()->getGpuCpuTime(&timeStamp); if (retVal) { *hostTimestamp = timeStamp.cpuTimeinNS; if (DebugManager.flags.EnableDeviceBasedTimestamps.get()) { diff --git a/shared/source/helpers/gfx_core_helper_xehp_and_later.inl b/shared/source/helpers/gfx_core_helper_xehp_and_later.inl index cae925fdcf..5b5c04d42f 100644 --- a/shared/source/helpers/gfx_core_helper_xehp_and_later.inl +++ b/shared/source/helpers/gfx_core_helper_xehp_and_later.inl @@ -126,9 +126,7 @@ inline uint32_t GfxCoreHelperHw::calculateMaxWorkGroupSize(const Kern template uint64_t GfxCoreHelperHw::getGpuTimeStampInNS(uint64_t timeStamp, double frequency) const { - constexpr uint64_t mask = static_cast(std::numeric_limits::max()); - - return static_cast((timeStamp & mask) * frequency); + return static_cast(timeStamp * frequency); } constexpr uint32_t planarYuvMaxHeight = 16128; diff --git a/shared/source/os_interface/create_os_time_drm.cpp b/shared/source/os_interface/create_os_time_drm.cpp index ac4dab8e2a..11c0db590f 100644 --- a/shared/source/os_interface/create_os_time_drm.cpp +++ b/shared/source/os_interface/create_os_time_drm.cpp @@ -13,7 +13,7 @@ namespace NEO { std::unique_ptr OSTime::create(OSInterface *osInterface) { if (osInterface) { - return OSTimeLinux::create(osInterface, std::make_unique(osInterface)); + return OSTimeLinux::create(*osInterface, std::make_unique(*osInterface)); } return std::make_unique(std::make_unique()); diff --git a/shared/source/os_interface/create_os_time_drm_or_wddm.cpp b/shared/source/os_interface/create_os_time_drm_or_wddm.cpp index 88c2f4bb78..7638ab3239 100644 --- a/shared/source/os_interface/create_os_time_drm_or_wddm.cpp +++ b/shared/source/os_interface/create_os_time_drm_or_wddm.cpp @@ -17,10 +17,10 @@ std::unique_ptr OSTime::create(OSInterface *osInterface) { if (nullptr == osInterface) { return std::make_unique(std::make_unique()); } else if (osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) { - return OSTimeLinux::create(osInterface, std::make_unique(osInterface)); + return OSTimeLinux::create(*osInterface, std::make_unique(*osInterface)); } else { auto wddm = osInterface->getDriverModel()->as(); - return OSTimeLinux::create(osInterface, std::make_unique(wddm)); + return OSTimeLinux::create(*osInterface, std::make_unique(wddm)); } } diff --git a/shared/source/os_interface/create_os_time_wddm.cpp b/shared/source/os_interface/create_os_time_wddm.cpp index c72290d323..da884b91a0 100644 --- a/shared/source/os_interface/create_os_time_wddm.cpp +++ b/shared/source/os_interface/create_os_time_wddm.cpp @@ -12,7 +12,7 @@ namespace NEO { std::unique_ptr OSTime::create(OSInterface *osInterface) { if (osInterface) { - return OSTimeWin::create(osInterface); + return OSTimeWin::create(*osInterface); } return std::make_unique(std::make_unique()); diff --git a/shared/source/os_interface/linux/device_time_drm.cpp b/shared/source/os_interface/linux/device_time_drm.cpp index 96bd9a62bb..43fbe59632 100644 --- a/shared/source/os_interface/linux/device_time_drm.cpp +++ b/shared/source/os_interface/linux/device_time_drm.cpp @@ -17,10 +17,8 @@ namespace NEO { -DeviceTimeDrm::DeviceTimeDrm(OSInterface *osInterface) { - if (osInterface) { - pDrm = osInterface->getDriverModel()->as(); - } +DeviceTimeDrm::DeviceTimeDrm(OSInterface &osInterface) { + pDrm = osInterface.getDriverModel()->as(); timestampTypeDetect(); } @@ -28,9 +26,6 @@ void DeviceTimeDrm::timestampTypeDetect() { RegisterRead reg = {}; int err; - if (pDrm == nullptr) - return; - reg.offset = (REG_GLOBAL_TIMESTAMP_LDW | 1); auto ioctlHelper = pDrm->getIoctlHelper(); err = ioctlHelper->ioctl(DrmIoctl::RegRead, ®); @@ -98,7 +93,11 @@ bool DeviceTimeDrm::getGpuTimeSplitted(uint64_t *timestamp) { return true; } -bool DeviceTimeDrm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { +std::optional initialGpuTimeStamp{}; +bool waitingForGpuTimeStampOverflow = false; +uint64_t gpuTimeStampOverflowCounter = 0; + +bool DeviceTimeDrm::getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) { if (nullptr == this->getGpuTime) { return false; } @@ -108,7 +107,6 @@ bool DeviceTimeDrm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { if (!osTime->getCpuTime(&pGpuCpuTime->cpuTimeinNS)) { return false; } - return true; } diff --git a/shared/source/os_interface/linux/device_time_drm.h b/shared/source/os_interface/linux/device_time_drm.h index 4213b9c941..a828a5936f 100644 --- a/shared/source/os_interface/linux/device_time_drm.h +++ b/shared/source/os_interface/linux/device_time_drm.h @@ -13,8 +13,8 @@ class Drm; class DeviceTimeDrm : public DeviceTime { public: - DeviceTimeDrm(OSInterface *osInterface); - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override; + DeviceTimeDrm(OSInterface &osInterface); + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override; typedef bool (DeviceTimeDrm::*TimestampFunction)(uint64_t *); void timestampTypeDetect(); TimestampFunction getGpuTime = nullptr; diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 7a00f99008..eed2388c0e 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1535,6 +1535,8 @@ void Drm::waitOnUserFences(const OsContextLinux &osContext, uint64_t address, ui completionFenceCpuAddress = ptrOffset(completionFenceCpuAddress, postSyncOffset); } } +const HardwareInfo *Drm::getHardwareInfo() const { return rootDeviceEnvironment.getHardwareInfo(); } + template std::vector Drm::query(uint32_t queryId, uint32_t queryItemFlags); template std::vector Drm::query(uint32_t queryId, uint32_t queryItemFlags); template std::vector Drm::query(uint32_t queryId, uint32_t queryItemFlags); diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index 6675df3c54..375af26128 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -195,6 +195,7 @@ class Drm : public DriverModel { const RootDeviceEnvironment &getRootDeviceEnvironment() const { return rootDeviceEnvironment; } + const HardwareInfo *getHardwareInfo() const override; bool resourceRegistrationEnabled() { return classHandles.size() > 0; diff --git a/shared/source/os_interface/linux/os_time_linux.cpp b/shared/source/os_interface/linux/os_time_linux.cpp index 0dcbca39d9..5d2499f7d8 100644 --- a/shared/source/os_interface/linux/os_time_linux.cpp +++ b/shared/source/os_interface/linux/os_time_linux.cpp @@ -7,7 +7,8 @@ #include "shared/source/os_interface/linux/os_time_linux.h" -#include "shared/source/os_interface/linux/device_time_drm.h" +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/os_interface.h" #include @@ -15,8 +16,13 @@ namespace NEO { -OSTimeLinux::OSTimeLinux(OSInterface *osInterface, std::unique_ptr deviceTime) { - this->osInterface = osInterface; +OSTimeLinux::OSTimeLinux(OSInterface &osInterface, std::unique_ptr deviceTime) { + this->osInterface = &osInterface; + auto hwInfo = osInterface.getDriverModel()->getHardwareInfo(); + if (hwInfo->capabilityTable.timestampValidBits < 64) { + this->maxGpuTimeStamp = 1ull << hwInfo->capabilityTable.timestampValidBits; + } + resolutionFunc = &clock_getres; getTimeFunc = &clock_gettime; this->deviceTime = std::move(deviceTime); @@ -55,7 +61,7 @@ uint64_t OSTimeLinux::getCpuRawTimestamp() { return timesInNsec / ticksInNsec; } -std::unique_ptr OSTimeLinux::create(OSInterface *osInterface, std::unique_ptr deviceTime) { +std::unique_ptr OSTimeLinux::create(OSInterface &osInterface, std::unique_ptr deviceTime) { return std::unique_ptr(new OSTimeLinux(osInterface, std::move(deviceTime))); } diff --git a/shared/source/os_interface/linux/os_time_linux.h b/shared/source/os_interface/linux/os_time_linux.h index c41089b188..79540ab9d9 100644 --- a/shared/source/os_interface/linux/os_time_linux.h +++ b/shared/source/os_interface/linux/os_time_linux.h @@ -15,12 +15,12 @@ namespace NEO { class OSTimeLinux : public OSTime { public: - OSTimeLinux(OSInterface *osInterface, std::unique_ptr deviceTime); + OSTimeLinux(OSInterface &osInterface, std::unique_ptr deviceTime); bool getCpuTime(uint64_t *timeStamp) override; double getHostTimerResolution() const override; uint64_t getCpuRawTimestamp() override; - static std::unique_ptr create(OSInterface *osInterface, std::unique_ptr deviceTime); + static std::unique_ptr create(OSInterface &osInterface, std::unique_ptr deviceTime); protected: typedef int (*resolutionFunc_t)(clockid_t, struct timespec *); diff --git a/shared/source/os_interface/linux/performance_counters_linux.cpp b/shared/source/os_interface/linux/performance_counters_linux.cpp index a7df743ae9..835dfdc7c9 100644 --- a/shared/source/os_interface/linux/performance_counters_linux.cpp +++ b/shared/source/os_interface/linux/performance_counters_linux.cpp @@ -9,9 +9,9 @@ #include "shared/source/device/device.h" #include "shared/source/device/sub_device.h" +#include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/os_interface/linux/drm_neo.h" -#include "shared/source/os_interface/linux/os_time_linux.h" #include "shared/source/os_interface/os_interface.h" namespace NEO { @@ -20,7 +20,7 @@ namespace NEO { //////////////////////////////////////////////////// std::unique_ptr PerformanceCounters::create(Device *device) { auto counter = std::make_unique(); - auto drm = device->getOSTime()->getOSInterface()->getDriverModel()->as(); + auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); auto &gfxCoreHelper = device->getGfxCoreHelper(); UNRECOVERABLE_IF(counter == nullptr); diff --git a/shared/source/os_interface/os_interface.h b/shared/source/os_interface/os_interface.h index 9e783600a4..eca968e7f9 100644 --- a/shared/source/os_interface/os_interface.h +++ b/shared/source/os_interface/os_interface.h @@ -17,6 +17,7 @@ namespace NEO { struct PhysicalDevicePciBusInfo; struct PhysicalDevicePciSpeedInfo; +struct HardwareInfo; enum class DriverModelType; class ExecutionEnvironment; class MemoryManager; @@ -95,6 +96,8 @@ class DriverModel : public NonCopyableClass { virtual void cleanup() {} virtual bool isGpuHangDetected(OsContext &osContext) = 0; + virtual const HardwareInfo *getHardwareInfo() const = 0; + const TopologyMap &getTopologyMap() { return topologyMap; }; diff --git a/shared/source/os_interface/os_time.cpp b/shared/source/os_interface/os_time.cpp index 0f59460a1e..cbf07cd9d1 100644 --- a/shared/source/os_interface/os_time.cpp +++ b/shared/source/os_interface/os_time.cpp @@ -9,13 +9,15 @@ #include "shared/source/helpers/hw_info.h" +#include + namespace NEO { double OSTime::getDeviceTimerResolution(HardwareInfo const &hwInfo) { return hwInfo.capabilityTable.defaultProfilingTimerResolution; }; -bool DeviceTime::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { +bool DeviceTime::getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) { pGpuCpuTime->cpuTimeinNS = 0; pGpuCpuTime->gpuTimeStamp = 0; @@ -29,6 +31,33 @@ uint64_t DeviceTime::getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) cons return static_cast(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo)); } +bool DeviceTime::getGpuCpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { + if (!getGpuCpuTimeImpl(pGpuCpuTime, osTime)) { + return false; + } + + auto maxGpuTimeStampValue = osTime->getMaxGpuTimeStamp(); + + static std::mutex gpuTimeStampOverflowCounterMutex; + std::lock_guard lock(gpuTimeStampOverflowCounterMutex); + pGpuCpuTime->gpuTimeStamp &= (maxGpuTimeStampValue - 1); + if (!initialGpuTimeStamp) { + initialGpuTimeStamp = pGpuCpuTime->gpuTimeStamp; + waitingForGpuTimeStampOverflow = true; + } else { + if (waitingForGpuTimeStampOverflow && pGpuCpuTime->gpuTimeStamp < *initialGpuTimeStamp) { + gpuTimeStampOverflowCounter++; + waitingForGpuTimeStampOverflow = false; + } + if (!waitingForGpuTimeStampOverflow && pGpuCpuTime->gpuTimeStamp > *initialGpuTimeStamp) { + waitingForGpuTimeStampOverflow = true; + } + + pGpuCpuTime->gpuTimeStamp += gpuTimeStampOverflowCounter * maxGpuTimeStampValue; + } + return true; +} + bool OSTime::getCpuTime(uint64_t *timeStamp) { *timeStamp = 0; return true; diff --git a/shared/source/os_interface/os_time.h b/shared/source/os_interface/os_time.h index 28009fbc28..e021a829bb 100644 --- a/shared/source/os_interface/os_time.h +++ b/shared/source/os_interface/os_time.h @@ -7,6 +7,7 @@ #pragma once #include +#include #define NSEC_PER_SEC (1000000000ULL) @@ -25,9 +26,14 @@ class OSTime; class DeviceTime { public: virtual ~DeviceTime() = default; - virtual bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime); + bool getGpuCpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime); + virtual bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime); virtual double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const; virtual uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const; + + std::optional initialGpuTimeStamp{}; + bool waitingForGpuTimeStampOverflow = false; + uint64_t gpuTimeStampOverflowCounter = 0; }; class OSTime { @@ -39,13 +45,10 @@ class OSTime { virtual bool getCpuTime(uint64_t *timeStamp); virtual double getHostTimerResolution() const; virtual uint64_t getCpuRawTimestamp(); - OSInterface *getOSInterface() const { - return osInterface; - } static double getDeviceTimerResolution(HardwareInfo const &hwInfo); - bool getCpuGpuTime(TimeStampData *gpuCpuTime) { - return deviceTime->getCpuGpuTime(gpuCpuTime, this); + bool getGpuCpuTime(TimeStampData *gpuCpuTime) { + return deviceTime->getGpuCpuTime(gpuCpuTime, this); } double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const { @@ -56,9 +59,12 @@ class OSTime { return deviceTime->getDynamicDeviceTimerClock(hwInfo); } + uint64_t getMaxGpuTimeStamp() const { return maxGpuTimeStamp; } + protected: OSTime() = default; OSInterface *osInterface = nullptr; std::unique_ptr deviceTime; + uint64_t maxGpuTimeStamp = 0; }; } // namespace NEO diff --git a/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp b/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp index 79ae8c6c70..e33bde9888 100644 --- a/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp @@ -12,7 +12,7 @@ #include "shared/source/os_interface/windows/wddm/wddm.h" namespace NEO { -bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { +bool DeviceTimeWddm::getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) { bool retVal = false; pGpuCpuTime->cpuTimeinNS = 0; @@ -31,4 +31,4 @@ bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { return retVal; } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp b/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp index 8d7686a418..0dc489e564 100644 --- a/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp @@ -12,7 +12,7 @@ #include "shared/source/os_interface/windows/wddm/wddm.h" namespace NEO { -bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { +bool DeviceTimeWddm::getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) { bool retVal = false; pGpuCpuTime->cpuTimeinNS = 0; @@ -33,4 +33,4 @@ bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { return retVal; } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/os_interface/windows/device_time_wddm.h b/shared/source/os_interface/windows/device_time_wddm.h index a559b04aee..37a01477f4 100644 --- a/shared/source/os_interface/windows/device_time_wddm.h +++ b/shared/source/os_interface/windows/device_time_wddm.h @@ -19,7 +19,7 @@ struct TimeStampDataHeader; class DeviceTimeWddm : public DeviceTime { public: DeviceTimeWddm(Wddm *wddm); - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override; + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override; double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override; uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override; diff --git a/shared/source/os_interface/windows/os_time_win.cpp b/shared/source/os_interface/windows/os_time_win.cpp index ca4bc3210a..e1edecfc65 100644 --- a/shared/source/os_interface/windows/os_time_win.cpp +++ b/shared/source/os_interface/windows/os_time_win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #include "shared/source/os_interface/windows/os_time_win.h" +#include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/windows/device_time_wddm.h" #include "shared/source/os_interface/windows/wddm/wddm.h" @@ -24,13 +25,17 @@ bool OSTimeWin::getCpuTime(uint64_t *timeStamp) { return true; }; -std::unique_ptr OSTimeWin::create(OSInterface *osInterface) { +std::unique_ptr OSTimeWin::create(OSInterface &osInterface) { return std::unique_ptr(new OSTimeWin(osInterface)); } -OSTimeWin::OSTimeWin(OSInterface *osInterface) { - this->osInterface = osInterface; - Wddm *wddm = osInterface ? osInterface->getDriverModel()->as() : nullptr; +OSTimeWin::OSTimeWin(OSInterface &osInterface) { + this->osInterface = &osInterface; + Wddm *wddm = osInterface.getDriverModel()->as(); + auto hwInfo = wddm->getHardwareInfo(); + if (hwInfo->capabilityTable.timestampValidBits < 64) { + maxGpuTimeStamp = 1ull << hwInfo->capabilityTable.timestampValidBits; + } this->deviceTime = std::make_unique(wddm); QueryPerformanceFrequency(&frequency); } diff --git a/shared/source/os_interface/windows/os_time_win.h b/shared/source/os_interface/windows/os_time_win.h index ab65b6631a..e2079741ca 100644 --- a/shared/source/os_interface/windows/os_time_win.h +++ b/shared/source/os_interface/windows/os_time_win.h @@ -1,12 +1,11 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once -#include "shared/source/os_interface/os_interface.h" #include "shared/source/os_interface/os_time.h" #include "shared/source/os_interface/windows/gfx_escape_wrapper.h" #include "shared/source/os_interface/windows/windows_wrapper.h" @@ -17,12 +16,12 @@ class Wddm; class OSTimeWin : public OSTime { public: - OSTimeWin(OSInterface *osInterface); + OSTimeWin(OSInterface &osInterface); bool getCpuTime(uint64_t *timeStamp) override; double getHostTimerResolution() const override; uint64_t getCpuRawTimestamp() override; - static std::unique_ptr create(OSInterface *osInterface); + static std::unique_ptr create(OSInterface &osInterface); protected: LARGE_INTEGER frequency; diff --git a/shared/source/os_interface/windows/performance_counters_win.cpp b/shared/source/os_interface/windows/performance_counters_win.cpp index 4087ae56c9..406f9c3439 100644 --- a/shared/source/os_interface/windows/performance_counters_win.cpp +++ b/shared/source/os_interface/windows/performance_counters_win.cpp @@ -11,7 +11,6 @@ #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/os_interface.h" -#include "shared/source/os_interface/windows/os_time_win.h" #include "shared/source/os_interface/windows/wddm/wddm.h" namespace NEO { @@ -20,7 +19,7 @@ namespace NEO { ///////////////////////////////////////////////////// std::unique_ptr PerformanceCounters::create(Device *device) { auto counter = std::make_unique(); - auto wddm = device->getOSTime()->getOSInterface()->getDriverModel()->as(); + auto wddm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); auto &gfxCoreHelper = device->getGfxCoreHelper(); UNRECOVERABLE_IF(counter == nullptr); diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 736a49438f..4c8ea9ea9a 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -185,6 +185,7 @@ class Wddm : public DriverModel { } const RootDeviceEnvironment &getRootDeviceEnvironment() const { return rootDeviceEnvironment; } + const HardwareInfo *getHardwareInfo() const override { return rootDeviceEnvironment.getHardwareInfo(); } uint32_t getTimestampFrequency() const { return timestampFrequency; } diff --git a/shared/test/common/common_main.cpp b/shared/test/common/common_main.cpp index 50c8bd009b..cc237e1528 100644 --- a/shared/test/common/common_main.cpp +++ b/shared/test/common/common_main.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/device/device.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/gmm_helper/gmm_interface.h" #include "shared/source/helpers/api_specific_config.h" @@ -418,6 +419,8 @@ int main(int argc, char **argv) { sipInitialized = true; } + Device::createPerformanceCountersFunc = [](Device *) -> std::unique_ptr { return {}; }; + retVal = RUN_ALL_TESTS(); if (showTestStats) { diff --git a/shared/test/common/mocks/linux/mock_os_time_linux.h b/shared/test/common/mocks/linux/mock_os_time_linux.h index fb6bed1710..51c3289985 100644 --- a/shared/test/common/mocks/linux/mock_os_time_linux.h +++ b/shared/test/common/mocks/linux/mock_os_time_linux.h @@ -14,15 +14,26 @@ namespace NEO { class MockDeviceTimeDrm : public DeviceTimeDrm { public: + using DeviceTimeDrm::DeviceTimeDrm; using DeviceTimeDrm::pDrm; - MockDeviceTimeDrm() : DeviceTimeDrm(nullptr) { + + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override { + if (callBaseGetGpuCpuTimeImpl) { + return DeviceTimeDrm::getGpuCpuTimeImpl(pGpuCpuTime, osTime); + } + *pGpuCpuTime = gpuCpuTimeValue; + return getGpuCpuTimeImplResult; } + bool callBaseGetGpuCpuTimeImpl = true; + bool getGpuCpuTimeImplResult = true; + TimeStampData gpuCpuTimeValue{}; }; class MockOSTimeLinux : public OSTimeLinux { public: - MockOSTimeLinux(OSInterface *osInterface) - : OSTimeLinux(osInterface, std::make_unique()) { + using OSTimeLinux::maxGpuTimeStamp; + MockOSTimeLinux(OSInterface &osInterface) + : OSTimeLinux(osInterface, std::make_unique(osInterface)) { } void setResolutionFunc(resolutionFunc_t func) { this->resolutionFunc = func; @@ -35,7 +46,7 @@ class MockOSTimeLinux : public OSTimeLinux { static_cast(this->deviceTime.get())->pDrm = drm; static_cast(this->deviceTime.get())->timestampTypeDetect(); } - static std::unique_ptr create(OSInterface *osInterface) { + static std::unique_ptr create(OSInterface &osInterface) { return std::unique_ptr(new MockOSTimeLinux(osInterface)); } diff --git a/shared/test/common/mocks/mock_driver_model.h b/shared/test/common/mocks/mock_driver_model.h index 5437f01f54..44ed73f273 100644 --- a/shared/test/common/mocks/mock_driver_model.h +++ b/shared/test/common/mocks/mock_driver_model.h @@ -10,6 +10,7 @@ #include "shared/source/helpers/driver_model_type.h" #include "shared/source/os_interface/driver_info.h" #include "shared/source/os_interface/os_interface.h" +#include "shared/test/common/helpers/default_hw_info.h" #include #include @@ -41,6 +42,8 @@ class MockDriverModel : public NEO::DriverModel { PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override { return pciSpeedInfo; } + const HardwareInfo *getHardwareInfo() const override { return nullptr; } + PhysicalDevicePciSpeedInfo pciSpeedInfo{}; PhysicalDevicePciBusInfo pciBusInfo{}; bool isGpuHangDetectedToReturn{}; diff --git a/shared/test/common/mocks/mock_ostime.h b/shared/test/common/mocks/mock_ostime.h index 2a01714eec..1bcdf77695 100644 --- a/shared/test/common/mocks/mock_ostime.h +++ b/shared/test/common/mocks/mock_ostime.h @@ -12,7 +12,7 @@ namespace NEO { static int PerfTicks = 0; constexpr uint64_t convertToNs = 100; class MockDeviceTime : public DeviceTime { - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override { pGpuCpuTime->gpuTimeStamp = ++PerfTicks; pGpuCpuTime->cpuTimeinNS = PerfTicks * convertToNs; return true; @@ -54,7 +54,7 @@ class MockDeviceTimeWithConstTimestamp : public DeviceTime { static constexpr uint64_t cpuTimeInNs = 1u; static constexpr uint64_t gpuTimestamp = 2u; - bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) override { + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override { pGpuCpuTime->gpuTimeStamp = gpuTimestamp; pGpuCpuTime->cpuTimeinNS = cpuTimeInNs; return true; diff --git a/shared/test/common/mocks/windows/mock_os_time_win.h b/shared/test/common/mocks/windows/mock_os_time_win.h index 8fde924408..b00495a077 100644 --- a/shared/test/common/mocks/windows/mock_os_time_win.h +++ b/shared/test/common/mocks/windows/mock_os_time_win.h @@ -11,7 +11,9 @@ namespace NEO { class MockOSTimeWin : public OSTimeWin { public: - MockOSTimeWin(OSInterface *osInterface) : OSTimeWin(osInterface){}; + using OSTimeWin::deviceTime; + using OSTimeWin::maxGpuTimeStamp; + MockOSTimeWin(OSInterface &osInterface) : OSTimeWin(osInterface){}; void overrideQueryPerformanceCounterFunction(decltype(&QueryPerformanceCounter) function) { this->QueryPerfomanceCounterFnc = function; diff --git a/shared/test/common/os_interface/linux/device_command_stream_fixture.h b/shared/test/common/os_interface/linux/device_command_stream_fixture.h index a85a21d907..6ca0d84e48 100644 --- a/shared/test/common/os_interface/linux/device_command_stream_fixture.h +++ b/shared/test/common/os_interface/linux/device_command_stream_fixture.h @@ -78,7 +78,7 @@ class DrmMockTime : public DrmMockSuccess { using DrmMockSuccess::DrmMockSuccess; int ioctl(DrmIoctl request, void *arg) override { auto *reg = reinterpret_cast(arg); - reg->value = getVal() << 32; + reg->value = getVal() << 32 | 0x1; return 0; }; diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 5c4b2f6ff2..287f0d0da3 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -24,6 +24,7 @@ #include "shared/test/common/mocks/mock_compiler_interface.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/mock_io_functions.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_product_helper.h" @@ -392,29 +393,13 @@ TEST_F(DeviceGetCapsTest, givenDeviceWithMidThreadPreemptionWhenDeviceIsCreatedT } TEST_F(DeviceGetCapsTest, whenDriverModelHasLimitationForMaxMemoryAllocationSizeThenTakeItIntoAccount) { - struct MockDriverModel : NEO::DriverModel { - size_t maxAllocSize; - - MockDriverModel(size_t maxAllocSize) : NEO::DriverModel(NEO::DriverModelType::UNKNOWN), maxAllocSize(maxAllocSize) {} - - void setGmmInputArgs(void *args) override {} - uint32_t getDeviceHandle() const override { return {}; } - PhysicalDevicePciBusInfo getPciBusInfo() const override { return {}; } - bool isGpuHangDetected(NEO::OsContext &osContext) override { - return false; - } - - size_t getMaxMemAllocSize() const override { - return maxAllocSize; - } - PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override { return {}; } - }; - DebugManagerStateRestore dbgRestorer; size_t maxAllocSizeTestValue = 512; auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); device->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); - device->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique(maxAllocSizeTestValue)); + auto driverModel = std::make_unique(); + driverModel->maxAllocSize = maxAllocSizeTestValue; + device->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(driverModel)); device->initializeCaps(); const auto &caps = device->getDeviceInfo(); EXPECT_EQ(maxAllocSizeTestValue, caps.maxMemAllocSize); diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp index dbaff6b128..f949a2c804 100644 --- a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -120,7 +120,7 @@ TEST(RootDeviceEnvironment, whenCreatingRootDeviceEnvironmentThenCreateOsAgnosti EXPECT_EQ(0u, rootDeviceEnvironment->osTime->getCpuRawTimestamp()); TimeStampData tsData{1, 2}; - EXPECT_TRUE(rootDeviceEnvironment->osTime->getCpuGpuTime(&tsData)); + EXPECT_TRUE(rootDeviceEnvironment->osTime->getGpuCpuTime(&tsData)); EXPECT_EQ(0u, tsData.cpuTimeinNS); EXPECT_EQ(0u, tsData.gpuTimeStamp); diff --git a/shared/test/unit_test/os_interface/linux/os_time_test.cpp b/shared/test/unit_test/os_interface/linux/os_time_test.cpp index 4982b4df47..167e0ed842 100644 --- a/shared/test/unit_test/os_interface/linux/os_time_test.cpp +++ b/shared/test/unit_test/os_interface/linux/os_time_test.cpp @@ -41,22 +41,22 @@ using namespace NEO; struct DrmTimeTest : public ::testing::Test { public: void SetUp() override { - osInterface = std::unique_ptr(new OSInterface()); - osTime = MockOSTimeLinux::create(osInterface.get()); + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0]; + rootDeviceEnvironment.osInterface = std::make_unique(); + rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique(mockFd, rootDeviceEnvironment)); + osTime = MockOSTimeLinux::create(*rootDeviceEnvironment.osInterface); osTime->setResolutionFunc(resolutionFuncTrue); osTime->setGetTimeFunc(getTimeFuncTrue); + deviceTime = osTime->getDeviceTime(); } void TearDown() override { } + MockDeviceTimeDrm *deviceTime = nullptr; std::unique_ptr osTime; - std::unique_ptr osInterface; MockExecutionEnvironment executionEnvironment; }; -TEST_F(DrmTimeTest, GivenMockOsTimeThenInitializes) { -} - TEST_F(DrmTimeTest, WhenGettingCpuTimeThenSucceeds) { uint64_t time = 0; auto error = osTime->getCpuTime(&time); @@ -98,60 +98,125 @@ TEST_F(DrmTimeTest, GivenInvalidDrmWhenGettingGpuTimeThenFails) { EXPECT_FALSE(error); } -TEST_F(DrmTimeTest, WhenGettingCpuGpuTimeThenSucceeds) { - TimeStampData cpuGpuTime01 = {0, 0}; - TimeStampData cpuGpuTime02 = {0, 0}; +TEST_F(DrmTimeTest, WhenGettingGpuCpuTimeThenSucceeds) { + TimeStampData gpuCpuTime01 = {0, 0}; + TimeStampData gpuCpuTime02 = {0, 0}; auto pDrm = new DrmMockTime(mockFd, *executionEnvironment.rootDeviceEnvironments[0]); osTime->updateDrm(pDrm); - auto error = osTime->getCpuGpuTime(&cpuGpuTime01); + auto error = osTime->getGpuCpuTime(&gpuCpuTime01); EXPECT_TRUE(error); - EXPECT_NE(0ULL, cpuGpuTime01.cpuTimeinNS); - EXPECT_NE(0ULL, cpuGpuTime01.gpuTimeStamp); - error = osTime->getCpuGpuTime(&cpuGpuTime02); + EXPECT_NE(0ULL, gpuCpuTime01.cpuTimeinNS); + EXPECT_NE(0ULL, gpuCpuTime01.gpuTimeStamp); + error = osTime->getGpuCpuTime(&gpuCpuTime02); EXPECT_TRUE(error); - EXPECT_NE(0ULL, cpuGpuTime02.cpuTimeinNS); - EXPECT_NE(0ULL, cpuGpuTime02.gpuTimeStamp); - EXPECT_GT(cpuGpuTime02.gpuTimeStamp, cpuGpuTime01.gpuTimeStamp); - EXPECT_GT(cpuGpuTime02.cpuTimeinNS, cpuGpuTime01.cpuTimeinNS); + EXPECT_NE(0ULL, gpuCpuTime02.cpuTimeinNS); + EXPECT_NE(0ULL, gpuCpuTime02.gpuTimeStamp); + EXPECT_GT(gpuCpuTime02.gpuTimeStamp, gpuCpuTime01.gpuTimeStamp); + EXPECT_GT(gpuCpuTime02.cpuTimeinNS, gpuCpuTime01.cpuTimeinNS); } -TEST_F(DrmTimeTest, GivenDrmWhenGettingCpuGpuTimeThenSucceeds) { - TimeStampData cpuGpuTime01 = {0, 0}; - TimeStampData cpuGpuTime02 = {0, 0}; +TEST_F(DrmTimeTest, GivenDrmWhenGettingGpuCpuTimeThenSucceeds) { + TimeStampData gpuCpuTime01 = {0, 0}; + TimeStampData gpuCpuTime02 = {0, 0}; auto pDrm = new DrmMockTime(mockFd, *executionEnvironment.rootDeviceEnvironments[0]); osTime->updateDrm(pDrm); - auto error = osTime->getCpuGpuTime(&cpuGpuTime01); + auto error = osTime->getGpuCpuTime(&gpuCpuTime01); EXPECT_TRUE(error); - EXPECT_NE(0ULL, cpuGpuTime01.cpuTimeinNS); - EXPECT_NE(0ULL, cpuGpuTime01.gpuTimeStamp); - error = osTime->getCpuGpuTime(&cpuGpuTime02); + EXPECT_NE(0ULL, gpuCpuTime01.cpuTimeinNS); + EXPECT_NE(0ULL, gpuCpuTime01.gpuTimeStamp); + error = osTime->getGpuCpuTime(&gpuCpuTime02); EXPECT_TRUE(error); - EXPECT_NE(0ULL, cpuGpuTime02.cpuTimeinNS); - EXPECT_NE(0ULL, cpuGpuTime02.gpuTimeStamp); - EXPECT_GT(cpuGpuTime02.gpuTimeStamp, cpuGpuTime01.gpuTimeStamp); - EXPECT_GT(cpuGpuTime02.cpuTimeinNS, cpuGpuTime01.cpuTimeinNS); + EXPECT_NE(0ULL, gpuCpuTime02.cpuTimeinNS); + EXPECT_NE(0ULL, gpuCpuTime02.gpuTimeStamp); + EXPECT_GT(gpuCpuTime02.gpuTimeStamp, gpuCpuTime01.gpuTimeStamp); + EXPECT_GT(gpuCpuTime02.cpuTimeinNS, gpuCpuTime01.cpuTimeinNS); } -TEST_F(DrmTimeTest, givenGetCpuGpuTimeWhenItIsUnavailableThenReturnFalse) { - TimeStampData cpuGpuTime = {0, 0}; - auto error = osTime->getCpuGpuTime(&cpuGpuTime); +TEST_F(DrmTimeTest, givenGetGpuCpuTimeWhenItIsUnavailableThenReturnFalse) { + TimeStampData gpuCpuTime = {0, 0}; + + deviceTime->callBaseGetGpuCpuTimeImpl = false; + deviceTime->getGpuCpuTimeImplResult = false; + auto error = osTime->getGpuCpuTime(&gpuCpuTime); EXPECT_FALSE(error); } -TEST_F(DrmTimeTest, GivenInvalidDrmWhenGettingCpuGpuTimeThenFails) { - TimeStampData cpuGpuTime01 = {0, 0}; +TEST_F(DrmTimeTest, given36BitGpuTimeStampWhenGpuTimeStampOverflowThenGpuTimeDoesNotDecrease) { + TimeStampData gpuCpuTime = {0ull, 0ull}; + + deviceTime->callBaseGetGpuCpuTimeImpl = false; + deviceTime->gpuCpuTimeValue = {100ull, 100ull}; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(100ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 200ll; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(200ull, gpuCpuTime.gpuTimeStamp); + + osTime->maxGpuTimeStamp = 1ull << 36; + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 10ull; // read below initial value + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(osTime->maxGpuTimeStamp + 10ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 30ull; // second read below initial value + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(osTime->maxGpuTimeStamp + 30ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 110ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(osTime->maxGpuTimeStamp + 110ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 70ull; // second overflow + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(2ull * osTime->maxGpuTimeStamp + 70ull, gpuCpuTime.gpuTimeStamp); +} + +TEST_F(DrmTimeTest, given64BitGpuTimeStampWhenGpuTimeStampOverflowThenOverflowsAreNotDetected) { + TimeStampData gpuCpuTime = {0ull, 0ull}; + + deviceTime->callBaseGetGpuCpuTimeImpl = false; + deviceTime->gpuCpuTimeValue = {100ull, 100ull}; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(100ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 200ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(200ull, gpuCpuTime.gpuTimeStamp); + + osTime->maxGpuTimeStamp = 0ull; + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 10ull; // read below initial value + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(10ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 30ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(30ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 110ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(110ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 70ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(70ull, gpuCpuTime.gpuTimeStamp); +} + +TEST_F(DrmTimeTest, GivenInvalidDrmWhenGettingGpuCpuTimeThenFails) { + TimeStampData gpuCpuTime01 = {0, 0}; auto pDrm = new DrmMockFail(*executionEnvironment.rootDeviceEnvironments[0]); osTime->updateDrm(pDrm); - auto error = osTime->getCpuGpuTime(&cpuGpuTime01); + auto error = osTime->getGpuCpuTime(&gpuCpuTime01); EXPECT_FALSE(error); } -TEST_F(DrmTimeTest, GivenInvalidFuncTimeWhenGettingCpuGpuTimeCpuThenFails) { - TimeStampData cpuGpuTime01 = {0, 0}; +TEST_F(DrmTimeTest, GivenInvalidFuncTimeWhenGettingGpuCpuTimeCpuThenFails) { + TimeStampData gpuCpuTime01 = {0, 0}; auto pDrm = new DrmMockTime(mockFd, *executionEnvironment.rootDeviceEnvironments[0]); osTime->setGetTimeFunc(getTimeFuncFalse); osTime->updateDrm(pDrm); - auto error = osTime->getCpuGpuTime(&cpuGpuTime01); + auto error = osTime->getGpuCpuTime(&gpuCpuTime01); EXPECT_FALSE(error); } @@ -221,15 +286,6 @@ TEST_F(DrmTimeTest, givenGetDynamicDeviceTimerClockWhenIoctlSucceedsThenNonDefau EXPECT_EQ(result, frequency); } -TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenNoDrmThenDefaultResolutionIsReturned) { - osTime->updateDrm(nullptr); - - auto defaultResolution = defaultHwInfo->capabilityTable.defaultProfilingTimerResolution; - - auto result = osTime->getDynamicDeviceTimerResolution(*defaultHwInfo); - EXPECT_DOUBLE_EQ(result, defaultResolution); -} - TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenIoctlSuccedsThenCorrectResolutionIsReturned) { auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]); osTime->updateDrm(drm); @@ -265,8 +321,18 @@ TEST_F(DrmTimeTest, givenAlwaysFailingGetTimeFuncWhenGetCpuRawTimestampIsCalledT auto retVal = osTime->getCpuRawTimestamp(); EXPECT_EQ(0ull, retVal); } + TEST_F(DrmTimeTest, givenAlwaysPassingResolutionFuncWhenGetCpuRawTimestampIsCalledThenReturnsNonzero) { actualTime = 4; auto retVal = osTime->getCpuRawTimestamp(); EXPECT_EQ(1ull, retVal); } + +TEST_F(DrmTimeTest, whenGettingMaxGpuTimeStampValueThenHwInfoBasedValueIsReturned) { + if (defaultHwInfo->capabilityTable.timestampValidBits < 64) { + auto expectedMaxGpuTimeStampValue = 1ull << defaultHwInfo->capabilityTable.timestampValidBits; + EXPECT_EQ(expectedMaxGpuTimeStampValue, osTime->getMaxGpuTimeStamp()); + } else { + EXPECT_EQ(0ull, osTime->getMaxGpuTimeStamp()); + } +} diff --git a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp index 25f30e2224..2c2b3b0331 100644 --- a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp +++ b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp @@ -797,7 +797,7 @@ TEST_F(WddmLinuxTest, whenCheckedIfResourcesCleanupCanBeSkippedAndDeviceIsLostTh class MockOsTimeLinux : public NEO::OSTimeLinux { public: - MockOsTimeLinux(NEO::OSInterface *osInterface, std::unique_ptr deviceTime) : NEO::OSTimeLinux(osInterface, std::move(deviceTime)) {} + MockOsTimeLinux(NEO::OSInterface &osInterface, std::unique_ptr deviceTime) : NEO::OSTimeLinux(osInterface, std::move(deviceTime)) {} bool getCpuTime(uint64_t *timeStamp) override { osTimeGetCpuTimeWasCalled = true; *timeStamp = 0x1234; @@ -814,27 +814,27 @@ class MockDeviceTimeWddm : public NEO::DeviceTimeWddm { } }; -TEST(OSTimeWinLinuxTests, givenOSInterfaceWhenGetCpuGpuTimeThenGetCpuTimeFromOsTimeWasCalled) { +TEST(OSTimeWinLinuxTests, givenOSInterfaceWhenGetGpuCpuTimeThenGetCpuTimeFromOsTimeWasCalled) { - NEO::TimeStampData cpuGpuTime01 = {0}; + NEO::TimeStampData gpuCpuTime01 = {0}; std::unique_ptr hwDeviceIdIn; auto osEnvironment = std::make_unique(); osEnvironment->gdi->closeAdapter = closeAdapterMock; osEnvironment->gdi->reserveGpuVirtualAddress = reserveDeviceAddressSpaceMock; NEO::MockExecutionEnvironment mockExecEnv; - NEO::MockRootDeviceEnvironment mockRootDeviceEnvironment{mockExecEnv}; + auto &rootDeviceEnvironment = *mockExecEnv.rootDeviceEnvironments[0]; hwDeviceIdIn.reset(new NEO::HwDeviceIdWddm(NULL_HANDLE, LUID{}, 1u, osEnvironment.get(), std::make_unique())); - std::unique_ptr osInterface(new NEO::OSInterface()); + rootDeviceEnvironment.osInterface = std::make_unique(); - std::unique_ptr wddm = std::make_unique(std::move(hwDeviceIdIn), mockRootDeviceEnvironment); + std::unique_ptr wddm = std::make_unique(std::move(hwDeviceIdIn), rootDeviceEnvironment); static_cast(*wddm->gfxPlatform) = NEO::defaultHwInfo->platform; - mockRootDeviceEnvironment.setHwInfoAndInitHelpers(NEO::defaultHwInfo.get()); + rootDeviceEnvironment.setHwInfoAndInitHelpers(NEO::defaultHwInfo.get()); auto mockDeviceTimeWddm = std::make_unique(wddm.get()); - osInterface->setDriverModel(std::move(wddm)); + rootDeviceEnvironment.osInterface->setDriverModel(std::move(wddm)); std::unique_ptr deviceTime = std::unique_ptr(mockDeviceTimeWddm.release()); - auto osTime = std::unique_ptr(new MockOsTimeLinux(osInterface.get(), std::move(deviceTime))); - osTime->getCpuGpuTime(&cpuGpuTime01); + auto osTime = std::unique_ptr(new MockOsTimeLinux(*rootDeviceEnvironment.osInterface, std::move(deviceTime))); + osTime->getGpuCpuTime(&gpuCpuTime01); EXPECT_TRUE(osTime->osTimeGetCpuTimeWasCalled); } diff --git a/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp b/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp index dba84978fd..a416343e1c 100644 --- a/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp @@ -8,6 +8,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_ostime.h" #include "shared/test/common/mocks/windows/mock_os_time_win.h" #include "shared/test/common/os_interface/windows/wddm_fixture.h" @@ -25,17 +26,97 @@ BOOL WINAPI QueryPerformanceCounterMock( return true; }; +class MockDeviceTimeWin : public MockDeviceTime { + public: + bool getGpuCpuTimeImpl(TimeStampData *pGpuCpuTime, OSTime *osTime) override { + *pGpuCpuTime = gpuCpuTimeValue; + return true; + } + TimeStampData gpuCpuTimeValue{}; +}; + struct OSTimeWinTest : public ::testing::Test { public: void SetUp() override { - osTime = std::unique_ptr(new MockOSTimeWin(nullptr)); + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0]; + auto wddm = new WddmMock(rootDeviceEnvironment); + rootDeviceEnvironment.osInterface = std::make_unique(); + rootDeviceEnvironment.osInterface->setDriverModel(std::unique_ptr(wddm)); + osTime = std::unique_ptr(new MockOSTimeWin(*rootDeviceEnvironment.osInterface)); } void TearDown() override { } + MockExecutionEnvironment executionEnvironment; std::unique_ptr osTime; }; +TEST_F(OSTimeWinTest, given36BitGpuTimeStampWhenGpuTimeStampOverflowThenGpuTimeDoesNotDecrease) { + auto deviceTime = new MockDeviceTimeWin(); + osTime->deviceTime.reset(deviceTime); + + TimeStampData gpuCpuTime = {0ull, 0ull}; + + deviceTime->gpuCpuTimeValue = {100ull, 100ull}; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(100ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 200ll; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(200ull, gpuCpuTime.gpuTimeStamp); + + osTime->maxGpuTimeStamp = 1ull << 36; + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 10ull; // read below initial value + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(osTime->maxGpuTimeStamp + 10ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 30ull; // second read below initial value + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(osTime->maxGpuTimeStamp + 30ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 110ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(osTime->maxGpuTimeStamp + 110ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 70ull; // second overflow + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(2ull * osTime->maxGpuTimeStamp + 70ull, gpuCpuTime.gpuTimeStamp); +} + +TEST_F(OSTimeWinTest, given64BitGpuTimeStampWhenGpuTimeStampOverflowThenOverflowsAreNotDetected) { + auto deviceTime = new MockDeviceTimeWin(); + osTime->deviceTime.reset(deviceTime); + + TimeStampData gpuCpuTime = {0ull, 0ull}; + + deviceTime->gpuCpuTimeValue = {100ull, 100ull}; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(100ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 200ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(200ull, gpuCpuTime.gpuTimeStamp); + + osTime->maxGpuTimeStamp = 0ull; + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 10ull; // read below initial value + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(10ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 30ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(30ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 110ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(110ull, gpuCpuTime.gpuTimeStamp); + + deviceTime->gpuCpuTimeValue.gpuTimeStamp = 70ull; + EXPECT_TRUE(osTime->getGpuCpuTime(&gpuCpuTime)); + EXPECT_EQ(70ull, gpuCpuTime.gpuTimeStamp); +} + TEST_F(OSTimeWinTest, givenZeroFrequencyWhenGetHostTimerFuncIsCalledThenReturnsZero) { LARGE_INTEGER frequency; frequency.QuadPart = 0; @@ -77,33 +158,41 @@ TEST(OSTimeWinTests, givenNoOSInterfaceWhenGetCpuTimeThenReturnsSuccess) { EXPECT_EQ(0u, time); } -TEST(OSTimeWinTests, givenNoOSInterfaceWhenGetCpuGpuTimeThenReturnsSuccess) { - TimeStampData CPUGPUTime = {0}; +TEST(OSTimeWinTests, givenNoOSInterfaceWhenGetGpuCpuTimeThenReturnsSuccess) { + TimeStampData gpuCpuTime = {0}; auto osTime(OSTime::create(nullptr)); - auto success = osTime->getCpuGpuTime(&CPUGPUTime); + auto success = osTime->getGpuCpuTime(&gpuCpuTime); EXPECT_TRUE(success); - EXPECT_EQ(0u, CPUGPUTime.cpuTimeinNS); - EXPECT_EQ(0u, CPUGPUTime.gpuTimeStamp); + EXPECT_EQ(0u, gpuCpuTime.cpuTimeinNS); + EXPECT_EQ(0u, gpuCpuTime.gpuTimeStamp); } -TEST(OSTimeWinTests, givenOSInterfaceWhenGetCpuGpuTimeThenReturnsSuccess) { +TEST(OSTimeWinTests, givenOSInterfaceWhenGetGpuCpuTimeThenReturnsSuccess) { MockExecutionEnvironment executionEnvironment; - RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); - rootDeviceEnvironment.setHwInfoAndInitHelpers(defaultHwInfo.get()); + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0]; auto wddm = new WddmMock(rootDeviceEnvironment); - TimeStampData CPUGPUTime01 = {0}; - TimeStampData CPUGPUTime02 = {0}; + TimeStampData gpuCpuTime01 = {0}; + TimeStampData gpuCpuTime02 = {0}; std::unique_ptr osInterface(new OSInterface()); osInterface->setDriverModel(std::unique_ptr(wddm)); auto osTime = OSTime::create(osInterface.get()); - auto success = osTime->getCpuGpuTime(&CPUGPUTime01); + auto success = osTime->getGpuCpuTime(&gpuCpuTime01); EXPECT_TRUE(success); - EXPECT_NE(0u, CPUGPUTime01.cpuTimeinNS); - EXPECT_NE(0u, CPUGPUTime01.gpuTimeStamp); - success = osTime->getCpuGpuTime(&CPUGPUTime02); + EXPECT_NE(0u, gpuCpuTime01.cpuTimeinNS); + EXPECT_NE(0u, gpuCpuTime01.gpuTimeStamp); + success = osTime->getGpuCpuTime(&gpuCpuTime02); EXPECT_TRUE(success); - EXPECT_NE(0u, CPUGPUTime02.cpuTimeinNS); - EXPECT_NE(0u, CPUGPUTime02.gpuTimeStamp); - EXPECT_GT(CPUGPUTime02.gpuTimeStamp, CPUGPUTime01.gpuTimeStamp); - EXPECT_GT(CPUGPUTime02.cpuTimeinNS, CPUGPUTime01.cpuTimeinNS); + EXPECT_NE(0u, gpuCpuTime02.cpuTimeinNS); + EXPECT_NE(0u, gpuCpuTime02.gpuTimeStamp); + EXPECT_GT(gpuCpuTime02.gpuTimeStamp, gpuCpuTime01.gpuTimeStamp); + EXPECT_GT(gpuCpuTime02.cpuTimeinNS, gpuCpuTime01.cpuTimeinNS); +} + +TEST_F(OSTimeWinTest, whenGettingMaxGpuTimeStampValueThenHwInfoBasedValueIsReturned) { + if (defaultHwInfo->capabilityTable.timestampValidBits < 64) { + auto expectedMaxGpuTimeStampValue = 1ull << defaultHwInfo->capabilityTable.timestampValidBits; + EXPECT_EQ(expectedMaxGpuTimeStampValue, osTime->getMaxGpuTimeStamp()); + } else { + EXPECT_EQ(0ull, osTime->getMaxGpuTimeStamp()); + } }