[SWDEV-398070] Adding logging to ROCm SMI (by default off)
Updates:
* [rocm-smi] Provide a thread-safe logging feature
* [rocm-smi] Adding logrotation into install/upgrade/remove
scripts
* [rocm-smi] Updated cmake lists to include rocm_smi_logger
* [rocm-smi] Updated DEB/RPM install/remove logging file &
folder with all users having r/w privledges for
/var/log/rocm_smi_lib/ROCm-SMI-lib.log
* [rocm-smi] Added ability to do a glob search for multiple files
(globFileExists), assists doing file searches with * strings
* [rocm-smi] Added ability to log system details when RSMI_LOGGING
is turned on (getSystemDetails())
* [rocm-smi] Added logging to provide which ROCm API is being called
when RSMI_LOGGING is on
* [rocm-smi] Added logging to provide SYSFS path and read value,
when RSMI_LOGGING is on. Provides error reponse on failure.
* [rocm-smi] Added logging to provide SYSFS path and read value,
when RSMI_LOGGING is on. Provides error reponse on failure.
* [rocm-smi] Added environment variable RSMI_LOGGING to control
when logging is enabled or disabled. By default, by not
setting this env. variable, logging is turned off. When
setting RSMI_LOGGING=<any value>, logging is enabled
which is placed in /var/log/rocm_smi_lib/ROCm-SMI-lib.log file.
Setting RSMI_LOGGING is allowed in both debug and release builds.
* [rocm-smi] Removed an initialize procedure which keeps
debug_inf_loop. Seems this feature is not being used.
Change-Id: I79b48387609c6233c6f05b04fb8bba66b68c2399
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
[ROCm/amdsmi commit: c3a095a180]
This commit is contained in:
@@ -170,6 +170,10 @@ struct RocmSMI_env_vars {
|
||||
// comma delimited values.
|
||||
std::unordered_set<uint32_t> enum_overrides;
|
||||
|
||||
// If RSMI_LOGGING is set, enables logging.
|
||||
// Otherwise unset values, signify logging is turned off.
|
||||
uint32_t logging_on;
|
||||
|
||||
// Sysfs path overrides
|
||||
|
||||
// Env. var. RSMI_DEBUG_DRM_ROOT_OVERRIDE
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* =============================================================================
|
||||
* The University of Illinois/NCSA
|
||||
* Open Source License (NCSA)
|
||||
*
|
||||
* Copyright (c) 2023, Advanced Micro Devices, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Developed by:
|
||||
*
|
||||
* AMD Research and AMD ROC Software Development
|
||||
*
|
||||
* Advanced Micro Devices, Inc.
|
||||
*
|
||||
* www.amd.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal with the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimers.
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimers in
|
||||
* the documentation and/or other materials provided with the distribution.
|
||||
* - Neither the names of <Name of Development Group, Name of Institution>,
|
||||
* nor the names of its contributors may be used to endorse or promote
|
||||
* products derived from this Software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS WITH THE SOFTWARE.
|
||||
*
|
||||
* Detail Description:
|
||||
* Implemented complete logging mechanism, supporting multiple logging type
|
||||
* like as file based logging, console base logging etc. It also supported
|
||||
* for different log types.
|
||||
*
|
||||
* Thread Safe logging mechanism. Compatible with G++ (Linux platform)
|
||||
*
|
||||
* Supported Log Type: ERROR, ALARM, ALWAYS, INFO, BUFFER, TRACE, DEBUG
|
||||
* No control for ERROR, ALRAM and ALWAYS messages. These type of messages
|
||||
* should be always captured -- IF logging is enabled.
|
||||
*
|
||||
* WARNING: Logging is controlled by users environment variable - RSMI_LOGGING.
|
||||
* Enabling RSMI_LOGGING, by export RSMI_LOGGING=<any value>. No logs will
|
||||
* be printed, unless RSMI_LOGGING is enabled.
|
||||
*
|
||||
* BUFFER log type should be use while logging raw buffer or raw messages
|
||||
* Having direct interface as well as C++ Singleton inface. Can use
|
||||
* whatever interface fits your needs.
|
||||
*/
|
||||
|
||||
#ifndef _ROCM_SMI_LOGGER_H_
|
||||
#define _ROCM_SMI_LOGGER_H_
|
||||
|
||||
// C++ Header File(s)
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
// POSIX Socket Header File(s)
|
||||
#include <errno.h>
|
||||
|
||||
// Code Specific Header Files(s)
|
||||
|
||||
|
||||
namespace ROCmLogging {
|
||||
// Direct Interface for logging into log file or console using MACRO(s)
|
||||
#define LOG_ERROR(x) (ROCmLogging::Logger::getInstance()->error(x))
|
||||
#define LOG_ALARM(x) (ROCmLogging::Logger::getInstance()->alarm(x))
|
||||
#define LOG_ALWAYS(x) (ROCmLogging::Logger::getInstance()->always(x))
|
||||
#define LOG_INFO(x) (ROCmLogging::Logger::getInstance()->info(x))
|
||||
#define LOG_BUFFER(x) (ROCmLogging::Logger::getInstance()->buffer(x))
|
||||
#define LOG_TRACE(x) (ROCmLogging::Logger::getInstance()->trace(x))
|
||||
#define LOG_DEBUG(x) (ROCmLogging::Logger::getInstance()->debug(x))
|
||||
|
||||
// enum for LOG_LEVEL
|
||||
typedef enum LOG_LEVEL {
|
||||
DISABLE_LOG = 1,
|
||||
LOG_LEVEL_INFO = 2,
|
||||
LOG_LEVEL_BUFFER = 3,
|
||||
LOG_LEVEL_TRACE = 4,
|
||||
LOG_LEVEL_DEBUG = 5,
|
||||
ENABLE_LOG = 6,
|
||||
} LogLevel;
|
||||
|
||||
// enum for LOG_TYPE
|
||||
typedef enum LOG_TYPE {
|
||||
NO_LOG = 1,
|
||||
CONSOLE = 2,
|
||||
FILE_LOG = 3,
|
||||
} LogType;
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
static Logger* getInstance() throw();
|
||||
|
||||
Logger& operator<<(std::string &s) {
|
||||
switch (this->m_LogLevel) {
|
||||
case DISABLE_LOG:
|
||||
break;
|
||||
case LOG_LEVEL_INFO:
|
||||
info(s);
|
||||
break;
|
||||
case LOG_LEVEL_BUFFER:
|
||||
buffer(s);
|
||||
break;
|
||||
case LOG_LEVEL_TRACE:
|
||||
trace(s);
|
||||
break;
|
||||
case LOG_LEVEL_DEBUG:
|
||||
debug(s);
|
||||
break;
|
||||
case ENABLE_LOG:
|
||||
always(s);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return *getInstance();
|
||||
};
|
||||
|
||||
Logger &operator<<(const char* s) {
|
||||
return operator<<(std::string(s));
|
||||
};
|
||||
|
||||
template <class T> Logger &operator<<(const T &v) {
|
||||
std::ostringstream s;
|
||||
s << v;
|
||||
std::string str = s.str();
|
||||
return operator<<(str);
|
||||
};
|
||||
|
||||
// Interface for Error Log
|
||||
void error(const char* text) throw();
|
||||
void error(std::string& text) throw();
|
||||
void error(std::ostringstream& stream) throw();
|
||||
|
||||
// Interface for Alarm Log
|
||||
void alarm(const char* text) throw();
|
||||
void alarm(std::string& text) throw();
|
||||
void alarm(std::ostringstream& stream) throw();
|
||||
|
||||
// Interface for Always Log
|
||||
void always(const char* text) throw();
|
||||
void always(std::string& text) throw();
|
||||
void always(std::ostringstream& stream) throw();
|
||||
|
||||
// Interface for Buffer Log
|
||||
void buffer(const char* text) throw();
|
||||
void buffer(std::string& text) throw();
|
||||
void buffer(std::ostringstream& stream) throw();
|
||||
|
||||
// Interface for Info Log
|
||||
void info(const char* text) throw();
|
||||
void info(std::string& text) throw();
|
||||
void info(std::ostringstream& stream) throw();
|
||||
|
||||
// Interface for Trace log
|
||||
void trace(const char* text) throw();
|
||||
void trace(std::string& text) throw();
|
||||
void trace(std::ostringstream& stream) throw();
|
||||
|
||||
// Interface for Debug log
|
||||
void debug(const char* text) throw();
|
||||
void debug(std::string& text) throw();
|
||||
void debug(std::ostringstream& stream) throw();
|
||||
|
||||
// Error and Alarm log must be always enable
|
||||
// Hence, there is no interfce to control error and alarm logs
|
||||
|
||||
// Interfaces to control log levels
|
||||
void updateLogLevel(LogLevel logLevel);
|
||||
void enableAllLogLevels(); // Enable all log levels
|
||||
void disableLog(); // Disable all log levels, except error and alarm
|
||||
|
||||
// Interfaces to control log Types
|
||||
void updateLogType(LogType logType);
|
||||
void enableConsoleLogging();
|
||||
void enableFileLogging();
|
||||
std::string getLogSettings();
|
||||
bool isLoggerEnabled();
|
||||
|
||||
protected:
|
||||
Logger();
|
||||
~Logger();
|
||||
|
||||
// Wrapper function for lock/unlock
|
||||
// For Extensible feature, lock and unlock should be in protected
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
std::string getCurrentTime();
|
||||
|
||||
private:
|
||||
static Logger* m_Instance;
|
||||
std::ofstream m_File;
|
||||
bool m_loggingIsOn = false;
|
||||
LogLevel m_LogLevel;
|
||||
LogType m_LogType;
|
||||
std::mutex m_Mutex;
|
||||
std::unique_lock<std::mutex> m_Lock{m_Mutex, std::defer_lock};
|
||||
|
||||
void logIntoFile(std::string& data);
|
||||
void logOnConsole(std::string& data);
|
||||
void operator=(const Logger& obj) {}
|
||||
void initialize_resources();
|
||||
void destroy_resources();
|
||||
};
|
||||
|
||||
} // namespace ROCmLogging
|
||||
|
||||
#endif // End of _ROCM_SMI_LOGGER_H_
|
||||
@@ -114,6 +114,7 @@ class RocmSMI {
|
||||
int get_node_index(uint32_t dv_ind, uint32_t *node_ind);
|
||||
const RocmSMI_env_vars& getEnv(void);
|
||||
void printEnvVarInfo(void);
|
||||
bool isLoggingOn(void);
|
||||
static const std::map<amd::smi::DevInfoTypes, std::string> devInfoTypesStrings;
|
||||
|
||||
private:
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace smi {
|
||||
pthread_mutex_t *GetMutex(uint32_t dv_ind);
|
||||
int SameFile(const std::string fileA, const std::string fileB);
|
||||
bool FileExists(char const *filename);
|
||||
std::vector<std::string> globFilesExist(const std::string& filePattern);
|
||||
int isRegularFile(std::string fname, bool *is_reg);
|
||||
int ReadSysfsStr(std::string path, std::string *retStr);
|
||||
int WriteSysfsStr(std::string path, std::string val);
|
||||
@@ -91,6 +92,10 @@ rsmi_status_t
|
||||
GetDevBinaryBlob(amd::smi::DevInfoTypes type,
|
||||
uint32_t dv_ind, std::size_t b_size, void* p_binary_data);
|
||||
rsmi_status_t ErrnoToRsmiStatus(int err);
|
||||
std::string getRSMIStatusString(rsmi_status_t ret);
|
||||
std::tuple<bool, std::string, std::string, std::string, std::string,
|
||||
std::string, std::string, std::string> getSystemDetails(void);
|
||||
void logSystemDetails(void);
|
||||
|
||||
struct pthread_wrap {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user