blob: 1ac8b2e346075e9931ff568e9277284f9e937db9 [file] [log] [blame]
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +00001/*
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
27enum {
28 __I915_SAMPLE_FREQ_ACT = 0,
29 __I915_SAMPLE_FREQ_REQ,
30 __I915_NUM_PMU_SAMPLERS
31};
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
42struct i915_pmu_sample {
43 u64 cur;
44 u32 prev;
45};
46
47struct i915_pmu {
48 /**
49 * @node: List node for CPU hotplug handling.
50 */
51 struct hlist_node node;
52 /**
53 * @base: PMU base.
54 */
55 struct pmu base;
56 /**
57 * @lock: Lock protecting enable mask and ref count handling.
58 */
59 spinlock_t lock;
60 /**
61 * @timer: Timer for internal i915 PMU sampling.
62 */
63 struct hrtimer timer;
64 /**
65 * @enable: Bitmask of all currently enabled events.
66 *
67 * Bits are derived from uAPI event numbers in a way that low 16 bits
68 * correspond to engine event _sample_ _type_ (I915_SAMPLE_QUEUED is
69 * bit 0), and higher bits correspond to other events (for instance
70 * I915_PMU_ACTUAL_FREQUENCY is bit 16 etc).
71 *
72 * In other words, low 16 bits are not per engine but per engine
73 * sampler type, while the upper bits are directly mapped to other
74 * event types.
75 */
76 u64 enable;
77 /**
78 * @enable_count: Reference counts for the enabled events.
79 *
80 * Array indices are mapped in the same way as bits in the @enable field
81 * and they are used to control sampling on/off when multiple clients
82 * are using the PMU API.
83 */
84 unsigned int enable_count[I915_PMU_MASK_BITS];
85 /**
86 * @sample: Current and previous (raw) counters for sampling events.
87 *
88 * These counters are updated from the i915 PMU sampling timer.
89 *
90 * Only global counters are held here, while the per-engine ones are in
91 * struct intel_engine_cs.
92 */
93 struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS];
94};
95
96#ifdef CONFIG_PERF_EVENTS
97void i915_pmu_register(struct drm_i915_private *i915);
98void i915_pmu_unregister(struct drm_i915_private *i915);
99#else
100static inline void i915_pmu_register(struct drm_i915_private *i915) {}
101static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
102#endif
103
104#endif