From patchwork Thu Feb 15 14:19:43 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: 10221369 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 AC74F60467 for ; Thu, 15 Feb 2018 14:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D57A29375 for ; Thu, 15 Feb 2018 14:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91EA52937B; Thu, 15 Feb 2018 14:19:56 +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 48EA329375 for ; Thu, 15 Feb 2018 14:19:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F6BE6E532; Thu, 15 Feb 2018 14:19:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC7606E483; Thu, 15 Feb 2018 14:19:48 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id w77so3533112wrc.6; Thu, 15 Feb 2018 06:19:48 -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=TKZLK5WMUzo9wTzZfuyVfJjlSmbtkwCf8PqdC/lD0HxbG1EEYGa0NDhXjdPC8Ks8H/ BkIBnnE2WzTHYnpS8ulAzX2W+ZfjTUBywMoAwr3sHoil9mUJec2c1N0G7AJYZSjLyr7r h0yUfTzqwBX34znF3YwSUxzcKCgPof+7do9Gb6b4oEYR/a+aCSTH5WWulmEtL471VREs acSXmWeYl3Tj8ygqiMYQEgypMvQLGgBVdWZTlIDw1IzAnacgNB3Cf+crUD8HAqAk93pw n8F+TaxVwxmprWa1Hz+YwFdxH7Ehn61XthI/2+6rgtVEwo8HYwUKRUZynDrHZCFfAL/E sIjg== 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=q4DcbUETHyf/IBv25aRmEwgIpUdQ+MHRTtlOSANTK5I9T19i6RFrE3qTQvf4xt/SrL jkoE6Ateq5z72bYlgxsn2pGwft5Z3PBtQJG2pimYlDuK3uPnlvbq9LMqDuNP7X96IPrt lzSlSxWTSdLLgHR71OJiEEyEFTezY06Zt21nF+/T8kUAmiZNh9kEqy9q8BNzm25S4rQ0 4zD8Y77KQYszhZIHmxYNBAWLCgEdnO3STzkjoxf9rB/Ej7afq6FRytGo/dXaob3LVrI6 YX85ncXSGR+yn5JSPp/BLJ7ZJJzPeId2I8RDE2+iAVyTcKHnVgUMdZvVFmOdjvdMuJ+v ZzVQ== X-Gm-Message-State: APf1xPC5t2AeUA/CGlzkzm2kPfogjs2iOSUwbTxFgo71YBj/WOnOo3R9 conFBIu52NdWYjRLqwHA0prN8A== X-Google-Smtp-Source: AH8x227O2jjM4JA/lXkrmu4su1oj9Rr5JIiW4TtkOQr4RTgPZgbRBX8uCYYqsGQfTbeQH94RomkHIA== X-Received: by 10.223.135.115 with SMTP id 48mr2936414wrz.212.1518704387029; Thu, 15 Feb 2018 06:19:47 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:3595:2adb:15ea:f8af]) by smtp.gmail.com with ESMTPSA id 19sm27382433wrv.0.2018.02.15.06.19.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 06:19:46 -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, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] drm/ttm: handle already locked BOs during eviction and swapout. Date: Thu, 15 Feb 2018 15:19:43 +0100 Message-Id: <20180215141944.4332-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180215141944.4332-1-christian.koenig@amd.com> References: <20180215141944.4332-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,