bench.c (71af75b6929458d85f63c0649dc26d6f4c19729e) bench.c (57fd1c63c9a687c5fdc86fa628c490d6733e8d0b)
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2020 Facebook */
3#define _GNU_SOURCE
4#include <argp.h>
5#include <linux/compiler.h>
6#include <sys/time.h>
7#include <sched.h>
8#include <fcntl.h>

--- 37 unchanged lines hidden (view full) ---

46 libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
47 libbpf_set_print(libbpf_print_fn);
48
49 err = bump_memlock_rlimit();
50 if (err)
51 fprintf(stderr, "failed to increase RLIMIT_MEMLOCK: %d", err);
52}
53
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2020 Facebook */
3#define _GNU_SOURCE
4#include <argp.h>
5#include <linux/compiler.h>
6#include <sys/time.h>
7#include <sched.h>
8#include <fcntl.h>

--- 37 unchanged lines hidden (view full) ---

46 libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
47 libbpf_set_print(libbpf_print_fn);
48
49 err = bump_memlock_rlimit();
50 if (err)
51 fprintf(stderr, "failed to increase RLIMIT_MEMLOCK: %d", err);
52}
53
54void false_hits_report_progress(int iter, struct bench_res *res, long delta_ns)
55{
56 long total = res->false_hits + res->hits + res->drops;
57
58 printf("Iter %3d (%7.3lfus): ",
59 iter, (delta_ns - 1000000000) / 1000.0);
60
61 printf("%ld false hits of %ld total operations. Percentage = %2.2f %%\n",
62 res->false_hits, total, ((float)res->false_hits / total) * 100);
63}
64
65void false_hits_report_final(struct bench_res res[], int res_cnt)
66{
67 long total_hits = 0, total_drops = 0, total_false_hits = 0, total_ops = 0;
68 int i;
69
70 for (i = 0; i < res_cnt; i++) {
71 total_hits += res[i].hits;
72 total_false_hits += res[i].false_hits;
73 total_drops += res[i].drops;
74 }
75 total_ops = total_hits + total_false_hits + total_drops;
76
77 printf("Summary: %ld false hits of %ld total operations. ",
78 total_false_hits, total_ops);
79 printf("Percentage = %2.2f %%\n",
80 ((float)total_false_hits / total_ops) * 100);
81}
82
54void hits_drops_report_progress(int iter, struct bench_res *res, long delta_ns)
55{
56 double hits_per_sec, drops_per_sec;
57 double hits_per_prod;
58
59 hits_per_sec = res->hits / 1000000.0 / (delta_ns / 1000000000.0);
60 hits_per_prod = hits_per_sec / env.producer_cnt;
61 drops_per_sec = res->drops / 1000000.0 / (delta_ns / 1000000000.0);

--- 65 unchanged lines hidden (view full) ---

127 { "prod-affinity", ARG_PROD_AFFINITY_SET, "CPUSET", 0,
128 "Set of CPUs for producer threads; implies --affinity"},
129 { "cons-affinity", ARG_CONS_AFFINITY_SET, "CPUSET", 0,
130 "Set of CPUs for consumer threads; implies --affinity"},
131 {},
132};
133
134extern struct argp bench_ringbufs_argp;
83void hits_drops_report_progress(int iter, struct bench_res *res, long delta_ns)
84{
85 double hits_per_sec, drops_per_sec;
86 double hits_per_prod;
87
88 hits_per_sec = res->hits / 1000000.0 / (delta_ns / 1000000000.0);
89 hits_per_prod = hits_per_sec / env.producer_cnt;
90 drops_per_sec = res->drops / 1000000.0 / (delta_ns / 1000000000.0);

--- 65 unchanged lines hidden (view full) ---

156 { "prod-affinity", ARG_PROD_AFFINITY_SET, "CPUSET", 0,
157 "Set of CPUs for producer threads; implies --affinity"},
158 { "cons-affinity", ARG_CONS_AFFINITY_SET, "CPUSET", 0,
159 "Set of CPUs for consumer threads; implies --affinity"},
160 {},
161};
162
163extern struct argp bench_ringbufs_argp;
164extern struct argp bench_bloom_map_argp;
135
136static const struct argp_child bench_parsers[] = {
137 { &bench_ringbufs_argp, 0, "Ring buffers benchmark", 0 },
165
166static const struct argp_child bench_parsers[] = {
167 { &bench_ringbufs_argp, 0, "Ring buffers benchmark", 0 },
168 { &bench_bloom_map_argp, 0, "Bloom filter map benchmark", 0 },
138 {},
139};
140
141static error_t parse_arg(int key, char *arg, struct argp_state *state)
142{
143 static int pos_args;
144
145 switch (key) {

--- 172 unchanged lines hidden (view full) ---

318extern const struct bench bench_trig_kprobe;
319extern const struct bench bench_trig_fentry;
320extern const struct bench bench_trig_fentry_sleep;
321extern const struct bench bench_trig_fmodret;
322extern const struct bench bench_rb_libbpf;
323extern const struct bench bench_rb_custom;
324extern const struct bench bench_pb_libbpf;
325extern const struct bench bench_pb_custom;
169 {},
170};
171
172static error_t parse_arg(int key, char *arg, struct argp_state *state)
173{
174 static int pos_args;
175
176 switch (key) {

--- 172 unchanged lines hidden (view full) ---

349extern const struct bench bench_trig_kprobe;
350extern const struct bench bench_trig_fentry;
351extern const struct bench bench_trig_fentry_sleep;
352extern const struct bench bench_trig_fmodret;
353extern const struct bench bench_rb_libbpf;
354extern const struct bench bench_rb_custom;
355extern const struct bench bench_pb_libbpf;
356extern const struct bench bench_pb_custom;
357extern const struct bench bench_bloom_lookup;
358extern const struct bench bench_bloom_update;
359extern const struct bench bench_bloom_false_positive;
326
327static const struct bench *benchs[] = {
328 &bench_count_global,
329 &bench_count_local,
330 &bench_rename_base,
331 &bench_rename_kprobe,
332 &bench_rename_kretprobe,
333 &bench_rename_rawtp,

--- 5 unchanged lines hidden (view full) ---

339 &bench_trig_kprobe,
340 &bench_trig_fentry,
341 &bench_trig_fentry_sleep,
342 &bench_trig_fmodret,
343 &bench_rb_libbpf,
344 &bench_rb_custom,
345 &bench_pb_libbpf,
346 &bench_pb_custom,
360
361static const struct bench *benchs[] = {
362 &bench_count_global,
363 &bench_count_local,
364 &bench_rename_base,
365 &bench_rename_kprobe,
366 &bench_rename_kretprobe,
367 &bench_rename_rawtp,

--- 5 unchanged lines hidden (view full) ---

373 &bench_trig_kprobe,
374 &bench_trig_fentry,
375 &bench_trig_fentry_sleep,
376 &bench_trig_fmodret,
377 &bench_rb_libbpf,
378 &bench_rb_custom,
379 &bench_pb_libbpf,
380 &bench_pb_custom,
381 &bench_bloom_lookup,
382 &bench_bloom_update,
383 &bench_bloom_false_positive,
347};
348
349static void setup_benchmark()
350{
351 int i, err;
352
353 if (!env.bench_name) {
354 fprintf(stderr, "benchmark name is not specified\n");

--- 111 unchanged lines hidden ---
384};
385
386static void setup_benchmark()
387{
388 int i, err;
389
390 if (!env.bench_name) {
391 fprintf(stderr, "benchmark name is not specified\n");

--- 111 unchanged lines hidden ---