diff mbox series

[bpf-next,1/2] selftests/bpf: Move bench specific metrics into union of structs

Message ID 20231221141501.3588586-2-houtao@huaweicloud.com (mailing list archive)
State New, archived
Delegated to: BPF
Headers show
Series bpf: Add benchmark for bpf memory allocator | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 4 maintainers not CCed: shuah@kernel.org aspsk@isovalent.com linux-kselftest@vger.kernel.org mykolal@fb.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns WARNING: line length of 87 exceeds 80 columns WARNING: line length of 91 exceeds 80 columns WARNING: line length of 95 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc

Commit Message

Hou Tao Dec. 21, 2023, 2:15 p.m. UTC
From: Hou Tao <houtao1@huawei.com>

Various benchmarks define its specific metrics in bench_res. This not
only bloats the size of bench_res, but also make the code that tries to
reuse the space hard to follow.

So move benchmark specific metrics into stand-alone structs and pack
these structs into a union to reduce the size of bench_res.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 tools/testing/selftests/bpf/bench.c               |  9 +++++----
 tools/testing/selftests/bpf/bench.h               | 15 ++++++++++++---
 .../testing/selftests/bpf/benchs/bench_htab_mem.c | 10 +++++-----
 .../benchs/bench_local_storage_rcu_tasks_trace.c  | 10 +++++-----
 4 files changed, 27 insertions(+), 17 deletions(-)

Comments

Song Liu Jan. 8, 2024, 8:51 p.m. UTC | #1
On Thu, Dec 21, 2023 at 6:14 AM Hou Tao <houtao@huaweicloud.com> wrote:
>
> From: Hou Tao <houtao1@huawei.com>
>
> Various benchmarks define its specific metrics in bench_res. This not
> only bloats the size of bench_res, but also make the code that tries to
> reuse the space hard to follow.
>
> So move benchmark specific metrics into stand-alone structs and pack
> these structs into a union to reduce the size of bench_res.
>
> Signed-off-by: Hou Tao <houtao1@huawei.com>

