Home | History | Annotate | Line # | Download | only in i915
      1  1.1  riastrad /*	$NetBSD: i915_pmu.h,v 1.2 2021/12/18 23:45:28 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * SPDX-License-Identifier: MIT
      5  1.1  riastrad  *
      6  1.1  riastrad  * Copyright  2017-2018 Intel Corporation
      7  1.1  riastrad  */
      8  1.1  riastrad 
      9  1.1  riastrad #ifndef __I915_PMU_H__
     10  1.1  riastrad #define __I915_PMU_H__
     11  1.1  riastrad 
     12  1.1  riastrad #include <linux/hrtimer.h>
     13  1.1  riastrad #include <linux/perf_event.h>
     14  1.1  riastrad #include <linux/spinlock_types.h>
     15  1.1  riastrad #include <drm/i915_drm.h>
     16  1.1  riastrad 
     17  1.1  riastrad struct drm_i915_private;
     18  1.1  riastrad 
     19  1.1  riastrad enum {
     20  1.1  riastrad 	__I915_SAMPLE_FREQ_ACT = 0,
     21  1.1  riastrad 	__I915_SAMPLE_FREQ_REQ,
     22  1.1  riastrad 	__I915_SAMPLE_RC6,
     23  1.1  riastrad 	__I915_SAMPLE_RC6_LAST_REPORTED,
     24  1.1  riastrad 	__I915_NUM_PMU_SAMPLERS
     25  1.1  riastrad };
     26  1.1  riastrad 
     27  1.1  riastrad /**
     28  1.1  riastrad  * How many different events we track in the global PMU mask.
     29  1.1  riastrad  *
     30  1.1  riastrad  * It is also used to know to needed number of event reference counters.
     31  1.1  riastrad  */
     32  1.1  riastrad #define I915_PMU_MASK_BITS \
     33  1.1  riastrad 	((1 << I915_PMU_SAMPLE_BITS) + \
     34  1.1  riastrad 	 (I915_PMU_LAST + 1 - __I915_PMU_OTHER(0)))
     35  1.1  riastrad 
     36  1.1  riastrad #define I915_ENGINE_SAMPLE_COUNT (I915_SAMPLE_SEMA + 1)
     37  1.1  riastrad 
     38  1.1  riastrad struct i915_pmu_sample {
     39  1.1  riastrad 	u64 cur;
     40  1.1  riastrad };
     41  1.1  riastrad 
     42  1.1  riastrad struct i915_pmu {
     43  1.1  riastrad 	/**
     44  1.1  riastrad 	 * @node: List node for CPU hotplug handling.
     45  1.1  riastrad 	 */
     46  1.1  riastrad 	struct hlist_node node;
     47  1.1  riastrad 	/**
     48  1.1  riastrad 	 * @base: PMU base.
     49  1.1  riastrad 	 */
     50  1.1  riastrad 	struct pmu base;
     51  1.1  riastrad 	/**
     52  1.1  riastrad 	 * @name: Name as registered with perf core.
     53  1.1  riastrad 	 */
     54  1.1  riastrad 	const char *name;
     55  1.1  riastrad 	/**
     56  1.1  riastrad 	 * @lock: Lock protecting enable mask and ref count handling.
     57  1.1  riastrad 	 */
     58  1.1  riastrad 	spinlock_t lock;
     59  1.1  riastrad 	/**
     60  1.1  riastrad 	 * @timer: Timer for internal i915 PMU sampling.
     61  1.1  riastrad 	 */
     62  1.1  riastrad 	struct hrtimer timer;
     63  1.1  riastrad 	/**
     64  1.1  riastrad 	 * @enable: Bitmask of all currently enabled events.
     65  1.1  riastrad 	 *
     66  1.1  riastrad 	 * Bits are derived from uAPI event numbers in a way that low 16 bits
     67  1.1  riastrad 	 * correspond to engine event _sample_ _type_ (I915_SAMPLE_QUEUED is
     68  1.1  riastrad 	 * bit 0), and higher bits correspond to other events (for instance
     69  1.1  riastrad 	 * I915_PMU_ACTUAL_FREQUENCY is bit 16 etc).
     70  1.1  riastrad 	 *
     71  1.1  riastrad 	 * In other words, low 16 bits are not per engine but per engine
     72  1.1  riastrad 	 * sampler type, while the upper bits are directly mapped to other
     73  1.1  riastrad 	 * event types.
     74  1.1  riastrad 	 */
     75  1.1  riastrad 	u64 enable;
     76  1.1  riastrad 
     77  1.1  riastrad 	/**
     78  1.1  riastrad 	 * @timer_last:
     79  1.1  riastrad 	 *
     80  1.1  riastrad 	 * Timestmap of the previous timer invocation.
     81  1.1  riastrad 	 */
     82  1.1  riastrad 	ktime_t timer_last;
     83  1.1  riastrad 
     84  1.1  riastrad 	/**
     85  1.1  riastrad 	 * @enable_count: Reference counts for the enabled events.
     86  1.1  riastrad 	 *
     87  1.1  riastrad 	 * Array indices are mapped in the same way as bits in the @enable field
     88  1.1  riastrad 	 * and they are used to control sampling on/off when multiple clients
     89  1.1  riastrad 	 * are using the PMU API.
     90  1.1  riastrad 	 */
     91  1.1  riastrad 	unsigned int enable_count[I915_PMU_MASK_BITS];
     92  1.1  riastrad 	/**
     93  1.1  riastrad 	 * @timer_enabled: Should the internal sampling timer be running.
     94  1.1  riastrad 	 */
     95  1.1  riastrad 	bool timer_enabled;
     96  1.1  riastrad 	/**
     97  1.1  riastrad 	 * @sample: Current and previous (raw) counters for sampling events.
     98  1.1  riastrad 	 *
     99  1.1  riastrad 	 * These counters are updated from the i915 PMU sampling timer.
    100  1.1  riastrad 	 *
    101  1.1  riastrad 	 * Only global counters are held here, while the per-engine ones are in
    102  1.1  riastrad 	 * struct intel_engine_cs.
    103  1.1  riastrad 	 */
    104  1.1  riastrad 	struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS];
    105  1.1  riastrad 	/**
    106  1.1  riastrad 	 * @sleep_last: Last time GT parked for RC6 estimation.
    107  1.1  riastrad 	 */
    108  1.1  riastrad 	ktime_t sleep_last;
    109  1.1  riastrad 	/**
    110  1.1  riastrad 	 * @i915_attr: Memory block holding device attributes.
    111  1.1  riastrad 	 */
    112  1.1  riastrad 	void *i915_attr;
    113  1.1  riastrad 	/**
    114  1.1  riastrad 	 * @pmu_attr: Memory block holding device attributes.
    115  1.1  riastrad 	 */
    116  1.1  riastrad 	void *pmu_attr;
    117  1.1  riastrad };
    118  1.1  riastrad 
    119  1.1  riastrad #ifdef CONFIG_PERF_EVENTS
    120  1.1  riastrad void i915_pmu_register(struct drm_i915_private *i915);
    121  1.1  riastrad void i915_pmu_unregister(struct drm_i915_private *i915);
    122  1.1  riastrad void i915_pmu_gt_parked(struct drm_i915_private *i915);
    123  1.1  riastrad void i915_pmu_gt_unparked(struct drm_i915_private *i915);
    124  1.1  riastrad #else
    125  1.1  riastrad static inline void i915_pmu_register(struct drm_i915_private *i915) {}
    126  1.1  riastrad static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
    127  1.1  riastrad static inline void i915_pmu_gt_parked(struct drm_i915_private *i915) {}
    128  1.1  riastrad static inline void i915_pmu_gt_unparked(struct drm_i915_private *i915) {}
    129  1.1  riastrad #endif
    130  1.1  riastrad 
    131  1.1  riastrad #endif
    132