From nobody Thu Jan 30 23:23:56 2025 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E68AB1D63E7 for ; Fri, 24 Jan 2025 01:58:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737683933; cv=none; b=QGXNSPqVX8jDx8T+NQVJ5HLXwsQXaQFkziTnXfTA4LlhoeA9mR76B9Px7nMGLs30hp589GAq7oHbDBte9MKfr77rPINFeOMmLVuF9SpKsiJtsWtgsjHgaGvdVAK9njeUglbvdLmtSHV8C/uBPXv4L/cAAwZ1SRLtfNVd7zmZOiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737683933; c=relaxed/simple; bh=sh2unf8Xeoi6Q+VSDQ1CR6UU8KtcNX5rCfAveB7F7g4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qjzmTAaFPA1tjuC4rIQ+JD/9VZA3MR686sbpxMyw2AyZNVkE7FlygHVgECQl5+Wnd0/6sb6TlOAT9AEgYTtE5CIi9iTPDyxtHSGVt/bfsCwsTZOfSiV7Q8OhIdzvwVgrc+Hf1PkgvOECkDOjJRSolDlLi2xaoLMVFYG6bExRpzo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org; spf=pass smtp.mailfrom=joelfernandes.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b=QM5Znsjg; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="QM5Znsjg" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b6ed9ed5b9so231652385a.2 for ; Thu, 23 Jan 2025 17:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1737683930; x=1738288730; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kRHySpG58abjuaHF+3dQ690cqYR/gs8q/AgyFnz04uw=; b=QM5ZnsjgRpfmjA2wejPdBLDlwknbe41yevnkg0RAp6+D9/52YSs3VwhNdspOHW5dMs sYD7zYueoMdANFOKNaDTCz96Ml9TCsImM7mbwnJ6CT7q6Pti220YKutJDQvKp8RaDO/Y wAjLHPk40ApzSeJw8UQqTxr9ej27gYBfUoWAA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737683930; x=1738288730; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kRHySpG58abjuaHF+3dQ690cqYR/gs8q/AgyFnz04uw=; b=AZEzSG1o/pBh41pcjzfgS5TPJQessDXotOhuf8rmqZwdYDrXvH0FqISUctUQU4v1uo pI5OIQH2llPbvryzAqEdrQ8osw4fueB0d8dRe+RZuKMi+qrwJNWpTWTQBvUDJgDIbya1 98piH6lkzgKFokHDOI88Ty6no65hhK/HsZH65p9utfwrZcmEwr6LdZzU8ur5Cl7tac7D /6kyoI6x6rZ5gFrkfKirHHkmpNiQk6CuW5H3GJjNyFyhuV8MqQLaLPfBSAoYC8VBPmgo izdB3jGcCM5uq5cQx8tm+Glnp57q8VZDVH7ExRcvVmrivaG93CzqoAjnax3/SNH2gy7L 9Zqw== X-Gm-Message-State: AOJu0YxD/fKEunbxlYItVjNPtx8ghjkDZCK2xKYcm2YpHL17PTSE2W4h J50IMh6vC7Eik4tamIOD6536i/zVGXsUHaWZK43f9QBN55rsq3PtObW2ukPqZemBIdepnZSAi1W K X-Gm-Gg: ASbGncswPg93GLmJH/QK8tRXZ7EDtVgctQJVDeWrLJ2D3wsCjfvBU5wX534L1dmmJIA k6BJlQT2fCzM+sx/KT0yBHpTVZLXTUu71WvEjky64o3BT8RKFMYI1qNaMXTE49Eh6czd57Vx63h 6xfdf+Y1raNbdWT7t11d/u57rUS8XdBtTo4u8CLA1s81oiQtdT6cvvX/5MxGbTv5Vit6EjMu3/B YZa1WrlxRql2x2sQcObRqMNdft796HgZyUvNrlN9aDP90ejBVnDay0kk+/7gCGX22zEtO1pFzRf Z0q654T333ueb21uHz5vfj1M8QPKAU2679IcBu/Q0E8L2+g= X-Google-Smtp-Source: AGHT+IHaXKdjk1Buyn6a6Xv4FIqoSmZ7YVk5544zLuI+aKxxiCP2bXeVGPwOfxrj/Gksc+jk8pGH9w== X-Received: by 2002:a05:620a:440f:b0:7b6:7a87:744a with SMTP id af79cd13be357-7be631e712amr4443518985a.5.1737683930638; Thu, 23 Jan 2025 17:58:50 -0800 (PST) Received: from joelbox2.. (c-73-251-172-144.hsd1.va.comcast.net. [73.251.172.144]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7be9ae8a5fbsm44741985a.31.2025.01.23.17.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 17:58:49 -0800 (PST) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org, "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Shuah Khan Cc: "Joel Fernandes (Google)" , rcu@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH RFC 3/5] rcutorture: mkinitrd: Allow to run optional commands passed to it Date: Thu, 23 Jan 2025 20:58:34 -0500 Message-Id: <20250124015836.732086-4-joel@joelfernandes.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250124015836.732086-1-joel@joelfernandes.org> References: <20250124015836.732086-1-joel@joelfernandes.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- .../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/tes= ting/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 #include @@ -33,6 +38,29 @@ cat > init.c << '___EOF___' =20 volatile unsigned long delaycount; =20 +void run_optional_command() { +EOF_HEAD + +if [ $# -gt 0 ]; then + # If command provided, generate run_optional_command() with the specif= ied 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 =3D fork(); + if (pid =3D=3D 0) { + char *args[] =3D {$(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 =3D 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 =20 # build using nolibc on supported archs (smaller executable) and fall # back to regular glibc on other ones. --=20 2.34.1