2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-07-20 13:54:03 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "debug_settings_manager.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-08-20 18:10:51 +08:00
|
|
|
#include "shared/source/debug_settings/debug_variables_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/debug_settings/definitions/translate_debug_settings.h"
|
2023-08-20 12:31:48 +08:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
|
|
|
#include "shared/source/helpers/string.h"
|
|
|
|
#include "shared/source/utilities/debug_settings_reader_creator.h"
|
2023-08-20 12:31:48 +08:00
|
|
|
#include "shared/source/utilities/io_functions.h"
|
2022-11-24 22:52:53 +08:00
|
|
|
#include "shared/source/utilities/logger.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-18 03:04:23 +08:00
|
|
|
#include <fstream>
|
2020-03-27 14:47:16 +08:00
|
|
|
#include <iostream>
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <sstream>
|
2022-09-06 01:20:23 +08:00
|
|
|
#include <type_traits>
|
2019-04-01 17:25:47 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-09-06 01:20:23 +08:00
|
|
|
template <typename T>
|
|
|
|
static std::string toString(const T &arg) {
|
|
|
|
if constexpr (std::is_convertible_v<std::string, T>) {
|
|
|
|
return static_cast<std::string>(arg);
|
|
|
|
} else {
|
|
|
|
return std::to_string(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template <DebugFunctionalityLevel DebugLevel>
|
2019-12-13 23:48:57 +08:00
|
|
|
DebugSettingsManager<DebugLevel>::DebugSettingsManager(const char *registryPath) {
|
2020-06-15 17:16:46 +08:00
|
|
|
readerImpl = SettingsReaderCreator::create(std::string(registryPath));
|
2023-08-20 12:31:48 +08:00
|
|
|
ApiSpecificConfig::initPrefixes();
|
2020-06-15 17:16:46 +08:00
|
|
|
injectSettingsFromReader();
|
|
|
|
dumpFlags();
|
2019-01-19 08:40:42 +08:00
|
|
|
translateDebugSettings(flags);
|
2020-04-22 16:24:00 +08:00
|
|
|
|
|
|
|
while (isLoopAtDriverInitEnabled())
|
|
|
|
;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <DebugFunctionalityLevel DebugLevel>
|
2020-07-30 18:28:19 +08:00
|
|
|
DebugSettingsManager<DebugLevel>::~DebugSettingsManager() {
|
|
|
|
readerImpl.reset();
|
|
|
|
};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-10-04 18:44:49 +08:00
|
|
|
template <DebugFunctionalityLevel DebugLevel>
|
|
|
|
void DebugSettingsManager<DebugLevel>::getHardwareInfoOverride(std::string &hwInfoConfig) {
|
|
|
|
std::string str = flags.HardwareInfoOverride.get();
|
|
|
|
if (str[0] == '\"') {
|
|
|
|
str.pop_back();
|
|
|
|
hwInfoConfig = str.substr(1, std::string::npos);
|
|
|
|
} else {
|
|
|
|
hwInfoConfig = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-20 12:31:48 +08:00
|
|
|
static const char *convPrefixToString(DebugVarPrefix prefix) {
|
|
|
|
if (prefix == DebugVarPrefix::Neo) {
|
|
|
|
return "NEO_";
|
|
|
|
} else if (prefix == DebugVarPrefix::Neo_L0) {
|
|
|
|
return "NEO_L0_";
|
|
|
|
} else if (prefix == DebugVarPrefix::Neo_Ocl) {
|
|
|
|
return "NEO_OCL_";
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 17:25:47 +08:00
|
|
|
template <DebugFunctionalityLevel DebugLevel>
|
|
|
|
template <typename DataType>
|
2022-09-22 19:22:29 +08:00
|
|
|
void DebugSettingsManager<DebugLevel>::dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue, std::ostringstream &ostring) {
|
2019-04-01 17:25:47 +08:00
|
|
|
if (variableValue != defaultValue) {
|
2022-09-06 01:20:23 +08:00
|
|
|
const auto variableStringValue = toString(variableValue);
|
2022-09-22 19:22:29 +08:00
|
|
|
ostring << "Non-default value of debug variable: " << variableName << " = " << variableStringValue.c_str() << '\n';
|
2019-04-01 17:25:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DebugFunctionalityLevel DebugLevel>
|
2022-09-22 19:22:29 +08:00
|
|
|
void DebugSettingsManager<DebugLevel>::getStringWithFlags(std::string &allFlags, std::string &changedFlags) const {
|
|
|
|
std::ostringstream allFlagsStream;
|
|
|
|
allFlagsStream.str("");
|
2019-04-01 17:25:47 +08:00
|
|
|
|
2022-09-22 19:22:29 +08:00
|
|
|
std::ostringstream changedFlagsStream;
|
|
|
|
changedFlagsStream.str("");
|
2019-04-01 17:25:47 +08:00
|
|
|
|
2023-09-07 20:44:36 +08:00
|
|
|
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
|
|
|
{ \
|
|
|
|
std::string neoKey = convPrefixToString(flags.variableName.getPrefixType()); \
|
|
|
|
neoKey += getNonReleaseKeyName(#variableName); \
|
|
|
|
allFlagsStream << neoKey.c_str() << " = " << flags.variableName.get() << '\n'; \
|
|
|
|
dumpNonDefaultFlag<dataType>(neoKey.c_str(), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
2023-08-20 12:31:48 +08:00
|
|
|
}
|
2020-08-20 18:10:51 +08:00
|
|
|
if (registryReadAvailable() || isDebugKeysReadEnabled()) {
|
2019-04-01 17:25:47 +08:00
|
|
|
#include "debug_variables.inl"
|
2020-06-15 17:16:46 +08:00
|
|
|
}
|
2021-01-11 04:36:01 +08:00
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
|
|
|
|
2023-09-07 20:44:36 +08:00
|
|
|
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
|
|
|
{ \
|
|
|
|
std::string neoKey = convPrefixToString(flags.variableName.getPrefixType()); \
|
|
|
|
neoKey += #variableName; \
|
|
|
|
allFlagsStream << neoKey.c_str() << " = " << flags.variableName.get() << '\n'; \
|
|
|
|
dumpNonDefaultFlag<dataType>(neoKey.c_str(), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
2023-08-20 12:31:48 +08:00
|
|
|
}
|
2020-06-15 17:16:46 +08:00
|
|
|
#include "release_variables.inl"
|
2019-04-01 17:25:47 +08:00
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2022-09-22 19:22:29 +08:00
|
|
|
|
|
|
|
allFlags = allFlagsStream.str();
|
|
|
|
changedFlags = changedFlagsStream.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DebugFunctionalityLevel DebugLevel>
|
|
|
|
void DebugSettingsManager<DebugLevel>::dumpFlags() const {
|
|
|
|
if (flags.PrintDebugSettings.get() == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ofstream settingsDumpFile{settingsDumpFileName, std::ios::out};
|
|
|
|
DEBUG_BREAK_IF(!settingsDumpFile.good());
|
|
|
|
|
|
|
|
std::string allFlags;
|
|
|
|
std::string changedFlags;
|
|
|
|
|
|
|
|
getStringWithFlags(allFlags, changedFlags);
|
|
|
|
PRINT_DEBUG_STRING(true, stdout, "%s", changedFlags.c_str());
|
|
|
|
|
|
|
|
settingsDumpFile << allFlags;
|
2019-04-05 14:51:01 +08:00
|
|
|
}
|
2019-04-01 17:25:47 +08:00
|
|
|
|
2018-12-13 20:46:32 +08:00
|
|
|
template <DebugFunctionalityLevel DebugLevel>
|
|
|
|
void DebugSettingsManager<DebugLevel>::injectSettingsFromReader() {
|
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2023-08-20 12:31:48 +08:00
|
|
|
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
|
|
|
{ \
|
|
|
|
DebugVarPrefix type; \
|
|
|
|
dataType tempData = readerImpl->getSetting(getNonReleaseKeyName(#variableName), flags.variableName.get(), type); \
|
|
|
|
flags.variableName.setPrefixType(type); \
|
|
|
|
flags.variableName.set(tempData); \
|
2018-12-13 20:46:32 +08:00
|
|
|
}
|
2020-06-15 17:16:46 +08:00
|
|
|
|
2020-08-20 18:10:51 +08:00
|
|
|
if (registryReadAvailable() || isDebugKeysReadEnabled()) {
|
2018-12-13 20:46:32 +08:00
|
|
|
#include "debug_variables.inl"
|
2020-06-15 17:16:46 +08:00
|
|
|
}
|
2021-01-11 04:36:01 +08:00
|
|
|
|
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2023-08-20 12:31:48 +08:00
|
|
|
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
|
|
|
{ \
|
|
|
|
DebugVarPrefix type; \
|
|
|
|
dataType tempData = readerImpl->getSetting(#variableName, flags.variableName.get(), type); \
|
|
|
|
flags.variableName.setPrefixType(type); \
|
|
|
|
flags.variableName.set(tempData); \
|
2021-01-11 04:36:01 +08:00
|
|
|
}
|
2020-06-15 17:16:46 +08:00
|
|
|
#include "release_variables.inl"
|
2019-01-19 08:40:42 +08:00
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2018-12-13 20:46:32 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-11-24 22:52:53 +08:00
|
|
|
void logDebugString(std::string_view debugString) {
|
|
|
|
NEO::fileLoggerInstance().logDebugString(true, debugString);
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template class DebugSettingsManager<DebugFunctionalityLevel::None>;
|
|
|
|
template class DebugSettingsManager<DebugFunctionalityLevel::Full>;
|
|
|
|
template class DebugSettingsManager<DebugFunctionalityLevel::RegKeys>;
|
2019-03-26 18:59:46 +08:00
|
|
|
}; // namespace NEO
|