i915_pmu.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright © 2017 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef __I915_PMU_H__
  25. #define __I915_PMU_H__
  26. enum {
  27. __I915_SAMPLE_FREQ_ACT = 0,
  28. __I915_SAMPLE_FREQ_REQ,
  29. __I915_SAMPLE_RC6,
  30. __I915_SAMPLE_RC6_ESTIMATED,
  31. __I915_NUM_PMU_SAMPLERS
  32. };
  33. /**
  34. * How many different events we track in the global PMU mask.
  35. *
  36. * It is also used to know to needed number of event reference counters.
  37. */
  38. #define I915_PMU_MASK_BITS \
  39. ((1 << I915_PMU_SAMPLE_BITS) + \
  40. (I915_PMU_LAST + 1 - __I915_PMU_OTHER(0)))
  41. struct i915_pmu_sample {
  42. u64 cur;
  43. };
  44. struct i915_pmu {
  45. /**
  46. * @node: List node for CPU hotplug handling.
  47. */
  48. struct hlist_node node;
  49. /**
  50. * @base: PMU base.
  51. */
  52. struct pmu base;
  53. /**
  54. * @lock: Lock protecting enable mask and ref count handling.
  55. */
  56. spinlock_t lock;
  57. /**
  58. * @timer: Timer for internal i915 PMU sampling.
  59. */
  60. struct hrtimer timer;
  61. /**
  62. * @enable: Bitmask of all currently enabled events.
  63. *
  64. * Bits are derived from uAPI event numbers in a way that low 16 bits
  65. * correspond to engine event _sample_ _type_ (I915_SAMPLE_QUEUED is
  66. * bit 0), and higher bits correspond to other events (for instance
  67. * I915_PMU_ACTUAL_FREQUENCY is bit 16 etc).
  68. *
  69. * In other words, low 16 bits are not per engine but per engine
  70. * sampler type, while the upper bits are directly mapped to other
  71. * event types.
  72. */
  73. u64 enable;
  74. /**
  75. * @enable_count: Reference counts for the enabled events.
  76. *
  77. * Array indices are mapped in the same way as bits in the @enable field
  78. * and they are used to control sampling on/off when multiple clients
  79. * are using the PMU API.
  80. */
  81. unsigned int enable_count[I915_PMU_MASK_BITS];
  82. /**
  83. * @timer_enabled: Should the internal sampling timer be running.
  84. */
  85. bool timer_enabled;
  86. /**
  87. * @sample: Current and previous (raw) counters for sampling events.
  88. *
  89. * These counters are updated from the i915 PMU sampling timer.
  90. *
  91. * Only global counters are held here, while the per-engine ones are in
  92. * struct intel_engine_cs.
  93. */
  94. struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS];
  95. /**
  96. * @suspended_jiffies_last: Cached suspend time from PM core.
  97. */
  98. unsigned long suspended_jiffies_last;
  99. /**
  100. * @i915_attr: Memory block holding device attributes.
  101. */
  102. void *i915_attr;
  103. /**
  104. * @pmu_attr: Memory block holding device attributes.
  105. */
  106. void *pmu_attr;
  107. };
  108. #ifdef CONFIG_PERF_EVENTS
  109. void i915_pmu_register(struct drm_i915_private *i915);
  110. void i915_pmu_unregister(struct drm_i915_private *i915);
  111. void i915_pmu_gt_parked(struct drm_i915_private *i915);
  112. void i915_pmu_gt_unparked(struct drm_i915_private *i915);
  113. #else
  114. static inline void i915_pmu_register(struct drm_i915_private *i915) {}
  115. static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
  116. static inline void i915_pmu_gt_parked(struct drm_i915_private *i915) {}
  117. static inline void i915_pmu_gt_unparked(struct drm_i915_private *i915) {}
  118. #endif
  119. #endif