From: Hou Tao <houtao1@xxxxxxxxxx> 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@xxxxxxxxxx> --- 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(-) 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) -- 2.29.2