Received: by 10.223.185.116 with SMTP id b49csp3556612wrg; Mon, 19 Feb 2018 01:58:05 -0800 (PST) X-Google-Smtp-Source: AH8x227ZH+eVM2yB1mydIpn4YjgT7XrpFvIc5hNBNzn1NWUqg9K0GD5kvcrEmk4WAamoGOWdIAaJ X-Received: by 2002:a17:902:b597:: with SMTP id a23-v6mr6938580pls.227.1519034285396; Mon, 19 Feb 2018 01:58:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519034285; cv=none; d=google.com; s=arc-20160816; b=FIEhAuVDZlrU7E/AeJltQhbrnzH0/ICiF0/hhpumas0V1M0ifiJGzZqV0rATqj26mW OWiLBXe89avwBFW/d5xzQ9HHwMIYJptIJ5ITvsNMEKOrAalAo3kZvozZpaNMHrtpN0Tz bjUItpzqlziJrgU2gPBu9n96sEF0sb1uSfxJdSlMTq71WMLGj/w1hUdnnv+O18ZsVDKu Sln/mi6WqJKWzfYDpxnH3FaEfs/Ca4kvaUg0tsrNXGVHnFlli0sOq8gt7EZulQbUuXXD RGkHNiT4yHS3hf+Tsx+GTeF835X9xsCuRHbHoZ6jRlAE4g10VVvTEbz8wTizQzWmTcjh gWOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=kW97Ekwnjs+aNOOtH1oekT50DUOly+gkCxV9VzLRnfQ=; b=Ilrgj0Kf6F9lwo0KcjpIphjrsc3Y+/t7bPJPM8UTskSSgZfW7r/LSu8Jy3U9YnXzVf iofUY6TpMBwx2TFXVRyx3IEtZBIUBDyWm1oemnVylLHyz6t7etS/zsnh64vNQt8AliGi pun9Lp2VtEtuf58ORRh1uXqWgT9eykS/mb4KBZwaGuplmV4j305g4W3NckDVe08AigYh oXlpByC85punQ/0Z9UpCD0mcLkgnzRpi3Wu2XYHL0bbMSKuKy4hrHylhYnxKihH4cCgy 6ffKxMM0TWdhvD0fgzHxb24fDFDGcNEWYowg750BybmKvF0wPmjC1O/8ePYqyVuaho9A PIbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NvojHrzc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si3328124pgn.571.2018.02.19.01.57.51; Mon, 19 Feb 2018 01:58:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NvojHrzc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752480AbeBSJ4P (ORCPT + 99 others); Mon, 19 Feb 2018 04:56:15 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35914 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752442AbeBSJ4O (ORCPT ); Mon, 19 Feb 2018 04:56:14 -0500 Received: by mail-wr0-f194.google.com with SMTP id u15so8969070wrg.3 for ; Mon, 19 Feb 2018 01:56:13 -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=kSw8JR2TXopw1Z2h5Yqh3hX5sZtRH3h0JH4Tk70hp9nErl0a383c6Z9W91EgW7UvuY n7/vB30SWWcRjtuDZqoeQ1fjXIcJ65aJoKRszLpvCu8w9KzHMJjexFSiT5HZ1Q8B+6FZ CHE7JqE4kuiHnwgZqCmunIC2QpzrzD3cgJTTyNTjOuuVoAwUSAtAZ6/5f27+64ugwao8 BwzR/2MkCXnoxBsuzx+PqJo8ooepn0oHB4T5ZWaX/XLGc+/UZuZe6SQUEjD0bd8IXmeE 1EnMterBrQk28/XBOKSXN7eSRXiYDwchSrxHpqck0ViouZua6owQRRr6QNd8OOhqLiRm qxHg== X-Gm-Message-State: APf1xPAxKgYpZt1l0iCEEIe9MxLIQNsS2jGtCBuRRtcACNMsFz7lcbN3 SLQnI3u6S/2ZK4C+cCAPn5w= 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.14.1