DPDK patches and discussions
 help / color / mirror / Atom feed
From: Artemy Kovalyov <artemyko@nvidia.com>
To: <dev@dpdk.org>
Cc: Thomas Monjalon <thomas@monjalon.net>,
	Anatoly Burakov <anatoly.burakov@intel.com>
Subject: [PATCH v2 1/5] app/test-mp: add multiprocess test
Date: Thu, 7 Mar 2024 07:01:09 +0000	[thread overview]
Message-ID: <20240307070113.29580-2-artemyko@nvidia.com> (raw)
In-Reply-To: <20240307070113.29580-1-artemyko@nvidia.com>

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

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
-- 
1.8.3.1


  reply	other threads:[~2024-03-07  7:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12  4:25 [PATCH 0/5] addressing races in concurrent process startup Artemy Kovalyov
2023-12-12  4:25 ` [PATCH 1/5] app/test-pm: add multiprocess test Artemy Kovalyov
2023-12-12 17:09   ` Stephen Hemminger
2023-12-17  3:53   ` [PATCH v2 1/5] app/test-mp: " Artemy Kovalyov
2024-03-06 20:20     ` David Marchand
2024-03-07  6:59   ` [PATCH 0/5] addressing races in concurrent process startup Artemy Kovalyov
2024-03-07  7:01   ` Artemy Kovalyov
2024-03-07  7:01     ` Artemy Kovalyov [this message]
2024-03-13 16:05       ` [PATCH v2 1/5] app/test-mp: add multiprocess test Burakov, Anatoly
2024-03-07  7:01     ` [PATCH v2 2/5] eal: fix multiprocess hotplug race Artemy Kovalyov
2024-03-13 16:05       ` Burakov, Anatoly
2024-03-07  7:01     ` [PATCH v2 3/5] ipc: fix mp channel closure to prevent message loss Artemy Kovalyov
2024-03-13 16:06       ` Burakov, Anatoly
2024-03-07  7:01     ` [PATCH v2 4/5] eal: fix first time primary autodetect Artemy Kovalyov
2024-03-13 16:06       ` Burakov, Anatoly
2024-03-07  7:01     ` [PATCH v2 5/5] eal: fix memzone fbarray cleanup Artemy Kovalyov
2024-03-13 16:17       ` Burakov, Anatoly
2023-12-12  4:25 ` [PATCH 2/5] eal: fix multiprocess hotplug race Artemy Kovalyov
2023-12-12  4:25 ` [PATCH 3/5] ipc: fix mp channel closure to prevent message loss Artemy Kovalyov
2023-12-12  4:25 ` [PATCH 4/5] eal: fix first time primary autodetect Artemy Kovalyov
2023-12-12  4:25 ` [PATCH 5/5] eal: fix memzone fbarray cleanup Artemy Kovalyov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240307070113.29580-2-artemyko@nvidia.com \
    --to=artemyko@nvidia.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).