main.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* cpufreq-bench CPUFreq microbenchmark
  2. *
  3. * Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
  4. *
  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.
  9. *
  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.
  14. *
  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.
  18. */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <unistd.h>
  23. #include <getopt.h>
  24. #include <errno.h>
  25. #include "config.h"
  26. #include "system.h"
  27. #include "benchmark.h"
  28. static struct option long_options[] = {
  29. {"output", 1, 0, 'o'},
  30. {"sleep", 1, 0, 's'},
  31. {"load", 1, 0, 'l'},
  32. {"verbose", 0, 0, 'v'},
  33. {"cpu", 1, 0, 'c'},
  34. {"governor", 1, 0, 'g'},
  35. {"prio", 1, 0, 'p'},
  36. {"file", 1, 0, 'f'},
  37. {"cycles", 1, 0, 'n'},
  38. {"rounds", 1, 0, 'r'},
  39. {"load-step", 1, 0, 'x'},
  40. {"sleep-step", 1, 0, 'y'},
  41. {"help", 0, 0, 'h'},
  42. {0, 0, 0, 0}
  43. };
  44. /*******************************************************************
  45. usage
  46. *******************************************************************/
  47. void usage()
  48. {
  49. printf("usage: ./bench\n");
  50. printf("Options:\n");
  51. printf(" -l, --load=<long int>\t\tinitial load time in us\n");
  52. printf(" -s, --sleep=<long int>\t\tinitial sleep time in us\n");
  53. printf(" -x, --load-step=<long int>\ttime to be added to load time, in us\n");
  54. printf(" -y, --sleep-step=<long int>\ttime to be added to sleep time, in us\n");
  55. printf(" -c, --cpu=<cpu #>\t\t\tCPU Nr. to use, starting at 0\n");
  56. printf(" -p, --prio=<priority>\t\t\tscheduler priority, HIGH, LOW or DEFAULT\n");
  57. printf(" -g, --governor=<governor>\t\tcpufreq governor to test\n");
  58. printf(" -n, --cycles=<int>\t\t\tload/sleep cycles\n");
  59. printf(" -r, --rounds<int>\t\t\tload/sleep rounds\n");
  60. printf(" -f, --file=<configfile>\t\tconfig file to use\n");
  61. printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
  62. printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
  63. printf(" -h, --help\t\t\t\tPrint this help screen\n");
  64. exit(1);
  65. }
  66. /*******************************************************************
  67. main
  68. *******************************************************************/
  69. int main(int argc, char **argv)
  70. {
  71. int c;
  72. int option_index = 0;
  73. struct config *config = NULL;
  74. config = prepare_default_config();
  75. if (config == NULL)
  76. return EXIT_FAILURE;
  77. while (1) {
  78. c = getopt_long (argc, argv, "hg:o:s:l:vc:p:f:n:r:x:y:",
  79. long_options, &option_index);
  80. if (c == -1)
  81. break;
  82. switch (c) {
  83. case 'o':
  84. if (config->output != NULL)
  85. fclose(config->output);
  86. config->output = prepare_output(optarg);
  87. if (config->output == NULL)
  88. return EXIT_FAILURE;
  89. dprintf("user output path -> %s\n", optarg);
  90. break;
  91. case 's':
  92. sscanf(optarg, "%li", &config->sleep);
  93. dprintf("user sleep time -> %s\n", optarg);
  94. break;
  95. case 'l':
  96. sscanf(optarg, "%li", &config->load);
  97. dprintf("user load time -> %s\n", optarg);
  98. break;
  99. case 'c':
  100. sscanf(optarg, "%u", &config->cpu);
  101. dprintf("user cpu -> %s\n", optarg);
  102. break;
  103. case 'g':
  104. strncpy(config->governor, optarg, 14);
  105. dprintf("user governor -> %s\n", optarg);
  106. break;
  107. case 'p':
  108. if (string_to_prio(optarg) != SCHED_ERR) {
  109. config->prio = string_to_prio(optarg);
  110. dprintf("user prio -> %s\n", optarg);
  111. } else {
  112. if (config != NULL) {
  113. if (config->output != NULL)
  114. fclose(config->output);
  115. free(config);
  116. }
  117. usage();
  118. }
  119. break;
  120. case 'n':
  121. sscanf(optarg, "%u", &config->cycles);
  122. dprintf("user cycles -> %s\n", optarg);
  123. break;
  124. case 'r':
  125. sscanf(optarg, "%u", &config->rounds);
  126. dprintf("user rounds -> %s\n", optarg);
  127. break;
  128. case 'x':
  129. sscanf(optarg, "%li", &config->load_step);
  130. dprintf("user load_step -> %s\n", optarg);
  131. break;
  132. case 'y':
  133. sscanf(optarg, "%li", &config->sleep_step);
  134. dprintf("user sleep_step -> %s\n", optarg);
  135. break;
  136. case 'f':
  137. if (prepare_config(optarg, config))
  138. return EXIT_FAILURE;
  139. break;
  140. case 'v':
  141. config->verbose = 1;
  142. dprintf("verbose output enabled\n");
  143. break;
  144. case 'h':
  145. case '?':
  146. default:
  147. if (config != NULL) {
  148. if (config->output != NULL)
  149. fclose(config->output);
  150. free(config);
  151. }
  152. usage();
  153. }
  154. }
  155. if (config->verbose) {
  156. printf("starting benchmark with parameters:\n");
  157. printf("config:\n\t"
  158. "sleep=%li\n\t"
  159. "load=%li\n\t"
  160. "sleep_step=%li\n\t"
  161. "load_step=%li\n\t"
  162. "cpu=%u\n\t"
  163. "cycles=%u\n\t"
  164. "rounds=%u\n\t"
  165. "governor=%s\n\n",
  166. config->sleep,
  167. config->load,
  168. config->sleep_step,
  169. config->load_step,
  170. config->cpu,
  171. config->cycles,
  172. config->rounds,
  173. config->governor);
  174. }
  175. prepare_user(config);
  176. prepare_system(config);
  177. start_benchmark(config);
  178. if (config->output != stdout)
  179. fclose(config->output);
  180. free(config);
  181. return EXIT_SUCCESS;
  182. }