Skip to content

Commit

Permalink
hwbench/turbostat: Implement version checking
Browse files Browse the repository at this point in the history
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 <e.velu@criteo.com>
  • Loading branch information
ErwanAliasr1 committed May 30, 2024
1 parent 54bc882 commit 0ad09dd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,4 +75,4 @@ Running the **simple.conf** job:
## Optional
- ipmitool
- ilorest (for HPE servers)
- stress-ng >= 0.17.04
- stress-ng >= 0.17.04
30 changes: 30 additions & 0 deletions hwbench/environment/turbostat.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 <lenb@kernel.org>
match = re.search(
r"turbostat version (?P<version>[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
Expand Down

0 comments on commit 0ad09dd

Please sign in to comment.