All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>,
	Tvrtko Ursulin <tursulin@ursulin.net>,
	Intel-gfx@lists.freedesktop.org
Subject: Re: [RFC v5 05/11] drm/i915/pmu: Suspend sampling when GPU is idle
Date: Fri, 15 Sep 2017 10:22:13 +0100	[thread overview]
Message-ID: <1252bbda-91f6-34a9-cc1e-ce2b4cef5fd0@linux.intel.com> (raw)
In-Reply-To: <150541903790.19729.13390119802028314652@mail.alporthouse.com>


On 14/09/2017 20:57, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2017-09-13 11:34:17)
>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> If only a subset of events is enabled we can afford to suspend
>> the sampling timer when the GPU is idle and so save some cycles
>> and power.
>>
>> v2: Rebase and limit timer even more.
>> v3: Rebase.
>> v4: Rebase.
>> v5: Skip action if perf PMU failed to register.
>>
>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>> ---
>>   drivers/gpu/drm/i915/i915_drv.h         |  8 ++++
>>   drivers/gpu/drm/i915/i915_gem.c         |  1 +
>>   drivers/gpu/drm/i915/i915_gem_request.c |  1 +
>>   drivers/gpu/drm/i915/i915_pmu.c         | 70 ++++++++++++++++++++++++++++-----
>>   4 files changed, 70 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
>> index 62646b8dfb7a..70be8c5d9a65 100644
>> --- a/drivers/gpu/drm/i915/i915_drv.h
>> +++ b/drivers/gpu/drm/i915/i915_drv.h
>> @@ -2244,6 +2244,10 @@ struct i915_pmu {
>>           */
>>          unsigned int enable_count[I915_PMU_MASK_BITS];
>>          /**
>> +        * @timer_enabled: Should the internal sampling timer be running.
>> +        */
>> +       bool timer_enabled;
>> +       /**
>>           * @sample: Current counter value for i915 events which need sampling.
>>           *
>>           * These counters are updated from the i915 PMU sampling timer.
>> @@ -3989,9 +3993,13 @@ extern void i915_perf_unregister(struct drm_i915_private *dev_priv);
>>   #ifdef CONFIG_PERF_EVENTS
>>   extern void i915_pmu_register(struct drm_i915_private *i915);
>>   extern void i915_pmu_unregister(struct drm_i915_private *i915);
>> +extern void i915_pmu_gt_idle(struct drm_i915_private *i915);
>> +extern void i915_pmu_gt_active(struct drm_i915_private *i915);
>>   #else
>>   static inline void i915_pmu_register(struct drm_i915_private *i915) {}
>>   static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
>> +static inline void i915_pmu_gt_idle(struct drm_i915_private *i915) {}
>> +static inline void i915_pmu_gt_active(struct drm_i915_private *i915) {}
>>   #endif
>>   
>>   /* i915_suspend.c */
>> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
>> index f445587c1a4b..201b09eda93b 100644
>> --- a/drivers/gpu/drm/i915/i915_gem.c
>> +++ b/drivers/gpu/drm/i915/i915_gem.c
>> @@ -3227,6 +3227,7 @@ i915_gem_idle_work_handler(struct work_struct *work)
>>   
>>          intel_engines_mark_idle(dev_priv);
>>          i915_gem_timelines_mark_idle(dev_priv);
>> +       i915_pmu_gt_idle(dev_priv);
>>   
>>          GEM_BUG_ON(!dev_priv->gt.awake);
>>          dev_priv->gt.awake = false;
>> diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c
>> index 813a3b546d6e..18a1e379253e 100644
>> --- a/drivers/gpu/drm/i915/i915_gem_request.c
>> +++ b/drivers/gpu/drm/i915/i915_gem_request.c
>> @@ -258,6 +258,7 @@ static void mark_busy(struct drm_i915_private *i915)
>>          i915_update_gfx_val(i915);
>>          if (INTEL_GEN(i915) >= 6)
>>                  gen6_rps_busy(i915);
>> +       i915_pmu_gt_active(i915);
>>   
>>          queue_delayed_work(i915->wq,
>>                             &i915->gt.retire_work,
>> diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
>> index e82648e6635b..22246918757c 100644
>> --- a/drivers/gpu/drm/i915/i915_pmu.c
>> +++ b/drivers/gpu/drm/i915/i915_pmu.c
>> @@ -90,6 +90,52 @@ static unsigned int event_enabled_bit(struct perf_event *event)
>>          return config_enabled_bit(event->attr.config);
>>   }
>>   
>> +static bool pmu_needs_timer(struct drm_i915_private *i915, bool gpu_active)
>> +{
>> +       u64 enable = i915->pmu.enable;
>> +
>> +       enable &= config_enabled_mask(I915_PMU_ACTUAL_FREQUENCY) |
>> +                 config_enabled_mask(I915_PMU_REQUESTED_FREQUENCY) |
>> +                 ENGINE_SAMPLE_MASK;
>> +
>> +       if (!gpu_active)
>> +               enable &= ~ENGINE_SAMPLE_MASK;
> 
> Ok.

I'll add a comment here. It gets even more advanced when busy stats are 
added.

>> +
>> +       return enable;
>> +}
>> +
>> +void i915_pmu_gt_idle(struct drm_i915_private *i915)
>> +{
>> +       if (!i915->pmu.base.event_init)
>> +               return;
>> +
>> +       spin_lock_irq(&i915->pmu.lock);
>> +       /*
>> +        * Signal sampling timer to stop if only engine events are enabled and
>> +        * GPU went idle.
>> +        */
>> +       i915->pmu.timer_enabled = pmu_needs_timer(i915, false);
>> +       spin_unlock_irq(&i915->pmu.lock);
>> +}
>> +
>> +void i915_pmu_gt_active(struct drm_i915_private *i915)
>> +{
>> +       if (!i915->pmu.base.event_init)
>> +               return;
>> +
>> +       spin_lock_irq(&i915->pmu.lock);
>> +       /*
>> +        * Re-enable sampling timer when GPU goes active.
>> +        */
>> +       if (!i915->pmu.timer_enabled && pmu_needs_timer(i915, true)) {
>> +               i915->pmu.timer_enabled = true;
>> +               hrtimer_start_range_ns(&i915->pmu.timer,
>> +                                      ns_to_ktime(PERIOD), 0,
>> +                                      HRTIMER_MODE_REL_PINNED);
>> +       }
> 
> Duplication here, __i915_pmu_gt_active() for the critical section. Then
> also helps allay fears that we hold the spinlock which is not clear from
> the diff context below.

Agreed, good cleanup suggestion.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-09-15  9:22 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11 15:25 [RFC v3 00/11] i915 PMU and engine busy stats Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 01/11] drm/i915: Convert intel_rc6_residency_us to ns Tvrtko Ursulin
2017-09-14 19:48   ` Chris Wilson
2017-09-11 15:25 ` [RFC 02/11] drm/i915: Add intel_energy_uJ Tvrtko Ursulin
2017-09-14 19:49   ` Chris Wilson
2017-09-15  9:18     ` Tvrtko Ursulin
2017-09-14 20:36   ` Ville Syrjälä
2017-09-15  6:56     ` Tvrtko Ursulin
2017-09-15  8:51       ` Chris Wilson
2017-09-15 10:07         ` Tvrtko Ursulin
2017-09-15 10:34           ` Ville Syrjälä
2017-09-15 10:38             ` Chris Wilson
2017-09-15 11:16               ` Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 03/11] drm/i915: Extract intel_get_cagf Tvrtko Ursulin
2017-09-14 19:51   ` Chris Wilson
2017-09-11 15:25 ` [RFC 04/11] drm/i915/pmu: Expose a PMU interface for perf queries Tvrtko Ursulin
2017-09-12  2:06   ` Rogozhkin, Dmitry V
2017-09-12 14:59     ` Tvrtko Ursulin
2017-09-13  8:57       ` [RFC v6 " Tvrtko Ursulin
2017-09-13 10:34         ` [RFC v7 " Tvrtko Ursulin
2017-09-15  0:00           ` Rogozhkin, Dmitry V
2017-09-15  7:57             ` Tvrtko Ursulin
2017-09-14 19:46   ` [RFC " Chris Wilson
2017-09-11 15:25 ` [RFC 05/11] drm/i915/pmu: Suspend sampling when GPU is idle Tvrtko Ursulin
2017-09-13 10:34   ` [RFC v5 " Tvrtko Ursulin
2017-09-14 19:57     ` Chris Wilson
2017-09-15  9:22       ` Tvrtko Ursulin [this message]
2017-09-11 15:25 ` [RFC 06/11] drm/i915: Wrap context schedule notification Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 07/11] drm/i915: Engine busy time tracking Tvrtko Ursulin
2017-09-14 20:16   ` Chris Wilson
2017-09-15  9:45     ` Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 08/11] drm/i915: Export engine busy stats in debugfs Tvrtko Ursulin
2017-09-14 20:17   ` Chris Wilson
2017-09-15  9:46     ` Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 09/11] drm/i915/pmu: Wire up engine busy stats to PMU Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 10/11] drm/i915: Export engine stats API to other users Tvrtko Ursulin
2017-09-12 18:35   ` Ben Widawsky
2017-09-14 20:26   ` Chris Wilson
2017-09-15  9:49     ` Tvrtko Ursulin
2017-09-19 19:50       ` Ben Widawsky
2017-09-19 20:11         ` Rogozhkin, Dmitry V
2017-09-29 10:59   ` Joonas Lahtinen
2017-09-11 15:25 ` [RFC 11/11] drm/i915: Gate engine stats collection with a static key Tvrtko Ursulin
2017-09-13 12:18   ` [RFC v3 " Tvrtko Ursulin
2017-09-14 20:22     ` Chris Wilson
2017-09-15  9:51       ` Tvrtko Ursulin
2017-09-11 15:50 ` ✗ Fi.CI.BAT: warning for i915 PMU and engine busy stats (rev3) Patchwork
2017-09-12  2:03 ` [RFC v3 00/11] i915 PMU and engine busy stats Rogozhkin, Dmitry V
2017-09-12 14:54   ` Tvrtko Ursulin
2017-09-12 22:01     ` Rogozhkin, Dmitry V
2017-09-13  8:54       ` [RFC v6 04/11] drm/i915/pmu: Expose a PMU interface for perf queries Tvrtko Ursulin
2017-09-13  9:01       ` [RFC v3 00/11] i915 PMU and engine busy stats Tvrtko Ursulin
2017-09-13  9:34 ` ✗ Fi.CI.BAT: warning for i915 PMU and engine busy stats (rev4) Patchwork
2017-09-13 10:46 ` ✗ Fi.CI.BAT: failure for i915 PMU and engine busy stats (rev6) Patchwork
2017-09-13 13:27 ` ✓ Fi.CI.BAT: success for i915 PMU and engine busy stats (rev7) Patchwork
2017-09-13 21:24 ` ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1252bbda-91f6-34a9-cc1e-ce2b4cef5fd0@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=tursulin@ursulin.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.