From patchwork Wed Nov 8 14:59:35 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: 10048631 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 0014F60381 for ; Wed, 8 Nov 2017 14:59:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E65B42933A for ; Wed, 8 Nov 2017 14:59:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB13629384; Wed, 8 Nov 2017 14:59:49 +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 8DEBD2933A for ; Wed, 8 Nov 2017 14:59:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C789B6E6EE; Wed, 8 Nov 2017 14:59:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 10BAD6E6EB; Wed, 8 Nov 2017 14:59:43 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id b9so11448417wmh.0; Wed, 08 Nov 2017 06:59:42 -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=wnwY+6aQhguC/q4DeRIoLoOVTnYDUl/GpvpJIJc1sGI=; b=rh1POhupbgzvPUhUfOmBS9B8UnwbQn++Q24emqI+pKZyQTK7ZzKUmBZwopSfycjqr4 lgcKveTKycqfI2bzjsKg8QdamVLF7cnoVpiL2UznGLutPXpBc1wSOlUZhWM3eSS6nQ5y mDT2wIm3S7lG+1qq8uDWR/UefP73CLladQ7Wzavy8Y/sUbJv9hR4y8J9No4/vk0572TH QQxZWfTkdn+z8+ev7VCyt3hYhVYkS7WPS0conyPIHKlEyDctds8u9x/U3W06WM6JTg1l p8L0dzdGVrbHlMD2SdZkyBoZza6ajqR/ZU2k5lcz9/9S/s7ISQMXM9ST9GIoD7YHYkiH HLdA== 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=wnwY+6aQhguC/q4DeRIoLoOVTnYDUl/GpvpJIJc1sGI=; b=oEggDcxE7wzzZ8oa8NaZYDyZ4558aLedvClkwCj+CXjB2MF9xGQ84XidJKBJTTS6qC pKGUy6kdLOVCFSz9E0qnFB0geO8U9icsAt9PfO+MiEoJ6XbOaGNVBqJE69e26Gpo/NJL miiihCLYO+N5oycKc0jEwbFWMt5nB8MMksYfBZiQgUkn8+g92dXVz/gYVEMDG0U27Tqb wXgy+Fcg+Z+7Gyg1GuJM0ILtaJjxmr9PWi4v+Ux2nFtm3JlatpwFEAUSfAiHatcPqXfX mkUdyK10R3wSuvbOdpwf87wp6KoZjCuczUSZ+s35CITiLZzKwU/PJCD7DYG1pTp/TpuA us7A== X-Gm-Message-State: AJaThX53hLxcBChmqmBu0V5Hjt09WCwSOHTwNKL2vRAvl4KB+96Cnyqm XRaw1J8zcroKVZRokMFcM5wuGg== X-Google-Smtp-Source: ABhQp+SNLUMxe9XPKvTqujzwoCCpd12Wj1U+9/XYmiqPyyeXRI1yyzlzPTiuu3DjXAodVgBgenXhrA== X-Received: by 10.28.231.25 with SMTP id e25mr688985wmh.157.1510153181722; Wed, 08 Nov 2017 06:59:41 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:c04d:fe7d:a3de:74ad]) by smtp.gmail.com with ESMTPSA id 61sm801346wrl.0.2017.11.08.06.59.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Nov 2017 06:59:41 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: Hongbo.He@amd.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 3/4] drm/ttm: make unlocking in ttm_bo_cleanup_refs optional Date: Wed, 8 Nov 2017 15:59:35 +0100 Message-Id: <20171108145936.27071-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171108145936.27071-1-christian.koenig@amd.com> References: <20171108145936.27071-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 6f55310a9d09..d23592cfe42e 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 = __ttm_bo_reserve(bo, false, true, NULL); - - /* - * 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 = __ttm_bo_reserve(bo, false, true, NULL); + /* + * 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; }