Skip to content

Commit

Permalink
kept working on trying to configure the topology
Browse files Browse the repository at this point in the history
  • Loading branch information
rh-jugraham committed Sep 24, 2024
1 parent 844dd05 commit a806093
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 83 deletions.
8 changes: 4 additions & 4 deletions libvirt/tests/cfg/cpu/vcpu_max_topology.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
cores = "many"
variants:
- default_clusters:
- clusters = ""
clusters = ""
- many_clusters:
- clusters = "many"
clusters = "many"
- one_core_per_socket:
sockets = "many"
cores = "one"
Expand All @@ -22,6 +22,6 @@
cores = "many"
variants:
- default_clusters:
- clusters = ""
clusters = ""
- many_clusters:
- clusters = "many"
clusters = "many"
182 changes: 103 additions & 79 deletions libvirt/tests/src/cpu/vcpu_max_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,24 @@ def run(test, params, env):
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vcpus_placement = params.get("vcpus_placement", "static")
sockets = params.get("sockets", "")
cores = params.get("cores", "")
clusters = params.get("clusters", "")
sockets_param = params.get("sockets", "")
cores_param = params.get("cores", "")
clusters_param = params.get("clusters", "")

vcpus_num = 0
sockets_list = []
cores_list = []
# max_test_combine = params.get("max_test_combine", "")
# option = params.get("option", "")
# combine = params.get("combine", "")
# invalid_domain = params.get("invalid_domain", "")
# domain_name = params.get("domain_name", "")
# invalid_cpulist = params.get("invalid_cpulist", "")
# status_error = params.get("status_error", "no")
# error_msg = eval(params.get('error_msg', '[]'))
# vcpus_list = ""
# offline_vcpus = ""
clusters_list = []

# Back up domain XML
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
vmxml_bakup = vmxml.copy()

# Set vcpus_num to the host online cpu number
if max_test_combine == "yes":
host_cpu_info = cpuutil.get_cpu_info()
host_online_cpus = int(host_cpu_info["On-line CPU(s) list"].split("-")[1]) + 1
logging.debug("Host online CPU number: %s", str(host_online_cpus))
vcpus_num = host_online_cpus
host_cpu_info = cpuutil.get_cpu_info()
host_online_cpus = int(host_cpu_info["On-line CPU(s) list"].split("-")[1]) + 1
logging.debug("Host online CPU number: %s", str(host_online_cpus))
vcpus_num = host_online_cpus

try:
# Modify vm
Expand All @@ -58,100 +48,134 @@ def run(test, params, env):

# one_socket case
# cores = vcpus_num // number of clusters
if sockets == "one":
if sockets_param == "one":
sockets_list = [1]

# many_clusters case
if clusters == "many":
cores_list = [vcpus_num // 2, vcpus_num // 4, vcpus_num // 6]
if clusters_param == "many":
clusters_list = [2, 4, 6]
cores_list = [vcpus_num // clusters for clusters in clusters_list]
# default_clusters case
else:
cores_list = [vcpus_num]

# one_core_per_socket case
elif sockets == "many" and cores == "one":
elif sockets_param == "many" and cores_param == "one":
sockets_list = [vcpus_num]
cores_list = [1]

# many_cores_per_socket
else:
# many_clusters case
# sockets = vcpus_num // number of cores // number of clusters
if clusters == "many":
cores_list = [2, 4, 6]
# defaulting to 2 clusters
sockets_list = [(vcpus_num // core) // 2 for core in cores_list]
if clusters_param == "many":
cores_list = [2, 2, 2] # defaulting to 2 cores
clusters_list = [2, 4, 6]
sockets_list = [(vcpus_num // 2) // clusters for clusters in clusters_list]
# default_clusters case
# sockets * cores = vcpus_num
else:
cores_list = [2, 4, 6]
sockets_list = [vcpus_num // core for core in cores_list]

# clean up sockets_list and cores_list
if (0 in sockets_list):
sockets_list = [socket for socket in sockets_list if socket != 0]
if (0 in cores_list):
cores_list = [core for core in cores_list if core != 0]
# ensure that vcpus_num is evenly divisble by the number of cores
sockets_list = [vcpus_num // cores for cores in cores_list if vcpus_num % cores == 0]
# remove any core amounts that are not evenly divisble by vcpus_num
cores_list = [cores for cores in cores_list if vcpus_num % cores == 0]

# note to self: ensure errors in edge cases
if not sockets_list or not cores_list:
# throw some error!
logging.debug("some error!!!")
elif (len(cores_list) == 1):
# len(sockets_list) will also be 1
vmxml.set_vm_vcpus(
vm_name,
vcpus_num,
current=vcpus_num,
sockets=sockets_list[0],
cores=cores_list[0],
threads=1,
add_topology=True
)
logging.debug("Define guest with '%s' vcpus, '%s' sockets, and '%s' cores",
str(vcpus_num), str(sockets_list[0]), str(cores_list[0]))
set_and_check_topology(vm, vm_name, vmxml, vcpus_num, sockets_list[0], cores_list[0])
else:
for i, core in enumerate(cores_list):
for i, cores in enumerate(cores_list):
if (cores == 0):
continue
if (len(sockets_list) == 1):
vmxml.set_vm_vcpus(
vm_name,
vcpus_num,
current=vcpus_num,
sockets=sockets_list[0],
cores=core,
threads=1,
add_topology=True
)
logging.debug("Define guest with '%s' vcpus, '%s' sockets, and '%s' cores",
str(vcpus_num), str(sockets_list[0]), str(core))
if clusters_list:
set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets_list[0], cores, clusters_list[i])
else:
set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets_list[0], cores)
else:
vmxml.set_vm_vcpus(
vm_name,
vcpus_num,
current=vcpus_num,
sockets=sockets_list[i],
cores=core,
threads=1,
add_topology=True
)
logging.debug("Define guest with '%s' vcpus, '%s' sockets, and '%s' cores",
str(vcpus_num), str(sockets_list[i]), str(core))

# Start guest agent in vm
try:
vm.prepare_guest_agent()
except virt_vm.VMStartError as info:
if "not supported" in str(info).lower():
test.cancel(info)
else:
test.error(info)


# more stuff
if (sockets_list[i] == 0):
continue
if clusters_list:
set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets_list[i], cores, clusters_list[i])
else:
set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets_list[i], cores)

finally:
# Recover VM
if vm.is_alive():
vm.destroy(gracefully=False)
logging.info("Restoring vm...")
vmxml_bakup.sync()


def set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets, cores, clusters=1):
'''
Helper function
'''
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)

logging.debug("Trying to define guest with '%s' vcpus, '%s' sockets, '%s' cores, and '%s' clusters",
str(vcpus_num), str(sockets), str(cores), str(clusters))
if clusters > 1:
# set manually
vmxml["vcpu"] = vcpus_num
vmxml["current_vcpu"] = vcpus_num
vmxml["cpu"]["topology"] = {
"sockets": sockets,
"cores": cores,
"threads": 1,
"clusters": clusters
}
else:
# set using set_vm_vcpus helper function
vmxml.set_vm_vcpus(
vm_name,
vcpus_num,
current=vcpus_num,
sockets=sockets,
cores=cores,
threads=1,
add_topology=True
)
logging.debug("Define guest with '%s' vcpus, '%s' sockets, and '%s' cores, and '%s' clusters",
str(vcpus_num), str(sockets), str(cores), str(clusters))
logging.debug("Full xml:\n %s", str(vmxml))

# Start guest agent in vm
try:
vm.prepare_guest_agent()
except virt_vm.VMStartError as info:
if "not supported" in str(info).lower():
test.cancel(info)
else:
test.error(info)


# from polarion: Check lscpu output within the vm is consistent with the topology configured
# Check the topology in the guest
# session = vm.wait_for_login()
# vm_topology_info = cpuutil.get_cpu_info(session)
# session.close()

# vm_cpus = vm_topology_info["CPU(s)"]
# vm_online_cpus = vm_topology_info["On-line CPU(s) list"]
# vm_threads_per_core = vm_topology_info["Thread(s) per core"]
# vm_cores_per_socket = vm_topology_info["Core(s) per socket"]
# vm_sockets = vm_topology_info["Socket(s)"]

# notes = cpus, online cpus, and threads per core always the same --> only cores per socket and sockets change


# from polarion: Check kernel file for coreid for each vcpu in the vm


# from polarion: Check vcpu cluster number


# from polarion: Check cluster cpu list

0 comments on commit a806093

Please sign in to comment.