Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Copyright (c) 2020 Facebook */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define _GNU_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <argp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <sys/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <pthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <sys/sysinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <sys/resource.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "bench.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "testing_helpers.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) struct env env = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	.warmup_sec = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	.duration_sec = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	.affinity = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	.consumer_cnt = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	.producer_cnt = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int libbpf_print_fn(enum libbpf_print_level level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		    const char *format, va_list args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	if (level == LIBBPF_DEBUG && !env.verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	return vfprintf(stderr, format, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int bump_memlock_rlimit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct rlimit rlim_new = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		.rlim_cur	= RLIM_INFINITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		.rlim_max	= RLIM_INFINITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	return setrlimit(RLIMIT_MEMLOCK, &rlim_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) void setup_libbpf()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	libbpf_set_print(libbpf_print_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	err = bump_memlock_rlimit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		fprintf(stderr, "failed to increase RLIMIT_MEMLOCK: %d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) void hits_drops_report_progress(int iter, struct bench_res *res, long delta_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	double hits_per_sec, drops_per_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	double hits_per_prod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	hits_per_sec = res->hits / 1000000.0 / (delta_ns / 1000000000.0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	hits_per_prod = hits_per_sec / env.producer_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	drops_per_sec = res->drops / 1000000.0 / (delta_ns / 1000000000.0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	printf("Iter %3d (%7.3lfus): ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	       iter, (delta_ns - 1000000000) / 1000.0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	printf("hits %8.3lfM/s (%7.3lfM/prod), drops %8.3lfM/s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	       hits_per_sec, hits_per_prod, drops_per_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) void hits_drops_report_final(struct bench_res res[], int res_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	double hits_mean = 0.0, drops_mean = 0.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	double hits_stddev = 0.0, drops_stddev = 0.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	for (i = 0; i < res_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		hits_mean += res[i].hits / 1000000.0 / (0.0 + res_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		drops_mean += res[i].drops / 1000000.0 / (0.0 + res_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (res_cnt > 1)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		for (i = 0; i < res_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			hits_stddev += (hits_mean - res[i].hits / 1000000.0) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				       (hits_mean - res[i].hits / 1000000.0) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				       (res_cnt - 1.0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			drops_stddev += (drops_mean - res[i].drops / 1000000.0) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 					(drops_mean - res[i].drops / 1000000.0) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 					(res_cnt - 1.0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		hits_stddev = sqrt(hits_stddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		drops_stddev = sqrt(drops_stddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	printf("Summary: hits %8.3lf \u00B1 %5.3lfM/s (%7.3lfM/prod), ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	       hits_mean, hits_stddev, hits_mean / env.producer_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	printf("drops %8.3lf \u00B1 %5.3lfM/s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	       drops_mean, drops_stddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) const char *argp_program_version = "benchmark";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) const char *argp_program_bug_address = "<bpf@vger.kernel.org>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) const char argp_program_doc[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) "benchmark    Generic benchmarking framework.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) "This tool runs benchmarks.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) "USAGE: benchmark <bench-name>\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) "EXAMPLES:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) "    # run 'count-local' benchmark with 1 producer and 1 consumer\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) "    benchmark count-local\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) "    # run 'count-local' with 16 producer and 8 consumer thread, pinned to CPUs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) "    benchmark -p16 -c8 -a count-local\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ARG_PROD_AFFINITY_SET = 1000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ARG_CONS_AFFINITY_SET = 1001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static const struct argp_option opts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	{ "list", 'l', NULL, 0, "List available benchmarks"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	{ "duration", 'd', "SEC", 0, "Duration of benchmark, seconds"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	{ "warmup", 'w', "SEC", 0, "Warm-up period, seconds"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	{ "producers", 'p', "NUM", 0, "Number of producer threads"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	{ "consumers", 'c', "NUM", 0, "Number of consumer threads"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	{ "verbose", 'v', NULL, 0, "Verbose debug output"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	{ "affinity", 'a', NULL, 0, "Set consumer/producer thread affinity"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	{ "prod-affinity", ARG_PROD_AFFINITY_SET, "CPUSET", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	  "Set of CPUs for producer threads; implies --affinity"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	{ "cons-affinity", ARG_CONS_AFFINITY_SET, "CPUSET", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	  "Set of CPUs for consumer threads; implies --affinity"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) extern struct argp bench_ringbufs_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static const struct argp_child bench_parsers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	{ &bench_ringbufs_argp, 0, "Ring buffers benchmark", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static error_t parse_arg(int key, char *arg, struct argp_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	static int pos_args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	case 'v':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		env.verbose = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	case 'l':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		env.list = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	case 'd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		env.duration_sec = strtol(arg, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (env.duration_sec <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			fprintf(stderr, "Invalid duration: %s\n", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			argp_usage(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	case 'w':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		env.warmup_sec = strtol(arg, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		if (env.warmup_sec <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			fprintf(stderr, "Invalid warm-up duration: %s\n", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			argp_usage(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	case 'p':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		env.producer_cnt = strtol(arg, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		if (env.producer_cnt <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			fprintf(stderr, "Invalid producer count: %s\n", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			argp_usage(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	case 'c':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		env.consumer_cnt = strtol(arg, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (env.consumer_cnt <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			fprintf(stderr, "Invalid consumer count: %s\n", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			argp_usage(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	case 'a':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		env.affinity = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	case ARG_PROD_AFFINITY_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		env.affinity = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		if (parse_num_list(arg, &env.prod_cpus.cpus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				   &env.prod_cpus.cpus_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			fprintf(stderr, "Invalid format of CPU set for producers.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			argp_usage(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	case ARG_CONS_AFFINITY_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		env.affinity = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (parse_num_list(arg, &env.cons_cpus.cpus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 				   &env.cons_cpus.cpus_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			fprintf(stderr, "Invalid format of CPU set for consumers.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			argp_usage(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	case ARGP_KEY_ARG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		if (pos_args++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			fprintf(stderr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 				"Unrecognized positional argument: %s\n", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			argp_usage(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		env.bench_name = strdup(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		return ARGP_ERR_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void parse_cmdline_args(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	static const struct argp argp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		.options = opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		.parser = parse_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		.doc = argp_program_doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		.children = bench_parsers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (argp_parse(&argp, argc, argv, 0, NULL, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (!env.list && !env.bench_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		argp_help(&argp, stderr, ARGP_HELP_DOC, "bench");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void collect_measurements(long delta_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static __u64 last_time_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static void sigalarm_handler(int signo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	long new_time_ns = get_time_ns();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	long delta_ns = new_time_ns - last_time_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	collect_measurements(delta_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	last_time_ns = new_time_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* set up periodic 1-second timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static void setup_timer()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	static struct sigaction sigalarm_action = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		.sa_handler = sigalarm_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct itimerval timer_settings = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	last_time_ns = get_time_ns();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	err = sigaction(SIGALRM, &sigalarm_action, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		fprintf(stderr, "failed to install SIGALRM handler: %d\n", -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	timer_settings.it_interval.tv_sec = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	timer_settings.it_value.tv_sec = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	err = setitimer(ITIMER_REAL, &timer_settings, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		fprintf(stderr, "failed to arm interval timer: %d\n", -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static void set_thread_affinity(pthread_t thread, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	cpu_set_t cpuset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	CPU_ZERO(&cpuset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	CPU_SET(cpu, &cpuset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		fprintf(stderr, "setting affinity to CPU #%d failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			cpu, errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int next_cpu(struct cpu_set *cpu_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (cpu_set->cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		/* find next available CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		for (i = cpu_set->next_cpu; i < cpu_set->cpus_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			if (cpu_set->cpus[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 				cpu_set->next_cpu = i + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		fprintf(stderr, "Not enough CPUs specified, need CPU #%d or higher.\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return cpu_set->next_cpu++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static struct bench_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	int res_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct bench_res *results;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	pthread_t *consumers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	pthread_t *producers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) } state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) const struct bench *bench = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) extern const struct bench bench_count_global;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) extern const struct bench bench_count_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) extern const struct bench bench_rename_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) extern const struct bench bench_rename_kprobe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) extern const struct bench bench_rename_kretprobe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) extern const struct bench bench_rename_rawtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) extern const struct bench bench_rename_fentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) extern const struct bench bench_rename_fexit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) extern const struct bench bench_trig_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) extern const struct bench bench_trig_tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) extern const struct bench bench_trig_rawtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) extern const struct bench bench_trig_kprobe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) extern const struct bench bench_trig_fentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) extern const struct bench bench_trig_fentry_sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) extern const struct bench bench_trig_fmodret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) extern const struct bench bench_rb_libbpf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) extern const struct bench bench_rb_custom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) extern const struct bench bench_pb_libbpf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) extern const struct bench bench_pb_custom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static const struct bench *benchs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	&bench_count_global,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	&bench_count_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	&bench_rename_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	&bench_rename_kprobe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	&bench_rename_kretprobe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	&bench_rename_rawtp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	&bench_rename_fentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	&bench_rename_fexit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	&bench_trig_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	&bench_trig_tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	&bench_trig_rawtp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	&bench_trig_kprobe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	&bench_trig_fentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	&bench_trig_fentry_sleep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	&bench_trig_fmodret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	&bench_rb_libbpf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	&bench_rb_custom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	&bench_pb_libbpf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	&bench_pb_custom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void setup_benchmark()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (!env.bench_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		fprintf(stderr, "benchmark name is not specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	for (i = 0; i < ARRAY_SIZE(benchs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		if (strcmp(benchs[i]->name, env.bench_name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			bench = benchs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (!bench) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		fprintf(stderr, "benchmark '%s' not found\n", env.bench_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	printf("Setting up benchmark '%s'...\n", bench->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	state.producers = calloc(env.producer_cnt, sizeof(*state.producers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	state.consumers = calloc(env.consumer_cnt, sizeof(*state.consumers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	state.results = calloc(env.duration_sec + env.warmup_sec + 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			       sizeof(*state.results));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (!state.producers || !state.consumers || !state.results)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (bench->validate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		bench->validate();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (bench->setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		bench->setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	for (i = 0; i < env.consumer_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		err = pthread_create(&state.consumers[i], NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 				     bench->consumer_thread, (void *)(long)i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			fprintf(stderr, "failed to create consumer thread #%d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 				i, -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		if (env.affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			set_thread_affinity(state.consumers[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 					    next_cpu(&env.cons_cpus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	/* unless explicit producer CPU list is specified, continue after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	 * last consumer CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (!env.prod_cpus.cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		env.prod_cpus.next_cpu = env.cons_cpus.next_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	for (i = 0; i < env.producer_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		err = pthread_create(&state.producers[i], NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 				     bench->producer_thread, (void *)(long)i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			fprintf(stderr, "failed to create producer thread #%d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				i, -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		if (env.affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			set_thread_affinity(state.producers[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 					    next_cpu(&env.prod_cpus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	printf("Benchmark '%s' started.\n", bench->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static pthread_mutex_t bench_done_mtx = PTHREAD_MUTEX_INITIALIZER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static pthread_cond_t bench_done = PTHREAD_COND_INITIALIZER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static void collect_measurements(long delta_ns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	int iter = state.res_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	struct bench_res *res = &state.results[iter];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	bench->measure(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	if (bench->report_progress)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		bench->report_progress(iter, res, delta_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (iter == env.duration_sec + env.warmup_sec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		pthread_mutex_lock(&bench_done_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		pthread_cond_signal(&bench_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		pthread_mutex_unlock(&bench_done_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	parse_cmdline_args(argc, argv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (env.list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		printf("Available benchmarks:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		for (i = 0; i < ARRAY_SIZE(benchs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			printf("- %s\n", benchs[i]->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	setup_benchmark();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	setup_timer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	pthread_mutex_lock(&bench_done_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	pthread_cond_wait(&bench_done, &bench_done_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	pthread_mutex_unlock(&bench_done_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (bench->report_final)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		/* skip first sample */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		bench->report_final(state.results + env.warmup_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 				    state.res_cnt - env.warmup_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }