Add a method to get the number of logical cores per cpu socket on a machine.

Signed-off-by: Ashwin Ganti <aganti@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3047 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 106fa2c..77b2397 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -699,6 +699,19 @@
     return arch
 
 
+def get_num_logical_cores(run_function=run):
+    """
+    Get the number of cores (including hyperthreading) per cpu.
+    run_function is used to execute the commands. It defaults to
+    utils.run() but a custom method (if provided) should be of the
+    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
+
+
 def merge_trees(src, dest):
     """
     Merges a source directory tree at 'src' into a destination tree at