From cd9ad1f04c664fef9f4b0ef649ee9269765d9931 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Wed, 26 Jul 2023 16:03:49 +0000 Subject: [PATCH] fix: decanonize GPU VA during TBX memory read. Signed-off-by: Dunajski, Bartosz --- .../aub_command_stream_receiver_hw.h | 2 +- .../aub_command_stream_receiver_hw_base.inl | 2 +- ...mand_stream_receiver_simulated_common_hw.h | 4 ++-- ...ream_receiver_simulated_common_hw_base.inl | 2 +- .../command_stream_receiver_simulated_hw.h | 2 +- .../tbx_command_stream_receiver_hw.h | 2 +- .../tbx_command_stream_receiver_hw.inl | 20 ++++++++++--------- shared/test/common/mocks/mock_aub_csr.h | 2 +- shared/test/common/mocks/mock_aub_manager.h | 8 ++++++-- .../aub_command_stream_receiver_2_tests.cpp | 4 ++-- .../tbx_command_stream_tests.cpp | 17 ++++++++++++++++ 11 files changed, 44 insertions(+), 21 deletions(-) diff --git a/shared/source/command_stream/aub_command_stream_receiver_hw.h b/shared/source/command_stream/aub_command_stream_receiver_hw.h index 6a6203afe9..7d2707aaf0 100644 --- a/shared/source/command_stream/aub_command_stream_receiver_hw.h +++ b/shared/source/command_stream/aub_command_stream_receiver_hw.h @@ -21,7 +21,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw BaseClass; using AUB = typename AUBFamilyMapper::AUB; using ExternalAllocationsContainer = std::vector; - using BaseClass::getParametersForWriteMemory; + using BaseClass::getParametersForMemory; using BaseClass::osContext; public: diff --git a/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl b/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl index 16c2bc33c0..b8da0f484f 100644 --- a/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl @@ -673,7 +673,7 @@ bool AUBCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA uint64_t gpuAddress; void *cpuAddress; size_t size; - if (!this->getParametersForWriteMemory(gfxAllocation, gpuAddress, cpuAddress, size)) { + if (!this->getParametersForMemory(gfxAllocation, gpuAddress, cpuAddress, size)) { return false; } diff --git a/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h b/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h index 7b89964618..79c7987ab0 100644 --- a/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h +++ b/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -28,7 +28,7 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw::AUB; using MiContextDescriptorReg = typename AUB::MiContextDescriptorReg; - bool getParametersForWriteMemory(GraphicsAllocation &graphicsAllocation, uint64_t &gpuAddress, void *&cpuAddress, size_t &size) const; + bool getParametersForMemory(GraphicsAllocation &graphicsAllocation, uint64_t &gpuAddress, void *&cpuAddress, size_t &size) const; void freeEngineInfo(AddressMapper >tRemap); MOCKABLE_VIRTUAL uint32_t getDeviceIndex() const; diff --git a/shared/source/command_stream/command_stream_receiver_simulated_common_hw_base.inl b/shared/source/command_stream/command_stream_receiver_simulated_common_hw_base.inl index fd8f3f758a..59d6b36138 100644 --- a/shared/source/command_stream/command_stream_receiver_simulated_common_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_simulated_common_hw_base.inl @@ -53,7 +53,7 @@ void CommandStreamReceiverSimulatedCommonHw::setupContext(OsContext & } template -bool CommandStreamReceiverSimulatedCommonHw::getParametersForWriteMemory(GraphicsAllocation &graphicsAllocation, uint64_t &gpuAddress, void *&cpuAddress, size_t &size) const { +bool CommandStreamReceiverSimulatedCommonHw::getParametersForMemory(GraphicsAllocation &graphicsAllocation, uint64_t &gpuAddress, void *&cpuAddress, size_t &size) const { cpuAddress = graphicsAllocation.getUnderlyingBuffer(); gpuAddress = peekExecutionEnvironment().rootDeviceEnvironments[graphicsAllocation.getRootDeviceIndex()].get()->gmmHelper.get()->decanonize(graphicsAllocation.getGpuAddress()); size = graphicsAllocation.getUnderlyingBufferSize(); diff --git a/shared/source/command_stream/command_stream_receiver_simulated_hw.h b/shared/source/command_stream/command_stream_receiver_simulated_hw.h index 284ee0fcbe..313a164bbf 100644 --- a/shared/source/command_stream/command_stream_receiver_simulated_hw.h +++ b/shared/source/command_stream/command_stream_receiver_simulated_hw.h @@ -94,7 +94,7 @@ class CommandStreamReceiverSimulatedHw : public CommandStreamReceiverSimulatedCo uint64_t gpuAddress; void *cpuAddress; size_t size; - this->getParametersForWriteMemory(graphicsAllocation, gpuAddress, cpuAddress, size); + this->getParametersForMemory(graphicsAllocation, gpuAddress, cpuAddress, size); int hint = graphicsAllocation.getAllocationType() == AllocationType::COMMAND_BUFFER ? AubMemDump::DataTypeHintValues::TraceBatchBuffer : AubMemDump::DataTypeHintValues::TraceNotype; diff --git a/shared/source/command_stream/tbx_command_stream_receiver_hw.h b/shared/source/command_stream/tbx_command_stream_receiver_hw.h index 14e22f2045..0759ac294c 100644 --- a/shared/source/command_stream/tbx_command_stream_receiver_hw.h +++ b/shared/source/command_stream/tbx_command_stream_receiver_hw.h @@ -27,7 +27,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw BaseClass; using AUB = typename AUBFamilyMapper::AUB; using BaseClass::forceSkipResourceCleanupRequired; - using BaseClass::getParametersForWriteMemory; + using BaseClass::getParametersForMemory; using BaseClass::osContext; uint32_t getMaskAndValueForPollForCompletion() const; diff --git a/shared/source/command_stream/tbx_command_stream_receiver_hw.inl b/shared/source/command_stream/tbx_command_stream_receiver_hw.inl index ae50c1c982..7da09ab252 100644 --- a/shared/source/command_stream/tbx_command_stream_receiver_hw.inl +++ b/shared/source/command_stream/tbx_command_stream_receiver_hw.inl @@ -437,7 +437,7 @@ bool TbxCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA uint64_t gpuAddress; void *cpuAddress; size_t size; - if (!this->getParametersForWriteMemory(gfxAllocation, gpuAddress, cpuAddress, size)) { + if (!this->getParametersForMemory(gfxAllocation, gpuAddress, cpuAddress, size)) { return false; } @@ -536,22 +536,24 @@ SubmissionStatus TbxCommandStreamReceiverHw::processResidency(const R template void TbxCommandStreamReceiverHw::downloadAllocationTbx(GraphicsAllocation &gfxAllocation) { + uint64_t gpuAddress = 0; + void *cpuAddress = nullptr; + size_t size = 0; + + this->getParametersForMemory(gfxAllocation, gpuAddress, cpuAddress, size); + if (hardwareContextController) { - hardwareContextController->readMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize(), + hardwareContextController->readMemory(gpuAddress, cpuAddress, size, this->getMemoryBank(&gfxAllocation), MemoryConstants::pageSize64k); return; } - auto cpuAddress = gfxAllocation.getUnderlyingBuffer(); - auto gpuAddress = gfxAllocation.getGpuAddress(); - auto length = gfxAllocation.getUnderlyingBufferSize(); - - if (length) { + if (size) { PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) { - DEBUG_BREAK_IF(offset > length); + DEBUG_BREAK_IF(offset > size); tbxStream.readMemory(physAddress, ptrOffset(cpuAddress, offset), size); }; - ppgtt->pageWalk(static_cast(gpuAddress), length, 0, 0, walker, this->getMemoryBank(&gfxAllocation)); + ppgtt->pageWalk(static_cast(gpuAddress), size, 0, 0, walker, this->getMemoryBank(&gfxAllocation)); } } diff --git a/shared/test/common/mocks/mock_aub_csr.h b/shared/test/common/mocks/mock_aub_csr.h index 11064263cb..2de229daea 100644 --- a/shared/test/common/mocks/mock_aub_csr.h +++ b/shared/test/common/mocks/mock_aub_csr.h @@ -58,7 +58,7 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { using AUBCommandStreamReceiverHw::taskCount; using AUBCommandStreamReceiverHw::latestSentTaskCount; using AUBCommandStreamReceiverHw::pollForCompletionTaskCount; - using AUBCommandStreamReceiverHw::getParametersForWriteMemory; + using AUBCommandStreamReceiverHw::getParametersForMemory; using AUBCommandStreamReceiverHw::writeMemory; using AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw; diff --git a/shared/test/common/mocks/mock_aub_manager.h b/shared/test/common/mocks/mock_aub_manager.h index 1a75b960dc..8e3a99075a 100644 --- a/shared/test/common/mocks/mock_aub_manager.h +++ b/shared/test/common/mocks/mock_aub_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -39,12 +39,16 @@ struct MockHardwareContext : public aub_stream::HardwareContext { void writeMMIO(uint32_t offset, uint32_t value) override { writeMMIOCalled = true; } void freeMemory(uint64_t gfxAddress, size_t size) override { freeMemoryCalled = true; } void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) override { expectMemoryCalled = true; } - void readMemory(uint64_t gfxAddress, void *memory, size_t size, uint32_t memoryBank, size_t pageSize) override { readMemoryCalled = true; } + void readMemory(uint64_t gfxAddress, void *memory, size_t size, uint32_t memoryBank, size_t pageSize) override { + readMemoryCalled = true; + latestGpuVaForMemoryRead = gfxAddress; + } void dumpBufferBIN(uint64_t gfxAddress, size_t size) override { dumpBufferBINCalled = true; } void dumpSurface(const SurfaceInfo &surfaceInfo) override { dumpSurfaceCalled = true; } void pollForFenceCompletion() override {} std::vector storedAllocationParams; + uint64_t latestGpuVaForMemoryRead = 0; bool storeAllocationParams = false; bool initializeCalled = false; bool pollForCompletionCalled = false; diff --git a/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp b/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp index 5154f6deb6..149e0f24ef 100644 --- a/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -292,7 +292,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenNoCpuPtrAndNotLockableAllocationWhe void *cpuAddress{}; size_t size{}; - aubCsr->getParametersForWriteMemory(allocation, gpuAddress, cpuAddress, size); + aubCsr->getParametersForMemory(allocation, gpuAddress, cpuAddress, size); EXPECT_EQ(nullptr, cpuAddress); EXPECT_EQ(initGpuAddress, gpuAddress); @@ -327,7 +327,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenNoCpuPtrAndLockableAllocationWhenGe void *cpuAddress{}; size_t size{}; - aubCsr->getParametersForWriteMemory(allocation, gpuAddress, cpuAddress, size); + aubCsr->getParametersForMemory(allocation, gpuAddress, cpuAddress, size); EXPECT_EQ(nullptr, cpuAddress); EXPECT_EQ(initGpuAddress, gpuAddress); diff --git a/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp b/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp index d65a558eb4..8ed1090057 100644 --- a/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp +++ b/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp @@ -9,6 +9,7 @@ #include "shared/source/command_stream/command_stream_receiver_with_aub_dump.h" #include "shared/source/command_stream/tbx_command_stream_receiver_hw.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/helpers/engine_node_helper.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/hardware_context_controller.h" @@ -551,6 +552,22 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenDownloadAllocat EXPECT_TRUE(mockHardwareContext->readMemoryCalled); } +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenDownloadAllocationIsCalledThenDecanonizeGpuVa) { + MockTbxCsr tbxCsr(*pDevice->executionEnvironment, pDevice->getDeviceBitfield()); + MockOsContext osContext(0, EngineDescriptorHelper::getDefaultDescriptor(pDevice->getDeviceBitfield())); + tbxCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); + + uint64_t gpuVa = pDevice->getHardwareInfo().capabilityTable.gpuAddressSpace; + uint64_t canonizedGpuVa = pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->getGmmHelper()->canonize(gpuVa); + + MockGraphicsAllocation allocation(reinterpret_cast(0x1230000), canonizedGpuVa, 0x10000); + tbxCsr.downloadAllocation(allocation); + + EXPECT_TRUE(mockHardwareContext->readMemoryCalled); + EXPECT_EQ(gpuVa, mockHardwareContext->latestGpuVaForMemoryRead); +} + HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenHardwareContextIsCreatedThenTbxStreamInCsrIsNotInitialized) { MockAubManager *mockManager = new MockAubManager(); MockAubCenter *mockAubCenter = new MockAubCenter(pDevice->getRootDeviceEnvironment(), false, "", CommandStreamReceiverType::CSR_TBX);