From 35c1d00f5a603988974f7148cf0dfd7c28c06f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20L=C3=B3pez?= Date: Mon, 5 Aug 2024 13:28:29 +0200 Subject: [PATCH] Updates driverInitialized() to support amdgpu built as module as well as kernel built-in. Fixes ROCm/rocm_smi_lib#102 and is an updated version of ROCm/rocm_smi_lib#104 Change-Id: Icb3abe820bc67035b822358a1c04bd09a7c22b6b Signed-off-by: Galantsev, Dmitrii Reviewed-by: Galantsev, Dmitrii --- python_smi_tools/rocm_smi.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/python_smi_tools/rocm_smi.py b/python_smi_tools/rocm_smi.py index d0eec6a503..c222d480c5 100755 --- a/python_smi_tools/rocm_smi.py +++ b/python_smi_tools/rocm_smi.py @@ -89,14 +89,17 @@ validClockNames.sort() def driverInitialized(): """ Returns true if amdgpu is found in the list of initialized modules """ - driverInitialized = '' - try: - driverInitialized = str(subprocess.check_output("cat /sys/module/amdgpu/initstate |grep live", shell=True)) - except subprocess.CalledProcessError: - pass - if len(driverInitialized) > 0: - return True - return False + driverInitialized = False + if os.path.exists("/sys/module/amdgpu") : + if os.path.exists("/sys/module/amdgpu/initstate"): + # amdgpu is loadable module + with open("/sys/module/amdgpu/initstate") as initstate: + if 'live' in initstate.read(): + driverInitialized = True + else: + # amdgpu is built into the kernel + driverInitialized = True + return driverInitialized def formatJson(device, log):