main.c 5.3 KB

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