From patchwork Tue Feb 20 12:58:28 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: 10230001 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 1180B602A7 for ; Tue, 20 Feb 2018 12:58:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0306B28464 for ; Tue, 20 Feb 2018 12:58:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBFD4285B7; Tue, 20 Feb 2018 12:58:38 +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 A15E828464 for ; Tue, 20 Feb 2018 12:58:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BB156E3F7; Tue, 20 Feb 2018 12:58:37 +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 2B9AE6E3F3; Tue, 20 Feb 2018 12:58:34 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id l43so14119789wrc.2; Tue, 20 Feb 2018 04:58:34 -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=r06siIiIZQv4H/HMYVBAb7oPQmb3T7vHR35cMHTiGrY=; b=pJO8M0gouCG88bfbsLoiX3QXPa9dsfaTm3By/5AHHibzRY/u8a36FdtpeyO6AuEXwT 7Ws3Cwu4PrsmjxSYSOkWg2K++JY7GwZXAXzG8A8lRRwTIcvf6Xr+T8gUqijdVLqC3Cam THgUaeFRlXXD62nLzaG9lblezHFZzMl1igErAbfuCJyiHaYK+7jcSMmEerR9YCRatL1q jJBza6TJZp4/htV1FnWsyGUPsjPgUzvFlkvBo8qX85bhgpSNkyEuDSsjrEpfcToEtuWJ sp3vBz2HVobxOTVjcZ4GMUlCaRG8AawyaK5tUivrHuw9QaVwDivQQ/A5vvJ9IzOSolTc AjZg== 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=r06siIiIZQv4H/HMYVBAb7oPQmb3T7vHR35cMHTiGrY=; b=RMQk/xJI5CglQkajot6gd94e4tOD8c70uSs9VINhXMx32YpbPBiedXz6xs4IhWyopc knglmao+GbA57ZHjhAreolnt9R+LnZtRDMYHUho4XlbQMjn5NUqKicmM6i03YKvk1gdp Thj5Blm4V+8sPR5oMydw34ysv3mul5c0Z7/fS50im8cCyGEQUtVA5KmJK/b5x6l6pQFc WWy7CyFF5mdUPG1j5jf0UixX6+yg22SXYB1bJ1VlY+2D8aB6MyXMcjDcPPzSG8T2DT4O bMyWs/kWf0mi3MzqK+a1scJNL7XptFBUeDn5cxlAMBpsVXVd9zst9MkH9RFfNf5kEjJc sOCQ== X-Gm-Message-State: APf1xPBMaaoznXZwhjepCj87a4+wiaODYbZTc84t26XEEDxt1zX+6QPO pHZSICRhmEQxAwFwBJ4zUYSRFA== X-Google-Smtp-Source: AH8x226F8n+aNWnh9FC/agHrvQazToseQcF+MK1+GnqC8rIvASIfXvLV+sS4mMZW8dVmK0zhlinCsw== X-Received: by 10.223.173.131 with SMTP id w3mr17103171wrc.195.1519131512628; Tue, 20 Feb 2018 04:58:32 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:7008:2819:5c1a:982d]) by smtp.gmail.com with ESMTPSA id 32sm24179502wrm.14.2018.02.20.04.58.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 04:58:32 -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, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] drm/ttm: handle already locked BOs during eviction and swapout. Date: Tue, 20 Feb 2018 13:58:28 +0100 Message-Id: <20180220125829.27060-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180220125829.27060-1-christian.koenig@amd.com> References: <20180220125829.27060-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..3a44c2ee4155 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, 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,