Commit 53cab833 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

scripts/bpf: Split program generation into a separate wrapper

The idea is to lower the amount of forks that happen when we put
bpftrace.sh tracer into a background job. This should help in spotting
potential stalls in tests that use bpf tracing. For more details
see:

  https://github.com/spdk/spdk/issues/3706



One immediate advantage is that the actual bpf program will be always
visible in autotest tracing. Second, lowered flakiness as now bpf
program will be always generated first, before an attempt to attach
bpftrace to target PID is made - in case gen.py blocks, as in the case
of one of the reports under #3706, it should be clearly visible now.

Change-Id: Id627fd5062f8f5c6de7ae9a2727ced3ee8cd078b
Signed-off-by: default avatarMichal Berger <michal.berger@nutanix.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26385


Reviewed-by: default avatarKonrad Sztyber <ksztyber@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
parent c7aa87ac
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
#  Copyright (C) 2025 Nutanix Inc.
#  All rights reserved.
#
set -e
curdir=$(readlink -f "$(dirname "$0")")

(($# > 1))
"$curdir/gen.py" -p "$@"
"$curdir/gen_enums.sh"
+10 −5
Original line number Diff line number Diff line
@@ -11,14 +11,19 @@ if [ $# -lt 2 ]; then
	echo ""
	echo "Environment variable BPF_OUTFILE can be set to save results to a file"
	echo "rather than print to stdout."
	echo "If USE_CMDLINE_BPF_PROGRAM is provided via environment <script> is treated as a"
	echo "string holding already generated BPF program."
	exit 1
fi
SCRIPTS_DIR=$(readlink -f $(dirname $0))
BIN_PATH=$(readlink -f /proc/$1/exe)
BPF_SCRIPT=$($SCRIPTS_DIR/bpf/gen.py -p $1 "${@:2}")
BPF_SCRIPT+=$($SCRIPTS_DIR/bpf/gen_enums.sh)
if [ -n "$ECHO_SCRIPT" ]; then
	echo "$BPF_SCRIPT"

BPF_PROGRAM=$2
if [[ -z $USE_CMDLINE_BPF_PROGRAM ]]; then
	BPF_PROGRAM=$("$SCRIPTS_DIR/gen_program.sh" "$@")
fi

bpftrace -p $1 -e "$BPF_SCRIPT" ${BPF_OUTFILE:+-o "$BPF_OUTFILE"}
[[ -n $BPF_PROGRAM ]]
[[ -n $ECHO_PROGRAM ]] && echo "$BPF_PROGRAM"

bpftrace -p $1 -e "$BPF_PROGRAM" ${BPF_OUTFILE:+-o "$BPF_OUTFILE"}
+7 −0
Original line number Diff line number Diff line
@@ -1726,6 +1726,13 @@ function gather_coverage() {
	rm -f "$output_dir/cov_base.info" "$output_dir/cov_test.info"
}

function bpftrace_setup() {
	local pid=$1 scripts=("${@:2}") bpf_program

	bpf_program=$("$rootdir/scripts/bpf/gen_program.sh" "$pid" "${scripts[@]}") || return 1
	USE_CMDLINE_BPF_PROGRAM=yes "$rootdir/scripts/bpftrace.sh" "$pid" "$bpf_program" &
}

# Define temp storage for all the tests. Look for 2GB at minimum
set_test_storage "${TEST_MIN_STORAGE_SIZE:-$((1 << 31))}"

+6 −3
Original line number Diff line number Diff line
@@ -12,8 +12,6 @@ MALLOC_BDEV_SIZE=64
MALLOC_BLOCK_SIZE=512

rpc_py="$rootdir/scripts/rpc.py"
bpf_sh="$rootdir/scripts/bpftrace.sh"

bdevperf_rpc_sock=/var/tmp/bdevperf.sock

# NQN prefix to use for subsystem NQNs
@@ -61,9 +59,14 @@ function set_ANA_state() {

# check for io on the expected ANA state port
function confirm_io_on_port() {
	$bpf_sh $nvmfapp_pid "$rootdir/scripts/bpf/nvmf_path.bt" &> "$testdir/trace.txt" &
	bpftrace_setup $nvmfapp_pid "$rootdir/scripts/bpf/nvmf_path.bt" &> "$testdir/trace.txt"
	dtrace_pid=$!

	# FIXME: This is awfully flaky. It's quite likely we should busy loop through the trace.txt until
	# we find a match or time out. Or at least check trace.txt for hints that bpftrace finally attached
	# itself to a PID before continuing.
	sleep 6

	active_port=$($rpc_py nvmf_subsystem_get_listeners $NQN | jq -r '.[] | select (.ana_states[0].ana_state=="'$1'") | .address.trsvcid')
	cat "$testdir/trace.txt"
	port=$(cut < "$testdir/trace.txt" -d ']' -f1 | awk '$1=="@path['$NVMF_FIRST_TARGET_IP'," {print $2}' | sed -n '1p')
+0 −2
Original line number Diff line number Diff line
@@ -13,8 +13,6 @@ MALLOC_BDEV_SIZE=64
MALLOC_BLOCK_SIZE=512

rpc_py="$rootdir/scripts/rpc.py"
bpf_sh="$rootdir/scripts/bpftrace.sh"

bdevperf_rpc_sock=/var/tmp/bdevperf.sock

# NQN prefix to use for subsystem NQNs
Loading