1 /* cpufreq-bench CPUFreq microbenchmark
3 * Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "benchmark.h"
31 static struct option long_options
[] = {
32 {"output", 1, 0, 'o'},
35 {"verbose", 0, 0, 'v'},
37 {"governor", 1, 0, 'g'},
40 {"cycles", 1, 0, 'n'},
41 {"rounds", 1, 0, 'r'},
42 {"load-step", 1, 0, 'x'},
43 {"sleep-step", 1, 0, 'y'},
48 /*******************************************************************
50 *******************************************************************/
54 printf("usage: ./bench\n");
56 printf(" -l, --load=<long int>\t\tinitial load time in us\n");
57 printf(" -s, --sleep=<long int>\t\tinitial sleep time in us\n");
58 printf(" -x, --load-step=<long int>\ttime to be added to load time, in us\n");
59 printf(" -y, --sleep-step=<long int>\ttime to be added to sleep time, in us\n");
60 printf(" -c, --cpu=<cpu #>\t\t\tCPU Nr. to use, starting at 0\n");
61 printf(" -p, --prio=<priority>\t\t\tscheduler priority, HIGH, LOW or DEFAULT\n");
62 printf(" -g, --governor=<governor>\t\tcpufreq governor to test\n");
63 printf(" -n, --cycles=<int>\t\t\tload/sleep cycles\n");
64 printf(" -r, --rounds<int>\t\t\tload/sleep rounds\n");
65 printf(" -f, --file=<configfile>\t\tconfig file to use\n");
66 printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
67 printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
68 printf(" -h, --help\t\t\t\tPrint this help screen\n");
72 /*******************************************************************
74 *******************************************************************/
76 int main(int argc
, char **argv
)
80 struct config
*config
= NULL
;
82 config
= prepare_default_config();
88 c
= getopt_long (argc
, argv
, "hg:o:s:l:vc:p:f:n:r:x:y:",
89 long_options
, &option_index
);
95 if (config
->output
!= NULL
)
96 fclose(config
->output
);
98 config
->output
= prepare_output(optarg
);
100 if (config
->output
== NULL
)
103 dprintf("user output path -> %s\n", optarg
);
106 sscanf(optarg
, "%li", &config
->sleep
);
107 dprintf("user sleep time -> %s\n", optarg
);
110 sscanf(optarg
, "%li", &config
->load
);
111 dprintf("user load time -> %s\n", optarg
);
114 sscanf(optarg
, "%u", &config
->cpu
);
115 dprintf("user cpu -> %s\n", optarg
);
118 strncpy(config
->governor
, optarg
, 14);
119 dprintf("user governor -> %s\n", optarg
);
122 if (string_to_prio(optarg
) != SCHED_ERR
) {
123 config
->prio
= string_to_prio(optarg
);
124 dprintf("user prio -> %s\n", optarg
);
126 if (config
!= NULL
) {
127 if (config
->output
!= NULL
)
128 fclose(config
->output
);
135 sscanf(optarg
, "%u", &config
->cycles
);
136 dprintf("user cycles -> %s\n", optarg
);
139 sscanf(optarg
, "%u", &config
->rounds
);
140 dprintf("user rounds -> %s\n", optarg
);
143 sscanf(optarg
, "%li", &config
->load_step
);
144 dprintf("user load_step -> %s\n", optarg
);
147 sscanf(optarg
, "%li", &config
->sleep_step
);
148 dprintf("user sleep_step -> %s\n", optarg
);
151 if (prepare_config(optarg
, config
))
156 dprintf("verbose output enabled\n");
161 if (config
!= NULL
) {
162 if (config
->output
!= NULL
)
163 fclose(config
->output
);
170 if (config
->verbose
) {
171 printf("starting benchmark with parameters:\n");
191 prepare_user(config
);
192 prepare_system(config
);
193 start_benchmark(config
);
195 if (config
->output
!= stdout
)
196 fclose(config
->output
);