1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* cpufreq-bench CPUFreq microbenchmark
4 * Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
16 #include "benchmark.h"
18 static struct option long_options
[] = {
19 {"output", 1, 0, 'o'},
22 {"verbose", 0, 0, 'v'},
24 {"governor", 1, 0, 'g'},
27 {"cycles", 1, 0, 'n'},
28 {"rounds", 1, 0, 'r'},
29 {"load-step", 1, 0, 'x'},
30 {"sleep-step", 1, 0, 'y'},
35 /*******************************************************************
37 *******************************************************************/
41 printf("usage: ./bench\n");
43 printf(" -l, --load=<long int>\t\tinitial load time in us\n");
44 printf(" -s, --sleep=<long int>\t\tinitial sleep time in us\n");
45 printf(" -x, --load-step=<long int>\ttime to be added to load time, in us\n");
46 printf(" -y, --sleep-step=<long int>\ttime to be added to sleep time, in us\n");
47 printf(" -c, --cpu=<cpu #>\t\t\tCPU Nr. to use, starting at 0\n");
48 printf(" -p, --prio=<priority>\t\t\tscheduler priority, HIGH, LOW or DEFAULT\n");
49 printf(" -g, --governor=<governor>\t\tcpufreq governor to test\n");
50 printf(" -n, --cycles=<int>\t\t\tload/sleep cycles\n");
51 printf(" -r, --rounds<int>\t\t\tload/sleep rounds\n");
52 printf(" -f, --file=<configfile>\t\tconfig file to use\n");
53 printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
54 printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
55 printf(" -h, --help\t\t\t\tPrint this help screen\n");
59 /*******************************************************************
61 *******************************************************************/
63 int main(int argc
, char **argv
)
67 struct config
*config
= NULL
;
69 config
= prepare_default_config();
75 c
= getopt_long (argc
, argv
, "hg:o:s:l:vc:p:f:n:r:x:y:",
76 long_options
, &option_index
);
82 if (config
->output
!= NULL
)
83 fclose(config
->output
);
85 config
->output
= prepare_output(optarg
);
87 if (config
->output
== NULL
)
90 dprintf("user output path -> %s\n", optarg
);
93 sscanf(optarg
, "%li", &config
->sleep
);
94 dprintf("user sleep time -> %s\n", optarg
);
97 sscanf(optarg
, "%li", &config
->load
);
98 dprintf("user load time -> %s\n", optarg
);
101 sscanf(optarg
, "%u", &config
->cpu
);
102 dprintf("user cpu -> %s\n", optarg
);
105 strncpy(config
->governor
, optarg
, 14);
106 dprintf("user governor -> %s\n", optarg
);
109 if (string_to_prio(optarg
) != SCHED_ERR
) {
110 config
->prio
= string_to_prio(optarg
);
111 dprintf("user prio -> %s\n", optarg
);
113 if (config
!= NULL
) {
114 if (config
->output
!= NULL
)
115 fclose(config
->output
);
122 sscanf(optarg
, "%u", &config
->cycles
);
123 dprintf("user cycles -> %s\n", optarg
);
126 sscanf(optarg
, "%u", &config
->rounds
);
127 dprintf("user rounds -> %s\n", optarg
);
130 sscanf(optarg
, "%li", &config
->load_step
);
131 dprintf("user load_step -> %s\n", optarg
);
134 sscanf(optarg
, "%li", &config
->sleep_step
);
135 dprintf("user sleep_step -> %s\n", optarg
);
138 if (prepare_config(optarg
, config
))
143 dprintf("verbose output enabled\n");
148 if (config
!= NULL
) {
149 if (config
->output
!= NULL
)
150 fclose(config
->output
);
157 if (config
->verbose
) {
158 printf("starting benchmark with parameters:\n");
178 prepare_user(config
);
179 prepare_system(config
);
180 start_benchmark(config
);
182 if (config
->output
!= stdout
)
183 fclose(config
->output
);