From 68095b50e7ed38d6bdfc747bfc88d313ee02ec66 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Mon, 21 Dec 2020 16:16:43 -0600 Subject: [PATCH] Introduce RSMI_DEBUG_INFINITE_LOOP The environment variable RSMI_DEBUG_INFINITE_LOOP is introduced to facilitate debugging RSMI in user applications. When this env. variable is non-zero, an infinite loop will be entered in rsmi_init(). At this point, a debugger can be attached and RSMI can be debugger. This only applies to debug builds. Change-Id: I23f6dd730fc965764295070de053314a1cc5b6aa --- include/rocm_smi/rocm_smi_common.h | 7 +++++++ src/rocm_smi_main.cc | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/include/rocm_smi/rocm_smi_common.h b/include/rocm_smi/rocm_smi_common.h index 4106739057..c488e595f6 100755 --- a/include/rocm_smi/rocm_smi_common.h +++ b/include/rocm_smi/rocm_smi_common.h @@ -143,6 +143,13 @@ struct rsmi_func_id_iter_handle { }; struct RocmSMI_env_vars { + // If RSMI_DEBUG_INFINITE_LOOP is non-zero, rsmi_init() will go into + // an infinite loop in debug builds. For release builds, this is + // ignored. This is useful for debugging RSMI applications with + // gdb. After attaching with gdb, the inf. loop can be exited and + // RSMI can be debugged. + uint32_t debug_inf_loop; + // Bitfield that is AND'd with various RSMI_DEBUG_* bits to determine // which debugging information should be turned on. Env. variable // RSMI_DEBUG_BITFIELD is used to set all the debug info bits. diff --git a/src/rocm_smi_main.cc b/src/rocm_smi_main.cc index 3822a65f4b..f1a3ec95cb 100755 --- a/src/rocm_smi_main.cc +++ b/src/rocm_smi_main.cc @@ -258,6 +258,8 @@ RocmSMI::Initialize(uint64_t flags) { GetEnvVariables(); + while (env_vars_.debug_inf_loop) {} + while (std::string(kAMDMonitorTypes[i]) != "") { amd_monitor_types_.insert(kAMDMonitorTypes[i]); ++i; @@ -386,12 +388,14 @@ void RocmSMI::GetEnvVariables(void) { env_vars_.path_HWMon_root_override = nullptr; env_vars_.path_power_root_override = nullptr; env_vars_.enum_override = 0; + env_vars_.debug_inf_loop = 0; #else env_vars_.debug_output_bitfield = GetEnvVarUInteger("RSMI_DEBUG_BITFIELD"); env_vars_.path_DRM_root_override = getenv("RSMI_DEBUG_DRM_ROOT_OVERRIDE"); env_vars_.path_HWMon_root_override = getenv("RSMI_DEBUG_HWMON_ROOT_OVERRIDE"); env_vars_.path_power_root_override = getenv("RSMI_DEBUG_PP_ROOT_OVERRIDE"); env_vars_.enum_override = GetEnvVarUInteger("RSMI_DEBUG_ENUM_OVERRIDE"); + env_vars_.debug_inf_loop = GetEnvVarUInteger("RSMI_DEBUG_INFINITE_LOOP"); #endif }