From patchwork Wed Jan 13 12:45:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 12016717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47AA2C433DB for ; Wed, 13 Jan 2021 12:46:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99F53230FC for ; Wed, 13 Jan 2021 12:46:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99F53230FC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8D8C6E97A; Wed, 13 Jan 2021 12:46:12 +0000 (UTC) Received: from fireflyinternet.com (unknown [77.68.26.236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A92E6E97A for ; Wed, 13 Jan 2021 12:46:11 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from build.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 23584214-1500050 for multiple; Wed, 13 Jan 2021 12:46:03 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 13 Jan 2021 12:45:59 +0000 Message-Id: <20210113124600.656-9-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210113124600.656-1-chris@chris-wilson.co.uk> References: <20210113124600.656-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 09/10] drm/i915/gt: Reduce engine runtime stats from seqlock to a latch X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chris Wilson Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 Reviewed-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 33 ++++++-------------- drivers/gpu/drm/i915/gt/intel_engine_stats.h | 24 +++----------- drivers/gpu/drm/i915/gt/intel_engine_types.h | 5 --- 3 files changed, 14 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_engine_cs.c b/drivers/gpu/drm/i915/gt/intel_engine_cs.c index e85396cadcb8..9142fefd5a17 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_cs.c +++ b/drivers/gpu/drm/i915/gt/intel_engine_cs.c @@ -342,7 +342,6 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id) engine->schedule = NULL; ewma__engine_latency_init(&engine->latency); - seqcount_init(&engine->stats.lock); ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier); @@ -1733,22 +1732,6 @@ void intel_engine_dump(struct intel_engine_cs *engine, intel_engine_print_breadcrumbs(engine, m); } -static ktime_t __intel_engine_get_busy_time(struct intel_engine_cs *engine, - ktime_t *now) -{ - ktime_t total = engine->stats.total; - - /* - * If the engine is executing something at the moment - * add it to the total. - */ - *now = ktime_get(); - if (READ_ONCE(engine->stats.active)) - total = ktime_add(total, ktime_sub(*now, engine->stats.start)); - - return total; -} - /** * intel_engine_get_busy_time() - Return current accumulated engine busyness * @engine: engine to report on @@ -1758,13 +1741,17 @@ static ktime_t __intel_engine_get_busy_time(struct intel_engine_cs *engine, */ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine, ktime_t *now) { - unsigned int seq; - ktime_t total; + ktime_t total = engine->stats.total; - do { - seq = read_seqcount_begin(&engine->stats.lock); - total = __intel_engine_get_busy_time(engine, now); - } while (read_seqcount_retry(&engine->stats.lock, seq)); + /* + * If the engine is executing something at the moment + * add it to the total. + */ + *now = ktime_get(); + if (READ_ONCE(engine->stats.active)) { + smp_rmb(); /* pairs with intel_engine_context_in/out */ + total = ktime_add(total, ktime_sub(*now, engine->stats.start)); + } return total; } diff --git a/drivers/gpu/drm/i915/gt/intel_engine_stats.h b/drivers/gpu/drm/i915/gt/intel_engine_stats.h index 24fbdd94351a..1d8314257ffa 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_stats.h +++ b/drivers/gpu/drm/i915/gt/intel_engine_stats.h @@ -15,46 +15,30 @@ static inline void intel_engine_context_in(struct intel_engine_cs *engine) { - unsigned long flags; - if (engine->stats.active) { engine->stats.active++; return; } /* The writer is serialised; but the pmu reader may be from hardirq */ - local_irq_save(flags); - write_seqcount_begin(&engine->stats.lock); - engine->stats.start = ktime_get(); - engine->stats.active++; - - write_seqcount_end(&engine->stats.lock); - local_irq_restore(flags); - - GEM_BUG_ON(!engine->stats.active); + smp_wmb(); /* pairs with intel_engine_get_busy_time() */ + WRITE_ONCE(engine->stats.active, 1); } static inline void intel_engine_context_out(struct intel_engine_cs *engine) { - unsigned long flags; - GEM_BUG_ON(!engine->stats.active); if (engine->stats.active > 1) { engine->stats.active--; return; } - local_irq_save(flags); - write_seqcount_begin(&engine->stats.lock); - - engine->stats.active--; engine->stats.total = ktime_add(engine->stats.total, ktime_sub(ktime_get(), engine->stats.start)); - - write_seqcount_end(&engine->stats.lock); - local_irq_restore(flags); + smp_wmb(); /* pairs with intel_engine_get_busy_time() */ + WRITE_ONCE(engine->stats.active, 0); } #endif /* __INTEL_ENGINE_STATS_H__ */ diff --git a/drivers/gpu/drm/i915/gt/intel_engine_types.h b/drivers/gpu/drm/i915/gt/intel_engine_types.h index d2346b425547..ed13012b9338 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_types.h +++ b/drivers/gpu/drm/i915/gt/intel_engine_types.h @@ -518,11 +518,6 @@ struct intel_engine_cs { */ unsigned int active; - /** - * @lock: Lock protecting the below fields. - */ - seqcount_t lock; - /** * @total: Total time this engine was busy. *