From patchwork Tue Apr 19 06:49:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8877181 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B867CBF29F for ; Tue, 19 Apr 2016 06:49:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9842220268 for ; Tue, 19 Apr 2016 06:49:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4BF5420272 for ; Tue, 19 Apr 2016 06:49:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8833E6E6A5; Tue, 19 Apr 2016 06:49:44 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id DD9666E6A5 for ; Tue, 19 Apr 2016 06:49:41 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id y144so2252418wmd.0 for ; Mon, 18 Apr 2016 23:49:41 -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=lw2bfC3aK8byCAqDaobgguUYvYghd5yczWW0GYct52c=; b=y6xQgA7IZp7GQT9DzrgA4tWjMssfE19yXYIJQRYZDEq12o4FxbZYh9LltRu7zW48cx Z2ycHCSH0ex3z5OrzTjRwCYXWcdthJkVWEm6YkM1aEWPd38VGJ4UV1AjS3L5YD+Ya0nX gA3jfjTXB8lWGekSrqBS74zIsNg/kdkTHj0kw+T2xJkKVdBecPyyhs7K1GC7iXpPEzQo +W6UJAV6OSkejJT5vV9eKq0ikuzp/m/QcpFNxr170fXjDCPj8z5NwcAl0yMzjdrY+niM uw6F2HJMOCc0jhP+J8nAEkj5/W8t8Amq7QJqpLrLOpqXqQnlbpquJ50eGhDlh8HdM7Ri rM9Q== 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=lw2bfC3aK8byCAqDaobgguUYvYghd5yczWW0GYct52c=; b=fsWwXsbNLBdNFBrRu1JWxyU9ov+eQSp3uJo4QRUOkQsOKmfjfYAYD9z8PD8nSD3INQ m4Dwxob7/Xr8bf61GqEiRHpUzbLQCyk/wqGGWG2mmmtTC1BNRF+4DR+tKupSUVmRqJbe QblPsr9SxuWiJYC0QG525Iazf3yRa0ds3W5iEnGzDvjE7iqGDsA0xY7FsdGfflZrbAAi eDfB6lPPGpqRgXNyzhQ+w51Hylsy0jxS2snJ5fkQQ+Vgmep5P65OaWeYg2Arf1lPmbib moRGtnzerh+s9i9/Z7fo4EE1WCk7xZe3DqYLVKJ5amOEkBP7jrNwOOlO/ucICsulmSd9 hrgA== X-Gm-Message-State: AOPr4FVMrfTWShsudJ1Me4ivymbWPNf//nJDZe+TPCw5YqLJ3NN1yA0B99OYPQIQ0SV6fA== X-Received: by 10.28.111.77 with SMTP id k74mr1655752wmc.37.1461048580242; Mon, 18 Apr 2016 23:49:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Apr 2016 23:49:39 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org, Tvrtko Ursulin Date: Tue, 19 Apr 2016 07:49:20 +0100 Message-Id: <1461048560-31983-10-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 9/9] drm/i915: Move releasing of the GEM request from free to retire/cancel 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 If we move the release of the GEM request (i.e. decoupling it from the various lists used for client and context tracking) after it is complete (either by the GPU retiring the request, or by the caller cancelling the request), we can remove the requirement that the final unreference of the GEM request need to be under the struct_mutex. v2,v3: Rebalance execlists by moving the context unpinning. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_gem.c | 4 ++-- drivers/gpu/drm/i915/i915_gem_request.c | 25 ++++++++++--------------- drivers/gpu/drm/i915/i915_gem_request.h | 14 -------------- drivers/gpu/drm/i915/intel_breadcrumbs.c | 2 +- drivers/gpu/drm/i915/intel_display.c | 2 +- drivers/gpu/drm/i915/intel_lrc.c | 4 ---- drivers/gpu/drm/i915/intel_pm.c | 2 +- 7 files changed, 15 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 4057c0febccd..1f5434f7a294 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2542,7 +2542,7 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file) ret = __i915_wait_request(req[i], true, args->timeout_ns > 0 ? &args->timeout_ns : NULL, to_rps_client(file)); - i915_gem_request_unreference__unlocked(req[i]); + i915_gem_request_unreference(req[i]); } return ret; @@ -3548,7 +3548,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file) return 0; ret = __i915_wait_request(target, true, NULL, NULL); - i915_gem_request_unreference__unlocked(target); + i915_gem_request_unreference(target); return ret; } diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c index 8d7c415f1896..c14dca3d8b87 100644 --- a/drivers/gpu/drm/i915/i915_gem_request.c +++ b/drivers/gpu/drm/i915/i915_gem_request.c @@ -250,6 +250,7 @@ i915_gem_request_remove_from_client(struct drm_i915_gem_request *request) static void i915_gem_request_retire(struct drm_i915_gem_request *request) { trace_i915_gem_request_retire(request); + list_del_init(&request->list); /* We know the GPU must have read the request to have * sent us the seqno + interrupt, so use the position @@ -261,9 +262,15 @@ static void i915_gem_request_retire(struct drm_i915_gem_request *request) */ request->ringbuf->last_retired_head = request->postfix; - list_del_init(&request->list); i915_gem_request_remove_from_client(request); + if (request->pinned_context) { + if (i915.enable_execlists) + intel_lr_context_unpin(request->pinned_context, + request->engine); + } + + i915_gem_context_unreference(request->ctx); i915_gem_request_unreference(request); } @@ -636,19 +643,7 @@ int i915_wait_request(struct drm_i915_gem_request *req) void i915_gem_request_free(struct kref *req_ref) { - struct drm_i915_gem_request *req = container_of(req_ref, - typeof(*req), ref); - struct intel_context *ctx = req->ctx; - - if (req->file_priv) - i915_gem_request_remove_from_client(req); - - if (req->pinned_context) { - if (i915.enable_execlists) - intel_lr_context_unpin(req->pinned_context, - req->engine); - } - - i915_gem_context_unreference(ctx); + struct drm_i915_gem_request *req = + container_of(req_ref, typeof(*req), ref); 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 389813cbc19a..48bff7dc4f90 100644 --- a/drivers/gpu/drm/i915/i915_gem_request.h +++ b/drivers/gpu/drm/i915/i915_gem_request.h @@ -170,23 +170,9 @@ i915_gem_request_reference(struct drm_i915_gem_request *req) static inline void i915_gem_request_unreference(struct drm_i915_gem_request *req) { - WARN_ON(!mutex_is_locked(&req->engine->dev->struct_mutex)); kref_put(&req->ref, i915_gem_request_free); } -static inline void -i915_gem_request_unreference__unlocked(struct drm_i915_gem_request *req) -{ - struct drm_device *dev; - - if (!req) - return; - - dev = req->engine->dev; - if (kref_put_mutex(&req->ref, i915_gem_request_free, &dev->struct_mutex)) - mutex_unlock(&dev->struct_mutex); -} - static inline void i915_gem_request_assign(struct drm_i915_gem_request **pdst, struct drm_i915_gem_request *src) { diff --git a/drivers/gpu/drm/i915/intel_breadcrumbs.c b/drivers/gpu/drm/i915/intel_breadcrumbs.c index 79f175853548..d7d19e17318e 100644 --- a/drivers/gpu/drm/i915/intel_breadcrumbs.c +++ b/drivers/gpu/drm/i915/intel_breadcrumbs.c @@ -379,7 +379,7 @@ static int intel_breadcrumbs_signaler(void *arg) */ intel_engine_remove_wait(engine, &signal->wait); - i915_gem_request_unreference__unlocked(signal->request); + i915_gem_request_unreference(signal->request); /* Find the next oldest signal. Note that as we have * not been holding the lock, another client may diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index caff656417c2..07dfd55fff91 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -11370,7 +11370,7 @@ static void intel_mmio_flip_work_func(struct work_struct *work) WARN_ON(__i915_wait_request(mmio_flip->req, false, NULL, &mmio_flip->i915->rps.mmioflips)); - i915_gem_request_unreference__unlocked(mmio_flip->req); + i915_gem_request_unreference(mmio_flip->req); } /* For framebuffer backed by dmabuf, wait for fence */ diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index 0e55f206e592..0eaa74fab87b 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -587,7 +587,6 @@ static void execlists_context_queue(struct drm_i915_gem_request *request) struct drm_i915_gem_request *cursor; int num_elements = 0; - intel_lr_context_pin(request->ctx, request->engine); i915_gem_request_reference(request); spin_lock_bh(&engine->execlist_lock); @@ -1006,9 +1005,6 @@ 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) { - if (req->pinned_context) - intel_lr_context_unpin(req->pinned_context, engine); - list_del(&req->execlist_link); i915_gem_request_unreference(req); } diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c index b964c448bc03..565b725cd817 100644 --- a/drivers/gpu/drm/i915/intel_pm.c +++ b/drivers/gpu/drm/i915/intel_pm.c @@ -7364,7 +7364,7 @@ static void __intel_rps_boost_work(struct work_struct *work) if (!i915_gem_request_completed(req)) gen6_rps_boost(to_i915(req), NULL, req->emitted_jiffies); - i915_gem_request_unreference__unlocked(req); + i915_gem_request_unreference(req); kfree(boost); }