From patchwork Thu Nov 9 08:59: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: 10050521 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 623D160381 for ; Thu, 9 Nov 2017 08:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51A2A2ABB0 for ; Thu, 9 Nov 2017 08:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 460D72ABD2; Thu, 9 Nov 2017 08:59:36 +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 C3B1C2ABB0 for ; Thu, 9 Nov 2017 08:59:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A83B6E88B; Thu, 9 Nov 2017 08:59:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 634676E885; Thu, 9 Nov 2017 08:59:21 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id u40so4872044wrf.10; Thu, 09 Nov 2017 00:59:21 -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=Y2M4Gxjh1N+JAFefGH9K1FeQMxROrKKXajjdmYNTzyQ=; b=pRkBZy+rQkapdcNoiUljm4HL6en5xCFkpwsIDGaQbVkTwow/UK9OC4kMlvQz765hIl WarYqSxWGR0UyZrcfmzDETF6swTAsMdDpi9NDcbx3EV5i5Zkmz7qeOOfuQ+pwklJvAXO R4bQWr7IOtd677VSAQEEWePytwghrFKKROuAAnaO0M0G1J/6KXW8EddLSMBjttAQXQ6c L3WA16LtC9NrRcMZz5Y3VSKMhupc0OikSFvJ6MNmbBNJcddAhY8u9YRBq1TweeK3PifB iE5iWYYqF06ynBB37hb/TG6rqd5A3IbmIQYhtNci8dI5bpgGhqkh6pAj/WhHKZqBc5hA yLeg== 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=Y2M4Gxjh1N+JAFefGH9K1FeQMxROrKKXajjdmYNTzyQ=; b=eGEU8+Ls6FgHLFcwSzUJteLmx3VLO7XuoqmYU2eln3KfDyrJz1IJ5ODfMew6dBvL3d NHO7uGHbOHclBBBsZnLNcXb167SSWHkaPnAV3OV7J9raxFjPLBrhA21l4a4JtK4HfrTK e8mX7CsryaIq2FCzoJlLvSTNYPpE6UMNQSAjDvvWHstFEV9T//zISMeI3EEW/FQ686DI LOJpeDXmFRHFSH18OohPn87rfeb1rmbS6Ke4Dzn05zp8Dh3UC/Qogbk1Bre4w1/5Ptu0 7xGhgmoURn7Gk9NPHwgM73w9QCGKgQ9rhiYcgdOYnkBsG8ux2KyGiKRUR70W9fJDIAfb xprg== X-Gm-Message-State: AJaThX57Tlcy+ZDkH3I6JMrpuOC3yxuP9r8lma6d0hFPdmYXvlh5NuUX BCWyewcCiUDyzM/Ti+rToSUn+w== X-Google-Smtp-Source: ABhQp+SIiBw0fkig5aIqYtNFW3DFEcWdLsiHdyqcln6yMQZPIBCSzAa1BZfyobehHHDPB/ysDkYUcA== X-Received: by 10.223.160.184 with SMTP id m53mr3030334wrm.126.1510217959679; Thu, 09 Nov 2017 00:59:19 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:61f0:1658:ce3b:16a3]) by smtp.gmail.com with ESMTPSA id 69sm8893723wmp.37.2017.11.09.00.59.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 00:59:19 -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, Hongbo.He@amd.com, michel@daenzer.net Subject: [PATCH 7/7] drm/ttm: optimize ttm_mem_evict_first v2 Date: Thu, 9 Nov 2017 09:59:09 +0100 Message-Id: <20171109085909.1653-7-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171109085909.1653-1-christian.koenig@amd.com> References: <20171109085909.1653-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. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 50a678b504f3..6545c4344684 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -735,20 +735,37 @@ 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; + bool locked; unsigned i; spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { list_for_each_entry(bo, &man->lru[i], lru) { + if (bo->resv == resv) { + if (list_empty(&bo->ddestroy)) + continue; + + if (place && + !bdev->driver->eviction_valuable(bo, place)) + continue; + + ttm_bo_del_from_lru(bo); + + ret = 0; + locked = false; + break; + } + ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; if (ret) continue; @@ -760,6 +777,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, continue; } + locked = true; break; } @@ -775,7 +793,8 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, 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,7 +805,10 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, 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; @@ -850,7 +872,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; @@ -1353,7 +1375,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);