From patchwork Mon Nov 13 09:54:09 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: 10055453 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 BB8DC60365 for ; Mon, 13 Nov 2017 09:54:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C850229223 for ; Mon, 13 Nov 2017 09:54:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBF0E29243; Mon, 13 Nov 2017 09:54: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 71A7929223 for ; Mon, 13 Nov 2017 09:54:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D0606E530; Mon, 13 Nov 2017 09:54:17 +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 07D106E52A; Mon, 13 Nov 2017 09:54:15 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id g141so13793237wmg.2; Mon, 13 Nov 2017 01:54: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=KGUwwwEMQu4roUtvFr7ADVa74XPUea1MhRMMv7c0tMc=; b=GM6a4jbxelXrJ1qSL+PLTONUOyJB8W4r7AsFitxtS+WILK2LFyZSglsoZVpGf6BsYm GK2D4apBYKhxX8r8iOtbxAS+H9uHuIl00tjXn2WmnzBQJQCulbkYTfS64KtenfvmEzyw LvEcMkOmC1cxJN6WD784GUrjJht4GtTeR6P2iKYMP80RO9vUl1qFVNUdODgvIqE5MfMu eyRYENxXZ+NFctJPyP2DRIPQ/9OytGAjKRVRwtppyq88jG89tBRICSWYVO/ysus/WlhZ nEfmGayLqIMQt/HQIdADgN37hLis6tjl+fQf80LsZhTlfwasZiJRG52alD/oaTV8IVfu YkYA== 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=KGUwwwEMQu4roUtvFr7ADVa74XPUea1MhRMMv7c0tMc=; b=IDiex7nJy1HCjwrV2PNzCVuEml1fKC6qc5T2JKpIyiOJYJlUSo5s3dILJfJVTymh14 KtovIgygH3IqRKO1Ty7gisQYOlk8Hd2JEtrDbRtt6MWwz0DHpwB5P8d5Ig74999lK683 T9yDLr4RrEF9WlGflX+zcQmatcggtFyy67BaJQy8GqYvhit2LTuMwJKbjIYdhWb8cQZq 1wMoOoCrmRY019FDm+k5MVOE2P2+kRrqM3p7k1DnGESRJQbp9PKNso4j0PPpKMTMudtf NsU3dJk5cV3tofsmVGMZ9IAbAy7e9JxUCluPFW4UqaTyHo43k1IDBzK4FDggbzMZD0Er bPBg== X-Gm-Message-State: AJaThX7n5WKP0/84VPpb8b0XRxLQKR3EhvlODM8a2aqw1q40Phoc2S2L dJ40Qj8izya1HJckalrvnIdlhw== X-Google-Smtp-Source: AGs4zMYNSN1pABGTToersQZWhIhE8gyuxVL4G3jZT4FUTxLvM7BDaC7eBbYk2Ymq4oSNJ9EnuhUgEg== X-Received: by 10.28.154.70 with SMTP id c67mr4720741wme.142.1510566853478; Mon, 13 Nov 2017 01:54:13 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:3db5:1e14:a31e:2a75]) by smtp.gmail.com with ESMTPSA id m187sm14472859wmb.17.2017.11.13.01.54.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Nov 2017 01:54:12 -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 Subject: [PATCH 2/2] drm/ttm: optimize ttm_mem_evict_first v4 Date: Mon, 13 Nov 2017 10:54:09 +0100 Message-Id: <20171113095409.1904-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171113095409.1904-1-christian.koenig@amd.com> References: <20171113095409.1904-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 Deleted BOs with the same reservation object can be reaped even if they can't be reserved. v2: rebase and we still need to remove/add the BO from/to the LRU. v3: fix remove/add one more time, cleanup the logic a bit v4: we should still check if the eviction is valuable Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 54 +++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 691646c0f8d3..7b1525d39ea8 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -738,47 +738,57 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, EXPORT_SYMBOL(ttm_bo_eviction_valuable); static int ttm_mem_evict_first(struct ttm_bo_device *bdev, - uint32_t mem_type, - const struct ttm_place *place, - bool interruptible, - bool no_wait_gpu) + struct reservation_object *resv, + uint32_t mem_type, + const struct ttm_place *place, + bool interruptible, + bool no_wait_gpu) { struct ttm_bo_global *glob = bdev->glob; struct ttm_mem_type_manager *man = &bdev->man[mem_type]; - struct ttm_buffer_object *bo; - int ret = -EBUSY; + struct ttm_buffer_object *bo = NULL; + bool locked = false; unsigned i; + int ret; spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { list_for_each_entry(bo, &man->lru[i], lru) { - ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; - if (ret) - continue; + if (bo->resv == resv) { + if (list_empty(&bo->ddestroy)) + continue; + + } else { + locked = reservation_object_trylock(bo->resv); + if (!locked) + continue; + } if (place && !bdev->driver->eviction_valuable(bo, place)) { - reservation_object_unlock(bo->resv); - ret = -EBUSY; + if (locked) + reservation_object_unlock(bo->resv); continue; } - break; } - if (!ret) + if (&bo->lru != &man->lru[i]) break; + else + bo = NULL; } - if (ret) { + if (!bo) { spin_unlock(&glob->lru_lock); - return ret; + return -EBUSY; } kref_get(&bo->list_kref); if (!list_empty(&bo->ddestroy)) { - ret = ttm_bo_cleanup_refs(bo, interruptible, no_wait_gpu, true); + ret = ttm_bo_cleanup_refs(bo, interruptible, no_wait_gpu, + locked); kref_put(&bo->list_kref, ttm_bo_release_list); return ret; } @@ -786,10 +796,11 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, ttm_bo_del_from_lru(bo); spin_unlock(&glob->lru_lock); - BUG_ON(ret != 0); - ret = ttm_bo_evict(bo, interruptible, no_wait_gpu); - ttm_bo_unreserve(bo); + if (locked) + ttm_bo_unreserve(bo); + else + ttm_bo_add_to_lru(bo); kref_put(&bo->list_kref, ttm_bo_release_list); return ret; @@ -853,7 +864,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, return ret; if (mem->mm_node) break; - ret = ttm_mem_evict_first(bdev, mem_type, place, + ret = ttm_mem_evict_first(bdev, bo->resv, mem_type, place, interruptible, no_wait_gpu); if (unlikely(ret != 0)) return ret; @@ -1356,7 +1367,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { while (!list_empty(&man->lru[i])) { spin_unlock(&glob->lru_lock); - ret = ttm_mem_evict_first(bdev, mem_type, NULL, false, false); + ret = ttm_mem_evict_first(bdev, NULL, mem_type, NULL, + false, false); if (ret) return ret; spin_lock(&glob->lru_lock);