diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 49a8b9abfe..fdcb3b525d 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -229,15 +229,11 @@ bool Device::createDeviceImpl() { } executionEnvironment->memoryManager->setDefaultEngineIndex(getRootDeviceIndex(), defaultEngineIndexWithinMemoryManager); - auto osInterface = getRootDeviceEnvironment().osInterface.get(); - - if (!osTime) { - osTime = OSTime::create(osInterface); - } + getRootDeviceEnvironmentRef().initOsTime(); initializeCaps(); - if (osTime->getOSInterface()) { + if (getOSTime()->getOSInterface()) { if (hwInfo.capabilityTable.instrumentationEnabled) { performanceCounters = createPerformanceCountersFunc(this); } @@ -365,11 +361,11 @@ const DeviceInfo &Device::getDeviceInfo() const { } double Device::getProfilingTimerResolution() { - return osTime->getDynamicDeviceTimerResolution(getHardwareInfo()); + return getOSTime()->getDynamicDeviceTimerResolution(getHardwareInfo()); } uint64_t Device::getProfilingTimerClock() { - return osTime->getDynamicDeviceTimerClock(getHardwareInfo()); + return getOSTime()->getDynamicDeviceTimerClock(getHardwareInfo()); } bool Device::isSimulation() const { @@ -389,8 +385,10 @@ bool Device::isSimulation() const { } double Device::getPlatformHostTimerResolution() const { - if (osTime.get()) - return osTime->getHostTimerResolution(); + if (getOSTime()) { + return getOSTime()->getHostTimerResolution(); + } + return 0.0; } @@ -569,4 +567,6 @@ void Device::initializeRayTracing() { rtMemoryBackedBuffer = getMemoryManager()->allocateGraphicsMemoryWithProperties({getRootDeviceIndex(), size, GraphicsAllocation::AllocationType::BUFFER, getDeviceBitfield()}); } } + +OSTime *Device::getOSTime() const { return getRootDeviceEnvironment().osTime.get(); }; } // namespace NEO diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 1f15b0dac3..8481731e18 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -70,7 +70,7 @@ class Device : public ReferenceTrackedObject { MemoryManager *getMemoryManager() const; GmmHelper *getGmmHelper() const; GmmClientContext *getGmmClientContext() const; - OSTime *getOSTime() const { return osTime.get(); }; + OSTime *getOSTime() const; double getProfilingTimerResolution(); uint64_t getProfilingTimerClock(); double getPlatformHostTimerResolution() const; @@ -161,7 +161,6 @@ class Device : public ReferenceTrackedObject { DeviceInfo deviceInfo = {}; HardwareCapabilities hardwareCapabilities = {}; - std::unique_ptr osTime; std::unique_ptr performanceCounters; std::vector> commandStreamReceivers; std::vector engines; diff --git a/shared/source/execution_environment/root_device_environment.cpp b/shared/source/execution_environment/root_device_environment.cpp index 1295260bcc..6e779bdc36 100644 --- a/shared/source/execution_environment/root_device_environment.cpp +++ b/shared/source/execution_environment/root_device_environment.cpp @@ -20,6 +20,7 @@ #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/os_time.h" #include "shared/source/utilities/software_tags_manager.h" namespace NEO { @@ -91,6 +92,12 @@ void RootDeviceEnvironment::initGmm() { } } +void RootDeviceEnvironment::initOsTime() { + if (!osTime) { + osTime = OSTime::create(osInterface.get()); + } +} + BindlessHeapsHelper *RootDeviceEnvironment::getBindlessHeapsHelper() const { return bindlessHeapsHelper.get(); } diff --git a/shared/source/execution_environment/root_device_environment.h b/shared/source/execution_environment/root_device_environment.h index 2a1cddf8d6..83934372a4 100644 --- a/shared/source/execution_environment/root_device_environment.h +++ b/shared/source/execution_environment/root_device_environment.h @@ -30,6 +30,7 @@ class HwDeviceId; class MemoryManager; class MemoryOperationsHandler; class OSInterface; +class OSTime; class SipKernel; class SWTagsManager; struct HardwareInfo; @@ -50,6 +51,7 @@ struct RootDeviceEnvironment { MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); bool initOsInterface(std::unique_ptr &&hwDeviceId, uint32_t rootDeviceIndex); + void initOsTime(); void initGmm(); void initDebugger(); MOCKABLE_VIRTUAL bool initAilConfiguration(); @@ -67,6 +69,7 @@ struct RootDeviceEnvironment { std::unique_ptr memoryOperationsInterface; std::unique_ptr aubCenter; std::unique_ptr bindlessHeapsHelper; + std::unique_ptr osTime; std::unique_ptr compilerInterface; std::unique_ptr builtins; diff --git a/shared/test/common/mocks/mock_device.cpp b/shared/test/common/mocks/mock_device.cpp index 140c130712..58325c9598 100644 --- a/shared/test/common/mocks/mock_device.cpp +++ b/shared/test/common/mocks/mock_device.cpp @@ -47,7 +47,10 @@ const char *MockDevice::getProductAbbrev() const { MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : RootDevice(executionEnvironment, rootDeviceIndex) { UltDeviceFactory::initializeMemoryManager(*executionEnvironment); - this->osTime = MockOSTime::create(); + + if (!getOSTime()) { + getRootDeviceEnvironmentRef().osTime = MockOSTime::create(); + } auto &hwInfo = getHardwareInfo(); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo); initializeCaps(); @@ -62,8 +65,8 @@ bool MockDevice::createDeviceImpl() { } void MockDevice::setOSTime(OSTime *osTime) { - this->osTime.reset(osTime); -}; + getRootDeviceEnvironmentRef().osTime.reset(osTime); +} void MockDevice::injectMemoryManager(MemoryManager *memoryManager) { executionEnvironment->memoryManager.reset(memoryManager);