From patchwork Mon Jan 11 10:44:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8001371 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 18BB89F1C0 for ; Mon, 11 Jan 2016 10:47:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF6BD202B8 for ; Mon, 11 Jan 2016 10:47:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C1FD620279 for ; Mon, 11 Jan 2016 10:47:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1F1C96E2E5; Mon, 11 Jan 2016 02:47:33 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id E21BC6E2CB for ; Mon, 11 Jan 2016 02:46:59 -0800 (PST) Received: by mail-wm0-f66.google.com with SMTP id b14so25703753wmb.1 for ; Mon, 11 Jan 2016 02:46:59 -0800 (PST) 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=C+FjsZRBNvhSnKzmUricIP+9cNTkYQKaK7So7iGKK68=; b=mxkXgRKH6zO3MFophqnfiQMHTZlHyCv18ivEzmtphoqUIYZmh2I2PLwdn9oxwbO9P4 pNWzgkLbubUg7QymJsUo5KR8H570GAeock0+uDk2g44HRlgEU7zIuRMPo7ngEl1qsd4C nNMWb+zGOjU/18WyyAYO5vyRvFHZT0GZSHOLCapBNT7pT8MyVvAW5jGmmSQM95ji7ntV jjJcMiylbHbkuKKTkM48XcVmZso7g3lzpjtizbkpP2iFZjuYEHxjekKhX1WxeyJI3B0z z/4fiKXjEEkSSc+T9+cMfSkhGIL05pKv2mOVS+oFL3w9+QqJw+cdGnidL5rSSLmCrk63 lXVg== X-Received: by 10.28.45.207 with SMTP id t198mr13683089wmt.32.1452509218737; Mon, 11 Jan 2016 02:46:58 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id t3sm118879383wjz.11.2016.01.11.02.46.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 02:46:57 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Mon, 11 Jan 2016 10:44:59 +0000 Message-Id: <1452509174-16671-29-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.7.0.rc3 In-Reply-To: <1452509174-16671-1-git-send-email-chris@chris-wilson.co.uk> References: <1452503961-14837-1-git-send-email-chris@chris-wilson.co.uk> <1452509174-16671-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 115/190] 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 | 51 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index f30207596ec6..95d4d2460f6a 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -3559,34 +3559,39 @@ 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. - */ - i915_gem_object_flush_active(obj); + args->busy = 0; + if (__I915_BO_ACTIVE(obj)) { + struct drm_i915_gem_request *req; + int i; - BUILD_BUG_ON(I915_NUM_RINGS > 16); - args->busy = I915_BO_ACTIVE(obj) << 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; - 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) { + if (!i915_gem_request_completed(req)) + args->busy |= 1 << req->engine->id; + i915_gem_request_put(req); + } + rcu_read_unlock(); + } + + drm_gem_object_unreference_unlocked(&obj->base); + return 0; } int