From patchwork Sun Nov 12 15:31:19 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: 10054819 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 6AFAE6028A for ; Sun, 12 Nov 2017 15:31:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6144D2976C for ; Sun, 12 Nov 2017 15:31:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55F0B29789; Sun, 12 Nov 2017 15:31:30 +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 80D762976C for ; Sun, 12 Nov 2017 15:31:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E8AA6E39D; Sun, 12 Nov 2017 15:31:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id C36F06E39B; Sun, 12 Nov 2017 15:31:25 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id k61so12333675wrc.4; Sun, 12 Nov 2017 07:31:25 -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=GwLSjDuIDcskeZTWpC37Ok/oZyBzzMiaWPH3aleJD/08gOetzDV/Ttuv1zxStrbXId 8wRrEL6GkpleJ0NREP1nwV8pcnEjr2MbI442Sf1Z0Oxp1t9ZrSMahLTX8yPAwxZaWq8H tNtTwzjVmB+aMTgOSNWy4+WUEGxOUSOvWpDvtK48axP3NI9xbqhghdOiGkTkAqVvHv5T h3e66M8/Vu7UOh56daL0nH86Nr4cZ5UcZxZM2Ib9+gjWnzbC8Xz/yDRZX42EW7dCtgaw xArdkMK2n6T0SRxOK+iXgc2ItbSzOX9UgVYXw2vH1pDL5ce/h6YsRsLYDhuwLpYNokcn JH2Q== 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=tBAOdYL6tAruAhymQfVoDi+ATdHC5EV7UgYYDQF75neM2UODS0LHuaOTmBXNzOISc+ WlYG9SQyUkyipAB5UssAJsAZB0YsqkG+CYjx/RS7RCC2R6wejjxwsYOjz/QIYY9s9Gtk B9ooRvqllvsmOnA9EjYomH6wI1VrOwD2l1s0L/+zqZUJoMFwfYvgho85TmUUw73ShvIm UIpRJiOe205m4GX612HPm5TfUmN4HKMSsPwHPZfQhRVP3Dt6Va4UVc1SV+FC473juOeI Z/xoCfr+rKlUl50WwpN2hq5/oFMEWcq0aHwjdcA1Ad1B6mE21BV6JtuFPwEhwF2JKV6c Bz5A== X-Gm-Message-State: AJaThX5E9g04Fl+LPzeQoLPZRHSlDVfgSkggtKVvjVMne++IXClIyQ+w chKny1zjwvSKwJvaGI/0KXpDlA== X-Google-Smtp-Source: AGs4zMb9yyTjjMCUDUqzyA+LXdZETYn92Tk0WRb5WwQUMT6nxI58Hy2nX5fWwAkGAb1ntTxiHhxTtQ== X-Received: by 10.223.179.194 with SMTP id x2mr5251893wrd.266.1510500684083; Sun, 12 Nov 2017 07:31:24 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:9d6d:7508:2f91:be0c]) by smtp.gmail.com with ESMTPSA id 19sm7927465wmn.15.2017.11.12.07.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Nov 2017 07:31:23 -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: Sun, 12 Nov 2017 16:31:19 +0100 Message-Id: <20171112153120.16028-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; }