From bddf1bbe767fe80075205dbc95c4dc2b96fbbc35 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 15 Nov 2022 11:21:56 +0000 Subject: [PATCH] Return SubmissionStatus from printBOsForSubmit method it allows to return non-binary status to API layer Related-To: NEO-7412 Signed-off-by: Mateusz Jablonski --- .../linux/drm_command_stream_tests_2.cpp | 43 --------- .../os_interface/linux/drm_command_stream.h | 2 +- .../os_interface/linux/drm_command_stream.inl | 18 +++- .../common/mocks/linux/mock_drm_allocation.h | 3 + .../linux/drm_command_stream_tests_1.cpp | 87 +++++++++++++++++++ 5 files changed, 105 insertions(+), 48 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp index b32529c3d8..fd83bab464 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp @@ -544,49 +544,6 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, WhenFlushNotCalledThenClearResi mm->freeGraphicsMemory(allocation2); } -HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenPrintBOsForSubmitWhenPrintThenProperValuesArePrinted) { - DebugManagerStateRestore restorer; - DebugManager.flags.PrintBOsForSubmit.set(true); - - auto allocation1 = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); - auto allocation2 = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); - auto buffer = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); - ASSERT_NE(nullptr, allocation1); - ASSERT_NE(nullptr, allocation2); - ASSERT_NE(nullptr, buffer); - - csr->makeResident(*allocation1); - csr->makeResident(*allocation2); - - ResidencyContainer residency; - residency.push_back(allocation1); - residency.push_back(allocation2); - - testing::internal::CaptureStdout(); - - static_cast *>(csr)->printBOsForSubmit(residency, *buffer); - - std::string output = testing::internal::GetCapturedStdout(); - - std::vector bos; - allocation1->makeBOsResident(&csr->getOsContext(), 0, &bos, true); - allocation2->makeBOsResident(&csr->getOsContext(), 0, &bos, true); - buffer->makeBOsResident(&csr->getOsContext(), 0, &bos, true); - - std::stringstream expected; - expected << "Buffer object for submit\n"; - for (const auto &bo : bos) { - expected << "BO-" << bo->peekHandle() << ", range: " << std::hex << bo->peekAddress() << " - " << ptrOffset(bo->peekAddress(), bo->peekSize()) << ", size: " << std::dec << bo->peekSize() << "\n"; - } - expected << "\n"; - - EXPECT_FALSE(output.compare(expected.str())); - - mm->freeGraphicsMemory(allocation1); - mm->freeGraphicsMemory(allocation2); - mm->freeGraphicsMemory(buffer); -} - HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenFlushMultipleTimesThenSucceeds) { auto &cs = csr->getCS(); auto commandBuffer = static_cast(cs.getGraphicsAllocation()); diff --git a/shared/source/os_interface/linux/drm_command_stream.h b/shared/source/os_interface/linux/drm_command_stream.h index e7a5104076..6b1dc1ba86 100644 --- a/shared/source/os_interface/linux/drm_command_stream.h +++ b/shared/source/os_interface/linux/drm_command_stream.h @@ -61,7 +61,7 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver { gemCloseWorkerOperationMode = gemCloseWorkerMode::gemCloseWorkerInactive; } - void printBOsForSubmit(ResidencyContainer &allocationsForResidency, GraphicsAllocation &cmdBufferAllocation); + SubmissionStatus printBOsForSubmit(ResidencyContainer &allocationsForResidency, GraphicsAllocation &cmdBufferAllocation); using CommandStreamReceiver::pageTableManager; diff --git a/shared/source/os_interface/linux/drm_command_stream.inl b/shared/source/os_interface/linux/drm_command_stream.inl index b9e82d8ef1..91ed4068a7 100644 --- a/shared/source/os_interface/linux/drm_command_stream.inl +++ b/shared/source/os_interface/linux/drm_command_stream.inl @@ -114,7 +114,10 @@ SubmissionStatus DrmCommandStreamReceiver::flush(BatchBuffer &batchBu lock = memoryOperationsInterface->lockHandlerIfUsed(); } - this->printBOsForSubmit(allocationsForResidency, *batchBuffer.commandBufferAllocation); + auto submissionStatus = this->printBOsForSubmit(allocationsForResidency, *batchBuffer.commandBufferAllocation); + if (submissionStatus != SubmissionStatus::SUCCESS) { + return submissionStatus; + } if (this->drm->isVmBindAvailable()) { allocationsForResidency.push_back(batchBuffer.commandBufferAllocation); @@ -174,17 +177,23 @@ void DrmCommandStreamReceiver::readBackAllocation(void *source) { } template -void DrmCommandStreamReceiver::printBOsForSubmit(ResidencyContainer &allocationsForResidency, GraphicsAllocation &cmdBufferAllocation) { +SubmissionStatus DrmCommandStreamReceiver::printBOsForSubmit(ResidencyContainer &allocationsForResidency, GraphicsAllocation &cmdBufferAllocation) { if (DebugManager.flags.PrintBOsForSubmit.get()) { std::vector bosForSubmit; for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) { if (osContext->getDeviceBitfield().test(drmIterator)) { for (auto gfxAllocation = allocationsForResidency.begin(); gfxAllocation != allocationsForResidency.end(); gfxAllocation++) { auto drmAllocation = static_cast(*gfxAllocation); - drmAllocation->makeBOsResident(osContext, drmIterator, &bosForSubmit, true); + auto retCode = drmAllocation->makeBOsResident(osContext, drmIterator, &bosForSubmit, true); + if (retCode) { + return Drm::getSubmissionStatusFromReturnCode(retCode); + } } auto drmCmdBufferAllocation = static_cast(&cmdBufferAllocation); - drmCmdBufferAllocation->makeBOsResident(osContext, drmIterator, &bosForSubmit, true); + auto retCode = drmCmdBufferAllocation->makeBOsResident(osContext, drmIterator, &bosForSubmit, true); + if (retCode) { + return Drm::getSubmissionStatusFromReturnCode(retCode); + } } } printf("Buffer object for submit\n"); @@ -193,6 +202,7 @@ void DrmCommandStreamReceiver::printBOsForSubmit(ResidencyContainer & } printf("\n"); } + return SubmissionStatus::SUCCESS; } template diff --git a/shared/test/common/mocks/linux/mock_drm_allocation.h b/shared/test/common/mocks/linux/mock_drm_allocation.h index 13a96bae11..19d102ef3f 100644 --- a/shared/test/common/mocks/linux/mock_drm_allocation.h +++ b/shared/test/common/mocks/linux/mock_drm_allocation.h @@ -8,6 +8,7 @@ #pragma once #include "shared/source/os_interface/linux/drm_allocation.h" #include "shared/source/os_interface/linux/drm_buffer_object.h" +#include "shared/test/common/test_macros/mock_method_macros.h" namespace NEO { @@ -60,6 +61,8 @@ class MockDrmAllocation : public DrmAllocation { return bindBOsRetValue; } + ADDMETHOD_NOBASE(makeBOsResident, int, 0, (OsContext * osContext, uint32_t vmHandleId, std::vector *bufferObjects, bool bind)); + bool registerBOBindExtHandleCalled = false; bool markedForCapture = false; bool bindBOsCalled = false; diff --git a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp index d5ab68867d..6ecd88df0c 100644 --- a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp @@ -30,6 +30,7 @@ #include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/helpers/gtest_helpers.h" #include "shared/test/common/libult/linux/drm_mock.h" +#include "shared/test/common/mocks/linux/mock_drm_allocation.h" #include "shared/test/common/mocks/linux/mock_drm_command_stream_receiver.h" #include "shared/test/common/mocks/mock_allocation_properties.h" #include "shared/test/common/mocks/mock_gmm.h" @@ -950,3 +951,89 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenPageTableManagerAndMapFalseWhenUpd EXPECT_TRUE(result); EXPECT_EQ(1u, mockMngr->updateAuxTableCalled); } + +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenPrintBOsForSubmitWhenPrintThenProperValuesArePrinted) { + DebugManagerStateRestore restorer; + DebugManager.flags.PrintBOsForSubmit.set(true); + + MockDrmAllocation allocation1(AllocationType::BUFFER, MemoryPool::System4KBPages); + MockDrmAllocation allocation2(AllocationType::BUFFER, MemoryPool::System4KBPages); + MockDrmAllocation cmdBuffer(AllocationType::COMMAND_BUFFER, MemoryPool::System4KBPages); + + csr->makeResident(allocation1); + csr->makeResident(allocation2); + + ResidencyContainer residency; + residency.push_back(&allocation1); + residency.push_back(&allocation2); + + testing::internal::CaptureStdout(); + + EXPECT_EQ(SubmissionStatus::SUCCESS, static_cast *>(csr)->printBOsForSubmit(residency, cmdBuffer)); + + std::string output = testing::internal::GetCapturedStdout(); + + std::vector bos; + allocation1.makeBOsResident(&csr->getOsContext(), 0, &bos, true); + allocation2.makeBOsResident(&csr->getOsContext(), 0, &bos, true); + cmdBuffer.makeBOsResident(&csr->getOsContext(), 0, &bos, true); + + std::stringstream expected; + expected << "Buffer object for submit\n"; + for (const auto &bo : bos) { + expected << "BO-" << bo->peekHandle() << ", range: " << std::hex << bo->peekAddress() << " - " << ptrOffset(bo->peekAddress(), bo->peekSize()) << ", size: " << std::dec << bo->peekSize() << "\n"; + } + expected << "\n"; + + EXPECT_FALSE(output.compare(expected.str())); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenPrintBOsForSubmitAndFailureOnMakeResidentForCmdBufferWhenPrintThenErrorIsReturnedAndNothingIsPrinted) { + DebugManagerStateRestore restorer; + DebugManager.flags.PrintBOsForSubmit.set(true); + + MockDrmAllocation allocation1(AllocationType::BUFFER, MemoryPool::System4KBPages); + MockDrmAllocation allocation2(AllocationType::BUFFER, MemoryPool::System4KBPages); + MockDrmAllocation cmdBuffer(AllocationType::COMMAND_BUFFER, MemoryPool::System4KBPages); + + cmdBuffer.makeBOsResidentResult = ENOSPC; + + csr->makeResident(allocation1); + csr->makeResident(allocation2); + + ResidencyContainer residency; + residency.push_back(&allocation1); + residency.push_back(&allocation2); + + testing::internal::CaptureStdout(); + + EXPECT_EQ(SubmissionStatus::OUT_OF_HOST_MEMORY, static_cast *>(csr)->printBOsForSubmit(residency, cmdBuffer)); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_TRUE(output.empty()); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenPrintBOsForSubmitAndFailureOnMakeResidentForAllocationToResidencyWhenPrintThenErrorIsReturnedAndNothingIsPrinted) { + DebugManagerStateRestore restorer; + DebugManager.flags.PrintBOsForSubmit.set(true); + + MockDrmAllocation allocation1(AllocationType::BUFFER, MemoryPool::System4KBPages); + MockDrmAllocation allocation2(AllocationType::BUFFER, MemoryPool::System4KBPages); + MockDrmAllocation cmdBuffer(AllocationType::COMMAND_BUFFER, MemoryPool::System4KBPages); + + allocation1.makeBOsResidentResult = ENOSPC; + + csr->makeResident(allocation1); + csr->makeResident(allocation2); + + ResidencyContainer residency; + residency.push_back(&allocation1); + residency.push_back(&allocation2); + + testing::internal::CaptureStdout(); + + EXPECT_EQ(SubmissionStatus::OUT_OF_HOST_MEMORY, static_cast *>(csr)->printBOsForSubmit(residency, cmdBuffer)); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_TRUE(output.empty()); +} \ No newline at end of file