From patchwork Thu Aug 4 19:52:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9264227 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 67A7760839 for ; Thu, 4 Aug 2016 19:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59BAC2841C for ; Thu, 4 Aug 2016 19:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EC4028425; Thu, 4 Aug 2016 19:53:17 +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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0124F2841C for ; Thu, 4 Aug 2016 19:53:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 762A86EA50; Thu, 4 Aug 2016 19:53:03 +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 C47B26EA46 for ; Thu, 4 Aug 2016 19:52:57 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id q128so699425wma.1 for ; Thu, 04 Aug 2016 12:52:57 -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=Gs4YYWEaOGfNSyvh2yhaeCdR5BYpPR1cqczRX2K7pD4=; b=IugW9zuTy4are5zSIFADLPsbEL1pcj5S5MscnH4O48ZPndzDcqiiGwB4pMJkJOIdaz ICOUHo6s46ePAUNseo7WLZJ8GTllOY+heVOYp+0MHpY/k/iq54JF37axktDSw2ueiu6c LJ679aw4Ku8QCJW4P2tYl7OfRINTlkQ3V/wVIlg0yJTvWwgdZVQ4fjU8XRkWlEHHZVad g/6QK3A63Yd/udBui8C2iGgsTjynJrglEZt5u641+klmHyGxbsIzg69AXUFN8H2sinuu evgn8m6IWoLoFqhNbd8NHgZnOnrp9o5nhwRKZigJFImIhiKR7Y9M5X8LOGqGqTx9psYy 08tw== 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=Gs4YYWEaOGfNSyvh2yhaeCdR5BYpPR1cqczRX2K7pD4=; b=AfyJ7FDRGBejHxwFquA844uTbGm+7q6mQRG5U9S553DWcejFO/VtfA457Lp6681nMg rWaFNyvn5GFp4OTUx2+fne7IwfUV/t4EIzRD1d51d+wwzKX0pvY8sOfT+bH3vG96ee2Y R9MDa4QNVnRpxZkAJGIm/9Imkr6C3thZ4JceldtUV9uq+zO5sZik7odTVuVn6GHM755f Tim3uc7lTvvrkkDB309I4M0N9qGhK5EEnlQMara/kZpankg2+NM1TDctHSThuDpCCTwB Zbh6H02+ZHUHm6+j/bl5eUVXTv6mnYL1IJ85IR2klSPXr+KnlivSk11N/hsWbm5pJy9/ BsvQ== X-Gm-Message-State: AEkoouvhs07fcEVwMLsG3XiGNKep3x8T8d3QB58nf5suvGBRA4Tnh7mlyFIR/BZZx85QMQ== X-Received: by 10.28.64.86 with SMTP id n83mr78187786wma.52.1470340374044; Thu, 04 Aug 2016 12:52:54 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id i3sm14301931wjd.31.2016.08.04.12.52.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 12:52:53 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 4 Aug 2016 20:52:25 +0100 Message-Id: <1470340352-16118-13-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1470340352-16118-1-git-send-email-chris@chris-wilson.co.uk> References: <1470340352-16118-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 12/19] drm/i915: Remove (struct_mutex) locking for wait-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-Virus-Scanned: ClamAV using ClamSMTP With a bit of care (and leniency) we can iterate over the object and wait for previous rendering to complete with judicial use of atomic reference counting. The ABI requires us to ensure that an active object is eventually flushed (like the busy-ioctl) which is guaranteed by our management of requests (i.e. everything that is submitted to hardware is flushed in the same request). All we have to do is ensure that we can detect when the requests are complete for reporting when the object is idle (without triggering ETIME), locklessly - this is handled by i915_gem_active_wait_unlocked(). The impact of this is actually quite small - the return to userspace following the wait was already lockless and so we don't see much gain in latency improvement upon completing the wait. What we do achieve here is completing an already finished wait without hitting the struct_mutex, our hold is quite short and so we are typically just a victim of contention rather than a cause - but it is still one less contention point! v2: Break up a long line. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_gem.c | 43 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index fa0936a787a7..4ef3f704b8b2 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2620,47 +2620,28 @@ int i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { struct drm_i915_gem_wait *args = data; + struct intel_rps_client *rps = to_rps_client(file); struct drm_i915_gem_object *obj; - struct drm_i915_gem_request *requests[I915_NUM_ENGINES]; - int i, n = 0; - int ret; + unsigned long active; + int idx, ret = 0; if (args->flags != 0) return -EINVAL; - ret = i915_mutex_lock_interruptible(dev); - if (ret) - return ret; - obj = i915_gem_object_lookup(file, args->bo_handle); - if (!obj) { - mutex_unlock(&dev->struct_mutex); + if (!obj) return -ENOENT; - } - - if (!i915_gem_object_is_active(obj)) - goto out; - for (i = 0; i < I915_NUM_ENGINES; i++) { - struct drm_i915_gem_request *req; - - req = i915_gem_active_get(&obj->last_read[i], - &obj->base.dev->struct_mutex); - if (req) - requests[n++] = req; + active = __I915_BO_ACTIVE(obj); + for_each_active(active, idx) { + s64 *timeout = args->timeout_ns >= 0 ? &args->timeout_ns : NULL; + ret = i915_gem_active_wait_unlocked(&obj->last_read[idx], true, + timeout, rps); + if (ret) + break; } -out: - i915_gem_object_put(obj); - mutex_unlock(&dev->struct_mutex); - - for (i = 0; i < n; i++) { - if (ret == 0) - ret = i915_wait_request(requests[i], true, - args->timeout_ns > 0 ? &args->timeout_ns : NULL, - to_rps_client(file)); - i915_gem_request_put(requests[i]); - } + i915_gem_object_put_unlocked(obj); return ret; }