aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-02-02 16:04:38 -0500
committerDaniel Vetter <daniel.vetter@ffwll.ch>2017-02-03 05:10:32 -0500
commit4e64e5539d152e202ad6eea2b6f65f3ab58d9428 (patch)
tree14f90fc609bef7c9e51c6e218cff06062f4f8d6a /drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
parent17aad8a340e6f98b62c2482d02bc3814eebde9a5 (diff)
drm: Improve drm_mm search (and fix topdown allocation) with rbtrees
The drm_mm range manager claimed to support top-down insertion, but it was neither searching for the top-most hole that could fit the allocation request nor fitting the request to the hole correctly. In order to search the range efficiently, we create a secondary index for the holes using either their size or their address. This index allows us to find the smallest hole or the hole at the bottom or top of the range efficiently, whilst keeping the hole stack to rapidly service evictions. v2: Search for holes both high and low. Rename flags to mode. v3: Discover rb_entry_safe() and use it! v4: Kerneldoc for enum drm_mm_insert_mode. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: "Christian König" <christian.koenig@amd.com> Cc: David Airlie <airlied@linux.ie> Cc: Russell King <rmk+kernel@armlinux.org.uk> Cc: Daniel Vetter <daniel.vetter@intel.com> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Sean Paul <seanpaul@chromium.org> Cc: Lucas Stach <l.stach@pengutronix.de> Cc: Christian Gmeiner <christian.gmeiner@gmail.com> Cc: Rob Clark <robdclark@gmail.com> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: Stephen Warren <swarren@wwwdotorg.org> Cc: Alexandre Courbot <gnurou@gmail.com> Cc: Eric Anholt <eric@anholt.net> Cc: Sinclair Yeh <syeh@vmware.com> Cc: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Sinclair Yeh <syeh@vmware.com> # vmwgfx Reviewed-by: Lucas Stach <l.stach@pengutronix.de> #etnaviv Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/20170202210438.28702-1-chris@chris-wilson.co.uk
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index e4eb6dd3798a..0335c2f331e9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -97,8 +97,7 @@ int amdgpu_gtt_mgr_alloc(struct ttm_mem_type_manager *man,
97{ 97{
98 struct amdgpu_gtt_mgr *mgr = man->priv; 98 struct amdgpu_gtt_mgr *mgr = man->priv;
99 struct drm_mm_node *node = mem->mm_node; 99 struct drm_mm_node *node = mem->mm_node;
100 enum drm_mm_search_flags sflags = DRM_MM_SEARCH_BEST; 100 enum drm_mm_insert_mode mode;
101 enum drm_mm_allocator_flags aflags = DRM_MM_CREATE_DEFAULT;
102 unsigned long fpfn, lpfn; 101 unsigned long fpfn, lpfn;
103 int r; 102 int r;
104 103
@@ -115,15 +114,14 @@ int amdgpu_gtt_mgr_alloc(struct ttm_mem_type_manager *man,
115 else 114 else
116 lpfn = man->size; 115 lpfn = man->size;
117 116
118 if (place && place->flags & TTM_PL_FLAG_TOPDOWN) { 117 mode = DRM_MM_INSERT_BEST;
119 sflags = DRM_MM_SEARCH_BELOW; 118 if (place && place->flags & TTM_PL_FLAG_TOPDOWN)
120 aflags = DRM_MM_CREATE_TOP; 119 mode = DRM_MM_INSERT_HIGH;
121 }
122 120
123 spin_lock(&mgr->lock); 121 spin_lock(&mgr->lock);
124 r = drm_mm_insert_node_in_range_generic(&mgr->mm, node, mem->num_pages, 122 r = drm_mm_insert_node_in_range(&mgr->mm, node,
125 mem->page_alignment, 0, 123 mem->num_pages, mem->page_alignment, 0,
126 fpfn, lpfn, sflags, aflags); 124 fpfn, lpfn, mode);
127 spin_unlock(&mgr->lock); 125 spin_unlock(&mgr->lock);
128 126
129 if (!r) { 127 if (!r) {