Remove root device index from buffer object.

Graphics allocation is responsible for holding this information.
Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>

Change-Id: I5cf6fa7e92a7c716308213509aab5e446b5ef680
This commit is contained in:
Michal Mrozek 2020-03-19 10:41:35 +01:00 committed by sys_ocldev
parent d1b29496fa
commit 1ce4f56c9f
8 changed files with 25 additions and 12 deletions

View File

@ -46,10 +46,10 @@ TestedDrmMemoryManager::TestedDrmMemoryManager(bool enableLocalMemory,
}
void TestedDrmMemoryManager::injectPinBB(BufferObject *newPinBB) {
BufferObject *currentPinBB = pinBBs[newPinBB->peekRootDeviceIndex()];
pinBBs[newPinBB->peekRootDeviceIndex()] = nullptr;
BufferObject *currentPinBB = pinBBs[0u];
pinBBs[0u] = nullptr;
DrmMemoryManager::unreference(currentPinBB, true);
pinBBs[newPinBB->peekRootDeviceIndex()] = newPinBB;
pinBBs[0u] = newPinBB;
}
DrmGemCloseWorker *TestedDrmMemoryManager::getgemCloseWorker() { return this->gemCloseWorker.get(); }

View File

@ -45,6 +45,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
using DrmMemoryManager::eraseSharedBufferObject;
using DrmMemoryManager::getDefaultDrmContextId;
using DrmMemoryManager::getDrm;
using DrmMemoryManager::getRootDeviceIndex;
using DrmMemoryManager::gfxPartitions;
using DrmMemoryManager::lockResourceInLocalMemoryImpl;
using DrmMemoryManager::pinBBs;

View File

@ -159,7 +159,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
TEST(DrmBufferObjectSimpleTest, givenBufferObjectWhenConstructedWithASizeThenTheSizeIsInitialized) {
std::unique_ptr<DrmMockCustom> drmMock(new DrmMockCustom);
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 1, 0x1000, 0));
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 1, 0x1000));
EXPECT_EQ(0x1000u, bo->peekSize());
}

View File

@ -3437,6 +3437,8 @@ TEST(DrmMemoryMangerTest, givenMultipleRootDeviceWhenMemoryManagerGetsDrmThenDrm
for (auto i = 0u; i < platform()->peekExecutionEnvironment()->rootDeviceEnvironments.size(); i++) {
auto drmFromRootDevice = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->get()->getDrm();
EXPECT_EQ(drmFromRootDevice, &drmMemoryManager.getDrm(i));
EXPECT_EQ(i, drmMemoryManager.getRootDeviceIndex(drmFromRootDevice));
}
EXPECT_EQ(invalidRootDeviceIndex, drmMemoryManager.getRootDeviceIndex(nullptr));
}
} // namespace NEO

View File

@ -29,13 +29,11 @@
namespace NEO {
BufferObject::BufferObject(Drm *drm, int handle, size_t size, uint32_t rootDeviceIndex) : drm(drm), refCount(1), handle(handle), size(size), rootDeviceIndex(rootDeviceIndex), isReused(false) {
BufferObject::BufferObject(Drm *drm, int handle, size_t size) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) {
this->tiling_mode = I915_TILING_NONE;
this->lockedAddress = nullptr;
}
BufferObject::BufferObject(Drm *drm, int handle, uint32_t rootDeviceIndex) : BufferObject(drm, handle, 0, rootDeviceIndex) {}
uint32_t BufferObject::getRefCount() const {
return this->refCount.load();
}

View File

@ -22,8 +22,8 @@ class BufferObject {
friend DrmMemoryManager;
public:
BufferObject(Drm *drm, int handle, uint32_t rootDeviceIndex);
BufferObject(Drm *drm, int handle, size_t size, uint32_t rootDeviceIndex);
BufferObject(Drm *drm, int handle);
BufferObject(Drm *drm, int handle, size_t size);
MOCKABLE_VIRTUAL ~BufferObject(){};
bool setTiling(uint32_t mode, uint32_t stride);
@ -49,7 +49,6 @@ class BufferObject {
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
uint64_t peekUnmapSize() const { return unmapSize; }
bool peekIsReusableAllocation() const { return this->isReused; }
uint32_t peekRootDeviceIndex() { return rootDeviceIndex; }
protected:
Drm *drm = nullptr;
@ -58,7 +57,6 @@ class BufferObject {
int handle; // i915 gem object handle
uint64_t size;
uint32_t rootDeviceIndex = 0;
bool isReused;
//Tiling

View File

@ -84,7 +84,7 @@ void DrmMemoryManager::commonCleanup() {
void DrmMemoryManager::eraseSharedBufferObject(NEO::BufferObject *bo) {
auto it = std::find(sharingBufferObjects.begin(), sharingBufferObjects.end(), bo);
DEBUG_BREAK_IF(it == sharingBufferObjects.end());
releaseGpuRange(reinterpret_cast<void *>((*it)->gpuAddress), (*it)->peekUnmapSize(), (*it)->peekRootDeviceIndex());
releaseGpuRange(reinterpret_cast<void *>((*it)->gpuAddress), (*it)->peekUnmapSize(), this->getRootDeviceIndex(bo->drm));
sharingBufferObjects.erase(it);
}
@ -736,4 +736,15 @@ Drm &DrmMemoryManager::getDrm(uint32_t rootDeviceIndex) const {
return *this->executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm();
}
uint32_t DrmMemoryManager::getRootDeviceIndex(const Drm *drm) {
auto rootDeviceCount = this->executionEnvironment.rootDeviceEnvironments.size();
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceCount; rootDeviceIndex++) {
if (&getDrm(rootDeviceIndex) == drm) {
return rootDeviceIndex;
}
}
return std::numeric_limits<uint32_t>::max();
}
} // namespace NEO

View File

@ -13,12 +13,14 @@
#include "drm_gem_close_worker.h"
#include <limits>
#include <map>
#include <sys/mman.h>
namespace NEO {
class BufferObject;
class Drm;
constexpr uint32_t invalidRootDeviceIndex = std::numeric_limits<uint32_t>::max();
class DrmMemoryManager : public MemoryManager {
public:
@ -84,6 +86,7 @@ class DrmMemoryManager : public MemoryManager {
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
Drm &getDrm(uint32_t rootDeviceIndex) const;
uint32_t getRootDeviceIndex(const Drm *drm);
std::vector<BufferObject *> pinBBs;
std::vector<void *> memoryForPinBBs;