From patchwork Wed Dec 23 13:35:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 7912631 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 541B2BEEED for ; Wed, 23 Dec 2015 13:36:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C71A203DF for ; Wed, 23 Dec 2015 13:36:20 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 95D5E2047C for ; Wed, 23 Dec 2015 13:36:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 15C8A720AC; Wed, 23 Dec 2015 05:36:19 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [87.106.93.118]) by gabe.freedesktop.org (Postfix) with ESMTP id 67410720A5 for ; Wed, 23 Dec 2015 05:36:16 -0800 (PST) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 50367526-1500048 for multiple; Wed, 23 Dec 2015 13:36:26 +0000 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Wed, 23 Dec 2015 13:36:10 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Dec 2015 13:35:56 +0000 Message-Id: <1450877756-2902-3-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1450877756-2902-1-git-send-email-chris@chris-wilson.co.uk> References: <1450869563-23892-1-git-send-email-chris@chris-wilson.co.uk> <1450877756-2902-1-git-send-email-chris@chris-wilson.co.uk> X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH v2 3/3] drm/i915: Remove (struct_mutex) locking for busy-ioctl 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 By applying the same logic as for wait-ioctl, we can query whether a request has completed without holding struct_mutex. The biggest impact system-wide is removing the flush_active and the contention that causes. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_gem.c | 53 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 3e331f7e9d74..80810d5b5caf 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -3591,37 +3591,38 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, { struct drm_i915_gem_busy *args = data; struct drm_i915_gem_object *obj; - int ret; - - ret = i915_mutex_lock_interruptible(dev); - if (ret) - return ret; obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); - if (&obj->base == NULL) { - ret = -ENOENT; - goto unlock; - } + if (&obj->base == NULL) + return -ENOENT; - /* Count all active objects as busy, even if they are currently not used - * by the gpu. Users of this interface expect objects to eventually - * become non-busy without any further actions, therefore emit any - * necessary flushes here. - */ - ret = i915_gem_object_flush_active(obj); - if (ret) - goto unref; + args->busy = 0; + if (obj->active) { /* XXX READ_ONCE(obj->flags) */ + struct drm_i915_gem_request *req; + int i; - BUILD_BUG_ON(I915_NUM_RINGS > 16); - args->busy = obj->active << 16; - if (obj->last_write.request) - args->busy |= obj->last_write.request->engine->id; + BUILD_BUG_ON(I915_NUM_RINGS > 16); + rcu_read_lock(); + for (i = 0; i < I915_NUM_RINGS; i++) { + req = i915_gem_active_get_request_rcu(&obj->last_read[i]); + if (req == NULL) + continue; -unref: - drm_gem_object_unreference(&obj->base); -unlock: - mutex_unlock(&dev->struct_mutex); - return ret; + if (i915_gem_request_completed(req)) + args->busy |= 1 << (16 + i); + i915_gem_request_put(req); + } + + req = i915_gem_active_get_request_rcu(&obj->last_write); + if (req) { + args->busy |= req->engine->id; + i915_gem_request_put(req); + } + rcu_read_unlock(); + } + + drm_gem_object_unreference_unlocked(&obj->base); + return 0; } int