From patchwork Mon Feb 19 09:56:09 2018 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: 10227349 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 085CE602DC for ; Mon, 19 Feb 2018 09:56:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F11AE2884F for ; Mon, 19 Feb 2018 09:56:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E57282897F; Mon, 19 Feb 2018 09:56:19 +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 9C9A72884F for ; Mon, 19 Feb 2018 09:56:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF55F6E09F; Mon, 19 Feb 2018 09:56:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id BD6CE6E05C; Mon, 19 Feb 2018 09:56:14 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id z12so2800037wrg.4; Mon, 19 Feb 2018 01:56: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:in-reply-to:references:mime-version :content-transfer-encoding; bh=kW97Ekwnjs+aNOOtH1oekT50DUOly+gkCxV9VzLRnfQ=; b=NvojHrzcSmt8hKnC3jkUwBcrbuXgBbmCCnhhUKIFO5ndsewcv1B+3/8HGyVKYNRgNA 8/iaseIi1+V1pOVPDSWzfcb77Y5ZPBjrH2o7OXpeTSUhxBQYLGMqRYHSjBzGpZBcbeR2 lCre0Fdb5Ef/iGsVhtBOg6SAdjGf8dLFhgF9kOMKLQyO+alsId9a2bU4fZ8wkeGOXRkq 2bOCSagTwSbNTTcJ9MW6waUpwYMwWetixAmq6YyonVkzu0IkZ6Shok4aCjiwplc5yCF2 F/Z6WTUUOBSy+wVXPM+tgpGX7jbhgte/6fFIpizzuXoiKzW5r41mSjzhj/Vzlw68ZRgg 5NIA== 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=kW97Ekwnjs+aNOOtH1oekT50DUOly+gkCxV9VzLRnfQ=; b=Qr+bk1OOWqdupT3ssqQymcsNV/ZRcSa+2YzehzbORnX6i0403+DpEFqya3PnicFZOJ APq6rVi13BLCP0KTzWPdg698O4ilp2gOYwUCzota+SChMmw6i+Onu/TKurAM62ueWXRy Ln0kmYdB0u4MfrViAMwTUPtLWOfgOZolmvvQ9ko/06hrvqNYcpumS2heD10zxVYyYlK2 ahMcrHkv9cK2RFAl92NIYtTXsJ8fggZf9PndptLajilKHdTBSHiY8PB5I3/LpsP7yw7k Q4d+X+s8x3sBZScbs1tnJCmKLwm4TDCDbu4HJZ6ZyV8GYmgmn5Sf4SJbjinSEoL9U9HV 49Qg== X-Gm-Message-State: APf1xPC6OZJD76ZIUeJ7nQkXKdahcAZs0n7jr8gCFikNP5V3FSi+6uOi 1EinxxLEtpWKvxvyw4yosfg2PA== X-Google-Smtp-Source: AH8x225/B+riYYPDE7eqQvCq9ld0fLtBTQjJbQ67o3+38kv5Kl391VuDSBHYlVNxEjZYWSwKa3eswA== X-Received: by 10.223.128.201 with SMTP id 67mr2777664wrl.131.1519034173001; Mon, 19 Feb 2018 01:56:13 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:9533:206a:c0b5:3ad7]) by smtp.gmail.com with ESMTPSA id z74sm22309976wmz.21.2018.02.19.01.56.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 01:56:12 -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, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 3/4] drm/ttm: handle already locked BOs during eviction and swapout. Date: Mon, 19 Feb 2018 10:56:09 +0100 Message-Id: <20180219095610.2747-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180219095610.2747-1-christian.koenig@amd.com> References: <20180219095610.2747-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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 This solves the problem that when we swapout a BO from a domain we sometimes couldn't make room for it because holding the lock blocks all other BOs with this reservation object. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index d90b1cf10b27..fba40e22d088 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -713,31 +713,30 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, EXPORT_SYMBOL(ttm_bo_eviction_valuable); /** - * Check the target bo is allowable to be evicted or swapout, including cases: - * - * a. if share same reservation object with ctx->resv, have assumption - * reservation objects should already be locked, so not lock again and - * return true directly when either the opreation allow_reserved_eviction - * or the target bo already is in delayed free list; - * - * b. Otherwise, trylock it. + * Check if the target bo is allowed to be evicted or swapedout. */ static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo, - struct ttm_operation_ctx *ctx, bool *locked) + struct ttm_operation_ctx *ctx, + bool *locked) { - bool ret = false; + /* First check if we can lock it */ + *locked = reservation_object_trylock(bo->resv); + if (*locked) + return true; - *locked = false; + /* Check if it's locked because it is part of the current operation */ if (bo->resv == ctx->resv) { reservation_object_assert_held(bo->resv); - if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy)) - ret = true; - } else { - *locked = reservation_object_trylock(bo->resv); - ret = *locked; + return ctx->allow_reserved_eviction || + !list_empty(&bo->ddestroy); } - return ret; + /* Check if it's locked because it was already evicted */ + if (ww_mutex_is_owned_by(&bo->resv->lock, current, NULL)) + return true; + + /* Some other thread is using it, don't touch it */ + return false; } static int ttm_mem_evict_first(struct ttm_bo_device *bdev,