0001
0002
0003
0004 #include <argp.h>
0005 #include "bench.h"
0006 #include "bpf_hashmap_full_update_bench.skel.h"
0007 #include "bpf_util.h"
0008
0009
0010 static struct ctx {
0011 struct bpf_hashmap_full_update_bench *skel;
0012 } ctx;
0013
0014 #define MAX_LOOP_NUM 10000
0015
0016 static void validate(void)
0017 {
0018 if (env.consumer_cnt != 1) {
0019 fprintf(stderr, "benchmark doesn't support multi-consumer!\n");
0020 exit(1);
0021 }
0022 }
0023
0024 static void *producer(void *input)
0025 {
0026 while (true) {
0027
0028 syscall(__NR_getpgid);
0029 }
0030
0031 return NULL;
0032 }
0033
0034 static void *consumer(void *input)
0035 {
0036 return NULL;
0037 }
0038
0039 static void measure(struct bench_res *res)
0040 {
0041 }
0042
0043 static void setup(void)
0044 {
0045 struct bpf_link *link;
0046 int map_fd, i, max_entries;
0047
0048 setup_libbpf();
0049
0050 ctx.skel = bpf_hashmap_full_update_bench__open_and_load();
0051 if (!ctx.skel) {
0052 fprintf(stderr, "failed to open skeleton\n");
0053 exit(1);
0054 }
0055
0056 ctx.skel->bss->nr_loops = MAX_LOOP_NUM;
0057
0058 link = bpf_program__attach(ctx.skel->progs.benchmark);
0059 if (!link) {
0060 fprintf(stderr, "failed to attach program!\n");
0061 exit(1);
0062 }
0063
0064
0065 map_fd = bpf_map__fd(ctx.skel->maps.hash_map_bench);
0066 max_entries = bpf_map__max_entries(ctx.skel->maps.hash_map_bench);
0067 for (i = 0; i < max_entries; i++)
0068 bpf_map_update_elem(map_fd, &i, &i, BPF_ANY);
0069 }
0070
0071 void hashmap_report_final(struct bench_res res[], int res_cnt)
0072 {
0073 unsigned int nr_cpus = bpf_num_possible_cpus();
0074 int i;
0075
0076 for (i = 0; i < nr_cpus; i++) {
0077 u64 time = ctx.skel->bss->percpu_time[i];
0078
0079 if (!time)
0080 continue;
0081
0082 printf("%d:hash_map_full_perf %lld events per sec\n",
0083 i, ctx.skel->bss->nr_loops * 1000000000ll / time);
0084 }
0085 }
0086
0087 const struct bench bench_bpf_hashmap_full_update = {
0088 .name = "bpf-hashmap-ful-update",
0089 .validate = validate,
0090 .setup = setup,
0091 .producer_thread = producer,
0092 .consumer_thread = consumer,
0093 .measure = measure,
0094 .report_progress = NULL,
0095 .report_final = hashmap_report_final,
0096 };