From patchwork Tue Apr 19 06:49:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8877171 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F26EA9FB14 for ; Tue, 19 Apr 2016 06:49:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C6DAF20149 for ; Tue, 19 Apr 2016 06:49:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B72AB2015E for ; Tue, 19 Apr 2016 06:49:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0195D6E6A7; Tue, 19 Apr 2016 06:49:43 +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 C6C9F6E6A7 for ; Tue, 19 Apr 2016 06:49:40 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id y144so2252318wmd.0 for ; Mon, 18 Apr 2016 23:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=J3nuZElSGrm43H1M6ziOEY17txgJ//z5sGqNdV+A5ng=; b=SUeDQAeHk+O1/P+81GynQ8+Ui2+AovHAc7+YexKRn+iRxrUKfCeKNzLQWhc3t2zmY9 ChIrqqbrKsifs0SaJcPlLCjfjDNqRhSxPocJ9G8gQam3rPZWerLRxmiuclocfo2qe6Ur 3NyxcDxr/T3yXKdxmpxhvZA9H33oJh4b+Rz0IJkG3hZN7TMrrhax8qe0GH8Mfn3qesP9 Mf3NpyBFyPLH1Q/8va2sxTFiHe/izIlukLBs9wDAhN1DZY4ydOcmQ9Dmn3GLzoAqzJoc e13fFXg8Ll6YeWBYee9CWt5ONhvrzzuEFjCYdqOCZFm1H+l9O3gcjzpismdsD4z4Ounb /ZVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=J3nuZElSGrm43H1M6ziOEY17txgJ//z5sGqNdV+A5ng=; b=NzrhVMi7aW7PmsKgCf0mANJE2yOz72uSTHwkMqBNCTXeg89gK8b/mcCiN57L0uazNa 1WBjUf8EM77M6bfu9R+gFrKqOsHNzG8S0l13XibpD91ccRVmDIO99sMidRC/RHoX0ZZy Ca3QKbvININ+VhRQW5gJ7foL2ZQYcmyx6y8weN2F/+oTAzxT1keQOTIV3//YGhtaJ5Df Isgt0YblP82qdvVwZj5ac1oyDldblOYUCrLfvG0ftwBMQWNC3xMgW926tCxx1Uv+ajG1 NVMSiHp0SkZx9YFdkTj6zvu6jF3w3QQog1SHCqK6xHMMcN452X2BZZdeI6sTnv+LLYOR Gd3A== X-Gm-Message-State: AOPr4FXTLd+b6o3YCSC/AQ5xfWRwB4cnEltgex5f0NWubUlJYve2uZBtL3HXYNpwzBBvBQ== X-Received: by 10.194.95.167 with SMTP id dl7mr1263083wjb.163.1461048578982; Mon, 18 Apr 2016 23:49:38 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id w10sm56479720wjz.9.2016.04.18.23.49.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Apr 2016 23:49:37 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org, Tvrtko Ursulin Date: Tue, 19 Apr 2016 07:49:19 +0100 Message-Id: <1461048560-31983-9-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1461048560-31983-1-git-send-email-chris@chris-wilson.co.uk> References: <1460721275-1001-1-git-send-email-tvrtko.ursulin@linux.intel.com> <1461048560-31983-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 8/9] drm/i915: Track the previous pinned context inside the request 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: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As the contexts are accessed by the hardware until the switch is completed to a new context, the hardware may still be writing to the context object after the breadcrumb is visible. We must not unpin/unbind/prune that object whilst still active and so we keep the previous context pinned until the following request. If we move this tracking onto the request, we can simplify the code and enable freeing of the request without the struct_mutex in subsequent patches. Signed-off-by: Chris Wilson Reviewed-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_gem_request.c | 8 ++++---- drivers/gpu/drm/i915/i915_gem_request.h | 11 +++++++++++ drivers/gpu/drm/i915/intel_lrc.c | 12 +++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c index 33aacf1725dd..8d7c415f1896 100644 --- a/drivers/gpu/drm/i915/i915_gem_request.c +++ b/drivers/gpu/drm/i915/i915_gem_request.c @@ -643,12 +643,12 @@ void i915_gem_request_free(struct kref *req_ref) if (req->file_priv) i915_gem_request_remove_from_client(req); - if (ctx) { + if (req->pinned_context) { if (i915.enable_execlists) - intel_lr_context_unpin(ctx, req->engine); - - i915_gem_context_unreference(ctx); + intel_lr_context_unpin(req->pinned_context, + req->engine); } + i915_gem_context_unreference(ctx); kmem_cache_free(to_i915(req)->requests, req); } diff --git a/drivers/gpu/drm/i915/i915_gem_request.h b/drivers/gpu/drm/i915/i915_gem_request.h index 69a4d4e2c97b..389813cbc19a 100644 --- a/drivers/gpu/drm/i915/i915_gem_request.h +++ b/drivers/gpu/drm/i915/i915_gem_request.h @@ -85,6 +85,17 @@ struct drm_i915_gem_request { struct intel_context *ctx; struct intel_ringbuffer *ringbuf; + /** + * Context related to the previous request. + * As the contexts are accessed by the hardware until the switch is + * completed to a new context, the hardware may still be writing + * to the context object after the breadcrumb is visible. We must + * not unpin/unbind/prune that object whilst still active and so + * we keep the previous context pinned until the following (this) + * request is retired. + */ + struct intel_context *pinned_context; + /** Batch buffer related to this request if any (used for error state dump only) */ struct drm_i915_gem_object *batch_obj; diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index b0d20af38574..0e55f206e592 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -708,6 +708,7 @@ int intel_logical_ring_alloc_request_extras(struct drm_i915_gem_request *request request->ctx->engine[engine->id].initialised = true; } + request->pinned_context = request->ctx; return 0; } @@ -782,12 +783,8 @@ intel_logical_ring_advance_and_submit(struct drm_i915_gem_request *request) intel_logical_ring_emit(ringbuf, MI_NOOP); intel_logical_ring_advance(ringbuf); - if (engine->last_context != request->ctx) { - if (engine->last_context) - intel_lr_context_unpin(engine->last_context, engine); - intel_lr_context_pin(request->ctx, engine); - engine->last_context = request->ctx; - } + request->pinned_context = engine->last_context; + engine->last_context = request->ctx; if (dev_priv->guc.execbuf_client) i915_guc_submit(dev_priv->guc.execbuf_client, request); @@ -1009,7 +1006,8 @@ void intel_execlists_retire_requests(struct intel_engine_cs *engine) spin_unlock_bh(&engine->execlist_lock); list_for_each_entry_safe(req, tmp, &retired_list, execlist_link) { - intel_lr_context_unpin(req->ctx, engine); + if (req->pinned_context) + intel_lr_context_unpin(req->pinned_context, engine); list_del(&req->execlist_link); i915_gem_request_unreference(req);