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