cpupower-info.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * (C) 2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
  3. *
  4. * Licensed under the terms of the GNU GPL License version 2.
  5. */
  6. #include <unistd.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <errno.h>
  10. #include <string.h>
  11. #include <getopt.h>
  12. #include <cpufreq.h>
  13. #include "helpers/helpers.h"
  14. #include "helpers/sysfs.h"
  15. static struct option set_opts[] = {
  16. {"perf-bias", optional_argument, NULL, 'b'},
  17. { },
  18. };
  19. static void print_wrong_arg_exit(void)
  20. {
  21. printf(_("invalid or unknown argument\n"));
  22. exit(EXIT_FAILURE);
  23. }
  24. int cmd_info(int argc, char **argv)
  25. {
  26. extern char *optarg;
  27. extern int optind, opterr, optopt;
  28. unsigned int cpu;
  29. union {
  30. struct {
  31. int perf_bias:1;
  32. };
  33. int params;
  34. } params = {};
  35. int ret = 0;
  36. setlocale(LC_ALL, "");
  37. textdomain(PACKAGE);
  38. /* parameter parsing */
  39. while ((ret = getopt_long(argc, argv, "b", set_opts, NULL)) != -1) {
  40. switch (ret) {
  41. case 'b':
  42. if (params.perf_bias)
  43. print_wrong_arg_exit();
  44. params.perf_bias = 1;
  45. break;
  46. default:
  47. print_wrong_arg_exit();
  48. }
  49. };
  50. if (!params.params)
  51. params.params = 0x7;
  52. /* Default is: show output of CPU 0 only */
  53. if (bitmask_isallclear(cpus_chosen))
  54. bitmask_setbit(cpus_chosen, 0);
  55. /* Add more per cpu options here */
  56. if (!params.perf_bias)
  57. return ret;
  58. if (params.perf_bias) {
  59. if (!run_as_root) {
  60. params.perf_bias = 0;
  61. printf(_("Intel's performance bias setting needs root privileges\n"));
  62. } else if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS)) {
  63. printf(_("System does not support Intel's performance"
  64. " bias setting\n"));
  65. params.perf_bias = 0;
  66. }
  67. }
  68. /* loop over CPUs */
  69. for (cpu = bitmask_first(cpus_chosen);
  70. cpu <= bitmask_last(cpus_chosen); cpu++) {
  71. if (!bitmask_isbitset(cpus_chosen, cpu) ||
  72. cpufreq_cpu_exists(cpu))
  73. continue;
  74. printf(_("analyzing CPU %d:\n"), cpu);
  75. if (params.perf_bias) {
  76. ret = msr_intel_get_perf_bias(cpu);
  77. if (ret < 0) {
  78. fprintf(stderr,
  79. _("Could not read perf-bias value[%d]\n"), ret);
  80. exit(EXIT_FAILURE);
  81. } else
  82. printf(_("perf-bias: %d\n"), ret);
  83. }
  84. }
  85. return 0;
  86. }