Detect enable program debugging env variable

Resolves: NEO-4713

Change-Id: Id9ce30b84943c4b364f7756a430d58df2614a28b
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-06-08 16:19:52 +02:00
committed by sys_ocldev
parent dadbd5a09f
commit d55a0ae5c6
17 changed files with 107 additions and 25 deletions

View File

@@ -10,6 +10,7 @@
#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device/device.h" #include "shared/source/device/device.h"
#include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/os_interface/os_library.h" #include "shared/source/os_interface/os_library.h"
#include "level_zero/core/source/device/device_imp.h" #include "level_zero/core/source/device/device_imp.h"
@@ -161,7 +162,9 @@ DriverHandle *DriverHandle::create(std::vector<std::unique_ptr<NEO::Device>> dev
DriverHandleImp *driverHandle = new DriverHandleImp; DriverHandleImp *driverHandle = new DriverHandleImp;
UNRECOVERABLE_IF(nullptr == driverHandle); UNRECOVERABLE_IF(nullptr == driverHandle);
driverHandle->getEnv("ZE_AFFINITY_MASK", driverHandle->affinityMask); NEO::EnvironmentVariableReader envReader;
driverHandle->affinityMask = envReader.getSetting("ZE_AFFINITY_MASK", static_cast<int32_t>(driverHandle->affinityMask));
driverHandle->enableProgramDebugging = envReader.getSetting("ZET_ENABLE_PROGRAM_DEBUGGING", driverHandle->enableProgramDebugging);
ze_result_t res = driverHandle->initialize(std::move(devices)); ze_result_t res = driverHandle->initialize(std::move(devices));
if (res != ZE_RESULT_SUCCESS) { if (res != ZE_RESULT_SUCCESS) {

View File

@@ -58,16 +58,6 @@ struct DriverHandleImp : public DriverHandle {
size_t size, size_t size,
bool *allocationRangeCovered) override; bool *allocationRangeCovered) override;
template <typename T>
bool getEnv(const char *varName, T &varValue) {
char *varChar = getenv(varName);
if (varChar) {
varValue = static_cast<T>(atoi(varChar));
return true;
}
return false;
}
uint32_t numDevices = 0; uint32_t numDevices = 0;
std::unordered_map<std::string, void *> extensionFunctionsLookupMap; std::unordered_map<std::string, void *> extensionFunctionsLookupMap;
std::vector<Device *> devices; std::vector<Device *> devices;
@@ -75,6 +65,7 @@ struct DriverHandleImp : public DriverHandle {
NEO::SVMAllocsManager *svmAllocsManager = nullptr; NEO::SVMAllocsManager *svmAllocsManager = nullptr;
uint32_t affinityMask = std::numeric_limits<uint32_t>::max(); uint32_t affinityMask = std::numeric_limits<uint32_t>::max();
bool enableProgramDebugging = false;
}; };
} // namespace L0 } // namespace L0

View File

