brintos

brintos / linux-shallow public Read only

0
0
Text · 2.4 KiB · 005c401 Raw
99 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2#pragma once3#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	int consumer_cnt;30	int producer_cnt;31	int nr_cpus;32	struct cpu_set prod_cpus;33	struct cpu_set cons_cpus;34};35 36struct basic_stats {37	double mean;38	double stddev;39};40 41struct bench_res {42	long hits;43	long drops;44	long false_hits;45	long important_hits;46	unsigned long gp_ns;47	unsigned long gp_ct;48	unsigned int stime;49};50 51struct bench {52	const char *name;53	const struct argp *argp;54	void (*validate)(void);55	void (*setup)(void);56	void *(*producer_thread)(void *ctx);57	void *(*consumer_thread)(void *ctx);58	void (*measure)(struct bench_res* res);59	void (*report_progress)(int iter, struct bench_res* res, long delta_ns);60	void (*report_final)(struct bench_res res[], int res_cnt);61};62 63struct counter {64	long value;65} __attribute__((aligned(128)));66 67extern struct env env;68extern const struct bench *bench;69 70void setup_libbpf(void);71void hits_drops_report_progress(int iter, struct bench_res *res, long delta_ns);72void hits_drops_report_final(struct bench_res res[], int res_cnt);73void false_hits_report_progress(int iter, struct bench_res *res, long delta_ns);74void false_hits_report_final(struct bench_res res[], int res_cnt);75void ops_report_progress(int iter, struct bench_res *res, long delta_ns);76void ops_report_final(struct bench_res res[], int res_cnt);77void local_storage_report_progress(int iter, struct bench_res *res,78				   long delta_ns);79void local_storage_report_final(struct bench_res res[], int res_cnt);80void grace_period_latency_basic_stats(struct bench_res res[], int res_cnt,81				      struct basic_stats *gp_stat);82void grace_period_ticks_basic_stats(struct bench_res res[], int res_cnt,83				    struct basic_stats *gp_stat);84 85static inline void atomic_inc(long *value)86{87	(void)__atomic_add_fetch(value, 1, __ATOMIC_RELAXED);88}89 90static inline void atomic_add(long *value, long n)91{92	(void)__atomic_add_fetch(value, n, __ATOMIC_RELAXED);93}94 95static inline long atomic_swap(long *value, long n)96{97	return __atomic_exchange_n(value, n, __ATOMIC_RELAXED);98}99