From patchwork Mon Nov 13 09:54: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: 10055451 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 3D06960365 for ; Mon, 13 Nov 2017 09:54:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A38D29225 for ; Mon, 13 Nov 2017 09:54:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EB8C2922B; Mon, 13 Nov 2017 09:54:18 +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 A621E29225 for ; Mon, 13 Nov 2017 09:54:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B64496E527; Mon, 13 Nov 2017 09:54:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@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 5209F6E526; Mon, 13 Nov 2017 09:54:14 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id 9so8314300wme.4; Mon, 13 Nov 2017 01:54:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6VGJdKuVaORw23jyCXCFPBqOLztfjU+BXO+oc0AwndM=; b=SL4X74wJGWoyuCXl++JPRp+moU1VO1Iwu++VebSzSFCBWhf/eAjE8MMwJATs063BFQ bQohRb6BWlMvMSTsyTDkdFtJeyrnev7ceTPOjrX7Oxft2BK/lVz4SwvfSOxCb9wpLN7B sfAcCzQZtd5n9p8yASojxRbi1OefEuMnAxF0wYNvPWcNLSNCONPhhPcM2j+Gn//uhayE SmJdRZFengrkIQuCKlDsZJAMPPb9gnT7xpWpyoaT8r1tfPlRqjv2SvOPj+DDFunbRDVj 6yihwIvOXHKuRvNRn9RL7hR8ZTtsp70TD0SiraKcDdmNc7qk7Y6thhk5EO6EZ749P3P1 Mdog== 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:mime-version :content-transfer-encoding; bh=6VGJdKuVaORw23jyCXCFPBqOLztfjU+BXO+oc0AwndM=; b=UYYImOooD6t1ww4BhF+sBwYuougbZ8wbG9H6ERk8xzgrK9XWY7G+3hUWepHuG/u/TK lcmRSD636RZKvUCGsRkrXlzvwtlCdyxuFb9Y5lQC8hHN4QH8OH4QPmuI34ILS+Wc7sw1 g3ZwAeo3eIISP5ZOAaudiaolB8Gae8Rs7P54TgQD1McAkGMF9njSEuGVCpfc24rCNWxr 6IQvLMoPlidSneBXsC2mn8s3Vyj+LTq4alACJT66CVx21z/mpHY6XFctqj4DBsjQWiW9 +30KMIfZkx27y9yvyNnuWVgVKT1/qK+xFsC3lHeFJOODsANf0IkRGnTUw+f450QtJLDd HACg== X-Gm-Message-State: AJaThX4p47S/GAFk/T5BEThTsEeibmwphl2YkOmbMa9NR62WOnIFYo4z KDs8i+eQTi5t+wUML3zPN9Ne9w== X-Google-Smtp-Source: AGs4zMbupB0vzhwLS+/uqsPVRK4hWyNmGIyrYxXAIlxbock5YNy1JgzsJaETBo+gjSTE7mEnmi2+1w== X-Received: by 10.28.238.27 with SMTP id m27mr5444393wmh.47.1510566852438; Mon, 13 Nov 2017 01:54:12 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:3db5:1e14:a31e:2a75]) by smtp.gmail.com with ESMTPSA id m187sm14472859wmb.17.2017.11.13.01.54.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Nov 2017 01:54:11 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/ttm: make unlocking in ttm_bo_cleanup_refs optional v2 Date: Mon, 13 Nov 2017 10:54:08 +0100 Message-Id: <20171113095409.1904-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 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. v2: actually predicate all unlocks Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 59 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index db0f670911ec..691646c0f8d3 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,24 +533,28 @@ 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; } } if (ret || unlikely(list_empty(&bo->ddestroy))) { - reservation_object_unlock(bo->resv); + if (unlock_resv) + reservation_object_unlock(bo->resv); spin_unlock(&glob->lru_lock); return ret; } @@ -559,7 +565,9 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, spin_unlock(&glob->lru_lock); ttm_bo_cleanup_memtype_use(bo); - reservation_object_unlock(bo->resv); + + if (unlock_resv) + reservation_object_unlock(bo->resv); return 0; } @@ -600,8 +608,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 +778,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 +1742,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; }