Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cpu topology info support for dies and clusters #4038

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions virttest/libvirt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
cpu,
data_dir,
error_context,
kernel_interface,
libvirt_xml,
storage,
test_setup,
Expand Down Expand Up @@ -2578,8 +2579,8 @@ def get_cpu_topology_in_cmdline(self):
LOG.error("Fail to get VM pid")
else:
cmdline = open("/proc/%d/cmdline" % vm_pid).read()
values = re.findall(r"sockets=(\d+),cores=(\d+),threads=(\d+)", cmdline)[0]
cpu_topology = dict(zip(["sockets", "cores", "threads"], values))
values = re.findall(r"(sockets|dies|clusters|cores|threads)=(\d+)", cmdline)
cpu_topology = dict(values)
return cpu_topology

def get_cpu_topology_in_vm(self):
Expand All @@ -2589,6 +2590,71 @@ def get_cpu_topology_in_vm(self):
cpu_topology["sockets"] = cpu_info["Socket(s)"]
cpu_topology["cores"] = cpu_info["Core(s) per socket"]
cpu_topology["threads"] = cpu_info["Thread(s) per core"]
cpu_number = cpu_info["CPU(s)"]

def get_cpu_topology_num(key, session):
"""
Return cpu topology key number per socket

:param key: cpu topology key
:param session: session object
:return: cpu topology key number per socket
"""

def get_cpu_topology_info(cpu_id, key, session):
"""
Return cpu topology key info of specific cpu

:param cpu_id: cpu id
:param key: cpu topology key
:param session: session object
:return: cpu topology key info of specific cpu
"""
key_path = "/sys/devices/system/cpu/cpu%s/topology/%s" % (
cpu_id,
key,
)
try:
key_info = kernel_interface.SysFS(
key_path, session=session, regex="\d+%s"
)
key_value = str(key_info.sys_fs_value).rstrip("\n")
except IOError:
LOG.warning(
"Can not find file %s from sysfs. Please check "
"your system." % key_path
)
key_value = None
return key_value

count_dict = {}
for cpu_id in range(int(cpu_number)):
key_val = get_cpu_topology_info(cpu_id, key, session)
if key_val is None:
return None
socket_val = get_cpu_topology_info(
cpu_id, "physical_package_id", session
)
if socket_val in count_dict:
count_dict[socket_val].add(key_val)
else:
count_dict[socket_val] = {key_val}
key_per_socket_info = [len(i) for i in list(count_dict.values())]
if not all(x == key_per_socket_info[0] for x in key_per_socket_info):
raise ValueError(
"Different %s number on each socket, "
"the number per socket is: %s." % (key, key_per_socket_info)
)
return key_per_socket_info[0]

session = self.wait_for_login()
die_num = get_cpu_topology_num("die_id", session)
if die_num is not None:
cpu_topology["dies"] = str(die_num)
cluster_num = get_cpu_topology_num("cluster_id", session)
if cluster_num is not None:
cpu_topology["clusters"] = str(cluster_num)
session.close()
return cpu_topology

def activate_nic(self, nic_index_or_name):
Expand Down