Skip to content

Commit 5d12bd8

Browse files
Move ownership of Drm to OsInterface
Related-To: NEO-4208 Change-Id: Iaf5255500b5629739065303e4e4f8a724458dbce Signed-off-by: Jablonski, Mateusz <mateusz.jablonski@intel.com>
1 parent fd4c029 commit 5d12bd8

34 files changed

+120
-307
lines changed

core/execution_environment/execution_environment.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ ExecutionEnvironment::~ExecutionEnvironment() {
2525
debugger.reset();
2626
compilerInterface.reset();
2727
builtins.reset();
28+
if (memoryManager) {
29+
memoryManager->commonCleanup();
30+
}
2831
rootDeviceEnvironments.clear();
2932
}
3033

core/memory_manager/memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class MemoryManager {
163163
GfxPartition *getGfxPartition(uint32_t rootDeviceIndex) { return gfxPartitions.at(rootDeviceIndex).get(); }
164164

165165
static uint32_t maxOsContextCount;
166+
virtual void commonCleanup(){};
166167

167168
protected:
168169
struct AllocationData {

core/os_interface/linux/device_factory_linux.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,5 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi
5555
}
5656

5757
void DeviceFactory::releaseDevices() {
58-
if (DeviceFactory::numDevices > 0) {
59-
for (unsigned int i = 0; i < DeviceFactory::numDevices; ++i) {
60-
Drm::closeDevice(i);
61-
}
62-
}
63-
DeviceFactory::numDevices = 0;
6458
}
6559
} // namespace NEO

core/os_interface/linux/drm_buffer_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BufferObject {
5252
uint32_t peekRootDeviceIndex() { return rootDeviceIndex; }
5353

5454
protected:
55-
Drm *drm;
55+
Drm *drm = nullptr;
5656

5757
std::atomic<uint32_t> refCount;
5858

core/os_interface/linux/drm_memory_manager.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode,
6060
}
6161

6262
DrmMemoryManager::~DrmMemoryManager() {
63+
if (memoryForPinBB) {
64+
MemoryManager::alignedFreeWrapper(memoryForPinBB);
65+
}
66+
}
67+
68+
void DrmMemoryManager::commonCleanup() {
6369
if (gemCloseWorker) {
6470
gemCloseWorker->close(false);
6571
}
6672
if (pinBB) {
6773
DrmMemoryManager::unreference(pinBB, true);
68-
pinBB = nullptr;
69-
}
70-
if (memoryForPinBB) {
71-
MemoryManager::alignedFreeWrapper(memoryForPinBB);
7274
}
7375
}
7476

core/os_interface/linux/drm_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class DrmMemoryManager : public MemoryManager {
4242

4343
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
4444
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
45+
void commonCleanup() override;
4546

4647
// drm/i915 ioctl wrappers
4748
MOCKABLE_VIRTUAL uint32_t unreference(BufferObject *bo, bool synchronousDestroy);

core/os_interface/linux/drm_neo.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class Drm {
4545
friend DeviceFactory;
4646

4747
public:
48-
static Drm *get(int32_t deviceOrdinal);
49-
5048
virtual ~Drm();
5149

5250
virtual int ioctl(unsigned long request, void *arg);
@@ -94,6 +92,8 @@ class Drm {
9492

9593
static std::unique_ptr<HwDeviceId> discoverDevices();
9694

95+
static Drm *create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
96+
9797
protected:
9898
int getQueueSliceCount(drm_i915_gem_context_param_sseu *sseu);
9999
bool sliceCountChangeSupported = false;
@@ -109,9 +109,6 @@ class Drm {
109109
std::unique_ptr<EngineInfo> engineInfo;
110110
std::unique_ptr<MemoryInfo> memoryInfo;
111111

112-
static Drm *create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
113-
static void closeDevice(int32_t deviceOrdinal);
114-
115112
std::string getSysFsPciPath(int deviceID);
116113
void *query(uint32_t queryId);
117114

core/os_interface/linux/drm_neo_create.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@ namespace NEO {
1111

1212
Drm::~Drm() = default;
1313

14-
Drm *Drm::get(int32_t deviceOrdinal) {
15-
return nullptr;
16-
}
17-
1814
Drm *Drm::create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) {
1915
return nullptr;
2016
}
21-
22-
void Drm::closeDevice(int32_t deviceOrdinal) {
23-
return;
24-
}
2517
} // namespace NEO

core/os_interface/linux/os_interface.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77

88
#include "core/os_interface/linux/os_interface.h"
99

10+
#include "core/os_interface/linux/drm_neo.h"
11+
1012
namespace NEO {
1113

1214
bool OSInterface::osEnabled64kbPages = false;
1315

16+
OSInterface::OSInterfaceImpl::OSInterfaceImpl() = default;
17+
OSInterface::OSInterfaceImpl::~OSInterfaceImpl() = default;
18+
void OSInterface::OSInterfaceImpl::setDrm(Drm *drm) {
19+
this->drm.reset(drm);
20+
}
21+
1422
OSInterface::OSInterface() {
1523
osInterfaceImpl = new OSInterfaceImpl();
1624
}

core/os_interface/linux/os_interface.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@
88
#pragma once
99
#include "core/os_interface/os_interface.h"
1010

11+
#include <memory>
12+
1113
namespace NEO {
1214
class Drm;
1315

1416
class OSInterface::OSInterfaceImpl {
1517
public:
16-
OSInterfaceImpl() {
17-
drm = nullptr;
18-
}
18+
OSInterfaceImpl();
19+
~OSInterfaceImpl();
1920
Drm *getDrm() const {
20-
return drm;
21-
}
22-
void setDrm(Drm *drm) {
23-
this->drm = drm;
21+
return drm.get();
2422
}
23+
void setDrm(Drm *drm);
2524

2625
protected:
27-
Drm *drm;
26+
std::unique_ptr<Drm> drm;
2827
};
2928
} // namespace NEO

0 commit comments

Comments
 (0)