dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: j.glisse@gmail.com
To: dri-devel@lists.freedesktop.org
Cc: Jerome Glisse <jglisse@redhat.com>
Subject: [PATCH] drm/ttm: add minimum residency constraint for bo eviction
Date: Wed, 28 Nov 2012 10:58:48 -0500	[thread overview]
Message-ID: <1354118328-8104-2-git-send-email-j.glisse@gmail.com> (raw)
In-Reply-To: <1354118328-8104-1-git-send-email-j.glisse@gmail.com>

From: Jerome Glisse <jglisse@redhat.com>

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 <jglisse@redhat.com>
---
 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:
-- 
1.7.11.7

  reply	other threads:[~2012-11-28 21:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-28 15:58 [RFC] drm/ttm: add minimum residency constraint for bo eviction j.glisse
2012-11-28 15:58 ` j.glisse [this message]
2012-11-28 23:18   ` [PATCH] " Thomas Hellstrom
2012-11-28 23:24     ` Jerome Glisse
2012-11-28 23:44       ` Alan Swanson
2012-11-29  0:01         ` Jerome Glisse
2012-11-29  2:15         ` Marek Olšák
2012-11-29  8:04           ` Thomas Hellstrom
2012-11-29 12:52             ` Marek Olšák
2012-11-29 20:33               ` Thomas Hellstrom
2012-11-29 21:58                 ` Marek Olšák
2012-11-30  8:38                   ` Thomas Hellstrom
2012-11-30  9:39                   ` Asynchronous eviction [WAS Re: [PATCH] drm/ttm: add minimum residency constraint for bo eviction] Thomas Hellstrom
2012-11-30 16:30                     ` Jerome Glisse
2012-11-30 17:08                       ` Thomas Hellstrom
2012-11-30 17:18                         ` Jerome Glisse
2012-11-30 17:43                           ` Thomas Hellstrom
2012-11-30 18:07                             ` Jerome Glisse
2012-11-30 18:31                               ` Thomas Hellstrom
2012-11-30 19:25                                 ` Jerome Glisse
2012-11-30 20:35                                   ` Thomas Hellstrom
2012-11-30 21:07                                     ` Jerome Glisse
2012-11-30 21:36                                       ` Thomas Hellstrom
2012-11-30 22:02                                         ` Jerome Glisse
2012-11-29  8:41       ` [PATCH] drm/ttm: add minimum residency constraint for bo eviction Thomas Hellstrom
2012-11-29 15:50         ` Jerome Glisse
2012-11-28 21:51 ` [RFC] " Marek Olšák
2012-11-28 23:18   ` Jerome Glisse
2012-11-29  9:18   ` Thomas Hellstrom
2012-11-29  9:28     ` Michel Dänzer
2012-11-29  9:48       ` Thomas Hellstrom
2012-11-29 19:20     ` Marek Olšák
2012-11-29 19:36       ` Jerome Glisse
2012-11-29 20:40       ` Thomas Hellstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354118328-8104-2-git-send-email-j.glisse@gmail.com \
    --to=j.glisse@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jglisse@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox