Skip to content

Commit

Permalink
Merge pull request #5732 from smitterl/cpu_cgroup2
Browse files Browse the repository at this point in the history
control_cgroup: move controller check
  • Loading branch information
chloerh authored Aug 29, 2024
2 parents 2845fc7 + 0b12c7f commit fbe033e
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions libvirt/tests/src/guest_resource_control/control_cgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@
logging = log.getLogger('avocado.' + __name__)


def cancel_if_cpu_controller_not_mounted(test):
"""
Following is to deal the situation when realtime task existing.
In this situation, cpu controller cannot be enabled.
FYI: https://bugzilla.redhat.com/show_bug.cgi?id=1513930#c21
:param test: the test instance for failure reporting
"""
with open('/proc/mounts', 'r') as mnts:
cg_mount_point = re.findall(r"\s(\S*cgroup)\s", mnts.read())[0]
cg_subtree_file = os.path.join(cg_mount_point,
"cgroup.subtree_control")
with open(cg_subtree_file, 'r') as cg_subtree:
if "cpu" not in cg_subtree.read().replace("cpuset", ""):
test.cancel("CPU controller not mounted. This is a "
"limitation of cgroup v2 when realtime task "
"existing on host.")


def run(test, params, env):
"""
Cgroup related cases in function 'guest resource control'
Expand Down Expand Up @@ -165,21 +184,9 @@ def do_extra_operations(operations="daemon-reload"):
vmxml_backup = vmxml.copy()

cgtest = CgroupTest(None)
if cgtest.is_cgroup_v2_enabled():
is_cgroup_v2 = cgtest.is_cgroup_v2_enabled()
if is_cgroup_v2:
logging.info("The case executed on cgroup v2 environment.")
# Following is to deal the situation when realtime task existing.
# In this situation, cpu controller cannot be enabled.
# FYI: https://bugzilla.redhat.com/show_bug.cgi?id=1513930#c21
if "schedinfo" in virsh_cmd:
with open('/proc/mounts', 'r') as mnts:
cg_mount_point = re.findall(r"\s(\S*cgroup)\s", mnts.read())[0]
cg_subtree_file = os.path.join(cg_mount_point,
"cgroup.subtree_control")
with open(cg_subtree_file, 'r') as cg_subtree:
if "cpu" not in cg_subtree.read().replace("cpuset", ""):
test.cancel("CPU controller not mounted. This is a "
"limitation of cgroup v2 when realtime task "
"existing on host.")
else:
logging.info("The case executed on cgroup v1 environment.")

Expand Down Expand Up @@ -212,6 +219,8 @@ def do_extra_operations(operations="daemon-reload"):
try:
if start_vm == "yes" and not vm.is_alive():
vm.start()
if "schedinfo" in virsh_cmd and is_cgroup_v2:
cancel_if_cpu_controller_not_mounted(test)
vm.wait_for_login().close()
virsh_cmd_line = prepare_virsh_cmd(vm_name, virsh_cmd,
virsh_cmd_param,
Expand All @@ -230,6 +239,8 @@ def do_extra_operations(operations="daemon-reload"):
if "--config" in virsh_cmd_options:
try:
vm.start()
if "schedinfo" in virsh_cmd and is_cgroup_v2:
cancel_if_cpu_controller_not_mounted(test)
vm.wait_for_login().close()
if "iothread" in virsh_cmd_line:
add_iothread(vm)
Expand Down

0 comments on commit fbe033e

Please sign in to comment.