Acked-by: Song Liu <song@kernel.org>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
index 73ce11b0547d..4832cd4b1c3d 100644
--- a/tools/testing/selftests/bpf/bench.c
+++ b/tools/testing/selftests/bpf/bench.c
@@ -88,9 +88,10 @@  grace_period_latency_basic_stats(struct bench_res res[], int res_cnt, struct bas
 	memset(gp_stat, 0, sizeof(struct basic_stats));
 
 	for (i = 0; i < res_cnt; i++)
-		gp_stat->mean += res[i].gp_ns / 1000.0 / (double)res[i].gp_ct / (0.0 + res_cnt);
+		gp_stat->mean += res[i].rcu.gp_ns / 1000.0 / (double)res[i].rcu.gp_ct /
+				 (0.0 + res_cnt);
 
-#define IT_MEAN_DIFF (res[i].gp_ns / 1000.0 / (double)res[i].gp_ct - gp_stat->mean)
+#define IT_MEAN_DIFF (res[i].rcu.gp_ns / 1000.0 / (double)res[i].rcu.gp_ct - gp_stat->mean)
 	if (res_cnt > 1) {
 		for (i = 0; i < res_cnt; i++)
 			gp_stat->stddev += (IT_MEAN_DIFF * IT_MEAN_DIFF) / (res_cnt - 1.0);
@@ -106,9 +107,9 @@  grace_period_ticks_basic_stats(struct bench_res res[], int res_cnt, struct basic
 
 	memset(gp_stat, 0, sizeof(struct basic_stats));
 	for (i = 0; i < res_cnt; i++)
-		gp_stat->mean += res[i].stime / (double)res[i].gp_ct / (0.0 + res_cnt);
+		gp_stat->mean += res[i].rcu.stime / (double)res[i].rcu.gp_ct / (0.0 + res_cnt);
 
-#define IT_MEAN_DIFF (res[i].stime / (double)res[i].gp_ct - gp_stat->mean)
+#define IT_MEAN_DIFF (res[i].rcu.stime / (double)res[i].rcu.gp_ct - gp_stat->mean)
 	if (res_cnt > 1) {
 		for (i = 0; i < res_cnt; i++)
 			gp_stat->stddev += (IT_MEAN_DIFF * IT_MEAN_DIFF) / (res_cnt - 1.0);
diff --git a/tools/testing/selftests/bpf/bench.h b/tools/testing/selftests/bpf/bench.h
index 68180d8f8558..a6fcf111221f 100644
--- a/tools/testing/selftests/bpf/bench.h
+++ b/tools/testing/selftests/bpf/bench.h
@@ -42,9 +42,18 @@  struct bench_res {
 	long drops;
 	long false_hits;
 	long important_hits;
-	unsigned long gp_ns;
-	unsigned long gp_ct;
-	unsigned int stime;
+
+	/* benchmark specific metrics */
+	union {
+		struct {
+			unsigned long bytes;
+		} htab;
+		struct {
+			unsigned long gp_ns;
+			unsigned long gp_ct;
+			unsigned int stime;
+		} rcu;
+	};
 };
 
 struct bench {
diff --git a/tools/testing/selftests/bpf/benchs/bench_htab_mem.c b/tools/testing/selftests/bpf/benchs/bench_htab_mem.c
index 9146d3f414d2..2f37826332ed 100644
--- a/tools/testing/selftests/bpf/benchs/bench_htab_mem.c
+++ b/tools/testing/selftests/bpf/benchs/bench_htab_mem.c
@@ -293,7 +293,7 @@  static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value)
 static void htab_mem_measure(struct bench_res *res)
 {
 	res->hits = atomic_swap(&ctx.skel->bss->op_cnt, 0) / env.producer_cnt;
-	htab_mem_read_mem_cgrp_file("memory.current", &res->gp_ct);
+	htab_mem_read_mem_cgrp_file("memory.current", &res->htab.bytes);
 }
 
 static void htab_mem_report_progress(int iter, struct bench_res *res, long delta_ns)
@@ -301,7 +301,7 @@  static void htab_mem_report_progress(int iter, struct bench_res *res, long delta
 	double loop, mem;
 
 	loop = res->hits / 1000.0 / (delta_ns / 1000000000.0);
-	mem = res->gp_ct / 1048576.0;
+	mem = res->htab.bytes / 1048576.0;
 	printf("Iter %3d (%7.3lfus): ", iter, (delta_ns - 1000000000) / 1000.0);
 	printf("per-prod-op %7.2lfk/s, memory usage %7.2lfMiB\n", loop, mem);
 }
@@ -315,15 +315,15 @@  static void htab_mem_report_final(struct bench_res res[], int res_cnt)
 
 	for (i = 0; i < res_cnt; i++) {
 		loop_mean += res[i].hits / 1000.0 / (0.0 + res_cnt);
-		mem_mean += res[i].gp_ct / 1048576.0 / (0.0 + res_cnt);
+		mem_mean += res[i].htab.bytes / 1048576.0 / (0.0 + res_cnt);
 	}
 	if (res_cnt > 1)  {
 		for (i = 0; i < res_cnt; i++) {
 			loop_stddev += (loop_mean - res[i].hits / 1000.0) *
 				       (loop_mean - res[i].hits / 1000.0) /
 				       (res_cnt - 1.0);
-			mem_stddev += (mem_mean - res[i].gp_ct / 1048576.0) *
-				      (mem_mean - res[i].gp_ct / 1048576.0) /
+			mem_stddev += (mem_mean - res[i].htab.bytes / 1048576.0) *
+				      (mem_mean - res[i].htab.bytes / 1048576.0) /
 				      (res_cnt - 1.0);
 		}
 		loop_stddev = sqrt(loop_stddev);
diff --git a/tools/testing/selftests/bpf/benchs/bench_local_storage_rcu_tasks_trace.c b/tools/testing/selftests/bpf/benchs/bench_local_storage_rcu_tasks_trace.c
index edf0b00418c1..4842f4f2bbea 100644
--- a/tools/testing/selftests/bpf/benchs/bench_local_storage_rcu_tasks_trace.c
+++ b/tools/testing/selftests/bpf/benchs/bench_local_storage_rcu_tasks_trace.c
@@ -190,10 +190,10 @@  static void measure(struct bench_res *res)
 {
 	long ticks;
 
-	res->gp_ct = atomic_swap(&ctx.skel->bss->gp_hits, 0);
-	res->gp_ns = atomic_swap(&ctx.skel->bss->gp_times, 0);
+	res->rcu.gp_ct = atomic_swap(&ctx.skel->bss->gp_hits, 0);
+	res->rcu.gp_ns = atomic_swap(&ctx.skel->bss->gp_times, 0);
 	ticks = kthread_pid_ticks();
-	res->stime = ticks - ctx.prev_kthread_stime;
+	res->rcu.stime = ticks - ctx.prev_kthread_stime;
 	ctx.prev_kthread_stime = ticks;
 }
 
@@ -216,9 +216,9 @@  static void report_progress(int iter, struct bench_res *res, long delta_ns)
 		return;
 
 	printf("Iter %d\t avg tasks_trace grace period latency\t%lf ns\n",
-	       iter, res->gp_ns / (double)res->gp_ct);
+	       iter, res->rcu.gp_ns / (double)res->rcu.gp_ct);
 	printf("Iter %d\t avg ticks per tasks_trace grace period\t%lf\n",
-	       iter, res->stime / (double)res->gp_ct);
+	       iter, res->rcu.stime / (double)res->rcu.gp_ct);
 }
 
 static void report_final(struct bench_res res[], int res_cnt)