Skip to content

Commit 7b564b5

Browse files
Move OsTime to RootDeviceEnvironment
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent b46dc0a commit 7b564b5

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

shared/source/device/device.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,11 @@ bool Device::createDeviceImpl() {
229229
}
230230
executionEnvironment->memoryManager->setDefaultEngineIndex(getRootDeviceIndex(), defaultEngineIndexWithinMemoryManager);
231231

232-
auto osInterface = getRootDeviceEnvironment().osInterface.get();
233-
234-
if (!osTime) {
235-
osTime = OSTime::create(osInterface);
236-
}
232+
getRootDeviceEnvironmentRef().initOsTime();
237233

238234
initializeCaps();
239235

240-
if (osTime->getOSInterface()) {
236+
if (getOSTime()->getOSInterface()) {
241237
if (hwInfo.capabilityTable.instrumentationEnabled) {
242238
performanceCounters = createPerformanceCountersFunc(this);
243239
}
@@ -365,11 +361,11 @@ const DeviceInfo &Device::getDeviceInfo() const {
365361
}
366362

367363
double Device::getProfilingTimerResolution() {
368-
return osTime->getDynamicDeviceTimerResolution(getHardwareInfo());
364+
return getOSTime()->getDynamicDeviceTimerResolution(getHardwareInfo());
369365
}
370366

371367
uint64_t Device::getProfilingTimerClock() {
372-
return osTime->getDynamicDeviceTimerClock(getHardwareInfo());
368+
return getOSTime()->getDynamicDeviceTimerClock(getHardwareInfo());
373369
}
374370

375371
bool Device::isSimulation() const {
@@ -389,8 +385,10 @@ bool Device::isSimulation() const {
389385
}
390386

391387
double Device::getPlatformHostTimerResolution() const {
392-
if (osTime.get())
393-
return osTime->getHostTimerResolution();
388+
if (getOSTime()) {
389+
return getOSTime()->getHostTimerResolution();
390+
}
391+
394392
return 0.0;
395393
}
396394

@@ -569,4 +567,6 @@ void Device::initializeRayTracing() {
569567
rtMemoryBackedBuffer = getMemoryManager()->allocateGraphicsMemoryWithProperties({getRootDeviceIndex(), size, GraphicsAllocation::AllocationType::BUFFER, getDeviceBitfield()});
570568
}
571569
}
570+
571+
OSTime *Device::getOSTime() const { return getRootDeviceEnvironment().osTime.get(); };
572572
} // namespace NEO

shared/source/device/device.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Device : public ReferenceTrackedObject<Device> {
7070
MemoryManager *getMemoryManager() const;
7171
GmmHelper *getGmmHelper() const;
7272
GmmClientContext *getGmmClientContext() const;
73-
OSTime *getOSTime() const { return osTime.get(); };
73+
OSTime *getOSTime() const;
7474
double getProfilingTimerResolution();
7575
uint64_t getProfilingTimerClock();
7676
double getPlatformHostTimerResolution() const;
@@ -161,7 +161,6 @@ class Device : public ReferenceTrackedObject<Device> {
161161
DeviceInfo deviceInfo = {};
162162

163163
HardwareCapabilities hardwareCapabilities = {};
164-
std::unique_ptr<OSTime> osTime;
165164
std::unique_ptr<PerformanceCounters> performanceCounters;
166165
std::vector<std::unique_ptr<CommandStreamReceiver>> commandStreamReceivers;
167166
std::vector<EngineControl> engines;

shared/source/execution_environment/root_device_environment.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "shared/source/memory_manager/memory_manager.h"
2121
#include "shared/source/memory_manager/memory_operations_handler.h"
2222
#include "shared/source/os_interface/os_interface.h"
23+
#include "shared/source/os_interface/os_time.h"
2324
#include "shared/source/utilities/software_tags_manager.h"
2425

2526
namespace NEO {
@@ -91,6 +92,12 @@ void RootDeviceEnvironment::initGmm() {
9192
}
9293
}
9394

95+
void RootDeviceEnvironment::initOsTime() {
96+
if (!osTime) {
97+
osTime = OSTime::create(osInterface.get());
98+
}
99+
}
100+
94101
BindlessHeapsHelper *RootDeviceEnvironment::getBindlessHeapsHelper() const {
95102
return bindlessHeapsHelper.get();
96103
}

shared/source/execution_environment/root_device_environment.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class HwDeviceId;
3030
class MemoryManager;
3131
class MemoryOperationsHandler;
3232
class OSInterface;
33+
class OSTime;
3334
class SipKernel;
3435
class SWTagsManager;
3536
struct HardwareInfo;
@@ -50,6 +51,7 @@ struct RootDeviceEnvironment {
5051

5152
MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType);
5253
bool initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex);
54+
void initOsTime();
5355
void initGmm();
5456
void initDebugger();
5557
MOCKABLE_VIRTUAL bool initAilConfiguration();
@@ -67,6 +69,7 @@ struct RootDeviceEnvironment {
6769
std::unique_ptr<MemoryOperationsHandler> memoryOperationsInterface;
6870
std::unique_ptr<AubCenter> aubCenter;
6971
std::unique_ptr<BindlessHeapsHelper> bindlessHeapsHelper;
72+
std::unique_ptr<OSTime> osTime;
7073

7174
std::unique_ptr<CompilerInterface> compilerInterface;
7275
std::unique_ptr<BuiltIns> builtins;

shared/test/common/mocks/mock_device.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ const char *MockDevice::getProductAbbrev() const {
4747
MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex)
4848
: RootDevice(executionEnvironment, rootDeviceIndex) {
4949
UltDeviceFactory::initializeMemoryManager(*executionEnvironment);
50-
this->osTime = MockOSTime::create();
50+
51+
if (!getOSTime()) {
52+
getRootDeviceEnvironmentRef().osTime = MockOSTime::create();
53+
}
5154
auto &hwInfo = getHardwareInfo();
5255
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
5356
initializeCaps();
@@ -62,8 +65,8 @@ bool MockDevice::createDeviceImpl() {
6265
}
6366

6467
void MockDevice::setOSTime(OSTime *osTime) {
65-
this->osTime.reset(osTime);
66-
};
68+
getRootDeviceEnvironmentRef().osTime.reset(osTime);
69+
}
6770

6871
void MockDevice::injectMemoryManager(MemoryManager *memoryManager) {
6972
executionEnvironment->memoryManager.reset(memoryManager);

0 commit comments

Comments
 (0)