2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2023-07-20 05:54:03 +00:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "debug_settings_manager.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2020-08-20 12:10:51 +02:00
|
|
|
#include "shared/source/debug_settings/debug_variables_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/debug_settings/definitions/translate_debug_settings.h"
|
2023-08-20 04:31:48 +00:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
2020-02-23 22:44:01 +01: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 04:31:48 +00:00
|
|
|
#include "shared/source/utilities/io_functions.h"
|
2022-11-24 14:52:53 +00:00
|
|
|
#include "shared/source/utilities/logger.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-05-17 19:04:23 +00:00
|
|
|
#include <fstream>
|
2020-03-27 07:47:16 +01:00
|
|
|
#include <iostream>
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <sstream>
|
2022-09-05 17:20:23 +00:00
|
|
|
#include <type_traits>
|
2019-04-01 11:25:47 +02:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-09-05 17:20:23 +00: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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-23 17:09:04 +00:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
|
DebugSettingsManager<debugLevel>::DebugSettingsManager(const char *registryPath) {
|
2020-06-15 11:16:46 +02:00
|
|
|
readerImpl = SettingsReaderCreator::create(std::string(registryPath));
|
2023-08-20 04:31:48 +00:00
|
|
|
ApiSpecificConfig::initPrefixes();
|
2020-06-15 11:16:46 +02:00
|
|
|
injectSettingsFromReader();
|
|
|
|
|
dumpFlags();
|
2019-01-19 01:40:42 +01:00
|
|
|
translateDebugSettings(flags);
|
2020-04-22 10:24:00 +02:00
|
|
|
|
|
|
|
|
while (isLoopAtDriverInitEnabled())
|
|
|
|
|
;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-23 17:09:04 +00:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
|
DebugSettingsManager<debugLevel>::~DebugSettingsManager() {
|
2020-07-30 12:28:19 +02:00
|
|
|
readerImpl.reset();
|
|
|
|
|
};
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2023-11-23 17:09:04 +00:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
|
void DebugSettingsManager<debugLevel>::getHardwareInfoOverride(std::string &hwInfoConfig) {
|
2018-10-04 12:44:49 +02:00
|
|
|
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 04:31:48 +00: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 "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-23 17:09:04 +00:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
2019-04-01 11:25:47 +02:00
|
|
|
template <typename DataType>
|
2023-11-23 17:09:04 +00:00
|
|
|
void DebugSettingsManager<debugLevel>::dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue, std::ostringstream &ostring) {
|
2019-04-01 11:25:47 +02:00
|
|
|
if (variableValue != defaultValue) {
|
2022-09-05 17:20:23 +00:00
|
|
|
const auto variableStringValue = toString(variableValue);
|
2022-09-22 11:22:29 +00:00
|
|
|
ostring << "Non-default value of debug variable: " << variableName << " = " << variableStringValue.c_str() << '\n';
|
2019-04-01 11:25:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-23 17:09:04 +00:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
|
void DebugSettingsManager<debugLevel>::getStringWithFlags(std::string &allFlags, std::string &changedFlags) const {
|
2022-09-22 11:22:29 +00:00
|
|
|
std::ostringstream allFlagsStream;
|
|
|
|
|
allFlagsStream.str("");
|
2019-04-01 11:25:47 +02:00
|
|
|
|
2022-09-22 11:22:29 +00:00
|
|
|
std::ostringstream changedFlagsStream;
|
|
|
|
|
changedFlagsStream.str("");
|
2019-04-01 11:25:47 +02:00
|
|
|
|
2023-09-07 12:44:36 +00: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 04:31:48 +00:00
|
|
|
}
|
2020-08-20 12:10:51 +02:00
|
|
|
if (registryReadAvailable() || isDebugKeysReadEnabled()) {
|
2019-04-01 11:25:47 +02:00
|
|
|
#include "debug_variables.inl"
|
2020-06-15 11:16:46 +02:00
|
|
|
}
|
2021-01-10 21:36:01 +01:00
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
|
|
|
|
|
2023-09-07 12:44:36 +00: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 04:31:48 +00:00
|
|
|
}
|
2020-06-15 11:16:46 +02:00
|
|
|
#include "release_variables.inl"
|
2019-04-01 11:25:47 +02:00
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2022-09-22 11:22:29 +00:00
|
|
|
|
|
|
|
|
allFlags = allFlagsStream.str();
|
|
|
|
|
changedFlags = changedFlagsStream.str();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-23 17:09:04 +00:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
|
void DebugSettingsManager<debugLevel>::dumpFlags() const {
|
2022-09-22 11:22:29 +00:00
|
|
|
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 08:51:01 +02:00
|
|
|
}
|
2019-04-01 11:25:47 +02:00
|
|
|
|
2023-11-23 17:09:04 +00:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
|
void DebugSettingsManager<debugLevel>::injectSettingsFromReader() {
|
2018-12-13 13:46:32 +01:00
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2023-08-20 04:31:48 +00: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 13:46:32 +01:00
|
|
|
}
|
2020-06-15 11:16:46 +02:00
|
|
|
|
2020-08-20 12:10:51 +02:00
|
|
|
if (registryReadAvailable() || isDebugKeysReadEnabled()) {
|
2018-12-13 13:46:32 +01:00
|
|
|
#include "debug_variables.inl"
|
2020-06-15 11:16:46 +02:00
|
|
|
}
|
2021-01-10 21:36:01 +01:00
|
|
|
|
|
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2023-08-20 04:31:48 +00: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-10 21:36:01 +01:00
|
|
|
}
|
2020-06-15 11:16:46 +02:00
|
|
|
#include "release_variables.inl"
|
2019-01-19 01:40:42 +01:00
|
|
|
#undef DECLARE_DEBUG_VARIABLE
|
2018-12-13 13:46:32 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-11-24 14:52:53 +00:00
|
|
|
void logDebugString(std::string_view debugString) {
|
|
|
|
|
NEO::fileLoggerInstance().logDebugString(true, debugString);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
template class DebugSettingsManager<DebugFunctionalityLevel::None>;
|
|
|
|
|
template class DebugSettingsManager<DebugFunctionalityLevel::Full>;
|
|
|
|
|
template class DebugSettingsManager<DebugFunctionalityLevel::RegKeys>;
|
2019-03-26 11:59:46 +01:00
|
|
|
}; // namespace NEO
|