From patchwork Fri Mar 17 12:07:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9630483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 16BCA60245 for ; Fri, 17 Mar 2017 12:07:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 019A028138 for ; Fri, 17 Mar 2017 12:07:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA3EA2841E; Fri, 17 Mar 2017 12:07:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E68828138 for ; Fri, 17 Mar 2017 12:07:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA7F96E358; Fri, 17 Mar 2017 12:07:22 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id D83216E358 for ; Fri, 17 Mar 2017 12:07:20 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id z133so2945258wmb.2 for ; Fri, 17 Mar 2017 05:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TTUFlpbmloBQSO527PQ0rMAaQM3aYIDynYcaKo0aC1I=; b=ZBOIPwGD8FrBdKhSNmceuJ5gB0EVnyQefZZfg3IfyxtggZaGTsJQwvXODHRPPgi6U1 SwVcp70mGqIRfVakOQLzWVeIjPGS8Yv+rdUQ54E0Gdz3Yt8Qd71AvH39Ih6hME0EL/7w GzjGdCsNGzwFRS+uCtxjfSSf1jNRS3Z+K1tJRxHtNQe2p9AJSvbHAdq2moROEfQ1EN2q nH0x6l49/P30TtfBFUSFVJLc/Jt5ETeRZ2ogdtUY0ZIU/f1a67my1IeyhWYYwDGGHaUN 5n0q5fLB/L7Fqu9pSr59GpGluHzJvbaBhIOwc6DlidjN+Yysb4Nf//7cqMYGusGqftHA ZHzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TTUFlpbmloBQSO527PQ0rMAaQM3aYIDynYcaKo0aC1I=; b=jkn0IsZZttVXPDa5bWktz0yXSgl2CQfmijiGO9zmuHq/N+tui6pDq5UvGJ9DkWJvFF U6VNePVgf8N6Eg2wbmyajrJd4AgtwrwxWmExLM2OTSFw8/cFScnEmA82DJn6aUvhCgoZ eWbg7rVBQFYg5GfET5DVQO3/6LFcQwtH+pe4qger8y1QDQXNzccrNEh6lSoHH8LUIAYG /veMjH02/BJYxAdZ2cEqw/SCm3r41O7k0XnUlxdOVCwlCATtFoxEQ3cZu87oCOPpnd5N dJKBZSI+zleoPnKe6KxGFRA90F5Y09tGTNosDLoiPaIDFqBkOl52NCjbQTySb3vRgzde fNzw== X-Gm-Message-State: AFeK/H1P1Js6oxA34G21o/nelATvEEYtKKOoydVptct6I30XckrVEFqdTisIyOvxkDCWcA== X-Received: by 10.28.66.207 with SMTP id k76mr2550647wmi.121.1489752439518; Fri, 17 Mar 2017 05:07:19 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id c8sm9765832wrd.34.2017.03.17.05.07.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2017 05:07:18 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Fri, 17 Mar 2017 12:07:16 +0000 Message-Id: <20170317120716.17191-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170317112722.2848-1-chris@chris-wilson.co.uk> References: <20170317112722.2848-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v3] drm/i915: Skip execlists_dequeue() early if the list is empty X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Do an early read of the execlists' queue before we take the spinlock and start checking. This is safe as the first writer to the execlists queue will cause the tasklet to be run again after a memory barrier. v2: Keep guc in sync with execlists queue changes v3: Explain the mb between the tasklet running on one cpu and the execlist_first update and schedule from a second cpu. Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Cc: Joonas Lahtinen Cc: Michał Winiarski Reviewed-by: Tvrtko Ursulin Reviewed-by: Michał Winiarski --- drivers/gpu/drm/i915/i915_guc_submission.c | 12 ++++++++++++ drivers/gpu/drm/i915/intel_lrc.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c b/drivers/gpu/drm/i915/i915_guc_submission.c index a3636b31ebc3..832ac9e45801 100644 --- a/drivers/gpu/drm/i915/i915_guc_submission.c +++ b/drivers/gpu/drm/i915/i915_guc_submission.c @@ -577,6 +577,18 @@ static bool i915_guc_dequeue(struct intel_engine_cs *engine) struct rb_node *rb; bool submit = false; + /* After execlist_first is updated, the tasklet will be rescheduled. + * + * If we are currently running (inside the tasklet) and a third + * party queues a request and so updates engine->execlist_first under + * the spinlock (which we have elided), it will atomically set the + * TASKLET_SCHED flag causing the us to be re-executed and pick up + * the change in state (the update to TASKLET_SCHED incurs a memory + * barrier making this cross-cpu checking safe). + */ + if (!READ_ONCE(engine->execlist_first)) + return false; + spin_lock_irqsave(&engine->timeline->lock, flags); rb = engine->execlist_first; while (rb) { diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index becde55b02a3..77168e673e0a 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -403,6 +403,18 @@ static void execlists_dequeue(struct intel_engine_cs *engine) struct rb_node *rb; bool submit = false; + /* After execlist_first is updated, the tasklet will be rescheduled. + * + * If we are currently running (inside the tasklet) and a third + * party queues a request and so updates engine->execlist_first under + * the spinlock (which we have elided), it will atomically set the + * TASKLET_SCHED flag causing the us to be re-executed and pick up + * the change in state (the update to TASKLET_SCHED incurs a memory + * barrier making this cross-cpu checking safe). + */ + if (!READ_ONCE(engine->execlist_first)) + return; + last = port->request; if (last) /* WaIdleLiteRestore:bdw,skl