From patchwork Fri Apr 4 13:53:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 3938501 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C0BDFBFF02 for ; Fri, 4 Apr 2014 13:53:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE50420396 for ; Fri, 4 Apr 2014 13:53:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E02FC2038D for ; Fri, 4 Apr 2014 13:53:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E7226ED89; Fri, 4 Apr 2014 06:53:07 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by gabe.freedesktop.org (Postfix) with ESMTP id 45BB16ED89 for ; Fri, 4 Apr 2014 06:53:05 -0700 (PDT) Received: from Valinor ([84.248.177.169]) by mail.gmx.com (mrgmx103) with ESMTPA (Nemesis) id 0M0QLp-1XJlr83OV3-00uXmo for ; Fri, 04 Apr 2014 15:53:04 +0200 Date: Fri, 4 Apr 2014 16:53:38 +0300 From: Lauri Kasanen To: dri-devel@lists.freedesktop.org Subject: [RFC 3/3] drm/ttm: Enable the priority queue for VRAM Message-Id: <20140404165338.6352944e.cand@gmx.com> X-Mailer: Sylpheed 3.1.4 (GTK+ 2.18.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 X-Provags-ID: V03:K0:p+jRVbcIC/nOxBLQxJHZS6Z4NWRA+8fXkbt5ce/dZ3YjngQ9JVe uktbWN1ohySz7PN9Dqa9qriv2lqL3SaqEfUjbOp6tS/niQqUrrvjOniaX6r3v0nE05Mi3i/ pT1UQtEdYOyW7k2IODEyvsBElH+u3dqtu1S8Dj7NLvAaUyLsX19cPSLmt62lSk2Gg60MEwD ZUfbKLrZGnvjKRLziO5oQ== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 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-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Lauri Kasanen --- drivers/gpu/drm/ttm/ttm_bo.c | 68 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 621151c..80e5856 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -172,7 +172,12 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) BUG_ON(!list_empty(&bo->lru)); man = &bdev->man[bo->mem.mem_type]; - list_add_tail(&bo->lru, &man->lru); + + if (bdev->use_pqueue && bo->mem.mem_type == TTM_PL_VRAM) + ttm_prio_add(&man->pqueue, &bo->pqueue); + else + list_add_tail(&bo->lru, &man->lru); + kref_get(&bo->list_kref); if (bo->ttm != NULL) { @@ -186,6 +191,8 @@ EXPORT_SYMBOL(ttm_bo_add_to_lru); int ttm_bo_del_from_lru(struct ttm_buffer_object *bo) { int put_count = 0; + struct ttm_bo_device *bdev = bo->bdev; + struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type]; if (!list_empty(&bo->swap)) { list_del_init(&bo->swap); @@ -194,6 +201,10 @@ int ttm_bo_del_from_lru(struct ttm_buffer_object *bo) if (!list_empty(&bo->lru)) { list_del_init(&bo->lru); ++put_count; + } else if (bdev->use_pqueue && bo->mem.mem_type == TTM_PL_VRAM && + ttm_prio_is_queued(&bo->pqueue)) { + ttm_prio_remove(&man->pqueue, &bo->pqueue); + ++put_count; } /* @@ -725,10 +736,22 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, int ret = -EBUSY, put_count; spin_lock(&glob->lru_lock); - list_for_each_entry(bo, &man->lru, lru) { - ret = ttm_bo_reserve_nolru(bo, false, true, false, 0); - if (!ret) - break; + if (bdev->use_pqueue && mem_type == TTM_PL_VRAM) { + struct ttm_pqueue_entry *pe; + for (pe = ttm_prio_query_lowest(&man->pqueue); pe; + pe = ttm_prio_query_next(pe)) { + + bo = container_of(pe, struct ttm_buffer_object, pqueue); + ret = ttm_bo_reserve_nolru(bo, false, true, false, 0); + if (!ret) + break; + } + } else { + list_for_each_entry(bo, &man->lru, lru) { + ret = ttm_bo_reserve_nolru(bo, false, true, false, 0); + if (!ret) + break; + } } if (ret) { @@ -1125,6 +1148,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev, INIT_LIST_HEAD(&bo->ddestroy); INIT_LIST_HEAD(&bo->swap); INIT_LIST_HEAD(&bo->io_reserve_lru); + ttm_prio_init_entry(&bo->pqueue); mutex_init(&bo->wu_mutex); bo->bdev = bdev; bo->glob = bdev->glob; @@ -1243,17 +1267,32 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, */ spin_lock(&glob->lru_lock); - while (!list_empty(&man->lru)) { - spin_unlock(&glob->lru_lock); - ret = ttm_mem_evict_first(bdev, mem_type, false, false); - if (ret) { - if (allow_errors) { - return ret; - } else { - pr_err("Cleanup eviction failed\n"); + if (bdev->use_pqueue && mem_type == TTM_PL_VRAM) { + while (ttm_prio_query_lowest(&man->pqueue)) { + spin_unlock(&glob->lru_lock); + ret = ttm_mem_evict_first(bdev, mem_type, false, false); + if (ret) { + if (allow_errors) { + return ret; + } else { + pr_err("Cleanup eviction failed\n"); + } } + spin_lock(&glob->lru_lock); + } + } else { + while (!list_empty(&man->lru)) { + spin_unlock(&glob->lru_lock); + ret = ttm_mem_evict_first(bdev, mem_type, false, false); + if (ret) { + if (allow_errors) { + return ret; + } else { + pr_err("Cleanup eviction failed\n"); + } + } + spin_lock(&glob->lru_lock); } - spin_lock(&glob->lru_lock); } spin_unlock(&glob->lru_lock); return 0; @@ -1338,6 +1377,7 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, man->size = p_size; INIT_LIST_HEAD(&man->lru); + memset(&man->pqueue, 0, sizeof(struct ttm_pqueue)); return 0; }