All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [CI 5/5] drm/i915/gt: Reduce GT runtime stats from seqlock to a latch
Date: Fri, 15 Jan 2021 14:23:31 +0000	[thread overview]
Message-ID: <20210115142331.24458-5-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20210115142331.24458-1-chris@chris-wilson.co.uk>

Since we can compute the elapsed time to add to the total, during the
PMU sample we only need to have a consistent view of the (start, total,
active) tuple to be able to locally determine the runtime. That can be
arrange by a pair of memory bariiers and carefully sequencing of the
writes and reads.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Andi Shyti <andi.shyti@intel.com>
---
 drivers/gpu/drm/i915/gt/intel_gt_pm.c    | 38 +++++++-----------------
 drivers/gpu/drm/i915/gt/intel_gt_types.h |  5 ----
 2 files changed, 10 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/intel_gt_pm.c b/drivers/gpu/drm/i915/gt/intel_gt_pm.c
index c94e8ac884eb..fb8be4e1f63e 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_pm.c
+++ b/drivers/gpu/drm/i915/gt/intel_gt_pm.c
@@ -41,24 +41,18 @@ static void user_forcewake(struct intel_gt *gt, bool suspend)
 
 static void runtime_begin(struct intel_gt *gt)
 {
-	local_irq_disable();
-	write_seqcount_begin(&gt->stats.lock);
 	gt->stats.start = ktime_get();
-	gt->stats.active = true;
-	write_seqcount_end(&gt->stats.lock);
-	local_irq_enable();
+	smp_wmb(); /* pairs with intel_gt_get_busy_time() */
+	WRITE_ONCE(gt->stats.active, true);
 }
 
 static void runtime_end(struct intel_gt *gt)
 {
-	local_irq_disable();
-	write_seqcount_begin(&gt->stats.lock);
-	gt->stats.active = false;
 	gt->stats.total =
 		ktime_add(gt->stats.total,
 			  ktime_sub(ktime_get(), gt->stats.start));
-	write_seqcount_end(&gt->stats.lock);
-	local_irq_enable();
+	smp_wmb(); /* pairs with intel_gt_get_busy_time() */
+	WRITE_ONCE(gt->stats.active, false);
 }
 
 static int __gt_unpark(struct intel_wakeref *wf)
@@ -130,7 +124,6 @@ static const struct intel_wakeref_ops wf_ops = {
 void intel_gt_pm_init_early(struct intel_gt *gt)
 {
 	intel_wakeref_init(&gt->wakeref, gt->uncore->rpm, &wf_ops);
-	seqcount_mutex_init(&gt->stats.lock, &gt->wakeref.mutex);
 }
 
 void intel_gt_pm_init(struct intel_gt *gt)
@@ -364,26 +357,15 @@ int intel_gt_runtime_resume(struct intel_gt *gt)
 	return intel_uc_runtime_resume(&gt->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;
+	ktime_t total = gt->stats.total;
+	ktime_t start = gt->stats.start;
 
-	do {
-		seq = read_seqcount_begin(&gt->stats.lock);
-		total = __intel_gt_get_awake_time(gt);
-	} while (read_seqcount_retry(&gt->stats.lock, seq));
+	if (READ_ONCE(gt->stats.active)) {
+		smp_rmb(); /* pairs with runtime_begin/end */
+		total = ktime_add(total, ktime_sub(ktime_get(), start));
+	}
 
 	return total;
 }
diff --git a/drivers/gpu/drm/i915/gt/intel_gt_types.h b/drivers/gpu/drm/i915/gt/intel_gt_types.h
index a83d3e18254d..4205c3f022ad 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_types.h
+++ b/drivers/gpu/drm/i915/gt/intel_gt_types.h
@@ -91,11 +91,6 @@ struct intel_gt {
 	struct {
 		bool active;
 
-		/**
-		 * @lock: Lock protecting the below fields.
-		 */
-		seqcount_mutex_t lock;
-
 		/**
 		 * @total: Total time this engine was busy.
 		 *
-- 
2.20.1

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

  parent reply	other threads:[~2021-01-15 14:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 14:23 [Intel-gfx] [CI 1/5] drm/i915/gt: Drop atomic for engine->fw_active tracking Chris Wilson
2021-01-15 14:23 ` [Intel-gfx] [CI 2/5] drm/i915/gt: Extract busy-stats for ring-scheduler Chris Wilson
2021-01-15 14:23 ` [Intel-gfx] [CI 3/5] drm/i915/gt: Convert stats.active to plain unsigned int Chris Wilson
2021-01-15 14:23 ` [Intel-gfx] [CI 4/5] drm/i915/gt: Reduce engine runtime stats from seqlock to a latch Chris Wilson
2021-01-15 14:23 ` Chris Wilson [this message]
2021-01-15 19:38 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for series starting with [CI,1/5] drm/i915/gt: Drop atomic for engine->fw_active tracking Patchwork
2021-01-15 19:40 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2021-01-15 20:07 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2021-01-16  3:18 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " 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=20210115142331.24458-5-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /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.