From 0ad09dd7a350d60452a2632450869dcb3ac50cd9 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 30 May 2024 14:51:00 +0200 Subject: [PATCH] hwbench/turbostat: Implement version checking hwbench requires at least turbostat 2022.04.16 (from Kernel 5.19) unless filtering C1% field would not be possible. This commit is: - update the requirement in the documentation - implements a simple test when Turbostat() is instantiated to guarantee the minimal release is present. - If no suitable release is found, hwbench will stop with a fatal message. A typical example looks like the following : Monitoring/turbostat: Detected release 19.8.31 ERROR:root:Monitoring/turbostat: minimal expected release is 2022.4.16 Signed-off-by: Erwan Velu --- README.md | 4 ++-- hwbench/environment/turbostat.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1b66e2f..2656029 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Running the **simple.conf** job: ## Mandatory - python >= 3.9 - [python dependencies](./requirements/base.in) -- turbostat >= 2022.07.28 +- turbostat >= 2022.04.16 - numactl - dmidecode - util-linux >= 2.32 @@ -75,4 +75,4 @@ Running the **simple.conf** job: ## Optional - ipmitool - ilorest (for HPE servers) -- stress-ng >= 0.17.04 \ No newline at end of file +- stress-ng >= 0.17.04 diff --git a/hwbench/environment/turbostat.py b/hwbench/environment/turbostat.py index a13a306..52e1b30 100644 --- a/hwbench/environment/turbostat.py +++ b/hwbench/environment/turbostat.py @@ -1,6 +1,8 @@ import os +import re import subprocess from enum import Enum +from packaging.version import Version from ..environment.hardware import BaseHardware from ..bench.monitoring_structs import MonitorMetric, CPUContext, PowerContext from ..utils.helpers import is_binary_available, fatal @@ -49,6 +51,7 @@ def __init__( CPUSTATS.CORE_WATTS, CPUSTATS.PACKAGE_WATTS, } + self.min_release = Version("2022.04.16") self.header = "" self.freq_metrics = freq_metrics self.power_metrics = power_metrics @@ -59,8 +62,35 @@ def __init__( if not is_binary_available("turbostat"): fatal("Missing turbostat binary, please install it.") # Let's make a first quick run to detect system + self.check_version() self.pre_run() + def check_version(self): + english_env = os.environ.copy() + english_env["LC_ALL"] = "C" + self.process = subprocess.Popen( + ["turbostat", "-v"], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + env=english_env, + stdin=subprocess.DEVNULL, + ) + # turbostat version 2022.04.16 - Len Brown + match = re.search( + r"turbostat version (?P[0-9]+\.[0-9]+\.[0-9]+).*", + str(self.get_process_output()), + ) + + current_version = Version(match.group("version")) + if not match: + fatal(f"Monitoring/turbostat: Cannot detect turbostat version") + + print(f"Monitoring/turbostat: Detected release {current_version}") + if current_version < self.min_release: + fatal( + f"Monitoring/turbostat: minimal expected release is {self.min_release}" + ) + def reset_metrics(self, power_metrics=None): if power_metrics is not None: self.power_metrics = power_metrics