From 9322495e7d95ea7d13c0023bc0d3554bbd08fbb5 Mon Sep 17 00:00:00 2001 From: Young Jin Yoon Date: Thu, 6 Jun 2024 16:26:42 +0000 Subject: [PATCH] fix: read scratch page options during init Previous logic to initialize scratch page options during Drm::create causes issues when PerContextVm is used, so moved the location of logic to be configured before creating VM. Related-To: GSD-7611 Signed-off-by: Young Jin Yoon --- .../test/unit_test/linux/main_linux_dll.cpp | 23 +++++++++++++++++++ opencl/test/unit_test/linux/mock_os_layer.cpp | 5 ++++ opencl/test/unit_test/linux/mock_os_layer.h | 5 ++++ shared/source/dll/linux/drm_neo_create.cpp | 6 ++--- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/opencl/test/unit_test/linux/main_linux_dll.cpp b/opencl/test/unit_test/linux/main_linux_dll.cpp index 20b4241a01..da7240a64c 100644 --- a/opencl/test/unit_test/linux/main_linux_dll.cpp +++ b/opencl/test/unit_test/linux/main_linux_dll.cpp @@ -14,6 +14,7 @@ #include "shared/source/os_interface/driver_info.h" #include "shared/source/os_interface/linux/allocator_helper.h" #include "shared/source/os_interface/linux/i915.h" +#include "shared/source/os_interface/linux/ioctl_helper.h" #include "shared/source/os_interface/linux/sys_calls.h" #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/helpers/custom_event_listener.h" @@ -766,6 +767,28 @@ TEST_F(DrmTests, givenDrmIsCreatedWhenCreateVirtualMemoryFailsThenReturnVirtualM ::testing::internal::GetCapturedStdout(); } +TEST_F(DrmTests, givenDrmIsCreatedWithPerContextVmRequiredWhenCreateVirtualMemoryThenCapturedVirtualMemoryIsSettingScratchPageOptionCorrectly) { + DebugManagerStateRestore dbgRestorer; + debugManager.flags.PrintDebugMessages.set(true); + debugManager.flags.DisableScratchPages.set(true); + debugManager.flags.GpuFaultCheckThreshold.set(10); + + VariableBackup backupCaptureVirtualMemoryCreate(&captureVirtualMemoryCreate); + VariableBackup backupCapturedVmCreate(&capturedVmCreate); + + captureVirtualMemoryCreate = 1; + capturedVmCreate = {}; + + auto drm = DrmWrap::createDrm(*mockRootDeviceEnvironment); + EXPECT_NE(drm, nullptr); + + auto disableScratch = drm.get()->checkToDisableScratchPage(); + auto ioctlHelper = drm.get()->getIoctlHelper(); + for (auto ctl : capturedVmCreate) { + EXPECT_NE(0u, (ctl.flags & ioctlHelper->getFlagsForVmCreate(disableScratch, false, false))); + } +} + TEST(SysCalls, WhenSysCallsPollCalledThenCallIsRedirectedToOs) { struct pollfd pollFd; pollFd.fd = 0; diff --git a/opencl/test/unit_test/linux/mock_os_layer.cpp b/opencl/test/unit_test/linux/mock_os_layer.cpp index 167b6cdc89..35f6c922f5 100644 --- a/opencl/test/unit_test/linux/mock_os_layer.cpp +++ b/opencl/test/unit_test/linux/mock_os_layer.cpp @@ -41,6 +41,7 @@ int failOnVirtualMemoryCreate = 0; int failOnSetPriority = 0; int failOnPreemption = 0; int failOnDrmVersion = 0; +int captureVirtualMemoryCreate = 0; int accessCalledTimes = 0; int readLinkCalledTimes = 0; int fstatCalledTimes = 0; @@ -49,6 +50,7 @@ char providedDrmVersion[5] = {'i', '9', '1', '5', '\0'}; uint64_t gpuTimestamp = 0; int ioctlSeq[8] = {0, 0, 0, 0, 0, 0, 0, 0}; size_t ioctlCnt = 0; +std::vector capturedVmCreate{}; int fstat(int fd, struct stat *buf) { ++fstatCalledTimes; @@ -234,6 +236,9 @@ int drmVirtualMemoryCreate(NEO::GemVmControl *control) { if (!failOnVirtualMemoryCreate) { control->vmId = ++vmId; } + if (captureVirtualMemoryCreate) { + capturedVmCreate.push_back(*control); + } return failOnVirtualMemoryCreate; } diff --git a/opencl/test/unit_test/linux/mock_os_layer.h b/opencl/test/unit_test/linux/mock_os_layer.h index 41ebb2f8fc..25093cc94c 100644 --- a/opencl/test/unit_test/linux/mock_os_layer.h +++ b/opencl/test/unit_test/linux/mock_os_layer.h @@ -7,6 +7,8 @@ #pragma once +#include "shared/source/os_interface/linux/drm_wrappers.h" + #include #include #include @@ -16,6 +18,7 @@ #include #include #include +#include extern int (*openFunc)(const char *pathname, int flags, ...); extern int (*openFull)(const char *pathname, int flags, ...); @@ -38,6 +41,7 @@ extern int failOnSetPriority; extern int failOnPreemption; extern int havePreemption; extern int failOnDrmVersion; +extern int captureVirtualMemoryCreate; extern char providedDrmVersion[5]; extern int ioctlSeq[8]; extern size_t ioctlCnt; @@ -47,3 +51,4 @@ extern int accessCalledTimes; extern int readLinkCalledTimes; extern int fstatCalledTimes; extern bool forceExtraIoctlDuration; +extern std::vector capturedVmCreate; diff --git a/shared/source/dll/linux/drm_neo_create.cpp b/shared/source/dll/linux/drm_neo_create.cpp index 76c3284e40..fa1efd3384 100644 --- a/shared/source/dll/linux/drm_neo_create.cpp +++ b/shared/source/dll/linux/drm_neo_create.cpp @@ -98,6 +98,9 @@ Drm *Drm::create(std::unique_ptr &&hwDeviceId, RootDeviceEnvironm drm->isSetPairAvailable(); drm->isChunkingAvailable(); + drm->configureScratchPagePolicy(); + drm->configureGpuFaultCheckThreshold(); + if (!drm->isPerContextVMRequired()) { if (!drm->createVirtualMemoryAddressSpace(GfxCoreHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()))) { printDebugString(debugManager.flags.PrintDebugMessages.get(), stderr, "%s", "INFO: Device doesn't support GEM Virtual Memory\n"); @@ -106,9 +109,6 @@ Drm *Drm::create(std::unique_ptr &&hwDeviceId, RootDeviceEnvironm drm->queryAdapterBDF(); - drm->configureScratchPagePolicy(); - drm->configureGpuFaultCheckThreshold(); - return drm.release(); }