resource_coalition_internal_types_mac.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // This file defines data types used to retrieve coalition metrics from the OS.
  5. #ifndef COMPONENTS_POWER_METRICS_RESOURCE_COALITION_INTERNAL_TYPES_MAC_H_
  6. #define COMPONENTS_POWER_METRICS_RESOURCE_COALITION_INTERNAL_TYPES_MAC_H_
  7. #include <stdint.h>
  8. // Comes from osfmk/mach/coalition.h
  9. #define COALITION_TYPE_RESOURCE (0)
  10. #define COALITION_TYPE_JETSAM (1)
  11. #define COALITION_TYPE_MAX (1)
  12. #define COALITION_NUM_TYPES (COALITION_TYPE_MAX + 1)
  13. #define COALITION_NUM_THREAD_QOS_TYPES 7
  14. // Comes from osfmk/mach/thread_policy.h
  15. #define THREAD_QOS_UNSPECIFIED 0
  16. #define THREAD_QOS_DEFAULT THREAD_QOS_UNSPECIFIED /* Temporary rename */
  17. #define THREAD_QOS_MAINTENANCE 1
  18. #define THREAD_QOS_BACKGROUND 2
  19. #define THREAD_QOS_UTILITY 3
  20. #define THREAD_QOS_LEGACY 4 /* i.e. default workq threads */
  21. #define THREAD_QOS_USER_INITIATED 5
  22. #define THREAD_QOS_USER_INTERACTIVE 6
  23. #define THREAD_QOS_LAST 7
  24. static_assert(COALITION_NUM_THREAD_QOS_TYPES == THREAD_QOS_LAST,
  25. "Unexpected number of QoS levels.");
  26. // Comes from bsd/sys/coalition.h
  27. struct coalition_resource_usage {
  28. uint64_t tasks_started;
  29. uint64_t tasks_exited;
  30. uint64_t time_nonempty;
  31. uint64_t cpu_time;
  32. uint64_t interrupt_wakeups;
  33. uint64_t platform_idle_wakeups;
  34. uint64_t bytesread;
  35. uint64_t byteswritten;
  36. uint64_t gpu_time;
  37. uint64_t cpu_time_billed_to_me;
  38. uint64_t cpu_time_billed_to_others;
  39. uint64_t energy;
  40. uint64_t logical_immediate_writes;
  41. uint64_t logical_deferred_writes;
  42. uint64_t logical_invalidated_writes;
  43. uint64_t logical_metadata_writes;
  44. uint64_t logical_immediate_writes_to_external;
  45. uint64_t logical_deferred_writes_to_external;
  46. uint64_t logical_invalidated_writes_to_external;
  47. uint64_t logical_metadata_writes_to_external;
  48. uint64_t energy_billed_to_me;
  49. uint64_t energy_billed_to_others;
  50. uint64_t cpu_ptime;
  51. uint64_t cpu_time_eqos_len; /* Stores the number of thread QoS types */
  52. uint64_t cpu_time_eqos[COALITION_NUM_THREAD_QOS_TYPES];
  53. // `cpu_instructions` and `cpu_cycles` are only populated on macOS 10.15+
  54. uint64_t cpu_instructions;
  55. uint64_t cpu_cycles;
  56. uint64_t fs_metadata_writes;
  57. uint64_t pm_writes;
  58. };
  59. struct proc_pidcoalitioninfo {
  60. uint64_t coalition_id[COALITION_NUM_TYPES];
  61. uint64_t reserved1;
  62. uint64_t reserved2;
  63. uint64_t reserved3;
  64. };
  65. // Comes from bsd/sys/proc_info.h
  66. #define PROC_PIDCOALITIONINFO 20
  67. #endif // COMPONENTS_POWER_METRICS_RESOURCE_COALITION_INTERNAL_TYPES_MAC_H_