Change get_num_logical_cores to get_num_logical_cpus_per_socket, some
minor brush-up
From: Jiqing Tang <jiqingtang@google.com>
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3176 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 711ad42..302c6be 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -699,7 +699,7 @@
return arch
-def get_num_logical_cores(run_function=run):
+def get_num_logical_cpus_per_socket(run_function=run):
"""
Get the number of cores (including hyperthreading) per cpu.
run_function is used to execute the commands. It defaults to
@@ -707,9 +707,16 @@
same schema as utils.run. It should return a CmdResult object and
throw a CmdError exception.
"""
- coreinfo = run_function('grep "^siblings" /proc/cpuinfo').stdout.rstrip()
- cores = int(re.match('^siblings.*(\d+)', coreinfo).group(1))
- return cores
+ siblings = run_function('grep "^siblings" /proc/cpuinfo').stdout.rstrip()
+ num_siblings = map(int,
+ re.findall(r'^siblings\s*:\s*(\d+)\s*$',
+ siblings, re.M))
+ if len(num_siblings) == 0:
+ raise error.TestError('Unable to find siblings info in /proc/cpuinfo')
+ if min(num_siblings) != max(num_siblings):
+ raise error.TestError('Number of siblings differ %r' %
+ num_siblings)
+ return num_siblings[0]
def merge_trees(src, dest):