Re: [Intel-gfx] [CI] drm/i915/gt: Track the overall awake/busy time

2020-12-15 Thread Chris Wilson
Quoting Chris Wilson (2020-12-15 15:44:56)
> Since we wake the GT up before executing a request, and go to sleep as
> soon as it is retired, the GT wake time not only represents how long the
> device is powered up, but also provides a summary, albeit an overestimate,
> of the device runtime (i.e. the rc0 time to compare against rc6 time).
> 
> v2: s/busy/awake/
> v3: software-awake-time and I915_PMU_SOFTWARE_AWAKE_TIME

Last minute change to
__event(I915_PMU_SOFTWARE_GT_AWAKE_TIME, "software-gt-awake-time", "ns"),
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [CI] drm/i915/gt: Track the overall awake/busy time

2020-12-15 Thread Chris Wilson
Since we wake the GT up before executing a request, and go to sleep as
soon as it is retired, the GT wake time not only represents how long the
device is powered up, but also provides a summary, albeit an overestimate,
of the device runtime (i.e. the rc0 time to compare against rc6 time).

v2: s/busy/awake/
v3: software-awake-time and I915_PMU_SOFTWARE_AWAKE_TIME

Signed-off-by: Chris Wilson 
Reviewed-by: Tvrtko Ursulin 
Cc: Matthew Brost 
---
 drivers/gpu/drm/i915/gt/debugfs_gt_pm.c  |  5 ++-
 drivers/gpu/drm/i915/gt/intel_gt_pm.c| 49 
 drivers/gpu/drm/i915/gt/intel_gt_pm.h|  2 +
 drivers/gpu/drm/i915/gt/intel_gt_types.h | 24 
 drivers/gpu/drm/i915/i915_debugfs.c  |  5 ++-
 drivers/gpu/drm/i915/i915_pmu.c  |  6 +++
 include/uapi/drm/i915_drm.h  |  1 +
 7 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c 
b/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c
index 174a24553322..8975717ace06 100644
--- a/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c
+++ b/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c
@@ -11,6 +11,7 @@
 #include "i915_drv.h"
 #include "intel_gt.h"
 #include "intel_gt_clock_utils.h"
+#include "intel_gt_pm.h"
 #include "intel_llc.h"
 #include "intel_rc6.h"
 #include "intel_rps.h"
@@ -558,7 +559,9 @@ static int rps_boost_show(struct seq_file *m, void *data)
 
seq_printf(m, "RPS enabled? %s\n", yesno(intel_rps_is_enabled(rps)));
seq_printf(m, "RPS active? %s\n", yesno(intel_rps_is_active(rps)));
-   seq_printf(m, "GPU busy? %s\n", yesno(gt->awake));
+   seq_printf(m, "GPU busy? %s, %llums\n",
+  yesno(gt->awake),
+  ktime_to_ms(intel_gt_get_awake_time(gt)));
seq_printf(m, "Boosts outstanding? %d\n",
   atomic_read(>num_waiters));
seq_printf(m, "Interactive? %d\n", READ_ONCE(rps->power.interactive));
diff --git a/drivers/gpu/drm/i915/gt/intel_gt_pm.c 
b/drivers/gpu/drm/i915/gt/intel_gt_pm.c
index 274aa0dd7050..c94e8ac884eb 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_pm.c
+++ b/drivers/gpu/drm/i915/gt/intel_gt_pm.c
@@ -39,6 +39,28 @@ static void user_forcewake(struct intel_gt *gt, bool suspend)
intel_gt_pm_put(gt);
 }
 
+static void runtime_begin(struct intel_gt *gt)
+{
+   local_irq_disable();
+   write_seqcount_begin(>stats.lock);
+   gt->stats.start = ktime_get();
+   gt->stats.active = true;
+   write_seqcount_end(>stats.lock);
+   local_irq_enable();
+}
+
+static void runtime_end(struct intel_gt *gt)
+{
+   local_irq_disable();
+   write_seqcount_begin(>stats.lock);
+   gt->stats.active = false;
+   gt->stats.total =
+   ktime_add(gt->stats.total,
+ ktime_sub(ktime_get(), gt->stats.start));
+   write_seqcount_end(>stats.lock);
+   local_irq_enable();
+}
+
 static int __gt_unpark(struct intel_wakeref *wf)
 {
struct intel_gt *gt = container_of(wf, typeof(*gt), wakeref);
@@ -67,6 +89,7 @@ static int __gt_unpark(struct intel_wakeref *wf)
i915_pmu_gt_unparked(i915);
 
intel_gt_unpark_requests(gt);
+   runtime_begin(gt);
 
return 0;
 }
@@ -79,6 +102,7 @@ static int __gt_park(struct intel_wakeref *wf)
 
GT_TRACE(gt, "\n");
 
+   runtime_end(gt);
intel_gt_park_requests(gt);
 
i915_vma_parked(gt);
@@ -106,6 +130,7 @@ static const struct intel_wakeref_ops wf_ops = {
 void intel_gt_pm_init_early(struct intel_gt *gt)
 {
intel_wakeref_init(>wakeref, gt->uncore->rpm, _ops);
+   seqcount_mutex_init(>stats.lock, >wakeref.mutex);
 }
 
 void intel_gt_pm_init(struct intel_gt *gt)
@@ -339,6 +364,30 @@ int intel_gt_runtime_resume(struct intel_gt *gt)
return intel_uc_runtime_resume(>uc);
 }
 
+static ktime_t __intel_gt_get_awake_time(const struct intel_gt *gt)
+{
+   ktime_t total = gt->stats.total;
+
+   if (gt->stats.active)
+   total = ktime_add(total,
+ ktime_sub(ktime_get(), gt->stats.start));
+
+   return total;
+}
+
+ktime_t intel_gt_get_awake_time(const struct intel_gt *gt)
+{
+   unsigned int seq;
+   ktime_t total;
+
+   do {
+   seq = read_seqcount_begin(>stats.lock);
+   total = __intel_gt_get_awake_time(gt);
+   } while (read_seqcount_retry(>stats.lock, seq));
+
+   return total;
+}
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftest_gt_pm.c"
 #endif
diff --git a/drivers/gpu/drm/i915/gt/intel_gt_pm.h 
b/drivers/gpu/drm/i915/gt/intel_gt_pm.h
index 60f0e2fbe55c..63846a856e7e 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_pm.h
+++ b/drivers/gpu/drm/i915/gt/intel_gt_pm.h
@@ -58,6 +58,8 @@ int intel_gt_resume(struct intel_gt *gt);
 void intel_gt_runtime_suspend(struct intel_gt *gt);
 int intel_gt_runtime_resume(struct intel_gt *gt);
 
+ktime_t intel_gt_get_awake_time(const struct intel_gt *gt);
+
 static inline bool is_mock_gt(const struct