From patchwork Thu Nov 9 08:59:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10050523 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 DE6C060381 for ; Thu, 9 Nov 2017 08:59:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD5FC2ABB0 for ; Thu, 9 Nov 2017 08:59:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C084A2ABE7; Thu, 9 Nov 2017 08:59:48 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 52F522ABB0 for ; Thu, 9 Nov 2017 08:59:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F9DB6E893; Thu, 9 Nov 2017 08:59:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id B6AF36E885; Thu, 9 Nov 2017 08:59:20 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id b14so174747wme.2; Thu, 09 Nov 2017 00:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZTlPqkStGzTZmpi7rbrj2hdNRwQJjq3s65p4qJqALSk=; b=vc8DGYqwdtI/qt3+ODiswSmKGs1WZ5IJP1ZWj2grBvJQAd6Q59z+EuMn005bMK8OAX LNm64ndwngdjsam/KnmSjqnoGyHDYhPqrREhOJW2LJ1GvEDjkWclncZClrXjol75h6P4 W721Nbhl+7KVJr4uC497nhX31QOd8tnhnkN65WsJ51PauJDVSbiMTiU2wOWovBIVrR2K trE7/5qyhJZgqi/YH7lsJhQFeUetXXbeKgruzcsnCfDV1yt8TEZUOWQ+xX0FlkaEMn9C iaM76Sfq183Gpo4xEOQTE/eu7G+zfFmJix3lcUoMOiYHuQFj9MO/bq7YDunHByrAagwC zrzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZTlPqkStGzTZmpi7rbrj2hdNRwQJjq3s65p4qJqALSk=; b=mI5bDtlj/9Km3CAS29GjX0917U43Rciam9qhVtiGj4oq5aftlBv4UmsTpYb3hm8sCm kT286FiK/RzdidUOh8EbhoV4EScSB5k3r1HrHs4tdz6n4JOaWqKh8AtKgymynLrtD2Pi EBQoPtmpifzbfLDVWU8QvHYP7Lm6PSKiCuWGFiWAfwIZ7+O116G4x2qPI3PlFf6DNAdF XQKoloYZ6iDDoPf31tbrSXjakJdR7zog3Otyw+kdncLhhGx7q9+ftnRacYPAbCKLueGM 96F5XekkV2z+gUTb28sNeK3vAMfxlLDIJ0f4GV7qV6NbZHeBki3xuhij+LRy+qrzxP4N 3uMQ== X-Gm-Message-State: AJaThX5D1VkZgzSsXTua3tBhegR4lFyb4ppJYYexXYLWidK6RT4+9wOC K74wGK5HCPaUwycpBlKubSeJlQ== X-Google-Smtp-Source: ABhQp+S1WtCAlfAtiZwXbEpkyEWHXtDuIFd1F8lmAW62Rbl+7vm5uPm6KmbH19V4OuFF/k2C9spXQQ== X-Received: by 10.28.136.83 with SMTP id k80mr2315414wmd.133.1510217958871; Thu, 09 Nov 2017 00:59:18 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:61f0:1658:ce3b:16a3]) by smtp.gmail.com with ESMTPSA id 69sm8893723wmp.37.2017.11.09.00.59.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 00:59:18 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, Hongbo.He@amd.com, michel@daenzer.net Subject: [PATCH 6/7] drm/ttm: make unlocking in ttm_bo_cleanup_refs optional Date: Thu, 9 Nov 2017 09:59:08 +0100 Message-Id: <20171109085909.1653-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171109085909.1653-1-christian.koenig@amd.com> References: <20171109085909.1653-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Needed for the next patch. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 52 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 6f5d18366e6e..50a678b504f3 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -486,20 +486,21 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo) } /** - * function ttm_bo_cleanup_refs_and_unlock + * function ttm_bo_cleanup_refs * If bo idle, remove from delayed- and lru lists, and unref. * If not idle, do nothing. * * Must be called with lru_lock and reservation held, this function - * will drop both before returning. + * will drop the lru lock and optionally the reservation lock before returning. * * @interruptible Any sleeps should occur interruptibly. * @no_wait_gpu Never wait for gpu. Return -EBUSY instead. + * @unlock_resv Unlock the reservation lock as well. */ -static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, - bool interruptible, - bool no_wait_gpu) +static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo, + bool interruptible, bool no_wait_gpu, + bool unlock_resv) { struct ttm_bo_global *glob = bo->glob; struct reservation_object *resv; @@ -518,7 +519,8 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, if (ret && !no_wait_gpu) { long lret; - reservation_object_unlock(bo->resv); + if (unlock_resv) + reservation_object_unlock(bo->resv); spin_unlock(&glob->lru_lock); lret = reservation_object_wait_timeout_rcu(resv, true, @@ -531,19 +533,22 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, return -EBUSY; spin_lock(&glob->lru_lock); - ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; - - /* - * We raced, and lost, someone else holds the reservation now, - * and is probably busy in ttm_bo_cleanup_memtype_use. - * - * Even if it's not the case, because we finished waiting any - * delayed destruction would succeed, so just return success - * here. - */ - if (ret) { - spin_unlock(&glob->lru_lock); - return 0; + if (unlock_resv) { + ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; + /* + * We raced, and lost, someone else holds the reservation now, + * and is probably busy in ttm_bo_cleanup_memtype_use. + * + * Even if it's not the case, because we finished waiting any + * delayed destruction would succeed, so just return success + * here. + */ + if (ret) { + spin_unlock(&glob->lru_lock); + return 0; + } + } else { + ret = 0; } } @@ -600,8 +605,8 @@ static int ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) } if (!ret) - ret = ttm_bo_cleanup_refs_and_unlock(entry, false, - !remove_all); + ret = ttm_bo_cleanup_refs(entry, false, !remove_all, + true); else spin_unlock(&glob->lru_lock); @@ -770,8 +775,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, kref_get(&bo->list_kref); if (!list_empty(&bo->ddestroy)) { - ret = ttm_bo_cleanup_refs_and_unlock(bo, interruptible, - no_wait_gpu); + ret = ttm_bo_cleanup_refs(bo, interruptible, no_wait_gpu, true); kref_put(&bo->list_kref, ttm_bo_release_list); return ret; } @@ -1735,7 +1739,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink) kref_get(&bo->list_kref); if (!list_empty(&bo->ddestroy)) { - ret = ttm_bo_cleanup_refs_and_unlock(bo, false, false); + ret = ttm_bo_cleanup_refs(bo, false, false, true); kref_put(&bo->list_kref, ttm_bo_release_list); return ret; }