@@ -21,10 +21,11 @@ namespace L0 {
namespace ult { namespace ult {
template <> template <>
struct WhiteBox<::L0::DriverHandleImp> : public ::L0::DriverHandleImp { struct WhiteBox<::L0::DriverHandle> : public ::L0::DriverHandleImp {
using ::L0::DriverHandleImp::enableProgramDebugging;
}; };
using DriverHandle = WhiteBox<::L0::DriverHandleImp>; using DriverHandle = WhiteBox<::L0::DriverHandle>;
template <> template <>
struct Mock<DriverHandle> : public DriverHandleImp { struct Mock<DriverHandle> : public DriverHandleImp {

View File

@@ -9,6 +9,7 @@
#include "shared/source/os_interface/hw_info_config.h" #include "shared/source/os_interface/hw_info_config.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "opencl/test/unit_test/mocks/mock_io_functions.h"
#include "test.h" #include "test.h"
#include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h"
@@ -60,6 +61,40 @@ TEST(DriverTestFamilySupport, whenInitializingDriverOnNotSupportedFamilyThenDriv
EXPECT_EQ(nullptr, driverHandle); EXPECT_EQ(nullptr, driverHandle);
} }
TEST(DriverTest, givenNullEnvVariableWhenCreatingDriverThenEnableProgramDebuggingIsFalse) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
NEO::MockDevice *neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices)));
EXPECT_NE(nullptr, driverHandle);
EXPECT_FALSE(driverHandle->enableProgramDebugging);
delete driverHandle;
}
TEST(DriverTest, givenEnvVariableNonZeroWhenCreatingDriverThenEnableProgramDebuggingIsSetTrue) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<bool> mockDeviceFlagBackup(&IoFunctions::returnMockEnvValue, true);
NEO::MockDevice *neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices)));
EXPECT_NE(nullptr, driverHandle);
EXPECT_TRUE(driverHandle->enableProgramDebugging);
delete driverHandle;
}
struct DriverTestMultipleFamilySupport : public ::testing::Test { struct DriverTestMultipleFamilySupport : public ::testing::Test {
void SetUp() override { void SetUp() override {
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false); VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);

View File

@@ -17,7 +17,7 @@
#include "shared/source/helpers/ptr_math.h" #include "shared/source/helpers/ptr_math.h"
#include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/os_interface/linux/debug_env_reader.h" #include "shared/source/os_interface/debug_env_reader.h"
#include "shared/test/unit_test/cmd_parse/hw_parse.h" #include "shared/test/unit_test/cmd_parse/hw_parse.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "shared/test/unit_test/helpers/dispatch_flags_helper.h" #include "shared/test/unit_test/helpers/dispatch_flags_helper.h"

View File

@@ -19,7 +19,7 @@
#include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/unified_memory_manager.h" #include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/source/os_interface/linux/debug_env_reader.h" #include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/os_interface/os_context.h" #include "shared/source/os_interface/os_context.h"
#include "shared/test/unit_test/cmd_parse/hw_parse.h" #include "shared/test/unit_test/cmd_parse/hw_parse.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h"

View File

@@ -12,9 +12,13 @@ namespace IoFunctions {
fopenFuncPtr fopenPtr = &mockFopen; fopenFuncPtr fopenPtr = &mockFopen;
vfprintfFuncPtr vfprintfPtr = &mockVfptrinf; vfprintfFuncPtr vfprintfPtr = &mockVfptrinf;
fcloseFuncPtr fclosePtr = &mockFclose; fcloseFuncPtr fclosePtr = &mockFclose;
getenvFuncPtr getenvPtr = &mockGetenv;
uint32_t mockFopenCalled = 0; uint32_t mockFopenCalled = 0;
uint32_t mockVfptrinfCalled = 0; uint32_t mockVfptrinfCalled = 0;
uint32_t mockFcloseCalled = 0; uint32_t mockFcloseCalled = 0;
bool returnMockEnvValue = false;
std::string mockEnvValue = "1";
} // namespace IoFunctions } // namespace IoFunctions
} // namespace NEO } // namespace NEO

View File

@@ -9,6 +9,7 @@
#include "shared/source/utilities/io_functions.h" #include "shared/source/utilities/io_functions.h"
#include <cstdint> #include <cstdint>
#include <string>
namespace NEO { namespace NEO {
namespace IoFunctions { namespace IoFunctions {
@@ -16,6 +17,9 @@ extern uint32_t mockFopenCalled;
extern uint32_t mockVfptrinfCalled; extern uint32_t mockVfptrinfCalled;
extern uint32_t mockFcloseCalled; extern uint32_t mockFcloseCalled;
extern bool returnMockEnvValue;
extern std::string mockEnvValue;
inline FILE *mockFopen(const char *filename, const char *mode) { inline FILE *mockFopen(const char *filename, const char *mode) {
mockFopenCalled++; mockFopenCalled++;
return reinterpret_cast<FILE *>(0x40); return reinterpret_cast<FILE *>(0x40);
@@ -30,5 +34,13 @@ inline int mockFclose(FILE *stream) {
mockFcloseCalled++; mockFcloseCalled++;
return 0; return 0;
} }
inline char *mockGetenv(const char *name) noexcept {
if (returnMockEnvValue) {
return const_cast<char *>(mockEnvValue.c_str());
}
return getenv(name);
}
} // namespace IoFunctions } // namespace IoFunctions
} // namespace NEO } // namespace NEO

View File

@@ -5,7 +5,7 @@
* *
*/ */
#include "shared/source/os_interface/linux/debug_env_reader.h" #include "shared/source/os_interface/debug_env_reader.h"
#include "test.h" #include "test.h"

View File

@@ -19,6 +19,17 @@
using namespace NEO; using namespace NEO;
class MockSettingsReader : public SettingsReader {
public:
std::string getSetting(const char *settingName, const std::string &value) override {
return value;
}
bool getSetting(const char *settingName, bool defaultValue) override { return defaultValue; };
int64_t getSetting(const char *settingName, int64_t defaultValue) override { return defaultValue; };
int32_t getSetting(const char *settingName, int32_t defaultValue) override { return defaultValue; };
const char *appSpecificLocation(const std::string &name) override { return name.c_str(); };
};
TEST(SettingsReader, Create) { TEST(SettingsReader, Create) {
SettingsReader *reader = SettingsReader::create(oclRegPath); SettingsReader *reader = SettingsReader::create(oclRegPath);
EXPECT_NE(nullptr, reader); EXPECT_NE(nullptr, reader);
@@ -82,6 +93,7 @@ TEST(SettingsReader, givenPrintDebugStringWhenCalledWithTrueItPrintsToOutput) {
std::string output = testing::internal::GetCapturedStdout(); std::string output = testing::internal::GetCapturedStdout();
EXPECT_STRNE(output.c_str(), ""); EXPECT_STRNE(output.c_str(), "");
} }
TEST(SettingsReader, givenPrintDebugStringWhenCalledWithFalseThenNothingIsPrinted) { TEST(SettingsReader, givenPrintDebugStringWhenCalledWithFalseThenNothingIsPrinted) {
int i = 4; int i = 4;
testing::internal::CaptureStdout(); testing::internal::CaptureStdout();
@@ -89,3 +101,9 @@ TEST(SettingsReader, givenPrintDebugStringWhenCalledWithFalseThenNothingIsPrinte
std::string output = testing::internal::GetCapturedStdout(); std::string output = testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.c_str(), ""); EXPECT_STREQ(output.c_str(), "");
} }
TEST(SettingsReader, givenNonExistingEnvVarWhenGettingEnvThenNullptrIsReturned) {
MockSettingsReader reader;
auto value = reader.getenv("ThisEnvVarDoesNotExist");
EXPECT_EQ(nullptr, value);
}

View File

@@ -8,6 +8,8 @@ set(NEO_CORE_OS_INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.h
${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.h
${CMAKE_CURRENT_SOURCE_DIR}/device_factory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_factory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_factory.h ${CMAKE_CURRENT_SOURCE_DIR}/device_factory.h
${CMAKE_CURRENT_SOURCE_DIR}/driver_info.h ${CMAKE_CURRENT_SOURCE_DIR}/driver_info.h

View File

@@ -5,14 +5,12 @@
* *
*/ */
#include "shared/source/os_interface/linux/debug_env_reader.h" #include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/utilities/io_functions.h"
namespace NEO { namespace NEO {
SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string &regKey) {
return new EnvironmentVariableReader;
}
const char *EnvironmentVariableReader::appSpecificLocation(const std::string &name) { const char *EnvironmentVariableReader::appSpecificLocation(const std::string &name) {
return name.c_str(); return name.c_str();
} }
@@ -29,7 +27,7 @@ int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t d
int64_t value = defaultValue; int64_t value = defaultValue;
char *envValue; char *envValue;
envValue = getenv(settingName); envValue = IoFunctions::getenvPtr(settingName);
if (envValue) { if (envValue) {
value = atoi(envValue); value = atoi(envValue);
} }
@@ -41,7 +39,7 @@ std::string EnvironmentVariableReader::getSetting(const char *settingName, const
std::string keyValue; std::string keyValue;
keyValue.assign(value); keyValue.assign(value);
envValue = getenv(settingName); envValue = IoFunctions::getenvPtr(settingName);
if (envValue) { if (envValue) {
keyValue.assign(envValue); keyValue.assign(envValue);
} }

View File

@@ -7,8 +7,6 @@
set(NEO_CORE_OS_INTERFACE_LINUX set(NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.h
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/drm_allocation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_allocation.cpp
@@ -50,6 +48,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/page_table_manager_functions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/page_table_manager_functions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/print.cpp ${CMAKE_CURRENT_SOURCE_DIR}/print.cpp
${CMAKE_CURRENT_SOURCE_DIR}/settings_reader_create.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h ${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h
) )

View File

@@ -0,0 +1,15 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/debug_env_reader.h"
namespace NEO {
SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string &regKey) {
return new EnvironmentVariableReader;
}
} // namespace NEO

View File

@@ -12,5 +12,6 @@ namespace IoFunctions {
fopenFuncPtr fopenPtr = &fopen; fopenFuncPtr fopenPtr = &fopen;
vfprintfFuncPtr vfprintfPtr = &vfprintf; vfprintfFuncPtr vfprintfPtr = &vfprintf;
fcloseFuncPtr fclosePtr = &fclose; fcloseFuncPtr fclosePtr = &fclose;
getenvFuncPtr getenvPtr = &getenv;
} // namespace IoFunctions } // namespace IoFunctions
} // namespace NEO } // namespace NEO

View File

@@ -8,16 +8,19 @@
#pragma once #pragma once
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
#include <stdlib.h>
namespace NEO { namespace NEO {
namespace IoFunctions { namespace IoFunctions {
using fopenFuncPtr = FILE *(*)(const char *, const char *); using fopenFuncPtr = FILE *(*)(const char *, const char *);
using vfprintfFuncPtr = int (*)(FILE *, char const *const formatStr, va_list arg); using vfprintfFuncPtr = int (*)(FILE *, char const *const formatStr, va_list arg);
using fcloseFuncPtr = int (*)(FILE *); using fcloseFuncPtr = int (*)(FILE *);
using getenvFuncPtr = decltype(&getenv);
extern fopenFuncPtr fopenPtr; extern fopenFuncPtr fopenPtr;
extern vfprintfFuncPtr vfprintfPtr; extern vfprintfFuncPtr vfprintfPtr;
extern fcloseFuncPtr fclosePtr; extern fcloseFuncPtr fclosePtr;
extern getenvFuncPtr getenvPtr;
inline int fprintf(FILE *fileDesc, char const *const formatStr, ...) { inline int fprintf(FILE *fileDesc, char const *const formatStr, ...) {
va_list args; va_list args;