cpupower-monitor.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
  3. *
  4. * Licensed under the terms of the GNU GPL License version 2.
  5. *
  6. */
  7. #ifndef __CPUIDLE_INFO_HW__
  8. #define __CPUIDLE_INFO_HW__
  9. #include <stdarg.h>
  10. #include <time.h>
  11. #include "idle_monitor/idle_monitors.h"
  12. #define MONITORS_MAX 20
  13. #define MONITOR_NAME_LEN 20
  14. #define CSTATE_NAME_LEN 5
  15. #define CSTATE_DESC_LEN 60
  16. int cpu_count;
  17. /* Hard to define the right names ...: */
  18. enum power_range_e {
  19. RANGE_THREAD, /* Lowest in topology hierarcy, AMD: core, Intel: thread
  20. kernel sysfs: cpu */
  21. RANGE_CORE, /* AMD: unit, Intel: core, kernel_sysfs: core_id */
  22. RANGE_PACKAGE, /* Package, processor socket */
  23. RANGE_MACHINE, /* Machine, platform wide */
  24. RANGE_MAX };
  25. typedef struct cstate {
  26. int id;
  27. enum power_range_e range;
  28. char name[CSTATE_NAME_LEN];
  29. char desc[CSTATE_DESC_LEN];
  30. /* either provide a percentage or a general count */
  31. int (*get_count_percent)(unsigned int self_id, double *percent,
  32. unsigned int cpu);
  33. int (*get_count)(unsigned int self_id, unsigned long long *count,
  34. unsigned int cpu);
  35. } cstate_t;
  36. struct cpuidle_monitor {
  37. /* Name must not contain whitespaces */
  38. char name[MONITOR_NAME_LEN];
  39. int name_len;
  40. int hw_states_num;
  41. cstate_t *hw_states;
  42. int (*start) (void);
  43. int (*stop) (void);
  44. struct cpuidle_monitor* (*do_register) (void);
  45. void (*unregister)(void);
  46. unsigned int overflow_s;
  47. int needs_root;
  48. };
  49. extern long long timespec_diff_us(struct timespec start, struct timespec end);
  50. #define print_overflow_err(mes, ov) \
  51. { \
  52. fprintf(stderr, gettext("Measure took %u seconds, but registers could " \
  53. "overflow at %u seconds, results " \
  54. "could be inaccurate\n"), mes, ov); \
  55. }
  56. /* Taken over from x86info project sources -> return 0 on success */
  57. #include <sched.h>
  58. #include <sys/types.h>
  59. #include <unistd.h>
  60. static inline int bind_cpu(int cpu)
  61. {
  62. cpu_set_t set;
  63. if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) {
  64. CPU_ZERO(&set);
  65. CPU_SET(cpu, &set);
  66. return sched_setaffinity(getpid(), sizeof(set), &set);
  67. }
  68. return 1;
  69. }
  70. #endif /* __CPUIDLE_INFO_HW__ */