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
[] =
33 {"output", 1, 0, 'o'},
36 {"verbose", 0, 0, 'v'},
38 {"governor", 1, 0, 'g'},
41 {"cycles", 1, 0, 'n'},
42 {"rounds", 1, 0, 'r'},
43 {"load-step", 1, 0, 'x'},
44 {"sleep-step", 1, 0, 'y'},
49 /*******************************************************************
51 *******************************************************************/
55 printf("usage: ./bench\n");
57 printf(" -l, --load=<long int>\t\tinitial load time in us\n");
58 printf(" -s, --sleep=<long int>\t\tinitial sleep time in us\n");
59 printf(" -x, --load-step=<long int>\ttime to be added to load time, in us\n");
60 printf(" -y, --sleep-step=<long int>\ttime to be added to sleep time, in us\n");
61 printf(" -c, --cpu=<cpu #>\t\t\tCPU Nr. to use, starting at 0\n");
62 printf(" -p, --prio=<priority>\t\t\tscheduler priority, HIGH, LOW or DEFAULT\n");
63 printf(" -g, --governor=<governor>\t\tcpufreq governor to test\n");
64 printf(" -n, --cycles=<int>\t\t\tload/sleep cycles\n");
65 printf(" -r, --rounds<int>\t\t\tload/sleep rounds\n");
66 printf(" -f, --file=<configfile>\t\tconfig file to use\n");
67 printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
68 printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
69 printf(" -h, --help\t\t\t\tPrint this help screen\n");
73 /*******************************************************************
75 *******************************************************************/
77 int main(int argc
, char **argv
)
81 struct config
*config
= NULL
;
83 config
= prepare_default_config();
89 c
= getopt_long (argc
, argv
, "hg:o:s:l:vc:p:f:n:r:x:y:",
90 long_options
, &option_index
);
96 if (config
->output
!= NULL
)
97 fclose(config
->output
);
99 config
->output
= prepare_output(optarg
);
101 if (config
->output
== NULL
)
104 dprintf("user output path -> %s\n", optarg
);
107 sscanf(optarg
, "%li", &config
->sleep
);
108 dprintf("user sleep time -> %s\n", optarg
);
111 sscanf(optarg
, "%li", &config
->load
);
112 dprintf("user load time -> %s\n", optarg
);
115 sscanf(optarg
, "%u", &config
->cpu
);
116 dprintf("user cpu -> %s\n", optarg
);
119 strncpy(config
->governor
, optarg
, 14);
120 dprintf("user governor -> %s\n", optarg
);
123 if (string_to_prio(optarg
) != SCHED_ERR
) {
124 config
->prio
= string_to_prio(optarg
);
125 dprintf("user prio -> %s\n", optarg
);
127 if (config
!= NULL
) {
128 if (config
->output
!= NULL
)
129 fclose(config
->output
);
136 sscanf(optarg
, "%u", &config
->cycles
);
137 dprintf("user cycles -> %s\n", optarg
);
140 sscanf(optarg
, "%u", &config
->rounds
);
141 dprintf("user rounds -> %s\n", optarg
);
144 sscanf(optarg
, "%li", &config
->load_step
);
145 dprintf("user load_step -> %s\n", optarg
);
148 sscanf(optarg
, "%li", &config
->sleep_step
);
149 dprintf("user sleep_step -> %s\n", optarg
);
152 if (prepare_config(optarg
, config
))
157 dprintf("verbose output enabled\n");
162 if (config
!= NULL
) {
163 if (config
->output
!= NULL
)
164 fclose(config
->output
);
171 if (config
->verbose
) {
172 printf("starting benchmark with parameters:\n");
192 prepare_user(config
);
193 prepare_system(config
);
194 start_benchmark(config
);
196 if (config
->output
!= stdout
)
197 fclose(config
->output
);