Skip to content

Commit

Permalink
samples: pktgen: add trap SIGINT for printing execution result
Browse files Browse the repository at this point in the history
All pktgen samples can send indefinitely num messages per thread by
setting the count option to 0(-n 0). If running sample with setting
count 0 and press Ctrl-C to stop this program, the program prints the
result of the execution so far. Currently, the samples besides
sample{3...5} don't work properly. Because Ctrl-C stops the script, not
just pktgen.

This is results of samples:

    # DEV=eth0 DEST_IP=10.1.0.1 DST_MAC=00:11:22:33:44:55 ./pktgen_sample04_many_flows.sh -n 0
    Running... ctrl^C to stop
    ^CDevice: eth0@0
    Result: OK: 569657(c569538+d118) usec, 84650 (60byte,0frags)
    148597pps 71Mb/sec (71326560bps) errors: 0

    # DEV=eth0 DEST_IP=10.1.0.1 DST_MAC=00:11:22:33:44:55 ./pktgen_sample01_simple.sh -n 0
    Running... ctrl^C to stop
    ^C

In order to solve this, this commit adds trap SIGINT. Also, this commit
changes control_c function to print_result to maintain consistency with
other samples.

Signed-off-by: Juhee Kang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
claudiajkang authored and davem330 committed Aug 25, 2021
1 parent c0e9422 commit 6c882bd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 27 deletions.
19 changes: 13 additions & 6 deletions samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,21 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
pg_set $dev "burst $BURST"
done

# Run if user hits control-c
function print_result() {
# Print results
for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
dev=${DEV}@${thread}
echo "Device: $dev"
cat /proc/net/pktgen/$dev | grep -A2 "Result:"
done
}
# trap keyboard interrupt (Ctrl-C)
trap true SIGINT

# start_run
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2

# Print results
for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
dev=${DEV}@${thread}
echo "Device: $dev"
cat /proc/net/pktgen/$dev | grep -A2 "Result:"
done
print_result
19 changes: 13 additions & 6 deletions samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,21 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
pg_set $dev "xmit_mode queue_xmit"
done

# Run if user hits control-c
function print_result {
# Print results
for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
dev=${DEV}@${thread}
echo "Device: $dev"
cat /proc/net/pktgen/$dev | grep -A2 "Result:"
done
}
# trap keyboard interrupt (Ctrl-C)
trap true SIGINT

# start_run
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2

# Print results
for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
dev=${DEV}@${thread}
echo "Device: $dev"
cat /proc/net/pktgen/$dev | grep -A2 "Result:"
done
print_result
13 changes: 10 additions & 3 deletions samples/pktgen/pktgen_sample01_simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ pg_set $DEV "flag UDPSRC_RND"
pg_set $DEV "udp_src_min $UDP_SRC_MIN"
pg_set $DEV "udp_src_max $UDP_SRC_MAX"

# Run if user hits control-c
function print_result() {
# Print results
echo "Result device: $DEV"
cat /proc/net/pktgen/$DEV
}
# trap keyboard interrupt (Ctrl-C)
trap true SIGINT

if [ -z "$APPEND" ]; then
# start_run
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2

# Print results
echo "Result device: $DEV"
cat /proc/net/pktgen/$DEV
print_result
else
echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
fi
19 changes: 13 additions & 6 deletions samples/pktgen/pktgen_sample02_multiqueue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,25 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
pg_set $dev "udp_src_max $UDP_SRC_MAX"
done

if [ -z "$APPEND" ]; then
# start_run
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2

# Run if user hits control-c
function print_result() {
# Print results
for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
dev=${DEV}@${thread}
echo "Device: $dev"
cat /proc/net/pktgen/$dev | grep -A2 "Result:"
done
}
# trap keyboard interrupt (Ctrl-C)
trap true SIGINT

if [ -z "$APPEND" ]; then
# start_run
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2

print_result
else
echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
fi
19 changes: 13 additions & 6 deletions samples/pktgen/pktgen_sample06_numa_awared_queue_irq_affinity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,26 @@ for ((i = 0; i < $THREADS; i++)); do
pg_set $dev "udp_src_max $UDP_SRC_MAX"
done

# start_run
if [ -z "$APPEND" ]; then
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2

# Run if user hits control-c
function print_result() {
# Print results
for ((i = 0; i < $THREADS; i++)); do
thread=${cpu_array[$((i+F_THREAD))]}
dev=${DEV}@${thread}
echo "Device: $dev"
cat /proc/net/pktgen/$dev | grep -A2 "Result:"
done
}
# trap keyboard interrupt (Ctrl-C)
trap true SIGINT

# start_run
if [ -z "$APPEND" ]; then
echo "Running... ctrl^C to stop" >&2
pg_ctrl "start"
echo "Done" >&2

print_result
else
echo "Append mode: config done. Do more or use 'pg_ctrl start' to run"
fi

0 comments on commit 6c882bd

Please sign in to comment.