KVM test: timedrift test: set CPU affinity recursively for all children
In addition to setting the CPU affinity of the given process, set it for all of
its children too.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3686 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py
index 1ee7775..deab59e 100644
--- a/client/tests/kvm/kvm_tests.py
+++ b/client/tests/kvm/kvm_tests.py
@@ -578,6 +578,7 @@
def set_cpu_affinity(pid, mask):
"""
Set the CPU affinity of all threads of the process with PID pid.
+ Do this recursively for all child processes as well.
@param pid: The process ID.
@param mask: The CPU affinity mask.
@@ -589,6 +590,9 @@
prev_mask = commands.getoutput("taskset -p %s" % tid).split()[-1]
prev_masks[tid] = prev_mask
commands.getoutput("taskset -p %s %s" % (mask, tid))
+ children = commands.getoutput("ps --ppid=%s -o pid=" % pid).split()
+ for child in children:
+ prev_masks.update(set_cpu_affinity(child, mask))
return prev_masks
def restore_cpu_affinity(prev_masks):
@@ -683,13 +687,9 @@
output_func=logging.debug,
output_prefix="(host load %d) " % i,
timeout=0.5))
- # Set the CPU affinity of the shell running the load process
+ # Set the CPU affinity of the load process
pid = host_load_sessions[-1].get_shell_pid()
set_cpu_affinity(pid, cpu_mask)
- # Try setting the CPU affinity of the load process itself
- pid = host_load_sessions[-1].get_pid()
- if pid:
- set_cpu_affinity(pid, cpu_mask)
# Sleep for a while (during load)
logging.info("Sleeping for %s seconds..." % load_duration)