i915_pmu.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * SPDX-License-Identifier: MIT
  3. *
  4. * Copyright © 2017-2018 Intel Corporation
  5. */
  6. #ifndef __I915_PMU_H__
  7. #define __I915_PMU_H__
  8. #include <linux/hrtimer.h>
  9. #include <linux/perf_event.h>
  10. #include <linux/spinlock_types.h>
  11. #include <uapi/drm/i915_drm.h>
  12. struct drm_i915_private;
  13. struct intel_gt;
  14. /*
  15. * Non-engine events that we need to track enabled-disabled transition and
  16. * current state.
  17. */
  18. enum i915_pmu_tracked_events {
  19. __I915_PMU_ACTUAL_FREQUENCY_ENABLED = 0,
  20. __I915_PMU_REQUESTED_FREQUENCY_ENABLED,
  21. __I915_PMU_RC6_RESIDENCY_ENABLED,
  22. __I915_PMU_TRACKED_EVENT_COUNT, /* count marker */
  23. };
  24. /*
  25. * Slots used from the sampling timer (non-engine events) with some extras for
  26. * convenience.
  27. */
  28. enum {
  29. __I915_SAMPLE_FREQ_ACT = 0,
  30. __I915_SAMPLE_FREQ_REQ,
  31. __I915_SAMPLE_RC6,
  32. __I915_SAMPLE_RC6_LAST_REPORTED,
  33. __I915_NUM_PMU_SAMPLERS
  34. };
  35. #define I915_PMU_MAX_GT 2
  36. /*
  37. * How many different events we track in the global PMU mask.
  38. *
  39. * It is also used to know to needed number of event reference counters.
  40. */
  41. #define I915_PMU_MASK_BITS \
  42. (I915_ENGINE_SAMPLE_COUNT + \
  43. I915_PMU_MAX_GT * __I915_PMU_TRACKED_EVENT_COUNT)
  44. #define I915_ENGINE_SAMPLE_COUNT (I915_SAMPLE_SEMA + 1)
  45. struct i915_pmu_sample {
  46. u64 cur;
  47. };
  48. struct i915_pmu {
  49. /**
  50. * @base: PMU base.
  51. */
  52. struct pmu base;
  53. /**
  54. * @registered: PMU is registered and not in the unregistering process.
  55. */
  56. bool registered;
  57. /**
  58. * @name: Name as registered with perf core.
  59. */
  60. const char *name;
  61. /**
  62. * @lock: Lock protecting enable mask and ref count handling.
  63. */
  64. spinlock_t lock;
  65. /**
  66. * @unparked: GT unparked mask.
  67. */
  68. unsigned int unparked;
  69. /**
  70. * @timer: Timer for internal i915 PMU sampling.
  71. */
  72. struct hrtimer timer;
  73. /**
  74. * @enable: Bitmask of specific enabled events.
  75. *
  76. * For some events we need to track their state and do some internal
  77. * house keeping.
  78. *
  79. * Each engine event sampler type and event listed in enum
  80. * i915_pmu_tracked_events gets a bit in this field.
  81. *
  82. * Low bits are engine samplers and other events continue from there.
  83. */
  84. u32 enable;
  85. /**
  86. * @timer_last:
  87. *
  88. * Timestamp of the previous timer invocation.
  89. */
  90. ktime_t timer_last;
  91. /**
  92. * @enable_count: Reference counts for the enabled events.
  93. *
  94. * Array indices are mapped in the same way as bits in the @enable field
  95. * and they are used to control sampling on/off when multiple clients
  96. * are using the PMU API.
  97. */
  98. unsigned int enable_count[I915_PMU_MASK_BITS];
  99. /**
  100. * @timer_enabled: Should the internal sampling timer be running.
  101. */
  102. bool timer_enabled;
  103. /**
  104. * @sample: Current and previous (raw) counters for sampling events.
  105. *
  106. * These counters are updated from the i915 PMU sampling timer.
  107. *
  108. * Only global counters are held here, while the per-engine ones are in
  109. * struct intel_engine_cs.
  110. */
  111. struct i915_pmu_sample sample[I915_PMU_MAX_GT][__I915_NUM_PMU_SAMPLERS];
  112. /**
  113. * @sleep_last: Last time GT parked for RC6 estimation.
  114. */
  115. ktime_t sleep_last[I915_PMU_MAX_GT];
  116. /**
  117. * @irq_count: Number of interrupts
  118. *
  119. * Intentionally unsigned long to avoid atomics or heuristics on 32bit.
  120. * 4e9 interrupts are a lot and postprocessing can really deal with an
  121. * occasional wraparound easily. It's 32bit after all.
  122. */
  123. unsigned long irq_count;
  124. /**
  125. * @events_attr_group: Device events attribute group.
  126. */
  127. struct attribute_group events_attr_group;
  128. /**
  129. * @i915_attr: Memory block holding device attributes.
  130. */
  131. void *i915_attr;
  132. /**
  133. * @pmu_attr: Memory block holding device attributes.
  134. */
  135. void *pmu_attr;
  136. };
  137. #ifdef CONFIG_PERF_EVENTS
  138. void i915_pmu_register(struct drm_i915_private *i915);
  139. void i915_pmu_unregister(struct drm_i915_private *i915);
  140. void i915_pmu_gt_parked(struct intel_gt *gt);
  141. void i915_pmu_gt_unparked(struct intel_gt *gt);
  142. #else
  143. static inline void i915_pmu_register(struct drm_i915_private *i915) {}
  144. static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
  145. static inline void i915_pmu_gt_parked(struct intel_gt *gt) {}
  146. static inline void i915_pmu_gt_unparked(struct intel_gt *gt) {}
  147. #endif
  148. #endif