Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#pragma once
3#include <stdlib.h>
4#include <stdbool.h>
5#include <linux/err.h>
6#include <errno.h>
7#include <unistd.h>
8#include <bpf/bpf.h>
9#include <bpf/libbpf.h>
10#include <math.h>
11#include <time.h>
12#include <sys/syscall.h>
13#include <limits.h>
14
15struct cpu_set {
16 bool *cpus;
17 int cpus_len;
18 int next_cpu;
19};
20
21struct env {
22 char *bench_name;
23 int duration_sec;
24 int warmup_sec;
25 bool verbose;
26 bool list;
27 bool affinity;
28 bool quiet;
29 bool stacktrace;
30 int consumer_cnt;
31 int producer_cnt;
32 int nr_cpus;
33 struct cpu_set prod_cpus;
34 struct cpu_set cons_cpus;
35};
36
37struct basic_stats {
38 double mean;
39 double stddev;
40};
41
42struct bench_res {
43 long hits;
44 long drops;
45 long false_hits;
46 long important_hits;
47 unsigned long gp_ns;
48 unsigned long gp_ct;
49 unsigned int stime;
50 unsigned long duration_ns;
51};
52
53struct bench {
54 const char *name;
55 const struct argp *argp;
56 void (*validate)(void);
57 void (*setup)(void);
58 void *(*producer_thread)(void *ctx);
59 void *(*consumer_thread)(void *ctx);
60 void (*measure)(struct bench_res* res);
61 void (*report_progress)(int iter, struct bench_res* res, long delta_ns);
62 void (*report_final)(struct bench_res res[], int res_cnt);
63};
64
65struct counter {
66 long value;
67} __attribute__((aligned(128)));
68
69extern struct env env;
70extern const struct bench *bench;
71
72void setup_libbpf(void);
73void hits_drops_report_progress(int iter, struct bench_res *res, long delta_ns);
74void hits_drops_report_final(struct bench_res res[], int res_cnt);
75void false_hits_report_progress(int iter, struct bench_res *res, long delta_ns);
76void false_hits_report_final(struct bench_res res[], int res_cnt);
77void ops_report_progress(int iter, struct bench_res *res, long delta_ns);
78void ops_report_final(struct bench_res res[], int res_cnt);
79void local_storage_report_progress(int iter, struct bench_res *res,
80 long delta_ns);
81void local_storage_report_final(struct bench_res res[], int res_cnt);
82void grace_period_latency_basic_stats(struct bench_res res[], int res_cnt,
83 struct basic_stats *gp_stat);
84void grace_period_ticks_basic_stats(struct bench_res res[], int res_cnt,
85 struct basic_stats *gp_stat);
86
87static inline void atomic_inc(long *value)
88{
89 (void)__atomic_add_fetch(value, 1, __ATOMIC_RELAXED);
90}
91
92static inline void atomic_add(long *value, long n)
93{
94 (void)__atomic_add_fetch(value, n, __ATOMIC_RELAXED);
95}
96
97static inline long atomic_swap(long *value, long n)
98{
99 return __atomic_exchange_n(value, n, __ATOMIC_RELAXED);
100}