i915_pmu.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <drm/i915_drm.h>
  12. struct drm_i915_private;
  13. enum {
  14. __I915_SAMPLE_FREQ_ACT = 0,
  15. __I915_SAMPLE_FREQ_REQ,
  16. __I915_SAMPLE_RC6,
  17. __I915_SAMPLE_RC6_ESTIMATED,
  18. __I915_NUM_PMU_SAMPLERS
  19. };
  20. /**
  21. * How many different events we track in the global PMU mask.
  22. *
  23. * It is also used to know to needed number of event reference counters.
  24. */
  25. #define I915_PMU_MASK_BITS \
  26. ((1 << I915_PMU_SAMPLE_BITS) + \
  27. (I915_PMU_LAST + 1 - __I915_PMU_OTHER(0)))
  28. struct i915_pmu_sample {
  29. u64 cur;
  30. };
  31. struct i915_pmu {
  32. /**
  33. * @node: List node for CPU hotplug handling.
  34. */
  35. struct hlist_node node;
  36. /**
  37. * @base: PMU base.
  38. */
  39. struct pmu base;
  40. /**
  41. * @lock: Lock protecting enable mask and ref count handling.
  42. */
  43. spinlock_t lock;
  44. /**
  45. * @timer: Timer for internal i915 PMU sampling.
  46. */
  47. struct hrtimer timer;
  48. /**
  49. * @enable: Bitmask of all currently enabled events.
  50. *
  51. * Bits are derived from uAPI event numbers in a way that low 16 bits
  52. * correspond to engine event _sample_ _type_ (I915_SAMPLE_QUEUED is
  53. * bit 0), and higher bits correspond to other events (for instance
  54. * I915_PMU_ACTUAL_FREQUENCY is bit 16 etc).
  55. *
  56. * In other words, low 16 bits are not per engine but per engine
  57. * sampler type, while the upper bits are directly mapped to other
  58. * event types.
  59. */
  60. u64 enable;
  61. /**
  62. * @enable_count: Reference counts for the enabled events.
  63. *
  64. * Array indices are mapped in the same way as bits in the @enable field
  65. * and they are used to control sampling on/off when multiple clients
  66. * are using the PMU API.
  67. */
  68. unsigned int enable_count[I915_PMU_MASK_BITS];
  69. /**
  70. * @timer_enabled: Should the internal sampling timer be running.
  71. */
  72. bool timer_enabled;
  73. /**
  74. * @sample: Current and previous (raw) counters for sampling events.
  75. *
  76. * These counters are updated from the i915 PMU sampling timer.
  77. *
  78. * Only global counters are held here, while the per-engine ones are in
  79. * struct intel_engine_cs.
  80. */
  81. struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS];
  82. /**
  83. * @suspended_jiffies_last: Cached suspend time from PM core.
  84. */
  85. unsigned long suspended_jiffies_last;
  86. /**
  87. * @i915_attr: Memory block holding device attributes.
  88. */
  89. void *i915_attr;
  90. /**
  91. * @pmu_attr: Memory block holding device attributes.
  92. */
  93. void *pmu_attr;
  94. };
  95. #ifdef CONFIG_PERF_EVENTS
  96. void i915_pmu_register(struct drm_i915_private *i915);
  97. void i915_pmu_unregister(struct drm_i915_private *i915);
  98. void i915_pmu_gt_parked(struct drm_i915_private *i915);
  99. void i915_pmu_gt_unparked(struct drm_i915_private *i915);
  100. #else
  101. static inline void i915_pmu_register(struct drm_i915_private *i915) {}
  102. static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
  103. static inline void i915_pmu_gt_parked(struct drm_i915_private *i915) {}
  104. static inline void i915_pmu_gt_unparked(struct drm_i915_private *i915) {}
  105. #endif
  106. #endif