[lttng-dev] [PATCH lttng-tools stable-2.6 1/3] Tests: Introduce conf_proc_count()

Michael Jeanson mjeanson at efficios.com
Tue Mar 15 20:13:24 UTC 2016


From: Jérémie Galarneau <jeremie.galarneau at efficios.com>

Tests are using the nproc utility which return the number of
_available_ CPUs. The distinction between online, available and
configured CPUs is subtle, but important.

The number of "online" CPUs can change at runtime as CPUs are
hot-plugged. This could happen during a test and result in
unexpected results.

The number of "configured" CPUs includes any CPU which may be
offline at the time.

The number of "available" CPUs, which is what is returned by the
nproc utility, may differ from both "online" and "configured"
counts. This is the case in containers which are assigned to a
subset of configured CPUs.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
---
 tests/utils/utils.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh
index 9e78dc2..1f116a6 100644
--- a/tests/utils/utils.sh
+++ b/tests/utils/utils.sh
@@ -92,6 +92,16 @@ function randstring()
 	echo
 }
 
+# Return the number of _configured_ CPUs.
+function conf_proc_count()
+{
+	getconf _NPROCESSORS_CONF
+	if [ $? -ne 0 ]; then
+		diag "Failed to get the number of configured CPUs"
+	fi
+	echo
+}
+
 function lttng_enable_kernel_event
 {
 	local sess_name=$1
-- 
2.7.0



More information about the lttng-dev mailing list