[v2,1/5] app/test-mp: add multiprocess test

Message ID 20240307070113.29580-2-artemyko@nvidia.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series [v2,1/5] app/test-mp: add multiprocess test |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Artemy Kovalyov March 7, 2024, 7:01 a.m. UTC
  This commit adds a test scenario that initiates multiple processes
concurrently. These processes attach to the same shared heap, with an
automatic detection mechanism to identify the primary process.

Signed-off-by: Artemy Kovalyov <artemyko@nvidia.com>
---
 app/meson.build         |  1 +
 app/test-mp/main.c      | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 app/test-mp/meson.build |  8 ++++++++
 app/test-mp/run.sh      | 40 +++++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+)
 create mode 100644 app/test-mp/main.c
 create mode 100644 app/test-mp/meson.build
 create mode 100755 app/test-mp/run.sh
  

Comments

Burakov, Anatoly March 13, 2024, 4:05 p.m. UTC | #1
On 3/7/2024 8:01 AM, Artemy Kovalyov wrote:
> This commit adds a test scenario that initiates multiple processes
> concurrently. These processes attach to the same shared heap, with an
> automatic detection mechanism to identify the primary process.
> 
> Signed-off-by: Artemy Kovalyov <artemyko@nvidia.com>
> ---
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  

Patch

diff --git a/app/meson.build b/app/meson.build
index 8aaed59..1b80091 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -30,6 +30,7 @@  apps = [
         'test-flow-perf',
         'test-gpudev',
         'test-mldev',
+        'test-mp',
         'test-pipeline',
         'test-pmd',
         'test-regex',
diff --git a/app/test-mp/main.c b/app/test-mp/main.c
new file mode 100644
index 0000000..c2f309e
--- /dev/null
+++ b/app/test-mp/main.c
@@ -0,0 +1,52 @@ 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rte_malloc.h>
+#include <rte_launch.h>
+#include <rte_eal.h>
+#include <rte_cycles.h>
+#include <rte_test.h>
+
+static rte_atomic32_t g_count;
+
+static int
+done(const struct rte_mp_msg *msg __rte_unused, const void *arg __rte_unused)
+{
+	rte_atomic32_dec(&g_count);
+	return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+	void *p;
+	int ret;
+
+	ret = rte_eal_init(argc, argv);
+	RTE_TEST_ASSERT(ret >= 0, "init failed\n");
+
+	rte_atomic32_set(&g_count, atoi(argv[++ret]));
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		ret = rte_mp_action_register("done", done);
+		RTE_TEST_ASSERT_SUCCESS(ret, "register action failed\n");
+	}
+
+	p = rte_malloc(NULL, 0x1000000, 0x1000);
+	RTE_TEST_ASSERT_NOT_NULL(p, "allocation failed\n");
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		uint64_t timeout = rte_rdtsc() + 5 * rte_get_tsc_hz();
+
+		while (rte_atomic32_read(&g_count) > 0)
+			RTE_TEST_ASSERT(rte_rdtsc() < timeout, "timeout\n");
+	} else {
+		struct rte_mp_msg msg = { .name = "done" };
+
+		rte_mp_sendmsg(&msg);
+	}
+
+	rte_eal_cleanup();
+	return 0;
+}
diff --git a/app/test-mp/meson.build b/app/test-mp/meson.build
new file mode 100644
index 0000000..99de379
--- /dev/null
+++ b/app/test-mp/meson.build
@@ -0,0 +1,8 @@ 
+if is_windows
+    build = false
+    reason = 'not supported on Windows'
+    subdir_done()
+endif
+
+sources = files('main.c')
+deps = ['eal']
diff --git a/app/test-mp/run.sh b/app/test-mp/run.sh
new file mode 100755
index 0000000..03a71c7
--- /dev/null
+++ b/app/test-mp/run.sh
@@ -0,0 +1,40 @@ 
+#!/bin/bash
+
+logdir=/tmp/dpdk_test_mp
+repeat=1
+lastcore=$(($(nproc) - 1))
+log=1
+
+while getopts p:r:lL:d op; do case $op in
+    p) lastcore=$OPTARG ;;
+    r) repeat=$OPTARG ;;
+    L) logdir=$OPTARG ;;
+    l) log=0 ;;
+    d) debug=1 ;;
+esac done
+shift $((OPTIND-1))
+
+test=$1
+logpath=$logdir/$(date +%y%m%d-%H%M%S)
+
+rm -f core.*
+pkill dpdk-test-mp
+
+for j in $(seq $repeat) ; do
+    [ $log ] && mkdir -p $logpath/$j
+    pids=()
+    for i in $(seq 0 $lastcore) ; do
+	args="-l $i --file-prefix=dpdk1 --proc-type=auto"
+	if [ $debug ] ; then
+	    args="$args --log-level=lib.eal:8"
+	fi
+	if [ $log ] ; then
+	    $test $args $lastcore >$logpath/$j/$i.log 2>&1 &
+	else
+	    $test $args $lastcore &
+	fi
+	pids+=($!)
+    done
+    wait ${pids[@]} || { echo iteration $j failed ; break ; }
+    echo iteration $j passed
+done