Reduced a scope of the lock for AUB file stream

Related-To: NEO-2747

Change-Id: Ic164900f5898df35af74ccff9c31f8296dcf12fd
This commit is contained in:
Milczarek, Slawomir
2019-05-10 17:29:06 +02:00
committed by sys_ocldev
parent c34a9d737e
commit 972a79aaae
5 changed files with 48 additions and 12 deletions

View File

@ -139,11 +139,11 @@ struct AubFileStream : public AubStream {
MOCKABLE_VIRTUAL void expectMemory(uint64_t physAddress, const void *memory, size_t size,
uint32_t addressSpace, uint32_t compareOperation);
MOCKABLE_VIRTUAL bool addComment(const char *message);
MOCKABLE_VIRTUAL std::unique_lock<std::recursive_mutex> lockStream();
MOCKABLE_VIRTUAL std::unique_lock<std::mutex> lockStream();
std::ofstream fileHandle;
std::string fileName;
std::recursive_mutex mutex;
std::mutex mutex;
};
template <int addressingBits>

View File

@ -277,8 +277,8 @@ bool AubFileStream::addComment(const char *message) {
return true;
}
std::unique_lock<std::recursive_mutex> AubFileStream::lockStream() {
return std::unique_lock<std::recursive_mutex>(mutex);
std::unique_lock<std::mutex> AubFileStream::lockStream() {
return std::unique_lock<std::mutex>(mutex);
}
} // namespace AubMemDump

View File

@ -155,6 +155,8 @@ const std::string AUBCommandStreamReceiverHw<GfxFamily>::getFileName() {
template <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine() {
auto streamLocked = getAubStream()->lockStream();
if (hardwareContextController) {
hardwareContextController->initialize();
return;
@ -290,8 +292,6 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
}
}
auto streamLocked = getAubStream()->lockStream();
initializeEngine();
// Write our batch buffer
@ -380,6 +380,8 @@ bool AUBCommandStreamReceiverHw<GfxFamily>::addPatchInfoComments() {
template <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::submitBatchBuffer(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) {
auto streamLocked = getAubStream()->lockStream();
if (hardwareContextController) {
if (batchBufferSize) {
hardwareContextController->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k);
@ -619,7 +621,6 @@ bool AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxA
}
bool ownsLock = !gfxAllocation.isLocked();
uint64_t gpuAddress;
void *cpuAddress;
size_t size;
@ -627,12 +628,16 @@ bool AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxA
return false;
}
auto streamLocked = getAubStream()->lockStream();
if (aubManager) {
this->writeMemoryWithAubManager(gfxAllocation);
} else {
writeMemory(gpuAddress, cpuAddress, size, this->getMemoryBank(&gfxAllocation), this->getPPGTTAdditionalBits(&gfxAllocation));
}
streamLocked.unlock();
if (gfxAllocation.isLocked() && ownsLock) {
this->getMemoryManager()->unlockResource(&gfxAllocation);
}

View File

@ -171,18 +171,49 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenReopenFileIsCalled
EXPECT_TRUE(mockAubFileStream->lockStreamCalled);
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeLocked) {
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenInitializeEngineIsCalledThenFileStreamShouldBeLocked) {
auto mockAubFileStream = std::make_unique<MockAubFileStream>();
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
aubCsr->stream = static_cast<MockAubFileStream *>(mockAubFileStream.get());
aubCsr->initializeEngine();
EXPECT_TRUE(mockAubFileStream->lockStreamCalled);
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenSubmitBatchBufferIsCalledThenFileStreamShouldBeLocked) {
auto mockAubFileStream = std::make_unique<MockAubFileStream>();
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
LinearStream cs(aubExecutionEnvironment->commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
aubCsr->stream = static_cast<MockAubFileStream *>(mockAubFileStream.get());
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
ResidencyContainer allocationsForResidency = {};
auto pBatchBuffer = ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset);
auto batchBufferGpuAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
auto currentOffset = batchBuffer.usedSize;
auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset;
aubCsr->flush(batchBuffer, allocationsForResidency);
aubCsr->initializeEngine();
mockAubFileStream->lockStreamCalled = false;
aubCsr->submitBatchBuffer(batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer, aubCsr->getMemoryBank(batchBuffer.commandBufferAllocation),
aubCsr->getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation));
EXPECT_TRUE(mockAubFileStream->lockStreamCalled);
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledThenFileStreamShouldBeLocked) {
auto mockAubFileStream = std::make_unique<MockAubFileStream>();
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
aubCsr->stream = static_cast<MockAubFileStream *>(mockAubFileStream.get());
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
aubCsr->writeMemory(allocation);
EXPECT_TRUE(mockAubFileStream->lockStreamCalled);
}

View File

@ -42,7 +42,7 @@ struct MockAubFileStream : public AUBCommandStreamReceiver::AubFileStream {
void flush() override {
flushCalled = true;
}
std::unique_lock<std::recursive_mutex> lockStream() override {
std::unique_lock<std::mutex> lockStream() override {
lockStreamCalled = true;
return AUBCommandStreamReceiver::AubFileStream::lockStream();
}