mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-19 06:24:51 +08:00
Adding DisableDeepBind debug flag
Related-To: NEO-4946 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
c686fb250e
commit
66f4c75aea
@@ -77,6 +77,8 @@ if(WIN32)
|
||||
else()
|
||||
list(APPEND IGDRCL_SRCS_offline_compiler_tests
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_thread_linux.cpp
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
|
||||
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2018-2020 Intel Corporation
|
||||
# Copyright (C) 2018-2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -27,6 +27,8 @@ else()
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/safety_guard_caller_linux.cpp
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
|
||||
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -1,19 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/os_library_linux.h"
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
namespace SysCalls {
|
||||
|
||||
extern int dlOpenFlags;
|
||||
extern bool dlOpenCalled;
|
||||
} // namespace SysCalls
|
||||
|
||||
TEST(OsLibraryTest, WhenCreatingFullSystemPathThenProperPathIsConstructed) {
|
||||
auto fullPath = OsLibrary::createFullSystemPath("test");
|
||||
EXPECT_STREQ("test", fullPath.c_str());
|
||||
}
|
||||
|
||||
TEST(OsLibraryTest, GivenDisableDeepBindFlagWhenOpeningLibraryThenRtldDeepBindFlagIsNotPassed) {
|
||||
|
||||
DebugManagerStateRestore restorer;
|
||||
VariableBackup<int> dlOpenFlagsBackup{&NEO::SysCalls::dlOpenFlags, 0};
|
||||
VariableBackup<bool> dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false};
|
||||
|
||||
DebugManager.flags.DisableDeepBind.set(1);
|
||||
auto lib = std::make_unique<Linux::OsLibrary>("abc");
|
||||
EXPECT_TRUE(NEO::SysCalls::dlOpenCalled);
|
||||
EXPECT_EQ(0, NEO::SysCalls::dlOpenFlags & RTLD_DEEPBIND);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -23,6 +24,8 @@ namespace NEO {
|
||||
namespace SysCalls {
|
||||
uint32_t closeFuncCalled = 0u;
|
||||
int closeFuncArgPassed = 0;
|
||||
int dlOpenFlags = 0;
|
||||
bool dlOpenCalled = 0;
|
||||
constexpr int fakeFileDescriptor = 123;
|
||||
uint32_t vmId = 0;
|
||||
bool makeFakeDevicePath = false;
|
||||
@@ -43,6 +46,13 @@ int open(const char *file, int flags) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *dlopen(const char *filename, int flag) {
|
||||
dlOpenFlags = flag;
|
||||
dlOpenCalled = true;
|
||||
return ::dlopen(filename, flag);
|
||||
}
|
||||
|
||||
int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
|
||||
if (fileDescriptor == fakeFileDescriptor) {
|
||||
if (request == DRM_IOCTL_VERSION) {
|
||||
|
||||
@@ -214,3 +214,4 @@ ForceBtpPrefetchMode = -1
|
||||
OverrideProfilingTimerResolution = -1
|
||||
PreferCopyEngineForCopyBufferToBuffer = -1
|
||||
EnableStaticPartitioning = -1
|
||||
DisableDeepBind = 0
|
||||
|
||||
@@ -83,7 +83,9 @@ else()
|
||||
list(APPEND CLOC_LIB_SRCS_LIB
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
|
||||
${NEO_SOURCE_DIR}/opencl/source/dll/linux/options_linux.cpp
|
||||
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/os_library_linux.h"
|
||||
|
||||
namespace NEO {
|
||||
namespace Linux {
|
||||
void adjustLibraryFlags(int &dlopenFlag) {
|
||||
}
|
||||
} // namespace Linux
|
||||
} // namespace NEO
|
||||
@@ -230,3 +230,4 @@ DECLARE_DEBUG_VARIABLE(bool, ReturnRawGpuTimestamps, false, "Driver returns raw
|
||||
DECLARE_DEBUG_VARIABLE(bool, ForcePerDssBackedBufferProgramming, false, "Always program per-DSS memory backed buffer in preamble")
|
||||
DECLARE_DEBUG_VARIABLE(bool, DisableAtomicForPostSyncs, false, "When enabled, post syncs are not tracked with atomics")
|
||||
DECLARE_DEBUG_VARIABLE(bool, UseCommandBufferHeaderSizeForWddmQueueSubmission, true, "0: Page size (4096), 1: sizeof(COMMAND_BUFFER_HEADER)")
|
||||
DECLARE_DEBUG_VARIABLE(bool, DisableDeepBind, false, "Disable passing RTLD_DEEPBIND flag to all dlopen calls.")
|
||||
|
||||
@@ -47,6 +47,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library_helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp
|
||||
|
||||
21
shared/source/os_interface/linux/os_library_helper.cpp
Normal file
21
shared/source/os_interface/linux/os_library_helper.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/os_interface/linux/os_library_linux.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
namespace NEO {
|
||||
namespace Linux {
|
||||
void adjustLibraryFlags(int &dlopenFlag) {
|
||||
if (DebugManager.flags.DisableDeepBind.get()) {
|
||||
dlopenFlag &= ~RTLD_DEEPBIND;
|
||||
}
|
||||
}
|
||||
} // namespace Linux
|
||||
} // namespace NEO
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
* Copyright (C) 2017-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "shared/source/os_interface/linux/os_library_linux.h"
|
||||
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
@@ -32,15 +33,16 @@ namespace Linux {
|
||||
|
||||
OsLibrary::OsLibrary(const std::string &name) {
|
||||
if (name.empty()) {
|
||||
this->handle = dlopen(0, RTLD_LAZY);
|
||||
this->handle = SysCalls::dlopen(0, RTLD_LAZY);
|
||||
} else {
|
||||
#ifdef SANITIZER_BUILD
|
||||
constexpr auto dlopenFlag = RTLD_LAZY;
|
||||
auto dlopenFlag = RTLD_LAZY;
|
||||
#else
|
||||
constexpr auto dlopenFlag = RTLD_LAZY | RTLD_DEEPBIND;
|
||||
auto dlopenFlag = RTLD_LAZY | RTLD_DEEPBIND;
|
||||
/* Background: https://github.com/intel/compute-runtime/issues/122 */
|
||||
#endif
|
||||
this->handle = dlopen(name.c_str(), dlopenFlag);
|
||||
adjustLibraryFlags(dlopenFlag);
|
||||
this->handle = SysCalls::dlopen(name.c_str(), dlopenFlag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
* Copyright (C) 2017-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -11,6 +11,8 @@
|
||||
namespace NEO {
|
||||
namespace Linux {
|
||||
|
||||
void adjustLibraryFlags(int &dlopenFlag);
|
||||
|
||||
class OsLibrary : public NEO::OsLibrary {
|
||||
private:
|
||||
void *handle;
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace NEO {
|
||||
namespace SysCalls {
|
||||
int close(int fileDescriptor);
|
||||
int open(const char *file, int flags);
|
||||
void *dlopen(const char *filename, int flag);
|
||||
int ioctl(int fileDescriptor, unsigned long int request, void *arg);
|
||||
int getDevicePath(int deviceFd, char *buf, size_t &bufSize);
|
||||
int access(const char *pathname, int mode);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
@@ -27,6 +28,10 @@ int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
|
||||
return ::ioctl(fileDescriptor, request, arg);
|
||||
}
|
||||
|
||||
void *dlopen(const char *filename, int flag) {
|
||||
return ::dlopen(filename, flag);
|
||||
}
|
||||
|
||||
int access(const char *pathName, int mode) {
|
||||
return ::access(pathName, mode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user