improve memory placement for radeon
Subsystems (2)
So as a followup is 2 patch. The first one just stop trying to move object at each cs ioctl i believe it could be included in 3.7 as it improve performances (especialy with vram change from userspace).
The second one implement a vram eviction policy. It's a simple one, buffer used for write operation are more important than buffer used for read operation. Buffer get evicted from vram only if they haven't been use in the last 50ms (so in the last few frames) and only if there is buffer that have been recently use and that could be move into vram. This is mostly were i believe discussion should be, what kind of heuristic would work better than tat.
So without first patch and with mesa master xonotic high is at 17fps, with first patch it goes to 40fps, with second patch it goes to 48fps.
Cheers,
Jerome
PATCH 1/2 drm/radeon: do not move bo to different placement at each cs
From: Jerome Glisse <[email protected]>
The bo creation placement is where the bo will be. Instead of trying to move bo at each command stream let this work to another worker thread that will use more advance heuristic.
--- drivers/gpu/drm/radeon/radeon.h | 1 + drivers/gpu/drm/radeon/radeon_object.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
@@ -313,6 +313,7 @@ struct radeon_bo {struct list_head list;/* Protected by tbo.reserved */ u32 placements[3 ]; +u32 busy_placements[3 ];struct ttm_placement placement;struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;
drivers/gpu/drm/radeon/radeon_object.c +8 -9
@@ -84,7 +84,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain) rbo->placement.fpfn =0 ; rbo->placement.lpfn =0 ; rbo->placement.placement = rbo->placements; - rbo->placement.busy_placement = rbo->placements;if (domain &RADEON_GEM_DOMAIN_VRAM ) rbo->placements[c++] =TTM_PL_FLAG_WC |TTM_PL_FLAG_UNCACHED |TTM_PL_FLAG_VRAM ;
@@ -105,6 +104,14 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)if (!c) rbo->placements[c++] =TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM ; rbo->placement.num_placement = c; + + c =0 ; + rbo->placement.busy_placement = rbo->busy_placements; +if (rbo->rdev->flags &RADEON_IS_AGP ) { + rbo->busy_placements[c++] =TTM_PL_FLAG_WC |TTM_PL_FLAG_TT ; + }else { + rbo->busy_placements[c++] =TTM_PL_FLAG_CACHED |TTM_PL_FLAG_TT ; + } rbo->placement.num_busy_placement = c; }
@@ -360,17 +367,9 @@ int radeon_bo_list_validate(struct list_head *head)list_for_each_entry (lobj, head, tv.head) { bo = lobj->bo;if (!bo->pin_count) { - domain = lobj->wdomain ? lobj->wdomain : lobj->rdomain; - - retry: -radeon_ttm_placement_from_domain (bo, domain); r =ttm_bo_validate (&bo->tbo, &bo->placement, true, false, false);if (unlikely (r)) { -if (r != -ERESTARTSYS && domain ==RADEON_GEM_DOMAIN_VRAM ) { - domain |=RADEON_GEM_DOMAIN_GTT ; - goto retry; - }return r; } }
Signature · 1 line
1.7.11.7
Re: [PATCH 1/2] drm/radeon: do not move bo to different placement at each cs
Quoted 7 lines · On Thu, Nov 29, 2012 at 10:35 AM, <[email protected]> wrote:
From: Jerome Glisse <[email protected]>
The bo creation placement is where the bo will be. Instead of trying to move bo at each command stream let this work to another worker thread that will use more advance heuristic.
Signed-off-by Jerome Glisse <[email protected]>
What about including this for 3.8 it will mostly fix all regression performance and is a first valid step for proper bo placement.
Cheers,
Jerome
Quoted 65 lines
--- drivers/gpu/drm/radeon/radeon.h | 1 + drivers/gpu/drm/radeon/radeon_object.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-)drivers/gpu/drm/radeon/radeon.h +1
-0@@ -313,6 +313,7 @@ struct radeon_bo {struct list_head list;/* Protected by tbo.reserved */ u32 placements[3 ]; +u32 busy_placements[3 ];struct ttm_placement placement;struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;drivers/gpu/drm/radeon/radeon_object.c +8
-10@@ -84,7 +84,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain) rbo->placement.fpfn =0 ; rbo->placement.lpfn =0 ; rbo->placement.placement = rbo->placements; - rbo->placement.busy_placement = rbo->placements;if (domain &RADEON_GEM_DOMAIN_VRAM ) rbo->placements[c++] =TTM_PL_FLAG_WC |TTM_PL_FLAG_UNCACHED |TTM_PL_FLAG_VRAM ;@@ -105,6 +104,14 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)if (!c) rbo->placements[c++] =TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM ; rbo->placement.num_placement = c; + + c =0 ; + rbo->placement.busy_placement = rbo->busy_placements; +if (rbo->rdev->flags &RADEON_IS_AGP ) { + rbo->busy_placements[c++] =TTM_PL_FLAG_WC |TTM_PL_FLAG_TT ; + }else { + rbo->busy_placements[c++] =TTM_PL_FLAG_CACHED |TTM_PL_FLAG_TT ; + } rbo->placement.num_busy_placement = c; }@@ -360,17 +367,9 @@ int radeon_bo_list_validate(struct list_head *head)list_for_each_entry (lobj, head, tv.head) { bo = lobj->bo;if (!bo->pin_count) { - domain = lobj->wdomain ? lobj->wdomain : lobj->rdomain; - - retry: -radeon_ttm_placement_from_domain (bo, domain); r =ttm_bo_validate (&bo->tbo, &bo->placement, true, false, false);if (unlikely (r)) { -if (r != -ERESTARTSYS && domain ==RADEON_GEM_DOMAIN_VRAM ) { - domain |=RADEON_GEM_DOMAIN_GTT ; - goto retry; - }return r; } } --1.7.11.7
Re: [PATCH 1/2] drm/radeon: do not move bo to different placement at each cs
Quoted 11 lines · Jerome Glisse
Quoted 7 lines · On Thu, Nov 29, 2012 at 10:35 AM, <[email protected]> wrote:
From: Jerome Glisse <[email protected]>
The bo creation placement is where the bo will be. Instead of trying to move bo at each command stream let this work to another worker thread that will use more advance heuristic.
Signed-off-by Jerome Glisse <[email protected]>What about including this for 3.8 it will mostly fix all regression performance and is a first valid step for proper bo placement.
Looks good to me. I'll add it to my 3.8 tree unless there are any objections.
Alex
Quoted 69 lines
Cheers,
JeromeQuoted 65 lines
--- drivers/gpu/drm/radeon/radeon.h | 1 + drivers/gpu/drm/radeon/radeon_object.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-)drivers/gpu/drm/radeon/radeon.h +1
-0@@ -313,6 +313,7 @@ struct radeon_bo {struct list_head list;/* Protected by tbo.reserved */ u32 placements[3 ]; +u32 busy_placements[3 ];struct ttm_placement placement;struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;drivers/gpu/drm/radeon/radeon_object.c +8
-10@@ -84,7 +84,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain) rbo->placement.fpfn =0 ; rbo->placement.lpfn =0 ; rbo->placement.placement = rbo->placements; - rbo->placement.busy_placement = rbo->placements;if (domain &RADEON_GEM_DOMAIN_VRAM ) rbo->placements[c++] =TTM_PL_FLAG_WC |TTM_PL_FLAG_UNCACHED |TTM_PL_FLAG_VRAM ;@@ -105,6 +104,14 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)if (!c) rbo->placements[c++] =TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM ; rbo->placement.num_placement = c; + + c =0 ; + rbo->placement.busy_placement = rbo->busy_placements; +if (rbo->rdev->flags &RADEON_IS_AGP ) { + rbo->busy_placements[c++] =TTM_PL_FLAG_WC |TTM_PL_FLAG_TT ; + }else { + rbo->busy_placements[c++] =TTM_PL_FLAG_CACHED |TTM_PL_FLAG_TT ; + } rbo->placement.num_busy_placement = c; }@@ -360,17 +367,9 @@ int radeon_bo_list_validate(struct list_head *head)list_for_each_entry (lobj, head, tv.head) { bo = lobj->bo;if (!bo->pin_count) { - domain = lobj->wdomain ? lobj->wdomain : lobj->rdomain; - - retry: -radeon_ttm_placement_from_domain (bo, domain); r =ttm_bo_validate (&bo->tbo, &bo->placement, true, false, false);if (unlikely (r)) { -if (r != -ERESTARTSYS && domain ==RADEON_GEM_DOMAIN_VRAM ) { - domain |=RADEON_GEM_DOMAIN_GTT ; - goto retry; - }return r; } } --1.7.11.7
PATCH 2/2 drm/radeon: buffer memory placement work thread WIP
In reply to [email protected]From: Jerome Glisse <[email protected]>
Use delayed work thread to move buffer out of vram if they haven't been use over some period of time. This allow to make room for buffer that are actively use.
--- drivers/gpu/drm/radeon/radeon.h | 13 ++ drivers/gpu/drm/radeon/radeon_cs.c | 2 +- drivers/gpu/drm/radeon/radeon_device.c | 8 ++ drivers/gpu/drm/radeon/radeon_object.c | 241 ++++++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/radeon_object.h | 3 +- 5 files changed, 262 insertions(+), 5 deletions(-)
drivers/gpu/drm/radeon/radeon.h +13 -0
@@ -102,6 +102,8 @@ extern int radeon_lockup_timeout;*/ #define RADEON_MAX_USEC_TIMEOUT 100000/* 100 ms */ #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2) +#define RADEON_PLACEMENT_WORK_MS 500 +#define RADEON_PLACEMENT_MAX_EVICTION 8/* RADEON_IB_POOL_SIZE must be a power of 2 */ #define RADEON_IB_POOL_SIZE 16#define RADEON_DEBUGFS_MAX_COMPONENTS 32
@@ -311,6 +313,10 @@ struct radeon_bo_va {struct radeon_bo {/* Protected by gem.mutex */ struct list_head list; +/* Protected by rdev->placement_mutex */ +struct list_head plist; +struct list_head *head; +unsigned long last_use_jiffies;/* Protected by tbo.reserved */ u32 placements[3 ];u32 busy_placements[3 ];
@@ -1523,6 +1529,13 @@ struct radeon_device {struct drm_device *ddev;struct pci_dev *pdev;struct rw_semaphore exclusive_lock; +struct mutex placement_mutex; +struct list_head wvram_in_list; +struct list_head rvram_in_list; +struct list_head wvram_out_list; +struct list_head rvram_out_list; +struct delayed_work placement_work; +unsigned long vram_in_size;/* ASIC */ union radeon_asic_config config;enum radeon_family family;
drivers/gpu/drm/radeon/radeon_cs.c +1 -1
@@ -88,7 +88,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p) }else p->relocs[i].handle =0 ; } -return radeon_bo_list_validate (&p->validated); +return radeon_bo_list_validate (p->rdev, &p->validated); }static int radeon_cs_get_ring (struct radeon_cs_parser *p,u32 ring,s32 priority)
drivers/gpu/drm/radeon/radeon_device.c +8 -0
@@ -1001,6 +1001,14 @@ int radeon_device_init(struct radeon_device *rdev,init_rwsem (&rdev->pm.mclk_lock);init_rwsem (&rdev->exclusive_lock);init_waitqueue_head (&rdev->irq.vblank_queue); + +mutex_init (&rdev->placement_mutex); +INIT_LIST_HEAD (&rdev->wvram_in_list); +INIT_LIST_HEAD (&rdev->rvram_in_list); +INIT_LIST_HEAD (&rdev->wvram_out_list); +INIT_LIST_HEAD (&rdev->rvram_out_list); +INIT_DELAYED_WORK (&rdev->placement_work, radeon_placement_work_handler); + r =radeon_gem_init (rdev);if (r)return r;
drivers/gpu/drm/radeon/radeon_object.c +238 -3
292 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_object.h +2 -1
@@ -128,7 +128,7 @@ extern int radeon_bo_init(struct radeon_device *rdev);extern void radeon_bo_fini (struct radeon_device *rdev);extern void radeon_bo_list_add_object (struct radeon_bo_list *lobj,struct list_head *head); -extern int radeon_bo_list_validate (struct list_head *head); +extern int radeon_bo_list_validate (struct radeon_device *rdev,struct list_head *head);extern int radeon_bo_fbdev_mmap (struct radeon_bo *bo,struct vm_area_struct *vma); extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
@@ -141,6 +141,7 @@ extern void radeon_bo_move_notify(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem);extern int radeon_bo_fault_reserve_notify (struct ttm_buffer_object *bo);extern int radeon_bo_get_surface_reg (struct radeon_bo *bo); +extern void radeon_placement_work_handler (struct work_struct *work);/* * sub allocation
Signature · 1 line
1.7.11.7
Quoted 11 lines · On Thu, Nov 29, 2012 at 4:35 PM, <[email protected]> wrote:
So as a followup is 2 patch. The first one just stop trying to move object at each cs ioctl i believe it could be included in 3.7 as it improve performances (especialy with vram change from userspace).
The second one implement a vram eviction policy. It's a simple one, buffer used for write operation are more important than buffer used for read operation. Buffer get evicted from vram only if they haven't been use in the last 50ms (so in the last few frames) and only if there is buffer that have been recently use and that could be move into vram. This is mostly were i believe discussion should be, what kind of heuristic would work better than tat.
First off, I didn't review the patches, because I'm not as familiar with the DRM. Just some comments.
Isn't 50ms too little? You always need at least 20 fps for that to make sense. I think 200ms would be more reasonable, but still that isn't perfect either.
Another option would be to use something else than elapsed time, something that's based on actual usage.
This weekend, I'll try to make a Mesa patch that sends an end-of-frame flag to the kernel through the CS ioctl. I think there would be at most 2 end-of-frame flags received by the kernel each frame: one from the GL app and the other one from the compositor.
Marek
Quoted 13 lines · Marek Olšák
Quoted 11 lines · On Thu, Nov 29, 2012 at 4:35 PM, <[email protected]> wrote:
So as a followup is 2 patch. The first one just stop trying to move object at each cs ioctl i believe it could be included in 3.7 as it improve performances (especialy with vram change from userspace).
The second one implement a vram eviction policy. It's a simple one, buffer used for write operation are more important than buffer used for read operation. Buffer get evicted from vram only if they haven't been use in the last 50ms (so in the last few frames) and only if there is buffer that have been recently use and that could be move into vram. This is mostly were i believe discussion should be, what kind of heuristic would work better than tat.
Quoted 6 lines
First off, I didn't review the patches, because I'm not as familiar with the DRM. Just some comments.
Isn't 50ms too little? You always need at least 20 fps for that to make sense. I think 200ms would be more reasonable, but still that isn't perfect either.
Well it's an tunable, i did try several value btw 100ms and 500ms and 500ms gave the best result, i think it's mostly because there is still ping pong otherwise, ie one of the bo is big and it get evicted because for few frame is not use but at the same time other bo that move in are not that big and doesn't make much diff to be in vram or gtt, but then the big one suddenly is use again but this time its in gtt.
It's mostly guessing through what my printk shows in vram in and vram out.
Also there is quite few short lived bo and migrating any long lived bo out of vram hurts.
Quoted 9 lines
Another option would be to use something else than elapsed time, something that's based on actual usage.
This weekend, I'll try to make a Mesa patch that sends an end-of-frame flag to the kernel through the CS ioctl. I think there would be at most 2 end-of-frame flags received by the kernel each frame: one from the GL app and the other one from the compositor.
Marek
I am not sure how much value it's, if you take time like 15ms and assume that the program run at 60hz you get a good approximation. I think that rather than use last time since used metric for eviction i should rather compute use frequency, it would smooth things out ie things might stay in vram tiny bit longer than strictly necessary but at the same time buffer with high frequency usage would move in first, with my current algo a buffer might get lucky and move in just because it was last use.
But anyway we could probably also play with metric involving end of frame.
Cheers,
Jerome
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel