From 540fa198947c57e8ca768a9cd0dd9023f690a97b Mon Sep 17 00:00:00 2001 From: Brandon Yates Date: Tue, 3 Jun 2025 02:47:41 +0000 Subject: [PATCH] fix: mark resources for capture even when debugger is not init Some allocations are created before debugger is initialized. This change will ensure they get marked for capture. Debugger Enabled check added to bind path where capture flag is set Related-to: GSD-10856 Signed-off-by: Brandon Yates --- .../os_interface/linux/drm_memory_manager.cpp | 3 +-- shared/source/os_interface/linux/drm_neo.cpp | 5 +++-- .../linux/drm_memory_manager_tests.cpp | 22 ------------------- .../linux/drm_query_prelim_tests.cpp | 20 +++++++++++++++-- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index a0bccef499..4ea4f9219f 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1825,10 +1825,9 @@ void DrmMemoryManager::unregisterAllocation(GraphicsAllocation *allocation) { } void DrmMemoryManager::registerAllocationInOs(GraphicsAllocation *allocation) { - if (allocation && getDrm(allocation->getRootDeviceIndex()).getIoctlHelper()->resourceRegistrationEnabled()) { + if (allocation) { auto drmAllocation = static_cast(allocation); drmAllocation->registerBOBindExtHandle(&getDrm(drmAllocation->getRootDeviceIndex())); - if (isAllocationTypeToCapture(drmAllocation->getAllocationType())) { drmAllocation->markForCapture(); } diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 5534a598d8..a3d333b05c 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1508,7 +1508,8 @@ int changeBufferObjectBinding(Drm *drm, OsContext *osContext, uint32_t vmHandleI } // Use only when debugger is disabled - const bool guaranteePagingFence = forcePagingFence && !drm->getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled(); + auto debuggingEnabled = drm->getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled(); + const bool guaranteePagingFence = forcePagingFence && !debuggingEnabled; std::unique_ptr extensions; if (bind) { @@ -1516,7 +1517,7 @@ int changeBufferObjectBinding(Drm *drm, OsContext *osContext, uint32_t vmHandleI if (bo->getBindExtHandles().size() > 0 && allowUUIDsForDebug) { extensions = ioctlHelper->prepareVmBindExt(bo->getBindExtHandles(), bo->getRegisteredBindHandleCookie()); } - bool bindCapture = bo->isMarkedForCapture(); + bool bindCapture = debuggingEnabled && bo->isMarkedForCapture(); bool bindImmediate = bo->isImmediateBindingRequired(); bool bindMakeResident = false; bool readOnlyResource = bo->isReadOnlyGpuResource(); diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index af22e60a96..39195c8206 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -4663,28 +4663,6 @@ TEST_F(DrmAllocationTests, givenResourceRegistrationNotEnabledWhenRegisteringBin EXPECT_EQ(DrmResourceClass::maxSize, drm.registeredClass); } -TEST(DrmMemoryManager, givenTrackedAllocationTypeAndDisabledRegistrationInDrmWhenAllocatingThenRegisterBoBindExtHandleIsNotCalled) { - const uint32_t rootDeviceIndex = 0u; - auto executionEnvironment = std::make_unique(); - executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->initGmm(); - - auto mockDrm = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]); - executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); - executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr(mockDrm)); - auto memoryManager = std::make_unique(false, false, false, *executionEnvironment); - - EXPECT_FALSE(mockDrm->resourceRegistrationEnabled()); - - mockDrm->registeredDataSize = 0; - - MockDrmAllocation allocation(rootDeviceIndex, AllocationType::debugContextSaveArea, MemoryPool::system4KBPages); - - memoryManager->registerAllocationInOs(&allocation); - - EXPECT_FALSE(allocation.registerBOBindExtHandleCalled); - EXPECT_EQ(DrmResourceClass::maxSize, mockDrm->registeredClass); -} - TEST(DrmMemoryManager, givenResourceRegistrationEnabledAndAllocTypeToCaptureWhenRegisteringAllocationInOsThenItIsMarkedForCapture) { const uint32_t rootDeviceIndex = 0u; auto executionEnvironment = std::make_unique(); diff --git a/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp index a4f37c52c4..53d07594cf 100644 --- a/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp @@ -488,7 +488,23 @@ TEST(DrmBufferObjectTestPrelim, givenContextWhenQueryingVmIdThenIoctlIsCalled) { EXPECT_EQ(static_cast(drm.storedRetValForVmId), vmId); } -TEST(DrmBufferObjectTestPrelim, givenBufferObjectMarkedForCaptureWhenBindingThenCaptureFlagIsSet) { +TEST(DrmBufferObjectTestPrelim, givenBufferObjectMarkedForCaptureAndDebuggerEnabledWhenBindingThenCaptureFlagIsSet) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); + executionEnvironment->initializeMemoryManager(); + executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online); + DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + BufferObjectMock bo(0, &drm, 3, 1, 0, 1); + OsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor()); + osContext.ensureContextInitialized(false); + bo.markForCapture(); + + bo.bind(&osContext, 0, false); + ASSERT_TRUE(drm.context.receivedVmBind); + EXPECT_TRUE(drm.context.receivedVmBind->flags & DrmPrelimHelper::getCaptureVmBindFlag()); +} + +TEST(DrmBufferObjectTestPrelim, givenBufferObjectMarkedForCaptureAndDebuggerNotEnabledWhenBindingThenCaptureFlagIsNotSet) { auto executionEnvironment = std::make_unique(); executionEnvironment->rootDeviceEnvironments[0]->initGmm(); executionEnvironment->initializeMemoryManager(); @@ -500,7 +516,7 @@ TEST(DrmBufferObjectTestPrelim, givenBufferObjectMarkedForCaptureWhenBindingThen bo.bind(&osContext, 0, false); ASSERT_TRUE(drm.context.receivedVmBind); - EXPECT_TRUE(drm.context.receivedVmBind->flags & DrmPrelimHelper::getCaptureVmBindFlag()); + EXPECT_FALSE(drm.context.receivedVmBind->flags & DrmPrelimHelper::getCaptureVmBindFlag()); } TEST(DrmBufferObjectTestPrelim, givenNoActiveDirectSubmissionAndForceUseImmediateExtensionWhenBindingThenImmediateFlagIsSetAndExtensionListIsNotNull) {