drm/i915: add SNB power monitoring
Subsystems (2)
PATCH 1/2 drm/i915: add SNB power monitoring
Use CPU package registers to monitor CPU and GPU power consumption. Add a trace point for package power as well, to simplify data collection.
--- drivers/gpu/drm/i915/i915_debugfs.c | 50 +++++++++++++++++++++++++++------ drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/i915_reg.h | 3 ++ drivers/gpu/drm/i915/i915_trace.h | 14 +++++++++ drivers/gpu/drm/i915/intel_display.c | 3 ++ 5 files changed, 63 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +41 -9
@@ -1088,27 +1088,59 @@ static int i915_sr_status(struct seq_file *m, void *unused)return 0 ; } +/* Return current power draw in mW */ +static unsigned long i915_cur_power (struct drm_device *dev) +{ +drm_i915_private_t *dev_priv = dev->dev_private; +u32 pkg_power, units, tunit, eunit, punit; +unsigned long energy, time; + + units =I915_READ (GEN6_PKG_POWER_SKU_UNIT ); + pkg_power =I915_READ (GEN6_PKG_ENERGY_STATUS ); + + tunit = (units >>16 ) &0xf ;/* 1s / 2^tunit */ + eunit = (units >>8 ) &0x1f ;/* 1J / 2^enuit */ + punit = units &0xf ;/* 1W / 2^punit */ + + energy = pkg_power - dev_priv->last_pkg_power; + time =jiffies_to_msecs (jiffies) - dev_priv->last_pkg_power_time; + energy /= (1 << (eunit -10 )); + + dev_priv->last_pkg_power = pkg_power; + dev_priv->last_pkg_power_time =jiffies_to_msecs (jiffies); + +return (energy *1000 ) / time; +} +static int i915_emon_status (struct seq_file *m,void *unused) {struct drm_info_node *node = (struct drm_info_node *) m->private;struct drm_device *dev = node->minor->dev;drm_i915_private_t *dev_priv = dev->dev_private; -unsigned long temp, chipset, gfx;int ret; ret =mutex_lock_interruptible (&dev->struct_mutex);if (ret)return ret; - temp =i915_mch_val (dev_priv); - chipset =i915_chipset_val (dev_priv); - gfx =i915_gfx_val (dev_priv); -mutex_unlock (&dev->struct_mutex); +if (IS_GEN5 (dev)) { +unsigned long temp, chipset, gfx; + + temp =i915_mch_val (dev_priv); + chipset =i915_chipset_val (dev_priv); + gfx =i915_gfx_val (dev_priv); -seq_printf (m,"GMCH temp: %ld\n" , temp); -seq_printf (m,"Chipset power: %ld\n" , chipset); -seq_printf (m,"GFX power: %ld\n" , gfx); -seq_printf (m,"Total power: %ld\n" , chipset + gfx); +seq_printf (m,"GMCH temp: %ld\n" , temp); +seq_printf (m,"Chipset power: %ld\n" , chipset); +seq_printf (m,"GFX power: %ld\n" , gfx); +seq_printf (m,"Total power: %ld\n" , chipset + gfx); + }else if (IS_GEN6 (dev)) { +unsigned long power =i915_cur_power (dev); + +trace_i915_pkg_power (power); +seq_printf (m,"Current power draw: %ldmW\n" , power); + } +mutex_unlock (&dev->struct_mutex);return 0 ; }
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -697,6 +697,8 @@ typedef struct drm_i915_private {int r_t;u8 corr;spinlock_t *mchdev_lock; +u32 last_pkg_power; +unsigned long last_pkg_power_time;enum no_fbc_reason no_fbc_reason;
drivers/gpu/drm/i915/i915_reg.h +3 -0
@@ -1244,6 +1244,9 @@#define GEN6_RP_STATE_LIMITS 0x145994#define GEN6_RP_STATE_CAP 0x145998 +#define GEN6_PKG_POWER_SKU_UNIT 0x145938 +#define GEN6_PKG_ENERGY_STATUS 0x14593c +/* * Logical Context regs */
drivers/gpu/drm/i915/i915_trace.h +14 -0
@@ -410,6 +410,20 @@ TRACE_EVENT(i915_reg_rw, (u32)(__entry->val >> 32)) ); +TRACE_EVENT (i915_pkg_power, + TP_PROTO(unsigned long power), +TP_ARGS (power), +TP_STRUCT__entry ( + __field(unsigned long, power) + ), + +TP_fast_assign ( + __entry->power = power; + ), + +TP_printk ("pkg power=%ld" , __entry->power) +); +#endif /* _I915_TRACE_H_ */ /* This part must be outside protection */
drivers/gpu/drm/i915/intel_display.c +3 -0
@@ -6959,6 +6959,9 @@ void gen6_enable_rps(struct drm_i915_private *dev_priv)I915_WRITE (GEN6_PMINTRMSK ,0 );__gen6_force_wake_put (dev_priv); + + dev_priv->last_pkg_power =I915_READ (GEN6_PKG_ENERGY_STATUS ); + dev_priv->last_pkg_power_time =jiffies_to_msecs (jiffies); }void intel_enable_clock_gating (struct drm_device *dev)
Signature · 1 line
1.7.1
PATCH 2/2 drm/i915: add idle/busy tracepoints
Add trace points for when the GPU goes from idle to busy and vice-versa. Also trace when we start to idle the GPU and when it finally does idle (this could take awhile if the ring is full of commands).
--- drivers/gpu/drm/i915/i915_drv.h | 4 +++ drivers/gpu/drm/i915/i915_gem.c | 4 +++ drivers/gpu/drm/i915/i915_irq.c | 5 ++++ drivers/gpu/drm/i915/i915_trace.h | 35 +++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.c | 6 +++++ 5 files changed, 54 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -674,6 +674,10 @@ typedef struct drm_i915_private {int lvds_downclock;struct work_struct idle_work;struct timer_list idle_timer; + +bool gpu_busy; +unsigned long gpu_busy_start; +bool busy;u16 orig_clock;int child_dev_num;
drivers/gpu/drm/i915/i915_gem.c +4 -0
@@ -2208,6 +2208,8 @@ i915_gpu_idle(struct drm_device *dev)bool lists_empty;int ret, i; +trace_i915_gpu_idle_start (dev); + lists_empty = (list_empty (&dev_priv->mm.flushing_list) &&list_empty (&dev_priv->mm.active_list));if (lists_empty)
@@ -2220,6 +2222,8 @@ i915_gpu_idle(struct drm_device *dev)return ret; } +trace_i915_gpu_idle_end (dev); +return 0 ; }
drivers/gpu/drm/i915/i915_irq.c +5 -0
@@ -365,6 +365,11 @@ static void notify_ring(struct drm_device *dev, dev_priv->hangcheck_count =0 ;mod_timer (&dev_priv->hangcheck_timer, jiffies +msecs_to_jiffies (DRM_I915_HANGCHECK_PERIOD )); + +if (I915_READ_HEAD (ring) ==I915_READ_TAIL (ring)) { + dev_priv->gpu_busy = false; +trace_i915_gpu_busy_end (dev_priv->dev); + } }static void gen6_pm_irq_handler (struct drm_device *dev)
drivers/gpu/drm/i915/i915_trace.h +35 -0
@@ -410,6 +410,41 @@ TRACE_EVENT(i915_reg_rw, (u32)(__entry->val >> 32)) ); +DECLARE_EVENT_CLASS (i915_gpu_global, + TP_PROTO(struct drm_device *dev), +TP_ARGS (dev), + +TP_STRUCT__entry ( +__field (int, dev) + ), + +TP_fast_assign ( + __entry->dev = dev->primary->index; + ), + +TP_printk ("dev=%d" , __entry->dev) +); + +DEFINE_EVENT (i915_gpu_global, i915_gpu_idle_start, + TP_PROTO(struct drm_device *dev), +TP_ARGS (dev) +); + +DEFINE_EVENT (i915_gpu_global, i915_gpu_idle_end, + TP_PROTO(struct drm_device *dev), +TP_ARGS (dev) +); + +DEFINE_EVENT (i915_gpu_global, i915_gpu_busy_start, + TP_PROTO(struct drm_device *dev), +TP_ARGS (dev) +); + +DEFINE_EVENT (i915_gpu_global, i915_gpu_busy_end, + TP_PROTO(struct drm_device *dev), +TP_ARGS (dev) +); + TRACE_EVENT(i915_pkg_power, TP_PROTO(unsigned long power), TP_ARGS(power),
drivers/gpu/drm/i915/intel_ringbuffer.c +6 -0
@@ -1089,6 +1089,12 @@ gen6_ring_dispatch_execbuffer(struct intel_ring_buffer *ring,intel_ring_emit (ring, offset);intel_ring_advance (ring); +if (!dev_priv->gpu_busy) { + dev_priv->gpu_busy = true; +trace_i915_gpu_busy_start (ring->dev); + dev_priv->gpu_busy_start = jiffies; + } +return 0 ; }
Signature · 1 line
1.7.1
Re: [PATCH 2/2] drm/i915: add idle/busy tracepoints
Quoted 55 lines · Jesse Barnes
Add trace points for when the GPU goes from idle to busy and vice-versa. Also trace when we start to idle the GPU and when it finally does idle (this could take awhile if the ring is full of commands).
Signed-off-by Jesse Barnes <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 4 +++ drivers/gpu/drm/i915/i915_gem.c | 4 +++ drivers/gpu/drm/i915/i915_irq.c | 5 ++++ drivers/gpu/drm/i915/i915_trace.h | 35 +++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.c | 6 +++++ 5 files changed, 54 insertions(+), 0 deletions(-)drivers/gpu/drm/i915/i915_drv.h +4
-0@@ -674,6 +674,10 @@ typedef struct drm_i915_private {int lvds_downclock;struct work_struct idle_work;struct timer_list idle_timer; + +bool gpu_busy; +unsigned long gpu_busy_start; +bool busy;u16 orig_clock;int child_dev_num;drivers/gpu/drm/i915/i915_gem.c +4
-0@@ -2208,6 +2208,8 @@ i915_gpu_idle(struct drm_device *dev)bool lists_empty;int ret, i; +trace_i915_gpu_idle_start (dev); + lists_empty = (list_empty (&dev_priv->mm.flushing_list) &&list_empty (&dev_priv->mm.active_list));if (lists_empty)@@ -2220,6 +2222,8 @@ i915_gpu_idle(struct drm_device *dev)return ret; } +trace_i915_gpu_idle_end (dev); +return 0 ; }drivers/gpu/drm/i915/i915_irq.c +0
-0
drivers/gpu/drm/i915/i915_irq.c static void notify_ring(struct drm_device *dev, · line 373
Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +5
-0@@ -365,6 +365,11 @@ static void notify_ring(struct drm_device *dev, dev_priv->hangcheck_count =0 ;mod_timer (&dev_priv->hangcheck_timer, jiffies +msecs_to_jiffies (DRM_I915_HANGCHECK_PERIOD )); + +if (I915_READ_HEAD (ring) ==I915_READ_TAIL (ring)) { + dev_priv->gpu_busy = false; +trace_i915_gpu_busy_end (dev_priv->dev); + } }
IRQ notifies should in fact be few and far between. I do not see how you actually detect when the gpu goes idle should we not be waiting on a request. So I think you need a pair of ring->irq_get/irq_put in and add tracepoints for each ring as opposed to device! You can then have a device busy which is the summation of active rings...
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH 2/2] drm/i915: add idle/busy tracepoints
Quoted 63 lines · On Fri, 18 Mar 2011 18:12:25 +0000 Chris Wilson <[email protected]>…
Quoted 62 lines · Jesse Barnes
Add trace points for when the GPU goes from idle to busy and vice-versa. Also trace when we start to idle the GPU and when it finally does idle (this could take awhile if the ring is full of commands).
Signed-off-by Jesse Barnes <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 4 +++ drivers/gpu/drm/i915/i915_gem.c | 4 +++ drivers/gpu/drm/i915/i915_irq.c | 5 ++++ drivers/gpu/drm/i915/i915_trace.h | 35 +++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.c | 6 +++++ 5 files changed, 54 insertions(+), 0 deletions(-)drivers/gpu/drm/i915/i915_drv.h +4
-0@@ -674,6 +674,10 @@ typedef struct drm_i915_private {int lvds_downclock;struct work_struct idle_work;struct timer_list idle_timer; + +bool gpu_busy; +unsigned long gpu_busy_start; +bool busy;u16 orig_clock;int child_dev_num;drivers/gpu/drm/i915/i915_gem.c +4
-0@@ -2208,6 +2208,8 @@ i915_gpu_idle(struct drm_device *dev)bool lists_empty;int ret, i; +trace_i915_gpu_idle_start (dev); + lists_empty = (list_empty (&dev_priv->mm.flushing_list) &&list_empty (&dev_priv->mm.active_list));if (lists_empty)@@ -2220,6 +2222,8 @@ i915_gpu_idle(struct drm_device *dev)return ret; } +trace_i915_gpu_idle_end (dev); +return 0 ; }drivers/gpu/drm/i915/i915_irq.c +4
-0@@ -365,6 +365,11 @@ static void notify_ring(struct drm_device *dev, dev_priv->hangcheck_count =0 ;mod_timer (&dev_priv->hangcheck_timer, jiffies +msecs_to_jiffies (DRM_I915_HANGCHECK_PERIOD )); + +if (I915_READ_HEAD (ring) ==I915_READ_TAIL (ring)) { + dev_priv->gpu_busy = false; +trace_i915_gpu_busy_end (dev_priv->dev);
Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c static void notify_ring(struct drm_device *dev, · line 373
Quoted 2 lines
drivers/gpu/drm/i915/i915_irq.c +1
-0+ } }IRQ notifies should in fact be few and far between. I do not see how you actually detect when the gpu goes idle should we not be waiting on a request. So I think you need a pair of ring->irq_get/irq_put in and add tracepoints for each ring as opposed to device! You can then have a device busy which is the summation of active rings...
Oops, yeah I have a hack in my local tree that disables irq_put so I get a notify every time. We only want that if tracing is enabled though (even then it will make things a lot noisier and affect CPU utilization, but I guess totally invisible tracing isn't really possible).
Would probably be better to have trace points per ring to track busy idle for each. I'll fix it up.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center