[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250124015836.732086-4-joel@joelfernandes.org>
Date: Thu, 23 Jan 2025 20:58:34 -0500
From: "Joel Fernandes (Google)" <joel@...lfernandes.org>
To: linux-kernel@...r.kernel.org,
"Paul E. McKenney" <paulmck@...nel.org>,
Josh Triplett <josh@...htriplett.org>,
Steven Rostedt <rostedt@...dmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Lai Jiangshan <jiangshanlai@...il.com>,
Shuah Khan <shuah@...nel.org>
Cc: "Joel Fernandes (Google)" <joel@...lfernandes.org>,
rcu@...r.kernel.org,
linux-kselftest@...r.kernel.org
Subject: [PATCH RFC 3/5] rcutorture: mkinitrd: Allow to run optional commands passed to it
Embed commands to invoke into init.c via mkinitrd.sh args. This
allows init to spawn a child process running the command with the
required arguments.
Signed-off-by: Joel Fernandes (Google) <joel@...lfernandes.org>
---
.../selftests/rcutorture/bin/mkinitrd.sh | 35 +++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/rcutorture/bin/mkinitrd.sh b/tools/testing/selftests/rcutorture/bin/mkinitrd.sh
index f3f867129560..4ba5e962e3cf 100755
--- a/tools/testing/selftests/rcutorture/bin/mkinitrd.sh
+++ b/tools/testing/selftests/rcutorture/bin/mkinitrd.sh
@@ -2,6 +2,9 @@
# SPDX-License-Identifier: GPL-2.0+
#
# Create an initrd directory if one does not already exist.
+# Usage: mkinitrd.sh [command [args...]]
+# Example: mkinitrd.sh stress-ng --cpu 1 --cpu-method matrixprod --cpu-ops 1000000 --perf -t 5
+# Note that command/args are optional.
#
# Copyright (C) IBM Corporation, 2013
#
@@ -25,7 +28,9 @@ echo "Creating a statically linked C-language initrd"
cd $D
mkdir -p initrd
cd initrd
-cat > init.c << '___EOF___'
+
+# Generate the init.c with optional command
+cat > init.c << 'EOF_HEAD'
#ifndef NOLIBC
#include <unistd.h>
#include <sys/time.h>
@@ -33,6 +38,29 @@ cat > init.c << '___EOF___'
volatile unsigned long delaycount;
+void run_optional_command() {
+EOF_HEAD
+
+if [ $# -gt 0 ]; then
+ # If command provided, generate run_optional_command() with the specified command.
+ # We use printf to generate the command and args.
+ # Example: echo $(printf '"%s", ' cmd a1 a2) gives: "cmd", "a1", "a2",
+ cat >> init.c << EOF
+ pid_t pid = fork();
+ if (pid == 0) {
+ char *args[] = {$(printf '"%s", ' "$@")NULL};
+ execve(args[0], args, NULL);
+ }
+EOF
+else
+ # If no command provided, function will be empty
+ echo " /* No command specified */" >> init.c
+fi
+
+# Add the rest of the program
+cat >> init.c << 'EOF_TAIL'
+}
+
int main(int argc, char *argv[])
{
int i;
@@ -43,6 +71,9 @@ int main(int argc, char *argv[])
for (i = 0; i < argc; i++)
printf(" %s", argv[i]);
printf("\n");
+
+ run_optional_command();
+
for (;;) {
sleep(1);
/* Need some userspace time. */
@@ -62,7 +93,7 @@ int main(int argc, char *argv[])
}
return 0;
}
-___EOF___
+EOF_TAIL
# build using nolibc on supported archs (smaller executable) and fall
# back to regular glibc on other ones.
--
2.34.1
Powered by blists - more mailing lists