Extend mutex range in DrmMemoryOperationHandler

Related-To: NEO-4302

Change-Id: Id022a51071eeea076fbc91dd3a05000d5e85a417
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk 2020-05-25 09:02:14 +02:00 committed by sys_ocldev
parent 14f4d5c5b9
commit cc5fd45b47
5 changed files with 44 additions and 4 deletions

View File

@ -52,7 +52,8 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
protected:
void makeResidentBufferObjects(const DrmAllocation *drmAllocation, uint32_t handleId);
void makeResident(BufferObject *bo);
void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency);
MOCKABLE_VIRTUAL void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency);
MOCKABLE_VIRTUAL void exec(const BatchBuffer &batchBuffer, uint32_t drmContextId);
std::vector<BufferObject *> residency;

View File

@ -67,8 +67,14 @@ bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, Reside
}
}
auto memoryOperationsInterface = this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get();
static_cast<DrmMemoryOperationsHandler *>(memoryOperationsInterface)->mergeWithResidencyContainer(allocationsForResidency);
auto memoryOperationsInterface = static_cast<DrmMemoryOperationsHandler *>(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get());
std::unique_lock<std::mutex> lock;
if (DebugManager.flags.MakeAllBuffersResident.get()) {
lock = memoryOperationsInterface->acquireLock();
}
memoryOperationsInterface->mergeWithResidencyContainer(allocationsForResidency);
this->flushStamp->setStamp(bb->peekHandle());
this->flushInternal(batchBuffer, allocationsForResidency);

View File

@ -631,6 +631,34 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInt
mm->freeGraphicsMemory(commandBuffer);
}
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMakeAllBuffersResidentSetWhenFlushThenDrmMemoryOperationHandlerIsLocked) {
struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler {
using DrmMemoryOperationsHandler::mutex;
};
struct MockDrmCsr : public DrmCommandStreamReceiver<FamilyType> {
using DrmCommandStreamReceiver<FamilyType>::DrmCommandStreamReceiver;
void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override {
auto memoryOperationsInterface = static_cast<MockDrmMemoryOperationsHandler *>(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get());
EXPECT_FALSE(memoryOperationsInterface->mutex.try_lock());
}
};
DebugManagerStateRestore restorer;
DebugManager.flags.MakeAllBuffersResident.set(true);
auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
LinearStream cs(commandBuffer);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
CommandStreamReceiverHw<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr};
MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, gemCloseWorkerMode::gemCloseWorkerInactive);
mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations());
mm->freeGraphicsMemory(commandBuffer);
}
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenTwoAllocationsWhenBackingStorageIsDifferentThenMakeResidentShouldAddTwoLocations) {
auto allocation = static_cast<DrmAllocation *>(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}));
auto allocation2 = static_cast<DrmAllocation *>(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}));

View File

@ -36,7 +36,6 @@ MemoryOperationsStatus DrmMemoryOperationsHandler::isResident(GraphicsAllocation
}
void DrmMemoryOperationsHandler::mergeWithResidencyContainer(ResidencyContainer &residencyContainer) {
std::lock_guard<std::mutex> lock(mutex);
for (auto gfxAllocation = this->residency.begin(); gfxAllocation != this->residency.end(); gfxAllocation++) {
auto ret = std::find(residencyContainer.begin(), residencyContainer.end(), *gfxAllocation);
if (ret == residencyContainer.end()) {
@ -45,4 +44,8 @@ void DrmMemoryOperationsHandler::mergeWithResidencyContainer(ResidencyContainer
}
}
std::unique_lock<std::mutex> DrmMemoryOperationsHandler::acquireLock() {
return std::unique_lock<std::mutex>(this->mutex);
}
} // namespace NEO

View File

@ -24,6 +24,8 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
void mergeWithResidencyContainer(ResidencyContainer &residencyContainer);
std::unique_lock<std::mutex> acquireLock();
protected:
std::unordered_set<GraphicsAllocation *> residency;
std::mutex mutex;