diff --git a/avocado/utils/cpu.py b/avocado/utils/cpu.py index 3980a15117..bad944639d 100644 --- a/avocado/utils/cpu.py +++ b/avocado/utils/cpu.py @@ -27,7 +27,7 @@ import re import warnings -from avocado.utils import genio +from avocado.utils import genio, process #: Map vendor's name with expected string in /proc/cpuinfo. VENDORS_MAP = { @@ -550,6 +550,31 @@ def wrap(*args, **kwargs): return wrap +def lscpu(): + """ + Get Cores per socket, Physical sockets and Physical chips + by executing 'lscpu' command. + + :rtype: `dict_obj` with the following details + :cores per socket: + :physical sockets: + :physical chips: + :chips: physical sockets * physical chips + """ + output = process.run("lscpu") + res = {} + for line in output.stdout.decode("utf-8").split("\n"): + if "Core(s) per socket:" in line: + res["cores"] = int(line.split(":")[1].strip()) + if "Physical sockets:" in line: + res["physical_sockets"] = int(line.split(":")[1].strip()) + if "Physical chips:" in line: + res["physical_chips"] = int(line.split(":")[1].strip()) + if "physical_sockets" in res and "physical_chips" in res: + res["chips"] = res["physical_sockets"] * res["physical_chips"] + return res + + total_cpus_count = _deprecated(total_count, "total_cpus_count") _get_cpu_info = _deprecated(_get_info, "_get_cpu_info") _get_cpu_status = _deprecated(_get_status, "_get_cpu_status")