From patchwork Wed Nov 28 15:58:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 1818471 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 35771DF230 for ; Wed, 28 Nov 2012 21:06:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E8CEE6456 for ; Wed, 28 Nov 2012 13:06:26 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-gh0-f177.google.com (mail-gh0-f177.google.com [209.85.160.177]) by gabe.freedesktop.org (Postfix) with ESMTP id CC821E5F61 for ; Wed, 28 Nov 2012 13:00:29 -0800 (PST) Received: by mail-gh0-f177.google.com with SMTP id g22so2774942ghb.36 for ; Wed, 28 Nov 2012 13:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=iMJiki61A2tSjZwKgY3FU3oBGhU5Dja4wu2bcqnnWMI=; b=mAHcPxQC9ITKqom847blLZxwkJLaAF53LaZ4w48j+Cjh8rdSyLfUlGYzNh431fL/1B jWnTSrOMncuvfxUwbvIIdi3d0SmkJLAIqS8BUH/f8gc3IHQJ/D+QnstT6uE9Ji7gmBZy owZDuu3huEmIMAavCFV0emBnKkjhR1kPK1R+V4rHGvTuhbNt5mbfq/7DJg0QAfVcqlXy 8wX+N9rft6D6PmMqaDygBhdHjd6Cv6jikxE/tL5U5pNGmQf/5H59/+kNGauXTdmFxh7k kJr6RI4etKMK1PMjcnUPQpAsC/A46cJJeOvNzEkB+gVDQzmPpVJPHdZdWM61+Mzh2p5F IjsA== Received: by 10.236.113.6 with SMTP id z6mr4111729yhg.119.1354136429577; Wed, 28 Nov 2012 13:00:29 -0800 (PST) Received: from homer.localdomain.com ([66.187.233.206]) by mx.google.com with ESMTPS id n12sm20442923ani.7.2012.11.28.13.00.28 (version=SSLv3 cipher=OTHER); Wed, 28 Nov 2012 13:00:28 -0800 (PST) From: j.glisse@gmail.com To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/ttm: add minimum residency constraint for bo eviction Date: Wed, 28 Nov 2012 10:58:48 -0500 Message-Id: <1354118328-8104-2-git-send-email-j.glisse@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1354118328-8104-1-git-send-email-j.glisse@gmail.com> References: <1354118328-8104-1-git-send-email-j.glisse@gmail.com> Cc: Jerome Glisse X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org From: Jerome Glisse This patch add a minimum residency time configurable for each memory pool (VRAM, GTT, ...). Intention is to avoid having a lot of memory eviction from VRAM up to a point where the GPU pretty much spend all it's time moving things in and out. Signed-off-by: Jerome Glisse --- drivers/gpu/drm/radeon/radeon_ttm.c | 3 +++ drivers/gpu/drm/ttm/ttm_bo.c | 7 +++++++ include/drm/ttm/ttm_bo_api.h | 1 + include/drm/ttm/ttm_bo_driver.h | 1 + 4 files changed, 12 insertions(+) diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 5ebe1b3..88722c4 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -129,11 +129,13 @@ static int radeon_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, switch (type) { case TTM_PL_SYSTEM: /* System memory */ + man->minimum_residency_time_ms = 0; man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; man->available_caching = TTM_PL_MASK_CACHING; man->default_caching = TTM_PL_FLAG_CACHED; break; case TTM_PL_TT: + man->minimum_residency_time_ms = 0; man->func = &ttm_bo_manager_func; man->gpu_offset = rdev->mc.gtt_start; man->available_caching = TTM_PL_MASK_CACHING; @@ -156,6 +158,7 @@ static int radeon_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, break; case TTM_PL_VRAM: /* "On-card" video ram */ + man->minimum_residency_time_ms = 500; man->func = &ttm_bo_manager_func; man->gpu_offset = rdev->mc.vram_start; man->flags = TTM_MEMTYPE_FLAG_FIXED | diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 39dcc58..40476121 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -452,6 +452,7 @@ moved: bo->cur_placement = bo->mem.placement; } else bo->offset = 0; + bo->jiffies = jiffies; return 0; @@ -810,6 +811,12 @@ retry: } bo = list_first_entry(&man->lru, struct ttm_buffer_object, lru); + + if (time_after(jiffies, bo->jiffies) && jiffies_to_msecs(jiffies - bo->jiffies) >= man->minimum_residency_time_ms) { + spin_unlock(&glob->lru_lock); + return -EBUSY; + } + kref_get(&bo->list_kref); if (!list_empty(&bo->ddestroy)) { diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h index e8028ad..9e12313 100644 --- a/include/drm/ttm/ttm_bo_api.h +++ b/include/drm/ttm/ttm_bo_api.h @@ -275,6 +275,7 @@ struct ttm_buffer_object { unsigned long offset; uint32_t cur_placement; + unsigned long jiffies; struct sg_table *sg; }; diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index d803b92..7f60a18e6 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -280,6 +280,7 @@ struct ttm_mem_type_manager { struct mutex io_reserve_mutex; bool use_io_reserve_lru; bool io_reserve_fastpath; + unsigned long minimum_residency_time_ms; /* * Protected by @io_reserve_mutex: