Add benchmark to measure the throughput and latency of the bpf_loop call. Testing this on my dev machine on 1 thread, the data is as follows: nr_loops: 10 bpf_loop - throughput: 198.519 ± 0.155 M ops/s, latency: 5.037 ns/op nr_loops: 100 bpf_loop - throughput: 247.448 ± 0.305 M ops/s, latency: 4.041 ns/op nr_loops: 500 bpf_loop - throughput: 260.839 ± 0.380 M ops/s, latency: 3.834 ns/op nr_loops: 1000 bpf_loop - throughput: 262.806 ± 0.629 M ops/s, latency: 3.805 ns/op nr_loops: 5000 bpf_loop - throughput: 264.211 ± 1.508 M ops/s, latency: 3.785 ns/op nr_loops: 10000 bpf_loop - throughput: 265.366 ± 3.054 M ops/s, latency: 3.768 ns/op nr_loops: 50000 bpf_loop - throughput: 235.986 ± 20.205 M ops/s, latency: 4.238 ns/op nr_loops: 100000 bpf_loop - throughput: 264.482 ± 0.279 M ops/s, latency: 3.781 ns/op nr_loops: 500000 bpf_loop - throughput: 309.773 ± 87.713 M ops/s, latency: 3.228 ns/op nr_loops: 1000000 bpf_loop - throughput: 262.818 ± 4.143 M ops/s, latency: 3.805 ns/op >From this data, we can see that the latency per loop decreases as the number of loops increases. On this particular machine, each loop had an overhead of about ~4 ns, and we were able to run ~250 million loops per second. Signed-off-by: Joanne Koong <joannekoong@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20211130030622.4131246-5-joannekoong@fb.com
75 lines
1.4 KiB
Bash
75 lines
1.4 KiB
Bash
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
RUN_BENCH="sudo ./bench -w3 -d10 -a"
|
|
|
|
function header()
|
|
{
|
|
local len=${#1}
|
|
|
|
printf "\n%s\n" "$1"
|
|
for i in $(seq 1 $len); do printf '='; done
|
|
printf '\n'
|
|
}
|
|
|
|
function subtitle()
|
|
{
|
|
local len=${#1}
|
|
printf "\t%s\n" "$1"
|
|
}
|
|
|
|
function hits()
|
|
{
|
|
echo "$*" | sed -E "s/.*hits\s+([0-9]+\.[0-9]+ ± [0-9]+\.[0-9]+M\/s).*/\1/"
|
|
}
|
|
|
|
function drops()
|
|
{
|
|
echo "$*" | sed -E "s/.*drops\s+([0-9]+\.[0-9]+ ± [0-9]+\.[0-9]+M\/s).*/\1/"
|
|
}
|
|
|
|
function percentage()
|
|
{
|
|
echo "$*" | sed -E "s/.*Percentage\s=\s+([0-9]+\.[0-9]+).*/\1/"
|
|
}
|
|
|
|
function ops()
|
|
{
|
|
echo -n "throughput: "
|
|
echo -n "$*" | sed -E "s/.*throughput\s+([0-9]+\.[0-9]+ ± [0-9]+\.[0-9]+\sM\sops\/s).*/\1/"
|
|
echo -n -e ", latency: "
|
|
echo "$*" | sed -E "s/.*latency\s+([0-9]+\.[0-9]+\sns\/op).*/\1/"
|
|
}
|
|
|
|
function total()
|
|
{
|
|
echo "$*" | sed -E "s/.*total operations\s+([0-9]+\.[0-9]+ ± [0-9]+\.[0-9]+M\/s).*/\1/"
|
|
}
|
|
|
|
function summarize()
|
|
{
|
|
bench="$1"
|
|
summary=$(echo $2 | tail -n1)
|
|
printf "%-20s %s (drops %s)\n" "$bench" "$(hits $summary)" "$(drops $summary)"
|
|
}
|
|
|
|
function summarize_percentage()
|
|
{
|
|
bench="$1"
|
|
summary=$(echo $2 | tail -n1)
|
|
printf "%-20s %s%%\n" "$bench" "$(percentage $summary)"
|
|
}
|
|
|
|
function summarize_ops()
|
|
{
|
|
bench="$1"
|
|
summary=$(echo $2 | tail -n1)
|
|
printf "%-20s %s\n" "$bench" "$(ops $summary)"
|
|
}
|
|
|
|
function summarize_total()
|
|
{
|
|
bench="$1"
|
|
summary=$(echo $2 | tail -n1)
|
|
printf "%-20s %s\n" "$bench" "$(total $summary)"
|
|
}
|