BiSheng-opentuner/Driver-Improve-extraction-of-CPU-type-informa.patch
huanghe (AH) 6849f10653 Improve extraction of CPU type information
(cherry picked from commit 071b0b22f23f643cbf68996308561b1c29f69535)
2024-12-04 20:44:33 +08:00

53 lines
1.7 KiB
Diff

From c5d4306792bb14eacf2192fe372dcb1b37f862f1 Mon Sep 17 00:00:00 2001
From: Muhammad Asif Manzoor <muhammad.asif.manzoor1@huawei.com>
Date: Mon, 29 Apr 2024 13:32:15 -0400
Subject: [PATCH] [Driver] Improve extraction of CPU type information
Use lscpu command to extract 'model name' for Linux OS if 'model name' is not
available in /proc/cpuinfo file; return 'unknown' otherwise.
---
opentuner/measurement/driver.py | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/opentuner/measurement/driver.py b/opentuner/measurement/driver.py
index 707b4ec..512bcb5 100644
--- a/opentuner/measurement/driver.py
+++ b/opentuner/measurement/driver.py
@@ -221,11 +221,28 @@ class MeasurementDriver(DriverBase):
def _cputype():
- try:
- return re.search(r"model name\s*:\s*([^\n]*)",
- open("/proc/cpuinfo").read()).group(1)
- except:
- pass
+ if os.name is "posix":
+ try:
+ return re.search(
+ r"model name\s*:\s*([^\n]*)", open("/proc/cpuinfo").read()
+ ).group(1)
+ except:
+ pass
+ try:
+ # AArch64 machines may not have 'model name' attribute in
+ # /proc/cpuinfo file. Using lscpu command to extract 'model name'.
+ import subprocess
+
+ return re.search(
+ r"Model name\s*:\s*([^\n]*)",
+ subprocess.Popen(["lscpu"], stdout=subprocess.PIPE)
+ .communicate()[0]
+ .decode(),
+ ).group(1)
+ except:
+ log.warning("failed to get cpu type")
+ return "unknown"
+
try:
# for OS X
import subprocess
--
2.45.1.windows.1