From 6531fdd0fb58f1a636d5fe24a178ec52c3667fe6 Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Fri, 11 Jul 2025 11:37:23 -0500 Subject: [PATCH] Reduced calls to drm devinfo for getting virtualization_mode Signed-off-by: Maisam Arif Change-Id: I22a6a9ca15131b37a775e8d4f595fb13c0b043c7 [ROCm/amdsmi commit: 10f9aae0b3c792c412563a596563270a3bacb8b2] --- projects/amdsmi/amdsmi_cli/amdsmi_cli.py | 8 ++++++-- projects/amdsmi/amdsmi_cli/amdsmi_commands.py | 10 +++++++--- projects/amdsmi/amdsmi_cli/amdsmi_logger.py | 8 ++++++-- projects/amdsmi/amdsmi_cli/amdsmi_parser.py | 8 ++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_cli.py b/projects/amdsmi/amdsmi_cli/amdsmi_cli.py index fe8ed5151d..5d4e71cb1d 100755 --- a/projects/amdsmi/amdsmi_cli/amdsmi_cli.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_cli.py @@ -43,6 +43,7 @@ except ImportError as e: try: from amdsmi_init import * + from amdsmi_helpers import AMDSMIHelpers from amdsmi_commands import AMDSMICommands from amdsmi_parser import AMDSMIParser from amdsmi_logger import AMDSMILogger @@ -53,6 +54,7 @@ except ImportError: sys.path.append(cli_files_path) try: from amdsmi_init import * + from amdsmi_helpers import AMDSMIHelpers from amdsmi_commands import AMDSMICommands from amdsmi_parser import AMDSMIParser from amdsmi_logger import AMDSMILogger @@ -79,7 +81,8 @@ if __name__ == "__main__": else: sys.tracebacklimit = -1 - amd_smi_commands = AMDSMICommands() + amd_smi_helpers = AMDSMIHelpers() + amd_smi_commands = AMDSMICommands(helpers=amd_smi_helpers) amd_smi_parser = AMDSMIParser(amd_smi_commands.version, amd_smi_commands.list, amd_smi_commands.static, @@ -97,7 +100,8 @@ if __name__ == "__main__": amd_smi_commands.partition, amd_smi_commands.ras, amd_smi_commands.default, - sys_argv=sys.argv) + sys_argv=sys.argv, + helpers=amd_smi_helpers) try: try: argcomplete.autocomplete(amd_smi_parser) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index de59121fda..b48ac9bffb 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -41,9 +41,13 @@ class AMDSMICommands(): displaying the output to the specified format and destination. """ - def __init__(self, format='human_readable', destination='stdout') -> None: - self.helpers = AMDSMIHelpers() - self.logger = AMDSMILogger(format=format, destination=destination) + def __init__(self, format='human_readable', destination='stdout', helpers=None) -> None: + if helpers is None: + # If helpers is not provided, create a new instance + self.helpers = AMDSMIHelpers() + else: + self.helpers = helpers + self.logger = AMDSMILogger(format=format, destination=destination, helpers=self.helpers) self.device_handles = [] self.cpu_handles = [] self.core_handles = [] diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py index b5b456fbb4..c288e0bbd5 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py @@ -30,7 +30,7 @@ from amdsmi_helpers import AMDSMIHelpers import amdsmi_cli_exceptions class AMDSMILogger(): - def __init__(self, format='human_readable', destination='stdout') -> None: + def __init__(self, format='human_readable', destination='stdout', helpers=None) -> None: self.output = {} self.multiple_device_output = [] self.watch_output = [] @@ -41,7 +41,11 @@ class AMDSMILogger(): self.secondary_table_title = "" self.secondary_table_header = "" self.warning_message = "" - self.helpers = AMDSMIHelpers() + if helpers is None: + # If helpers is not provided, create a new instance + self.helpers = AMDSMIHelpers() + else: + self.helpers = helpers self._cper_exit_message = True self.store_cpu_json_output = [] self.store_core_json_output = [] diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_parser.py b/projects/amdsmi/amdsmi_cli/amdsmi_parser.py index 0cab2074e8..fa7446b1af 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_parser.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_parser.py @@ -69,10 +69,14 @@ class AMDSMIParser(argparse.ArgumentParser): """ def __init__(self, version, list, static, firmware, bad_pages, metric, process, profile, event, topology, set_value, reset, monitor, - xgmi, partition, ras, default, sys_argv=None): + xgmi, partition, ras, default, sys_argv=None, helpers=None): # Helper variables - self.helpers = AMDSMIHelpers() + if helpers is None: + # If helpers is not provided, create a new instance + self.helpers = AMDSMIHelpers() + else: + self.helpers = helpers # Get choices based on driver initialized if self.helpers.is_amdgpu_initialized():