cpupower-info.c 2.1 KB

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