TTM placement & caching issue/questions
Subsystems (4)
Hi folks !
I've been tracking down some problems with the recent DRI on powerpc and stumbled upon something that doesn't look right, and not necessarily only for us.
Now it's possible that I haven't fully understood the code here and I also don't know to what extent some of that behaviour is necessary for some platforms such as Intel GTT bits.
What I've observed with a simple/dumb (no DMA) driver like AST (but this probably happens more generally) is that when evicting a BO from VRAM into System memory, the TTM tries to preserve the existing caching attributes of the VRAM object.
Quoted 1 line
From what I can tell, we end up with going from VRAM to System memory
type, and we eventually call ttm_bo_select_caching() to select the caching option for the target.
This will, from what I can tell, try to use the same caching mode as the original object:
if ((cur_placement & caching) != 0) result |= (cur_placement & caching);
And cur_placement comes from bo->mem.placement which as far as I can tell is based on the placement array which the drivers set up.
Now they tend to uniformly setup the placement for System memory as TTM_PL_MASK_CACHING which enables all caching modes.
So I end up with, for example, my System memory BOs having TTM_PL_FLAG_CACHED not set (though they also don't have TTM_PL_FLAG_UNCACHED) and TTM_PL_FLAG_WC.
We don't seem to use the man->default_caching (which will have TTM_PL_FLAG_CACHED) unless there is no matching bit at all between the proposed placement and the existing caching mode.
Now this is a problem for several reason that I can think of:
- On a number of powerpc platforms, such as all our server 64-bit one
for example, it's actually illegal to map system memory non-cached. The system is fully cache coherent for all possible DMA originators (that we care about at least) and mapping memory non-cachable while it's mapped cachable in the linear mapping can cause nasty cache paradox which, when detected by HW, can checkstop the system.
- A similar issue exists, afaik, on ARM >= v7, so anything mapped
non-cachable must be removed from the linear mapping explicitly since otherwise it can be speculatively prefetched into the cache.
- I don't know about x86, but even then, it looks quite sub-optimal to
map the memory backing of the BOs and access it using a WC rather than a cachable mapping attribute.
Now, some folks on IRC mentioned that there might be reasons for the current behaviour as to not change the caching attributes when going in/out of the GTT on Intel, I don't know how that relates and how that works, but maybe that should be enforced by having a different placement mask specifically on those chipsets.
Dave, should we change the various PCI drivers for generally coherent devices such that the System memory type doesn't allow placements without CACHED attribute ? Or at least on coherent platforms ? How do detect that ? Should we have a TTM helper to establish the default memory placement attributes that "normal PCI" drivers call to set that up so we can have all the necessary arch ifdefs in one single place, at least for "classic PCI/PCIe" stuff (AGP might need additional tweaks) ?
Non-PCI and "special" drivers like Intel can use a different set of placement attributes to represent the requirements of those specific platforms (mostly thinking of embedded ARM here which under some circumstances might actually require non-cached mappings). Or am I missing another part of the puzzle ?
As it-is, things are broken for me even for dumb drivers, and I suspect to a large extent with radeon and nouveau too, though in some case we might get away with it most of the time ... until the machine locks up for some unexplainable reason... This might cause problems on existing distros such as RHEL7 with our radeon adapters even.
Any suggestion of what's the best approach to fix it ? I'm happy to produce the patches but I'm not that familiar with the TTM so I would like to make sure I'm the right track first :-)
Cheers,
Ben.
Quoted 82 lines · Benjamin Herrenschmidt
Hi folks !
I've been tracking down some problems with the recent DRI on powerpc and stumbled upon something that doesn't look right, and not necessarily only for us.
Now it's possible that I haven't fully understood the code here and I also don't know to what extent some of that behaviour is necessary for some platforms such as Intel GTT bits.
What I've observed with a simple/dumb (no DMA) driver like AST (but this probably happens more generally) is that when evicting a BO from VRAM into System memory, the TTM tries to preserve the existing caching attributes of the VRAM object.
From what I can tell, we end up with going from VRAM to System memory type, and we eventually call
ttm_bo_select_caching()to select the caching option for the target.This will, from what I can tell, try to use the same caching mode as the original object:
if ((cur_placement & caching) != 0) result |= (cur_placement & caching);And
cur_placementcomes frombo->mem.placementwhich as far as I can tell is based on the placement array which the drivers set up.Now they tend to uniformly setup the placement for System memory as
TTM_PL_MASK_CACHINGwhich enables all caching modes.So I end up with, for example, my System memory BOs having
TTM_PL_FLAG_CACHEDnot set (though they also don't haveTTM_PL_FLAG_UNCACHED) andTTM_PL_FLAG_WC.We don't seem to use the
man->default_caching(which will haveTTM_PL_FLAG_CACHED) unless there is no matching bit at all between the proposed placement and the existing caching mode.Now this is a problem for several reason that I can think of:
- On a number of powerpc platforms, such as all our server 64-bit one
for example, it's actually illegal to map system memory non-cached. The system is fully cache coherent for all possible DMA originators (that we care about at least) and mapping memory non-cachable while it's mapped cachable in the linear mapping can cause nasty cache paradox which, when detected by HW, can checkstop the system.- A similar issue exists, afaik, on ARM >= v7, so anything mapped
non-cachable must be removed from the linear mapping explicitly since otherwise it can be speculatively prefetched into the cache.- I don't know about x86, but even then, it looks quite sub-optimal to
map the memory backing of the BOs and access it using a WC rather than a cachable mapping attribute.Now, some folks on IRC mentioned that there might be reasons for the current behaviour as to not change the caching attributes when going in/out of the GTT on Intel, I don't know how that relates and how that works, but maybe that should be enforced by having a different placement mask specifically on those chipsets.
Dave, should we change the various PCI drivers for generally coherent devices such that the System memory type doesn't allow placements without CACHED attribute ? Or at least on coherent platforms ? How do detect that ? Should we have a TTM helper to establish the default memory placement attributes that "normal PCI" drivers call to set that up so we can have all the necessary arch ifdefs in one single place, at least for "classic PCI/PCIe" stuff (AGP might need additional tweaks) ?
Non-PCI and "special" drivers like Intel can use a different set of placement attributes to represent the requirements of those specific platforms (mostly thinking of embedded ARM here which under some circumstances might actually require non-cached mappings). Or am I missing another part of the puzzle ?
As it-is, things are broken for me even for dumb drivers, and I suspect to a large extent with radeon and nouveau too, though in some case we might get away with it most of the time ... until the machine locks up for some unexplainable reason... This might cause problems on existing distros such as RHEL7 with our radeon adapters even.
Quoted 3 lines
Any suggestion of what's the best approach to fix it ? I'm happy to produce the patches but I'm not that familiar with the TTM so I would like to make sure I'm the right track first :-)
While i agree about the issue of incoherent double map of same page, i think we have more issue. For instance lattely AMD have been pushing a lot of patches to move things to use uncached memory for radeon and as usual thoses patches comes with no comment to the motivations of those changes. I am ccing the usual suspect ;)
What i understand is that uncached mapping for some frequently use buffer give a significant performance boost (i am assuming this has to do with all the snoop pci transaction overhead).
Quoted 1 line
From my understanding this is something that is allow on other OS and
any driver wishing to compete from performance point of view will want that.
So i think we need to get a platform flags and or set_pages_array_wc|uc needs to fail and this would fallback to cached mapping if the fallback code still works. So if your arch properly return and error for those cache changing function then you should be fine.
This also means that we need to fix ttm_tt_set_placement_caching so that when it returns an error it switches to cached mapping. Which will always work.
Cheers,
Jérôme
Quoted 9 lines
Cheers,
Ben._______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 102 lines · Jerome Glisse
Quoted 82 lines · Benjamin Herrenschmidt
Hi folks !
I've been tracking down some problems with the recent DRI on powerpc and stumbled upon something that doesn't look right, and not necessarily only for us.
Now it's possible that I haven't fully understood the code here and I also don't know to what extent some of that behaviour is necessary for some platforms such as Intel GTT bits.
What I've observed with a simple/dumb (no DMA) driver like AST (but this probably happens more generally) is that when evicting a BO from VRAM into System memory, the TTM tries to preserve the existing caching attributes of the VRAM object.
From what I can tell, we end up with going from VRAM to System memory type, and we eventually call
ttm_bo_select_caching()to select the caching option for the target.This will, from what I can tell, try to use the same caching mode as the original object:
if ((cur_placement & caching) != 0) result |= (cur_placement & caching);And
cur_placementcomes frombo->mem.placementwhich as far as I can tell is based on the placement array which the drivers set up.Now they tend to uniformly setup the placement for System memory as
TTM_PL_MASK_CACHINGwhich enables all caching modes.So I end up with, for example, my System memory BOs having
TTM_PL_FLAG_CACHEDnot set (though they also don't haveTTM_PL_FLAG_UNCACHED) andTTM_PL_FLAG_WC.We don't seem to use the
man->default_caching(which will haveTTM_PL_FLAG_CACHED) unless there is no matching bit at all between the proposed placement and the existing caching mode.Now this is a problem for several reason that I can think of:
- On a number of powerpc platforms, such as all our server 64-bit one
for example, it's actually illegal to map system memory non-cached. The system is fully cache coherent for all possible DMA originators (that we care about at least) and mapping memory non-cachable while it's mapped cachable in the linear mapping can cause nasty cache paradox which, when detected by HW, can checkstop the system.- A similar issue exists, afaik, on ARM >= v7, so anything mapped
non-cachable must be removed from the linear mapping explicitly since otherwise it can be speculatively prefetched into the cache.- I don't know about x86, but even then, it looks quite sub-optimal to
map the memory backing of the BOs and access it using a WC rather than a cachable mapping attribute.Now, some folks on IRC mentioned that there might be reasons for the current behaviour as to not change the caching attributes when going in/out of the GTT on Intel, I don't know how that relates and how that works, but maybe that should be enforced by having a different placement mask specifically on those chipsets.
Dave, should we change the various PCI drivers for generally coherent devices such that the System memory type doesn't allow placements without CACHED attribute ? Or at least on coherent platforms ? How do detect that ? Should we have a TTM helper to establish the default memory placement attributes that "normal PCI" drivers call to set that up so we can have all the necessary arch ifdefs in one single place, at least for "classic PCI/PCIe" stuff (AGP might need additional tweaks) ?
Non-PCI and "special" drivers like Intel can use a different set of placement attributes to represent the requirements of those specific platforms (mostly thinking of embedded ARM here which under some circumstances might actually require non-cached mappings). Or am I missing another part of the puzzle ?
As it-is, things are broken for me even for dumb drivers, and I suspect to a large extent with radeon and nouveau too, though in some case we might get away with it most of the time ... until the machine locks up for some unexplainable reason... This might cause problems on existing distros such as RHEL7 with our radeon adapters even.
Quoted 3 lines
Any suggestion of what's the best approach to fix it ? I'm happy to produce the patches but I'm not that familiar with the TTM so I would like to make sure I'm the right track first :-)
While i agree about the issue of incoherent double map of same page, i think we have more issue. For instance lattely AMD have been pushing a lot of patches to move things to use uncached memory for radeon and as usual thoses patches comes with no comment to the motivations of those changes. I am ccing the usual suspect ;)
What i understand is that uncached mapping for some frequently use buffer give a significant performance boost (i am assuming this has to do with all the snoop pci transaction overhead).
From my understanding this is something that is allow on other OS and any driver wishing to compete from performance point of view will want that.
Quoted 8 lines
So i think we need to get a platform flags and or set_pages_array_wc|uc needs to fail and this would fallback to cached mapping if the fallback code still works. So if your arch properly return and error for those cache changing function then you should be fine.
This also means that we need to fix
ttm_tt_set_placement_cachingso that when it returns an error it switches to cached mapping. Which will always work.
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
It's not tested but i think it should work.
Quoted 9 lines
Cheers,
JérômeQuoted 5 lines
Cheers,
Ben.
Quoted 5 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-develFrom
df0b5d1488daed05d7b4508759401a3e89cd4a38Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <[email protected]>
Date: Wed, 3 Sep 2014 22:04:34 -0400
Subject: [PATCH] drm/ttm: force cached mapping on non x86 platform.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
People interested in providing uncached or write combined mapping on there architecture need to do the ground work inside there arch specific code to allow to break the linear kernel mapping so that page mapping attributes can be updated, in the meantime force cached mapping for non x86 architecture.
--- drivers/gpu/drm/ttm/ttm_tt.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +9 -8
@@ -89,14 +89,6 @@ static inline int ttm_tt_set_page_caching(struct page *p,return ret; } -#else /* CONFIG_X86 */ -static inline int ttm_tt_set_page_caching (struct page *p, -enum ttm_caching_state c_old, -enum ttm_caching_state c_new) -{ -return 0 ; -} -#endif /* CONFIG_X86 */ /* * Change caching policy for the linear kernel map
@@ -149,6 +141,15 @@ out_err: return ret; } +#else /* CONFIG_X86 */ +static int ttm_tt_set_caching (struct ttm_tt *ttm, +enum ttm_caching_state c_state) +{ + ttm->caching_state = tt_cached; +return 0 ; +} +#endif /* CONFIG_X86 */ +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement) {enum ttm_caching_state state;
Signature · 1 line
1.9.3
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 6 lines · Jerome Glisse
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
It's not tested but i think it should work.
I'm still getting placements with !CACHED going from bo_memcpy in ttm_io_prot() though ... I'm looking at filtering the placement attributes instead.
Ben.
Quoted 5 lines
Quoted 5 lines
Cheers,
JérômeQuoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Cheers,
Ben._______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines · Jerome Glisse
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
Quoted 7 lines
Quoted 1 line
It's not tested but i think it should work.
I'm still getting placements with !CACHED going from
bo_memcpyinttm_io_prot()though ... I'm looking at filtering the placement attributes instead.Ben.
Ok so this one should do the trick.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Cheers,
JérômeQuoted 5 lines
Cheers,
Ben.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-develFrom
def7a056d042220f91016d0a7c245ba8e96f90baMon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <[email protected]>
Date: Wed, 3 Sep 2014 22:04:34 -0400
Subject: [PATCH] drm/ttm: force cached mapping on non x86 platform.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
People interested in providing uncached or write combined mapping on there architecture need to do the ground work inside there arch specific code to allow to break the linear kernel mapping so that page mapping attributes can be updated, in the meantime force cached mapping for non x86 architecture.
--- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_tt.c | 47 ++++++++++++++++++++++++++++--------- include/drm/ttm/ttm_bo_driver.h | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
@@ -304,7 +304,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,return r; } - r =ttm_tt_set_placement_caching (bo->ttm, tmp_mem.placement); + r =ttm_tt_set_placement_caching (bo->ttm, &tmp_mem.placement);if (unlikely (r)) { goto out_cleanup; }
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -305,7 +305,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, goto out_err; } - ret =ttm_tt_set_placement_caching (bo->ttm, mem->placement); + ret =ttm_tt_set_placement_caching (bo->ttm, &mem->placement);if (ret) goto out_err;
drivers/gpu/drm/ttm/ttm_tt.c +36 -11
69 lines not on this page · raw message
include/drm/ttm/ttm_bo_driver.h +1 -1
@@ -669,7 +669,7 @@ extern int ttm_tt_swapin(struct ttm_tt *ttm);* hit RAM. This function may be very costly as it involves global TLB * and cache flushes and potential page splitting / combining. */ -extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement); +extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement);extern int ttm_tt_swapout (struct ttm_tt *ttm,struct file *persistent_swap_storage);
Signature · 1 line
1.9.3
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 10 lines · Jerome Glisse
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jerome Glisse
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
It's not tested but i think it should work.
Quoted 7 lines
Quoted 5 lines
I'm still getting placements with !CACHED going from
bo_memcpyinttm_io_prot()though ... I'm looking at filtering the placement attributes instead.Ben.
Ok so this one should do the trick.
And this one should build :)
Quoted 160 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Cheers,
JérômeQuoted 1 line
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Cheers,
Ben._______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-develFrom
def7a056d042220f91016d0a7c245ba8e96f90baMon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <[email protected]>
Date: Wed, 3 Sep 2014 22:04:34 -0400
Subject: [PATCH] drm/ttm: force cached mapping on non x86 platform.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitPeople interested in providing uncached or write combined mapping on there architecture need to do the ground work inside there arch specific code to allow to break the linear kernel mapping so that page mapping attributes can be updated, in the meantime force cached mapping for non x86 architecture.
Signed-off-by Jérôme Glisse <[email protected]>--- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_tt.c | 47 ++++++++++++++++++++++++++++--------- include/drm/ttm/ttm_bo_driver.h | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-)drivers/gpu/drm/radeon/radeon_ttm.c +1
-1@@ -304,7 +304,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,return r; } - r =ttm_tt_set_placement_caching (bo->ttm, tmp_mem.placement); + r =ttm_tt_set_placement_caching (bo->ttm, &tmp_mem.placement);if (unlikely (r)) { goto out_cleanup; }drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -305,7 +305,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, goto out_err; } - ret =ttm_tt_set_placement_caching (bo->ttm, mem->placement); + ret =ttm_tt_set_placement_caching (bo->ttm, &mem->placement);if (ret) goto out_err;drivers/gpu/drm/ttm/ttm_tt.c +36
-11@@ -89,14 +89,6 @@ static inline int ttm_tt_set_page_caching(struct page *p,return ret; } -#else /* CONFIG_X86 */ -static inline int ttm_tt_set_page_caching (struct page *p, -enum ttm_caching_state c_old, -enum ttm_caching_state c_new) -{ -return 0 ; -} -#endif /* CONFIG_X86 */ /* * Change caching policy for the linear kernel map @@ -149,19 +141,52 @@ out_err:return ret; } -int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement) +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) {enum ttm_caching_state state; -if (placement &TTM_PL_FLAG_WC ) +if (*placement &TTM_PL_FLAG_WC ) state = tt_wc; -else if (placement &TTM_PL_FLAG_UNCACHED ) +else if (*placement &TTM_PL_FLAG_UNCACHED ) state = tt_uncached;else state = tt_cached;return ttm_tt_set_caching (ttm, state); } +#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) +{ +if (placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + }else { +if (placement &TTM_PL_FLAG_WC ) + ttm->caching_state = tt_wc; +else if (placement &TTM_PL_FLAG_UNCACHED ) + ttm->caching_state = tt_uncached; +else + ttm->caching_state = tt_cached; + } +/* +* Some architecture force cached so we need to reflect the +* new ttm->caching_state into the mem->placement flags. +*/ + *placement &= ~TTM_PL_MASK_CACHING ; +switch (bo->ttm->caching_state) { +case tt_wc: + *placement |=TTM_PL_FLAG_WC ; +break ; +case tt_uncached: + *placement |=TTM_PL_FLAG_UNCACHED ; +break ; +case tt_cached: +default : + *placement |=TTM_PL_FLAG_CACHED ; +break ; + } +return 0 ; +} +#endif /* CONFIG_X86 */ EXPORT_SYMBOL (ttm_tt_set_placement_caching);void ttm_tt_destroy (struct ttm_tt *ttm)include/drm/ttm/ttm_bo_driver.h +1
-1@@ -669,7 +669,7 @@ extern int ttm_tt_swapin(struct ttm_tt *ttm);* hit RAM. This function may be very costly as it involves global TLB * and cache flushes and potential page splitting / combining. */ -extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement); +extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement);extern int ttm_tt_swapout (struct ttm_tt *ttm,struct file *persistent_swap_storage);Signature · 4 lines
1.9.3 From 6ed69ceee96873ab351881c6b9f931cec39f396a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <[email protected]>
Date: Wed, 3 Sep 2014 22:04:34 -0400
Subject: [PATCH] drm/ttm: force cached mapping on non x86 platform.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
People interested in providing uncached or write combined mapping on there architecture need to do the ground work inside there arch specific code to allow to break the linear kernel mapping so that page mapping attributes can be updated, in the meantime force cached mapping for non x86 architecture.
--- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_tt.c | 47 ++++++++++++++++++++++++++++--------- include/drm/ttm/ttm_bo_driver.h | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
@@ -304,7 +304,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,return r; } - r =ttm_tt_set_placement_caching (bo->ttm, tmp_mem.placement); + r =ttm_tt_set_placement_caching (bo->ttm, &tmp_mem.placement);if (unlikely (r)) { goto out_cleanup; }
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -305,7 +305,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, goto out_err; } - ret =ttm_tt_set_placement_caching (bo->ttm, mem->placement); + ret =ttm_tt_set_placement_caching (bo->ttm, &mem->placement);if (ret) goto out_err;
drivers/gpu/drm/ttm/ttm_tt.c +36 -11
69 lines not on this page · raw message
include/drm/ttm/ttm_bo_driver.h +1 -1
@@ -669,7 +669,7 @@ extern int ttm_tt_swapin(struct ttm_tt *ttm);* hit RAM. This function may be very costly as it involves global TLB * and cache flushes and potential page splitting / combining. */ -extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement); +extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement);extern int ttm_tt_swapout (struct ttm_tt *ttm,struct file *persistent_swap_storage);
Signature · 1 line
1.9.3
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 10 lines · Jerome Glisse
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jerome Glisse
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
It's not tested but i think it should work.
Quoted 7 lines
Quoted 5 lines
I'm still getting placements with !CACHED going from
bo_memcpyinttm_io_prot()though ... I'm looking at filtering the placement attributes instead.Ben.
Ok so this one should do the trick.
Ok final version ... famous last word.
Quoted 160 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Cheers,
JérômeQuoted 1 line
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Cheers,
Ben._______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-develFrom
def7a056d042220f91016d0a7c245ba8e96f90baMon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <[email protected]>
Date: Wed, 3 Sep 2014 22:04:34 -0400
Subject: [PATCH] drm/ttm: force cached mapping on non x86 platform.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitPeople interested in providing uncached or write combined mapping on there architecture need to do the ground work inside there arch specific code to allow to break the linear kernel mapping so that page mapping attributes can be updated, in the meantime force cached mapping for non x86 architecture.
Signed-off-by Jérôme Glisse <[email protected]>--- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_tt.c | 47 ++++++++++++++++++++++++++++--------- include/drm/ttm/ttm_bo_driver.h | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-)drivers/gpu/drm/radeon/radeon_ttm.c +1
-1@@ -304,7 +304,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,return r; } - r =ttm_tt_set_placement_caching (bo->ttm, tmp_mem.placement); + r =ttm_tt_set_placement_caching (bo->ttm, &tmp_mem.placement);if (unlikely (r)) { goto out_cleanup; }drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -305,7 +305,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, goto out_err; } - ret =ttm_tt_set_placement_caching (bo->ttm, mem->placement); + ret =ttm_tt_set_placement_caching (bo->ttm, &mem->placement);if (ret) goto out_err;drivers/gpu/drm/ttm/ttm_tt.c +36
-11@@ -89,14 +89,6 @@ static inline int ttm_tt_set_page_caching(struct page *p,return ret; } -#else /* CONFIG_X86 */ -static inline int ttm_tt_set_page_caching (struct page *p, -enum ttm_caching_state c_old, -enum ttm_caching_state c_new) -{ -return 0 ; -} -#endif /* CONFIG_X86 */ /* * Change caching policy for the linear kernel map @@ -149,19 +141,52 @@ out_err:return ret; } -int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement) +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) {enum ttm_caching_state state; -if (placement &TTM_PL_FLAG_WC ) +if (*placement &TTM_PL_FLAG_WC ) state = tt_wc; -else if (placement &TTM_PL_FLAG_UNCACHED ) +else if (*placement &TTM_PL_FLAG_UNCACHED ) state = tt_uncached;else state = tt_cached;return ttm_tt_set_caching (ttm, state); } +#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) +{ +if (placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + }else { +if (placement &TTM_PL_FLAG_WC ) + ttm->caching_state = tt_wc; +else if (placement &TTM_PL_FLAG_UNCACHED ) + ttm->caching_state = tt_uncached; +else + ttm->caching_state = tt_cached; + } +/* +* Some architecture force cached so we need to reflect the +* new ttm->caching_state into the mem->placement flags. +*/ + *placement &= ~TTM_PL_MASK_CACHING ; +switch (bo->ttm->caching_state) { +case tt_wc: + *placement |=TTM_PL_FLAG_WC ; +break ; +case tt_uncached: + *placement |=TTM_PL_FLAG_UNCACHED ; +break ; +case tt_cached: +default : + *placement |=TTM_PL_FLAG_CACHED ; +break ; + } +return 0 ; +} +#endif /* CONFIG_X86 */ EXPORT_SYMBOL (ttm_tt_set_placement_caching);void ttm_tt_destroy (struct ttm_tt *ttm)include/drm/ttm/ttm_bo_driver.h +1
-1@@ -669,7 +669,7 @@ extern int ttm_tt_swapin(struct ttm_tt *ttm);* hit RAM. This function may be very costly as it involves global TLB * and cache flushes and potential page splitting / combining. */ -extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement); +extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement);extern int ttm_tt_swapout (struct ttm_tt *ttm,struct file *persistent_swap_storage);Signature · 4 lines
1.9.3 From 236038e18dc303bb9aa877922e01963d3fb0b7af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <[email protected]>
Date: Wed, 3 Sep 2014 22:04:34 -0400
Subject: [PATCH] drm/ttm: force cached mapping on non x86 platform.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
People interested in providing uncached or write combined mapping on there architecture need to do the ground work inside there arch specific code to allow to break the linear kernel mapping so that page mapping attributes can be updated, in the meantime force cached mapping for non x86 architecture.
--- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_tt.c | 32 +++++++++++++++++++++----------- include/drm/ttm/ttm_bo_driver.h | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
@@ -304,7 +304,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,return r; } - r =ttm_tt_set_placement_caching (bo->ttm, tmp_mem.placement); + r =ttm_tt_set_placement_caching (bo->ttm, &tmp_mem.placement);if (unlikely (r)) { goto out_cleanup; }
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -305,7 +305,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, goto out_err; } - ret =ttm_tt_set_placement_caching (bo->ttm, mem->placement); + ret =ttm_tt_set_placement_caching (bo->ttm, &mem->placement);if (ret) goto out_err;
drivers/gpu/drm/ttm/ttm_tt.c +21 -11
@@ -89,14 +89,6 @@ static inline int ttm_tt_set_page_caching(struct page *p,return ret; } -#else /* CONFIG_X86 */ -static inline int ttm_tt_set_page_caching (struct page *p, -enum ttm_caching_state c_old, -enum ttm_caching_state c_new) -{ -return 0 ; -} -#endif /* CONFIG_X86 */ /* * Change caching policy for the linear kernel map
@@ -149,19 +141,37 @@ out_err:return ret; } -int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement) +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) {enum ttm_caching_state state; -if (placement &TTM_PL_FLAG_WC ) +if (*placement &TTM_PL_FLAG_WC ) state = tt_wc; -else if (placement &TTM_PL_FLAG_UNCACHED ) +else if (*placement &TTM_PL_FLAG_UNCACHED ) state = tt_uncached;else state = tt_cached;return ttm_tt_set_caching (ttm, state); } +#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) +{ +if (*placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + *placement &= ~TTM_PL_MASK_CACHING ; + *placement |=TTM_PL_FLAG_CACHED ; + }else { +if (*placement &TTM_PL_FLAG_WC ) + ttm->caching_state = tt_wc; +else if (placement &TTM_PL_FLAG_UNCACHED ) + ttm->caching_state = tt_uncached; +else + ttm->caching_state = tt_cached; + } +return 0 ; +} +#endif /* CONFIG_X86 */ EXPORT_SYMBOL (ttm_tt_set_placement_caching);void ttm_tt_destroy (struct ttm_tt *ttm)
include/drm/ttm/ttm_bo_driver.h +1 -1
@@ -669,7 +669,7 @@ extern int ttm_tt_swapin(struct ttm_tt *ttm);* hit RAM. This function may be very costly as it involves global TLB * and cache flushes and potential page splitting / combining. */ -extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement); +extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement);extern int ttm_tt_swapout (struct ttm_tt *ttm,struct file *persistent_swap_storage);
Signature · 1 line
1.9.3
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 15 lines · Jerome Glisse
Quoted 14 lines · Jerome Glisse
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jerome Glisse
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
It's not tested but i think it should work.
I'm still getting placements with !CACHED going from
bo_memcpyinttm_io_prot()though ... I'm looking at filtering the placement attributes instead.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Ben.
Ok so this one should do the trick.
Ok final version ... famous last word.
Minus a couple of obvious typos that prevent if from building, it seems to do the trick for me with the AST driver, no more bad mappings.
I'll still send a patch that catches the incorrect mapping attempts inside ttm_io_prot() and warns to help future debugging and avoid "random" behaviour. (I need to fix other things in the powerpc code in there anyway).
Cheers,
Ben.
Quoted 15 lines · Jerome Glisse
Quoted 14 lines · Jerome Glisse
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jerome Glisse
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
It's not tested but i think it should work.
I'm still getting placements with !CACHED going from
bo_memcpyinttm_io_prot()though ... I'm looking at filtering the placement attributes instead.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Ben.
Ok so this one should do the trick.
Ok final version ... famous last word.
[snipped older version]
Quoted 10 lines
Quoted 1 line
From
236038e18dc303bb9aa877922e01963d3fb0b7afMon Sep 17 00:00:00 2001From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <[email protected]>
Date: Wed, 3 Sep 2014 22:04:34 -0400
Subject: [PATCH] drm/ttm: force cached mapping on non x86 platform.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitPeople interested in providing uncached or write combined mapping on there architecture need to do the ground work inside there arch
s/there/their/g
Quoted 119 lines
specific code to allow to break the linear kernel mapping so that page mapping attributes can be updated, in the meantime force cached mapping for non x86 architecture.
Signed-off-by Jérôme Glisse <[email protected]>--- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_tt.c | 32 +++++++++++++++++++++----------- include/drm/ttm/ttm_bo_driver.h | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-)drivers/gpu/drm/radeon/radeon_ttm.c +1
-1@@ -304,7 +304,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,return r; } - r =ttm_tt_set_placement_caching (bo->ttm, tmp_mem.placement); + r =ttm_tt_set_placement_caching (bo->ttm, &tmp_mem.placement);if (unlikely (r)) { goto out_cleanup; }drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -305,7 +305,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, goto out_err; } - ret =ttm_tt_set_placement_caching (bo->ttm, mem->placement); + ret =ttm_tt_set_placement_caching (bo->ttm, &mem->placement);if (ret) goto out_err;drivers/gpu/drm/ttm/ttm_tt.c +21
-11@@ -89,14 +89,6 @@ static inline int ttm_tt_set_page_caching(struct page *p,return ret; } -#else /* CONFIG_X86 */ -static inline int ttm_tt_set_page_caching (struct page *p, -enum ttm_caching_state c_old, -enum ttm_caching_state c_new) -{ -return 0 ; -} -#endif /* CONFIG_X86 */ /* * Change caching policy for the linear kernel map @@ -149,19 +141,37 @@ out_err:return ret; } -int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement) +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) {enum ttm_caching_state state; -if (placement &TTM_PL_FLAG_WC ) +if (*placement &TTM_PL_FLAG_WC ) state = tt_wc; -else if (placement &TTM_PL_FLAG_UNCACHED ) +else if (*placement &TTM_PL_FLAG_UNCACHED ) state = tt_uncached;else state = tt_cached;return ttm_tt_set_caching (ttm, state); } +#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) +{ +if (*placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + *placement &= ~TTM_PL_MASK_CACHING ; + *placement |=TTM_PL_FLAG_CACHED ; + }else { +if (*placement &TTM_PL_FLAG_WC ) + ttm->caching_state = tt_wc; +else if (placement &TTM_PL_FLAG_UNCACHED ) + ttm->caching_state = tt_uncached; +else + ttm->caching_state = tt_cached; + } +return 0 ; +} +#endif /* CONFIG_X86 */ EXPORT_SYMBOL (ttm_tt_set_placement_caching);void ttm_tt_destroy (struct ttm_tt *ttm)include/drm/ttm/ttm_bo_driver.h +1
-1@@ -669,7 +669,7 @@ extern int ttm_tt_swapin(struct ttm_tt *ttm);* hit RAM. This function may be very costly as it involves global TLB * and cache flushes and potential page splitting / combining. */ -extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t placement); +extern int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement);extern int ttm_tt_swapout (struct ttm_tt *ttm,struct file *persistent_swap_storage);Signature · 7 lines
1.9.3 _______________________________________________ Linuxppc-dev mailing list [email protected] https://lists.ozlabs.org/listinfo/linuxppc-dev
Michel Dänzer
NAKQuoted 20 lines · Jerome Glisse
Quoted 10 lines · Jerome Glisse
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jerome Glisse
So in the meantime the attached patch should work, it just silently ignore the caching attribute request on non x86 instead of pretending that things are setup as expected and then latter the radeon ou nouveau hw unsetting the snoop bit.
It's not tested but i think it should work.
Quoted 7 lines
Quoted 5 lines
I'm still getting placements with !CACHED going from
bo_memcpyinttm_io_prot()though ... I'm looking at filtering the placement attributes instead.Ben.
Ok so this one should do the trick.
Ok final version ... famous last word.
[...]
drivers/gpu/drm/ttm/ttm_tt.c out_err: · line 163
Quoted 7 lines
drivers/gpu/drm/ttm/ttm_tt.c +7
-0+#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching (struct ttm_tt *ttm,uint32_t *placement) +{ +if (*placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + *placement &= ~TTM_PL_MASK_CACHING ; + *placement |=TTM_PL_FLAG_CACHED ;
NAK, this will break AGP on PowerMacs.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Quoted 10 lines · Michel Dänzer
Review
Quoted 2 lines
(quoted diff) +2
-0+#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t*placement)
drivers/gpu/drm/ttm/ttm_tt.c out_err: · line 163
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_tt.c +5
-0+{ +if (*placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + *placement &= ~TTM_PL_MASK_CACHING ; + *placement |=TTM_PL_FLAG_CACHED ;NAK, this will break AGP on PowerMacs.
... which doesn't work reliably anyway with DRI2 :-)
The problem is ... with DRI1 I think we had tricks to take out the AGP from the linear mapping but that want away, didn't we ?
In any case, we are playing with fire on these by allowing the cache paradox. It just happens that those old CPUs aren't *that* aggressive at speculative prefetch and we probably rarely hit the lockups that they would cause...
Michel, what do you recommend we do then ? The patch I sent to double check in ttm_io_prot() has a specific hack to avoid warning on PowerMac for the above reason, but we need to fix Jerome if we want to keep that broken-by-design Mac AGP functionality going :-)
Maybe we could add a similar ifdef in the above ?
Cheers,
Ben.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Michel Dänzer
Review
Quoted 2 lines
(quoted diff) +2
-0+#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t*placement)
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_tt.c +5
-0+{ +if (*placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + *placement &= ~TTM_PL_MASK_CACHING ; + *placement |=TTM_PL_FLAG_CACHED ;
Quoted 3 lines
Quoted 1 line
NAK, this will break AGP on PowerMacs.
... which doesn't work reliably anyway with DRI2 :-)
Define 'not reliably'. I have uptimes of weeks, and I'm pretty sure I'm not alone, at least with AGP 1x it seems to work quite well for most people. So I don't see the justification for intentionally breaking it completely for all of us.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Quoted 11 lines · Michel Dänzer
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Michel Dänzer
Review
Quoted 2 lines
(quoted diff) +2
-0+#else /* CONFIG_X86 */ +int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t*placement)
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_tt.c +5
-0+{ +if (*placement & (TTM_PL_TT |TTM_PL_FLAG_SYSTEM )) { + ttm->caching_state = tt_cached; + *placement &= ~TTM_PL_MASK_CACHING ; + *placement |=TTM_PL_FLAG_CACHED ;
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
NAK, this will break AGP on PowerMacs.
... which doesn't work reliably anyway with DRI2 :-)
Define 'not reliably'. I have uptimes of weeks, and I'm pretty sure I'm not alone, at least with AGP 1x it seems to work quite well for most people. So I don't see the justification for intentionally breaking it completely for all of us.
Even more so because PCI GART is unusably slow in general.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Quoted 5 lines · Michel Dänzer
Define 'not reliably'. I have uptimes of weeks, and I'm pretty sure I'm not alone, at least with AGP 1x it seems to work quite well for most people. So I don't see the justification for intentionally breaking it completely for all of us.
Oh I wasn't arguing for breaking it, just jesting. We need to keep it working. It's amazing how well broken stuff actually work though :-)
I mean, it's architecturally broken and if we get a collision between the cache and the NCU, the chip will crash. We just get lucky I suppose.
Anyway, I'll try a different approach tomorrow see how it goes.
Cheers,
Ben.
Quoted 8 lines · Jerome Glisse
So i think we need to get a platform flags and or set_pages_array_wc|uc needs to fail and this would fallback to cached mapping if the fallback code still works. So if your arch properly return and error for those cache changing function then you should be fine.
This also means that we need to fix
ttm_tt_set_placement_cachingso that when it returns an error it switches to cached mapping. Which will always work.
Can't I just filter the mem_type definitions in the mem_type_manager with something along that totally untested patch ?
Or do I *also* need to make those set_page_array_* things fail ?
drivers/gpu/drm/ttm/ttm_bo.c +20 -0
@@ -1308,6 +1308,24 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned }EXPORT_SYMBOL (ttm_bo_evict_mm); +static void ttm_bo_filter_mem_type (struct ttm_bo_device *bdev,unsigned type, +struct ttm_mem_type_manager *man) +{ +/* +* On some architectures/patforms, we cannot allow non-cachable +* mappings of system memory. This can be a problem with AGP on +* old G5 systems vs. TTM_PL_TT but we don't really have a choice +* at this point on ppc64 at least and the AGP on these never +* worked reliably anyway. +*/ +#if defined(CONFIG_PPC ) && !defined(CONFIG_NOT_COHERENT_CACHE ) +if (type ==TTM_PL_SYSTEM || type ==TTM_PL_TT ) { + man->available_caching &=TTM_PL_FLAG_CACHED ; + man->default_caching &= man->available_caching; + } +#endif +} +int ttm_bo_init_mm (struct ttm_bo_device *bdev,unsigned type,unsigned long p_size) {
@@ -1327,6 +1345,8 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned tyreturn ret; man->bdev = bdev; +ttm_bo_filter_mem_type (bdev, type, man); + ret =0 ;if (type !=TTM_PL_SYSTEM ) { ret = (*man->func->init)(man, p_size);
Quoted 6 lines · Jerome Glisse
While i agree about the issue of incoherent double map of same page, i think we have more issue. For instance lattely AMD have been pushing a lot of patches to move things to use uncached memory for radeon and as usual thoses patches comes with no comment to the motivations of those changes.
That would have been a fair review comment...
Quoted 3 lines
What i understand is that uncached mapping for some frequently use buffer give a significant performance boost (i am assuming this has to do with all the snoop pci transaction overhead).
Exactly, although it's a win even if the data is written by the CPU only once and read by the GPU only once.
Quoted 3 lines
This also means that we need to fix
ttm_tt_set_placement_cachingso that when it returns an error it switches to cached mapping. Which will always work.
GTT with AGP being one exception.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Hi!
Let me try to bring some clarity and suggestions into this.
Quoted 19 lines · Benjamin Herrenschmidt
Hi folks !
I've been tracking down some problems with the recent DRI on powerpc and stumbled upon something that doesn't look right, and not necessarily only for us.
Now it's possible that I haven't fully understood the code here and I also don't know to what extent some of that behaviour is necessary for some platforms such as Intel GTT bits.
What I've observed with a simple/dumb (no DMA) driver like AST (but this probably happens more generally) is that when evicting a BO from VRAM into System memory, the TTM tries to preserve the existing caching attributes of the VRAM object.
Quoted 1 line
From what I can tell, we end up with going from VRAM to System memory
type, and we eventually call
ttm_bo_select_caching()to select the caching option for the target.
Quoted 8 lines
This will, from what I can tell, try to use the same caching mode as the original object:
if ((cur_placement & caching) != 0) result |= (cur_placement & caching);And
cur_placementcomes frombo->mem.placementwhich as far as I can tell is based on the placement array which the drivers set up.
This originates from the fact that when evicting GTT memory, on x86 it's unnecessary and undesirable to switch caching mode when going to system.
Quoted 21 lines
Now they tend to uniformly setup the placement for System memory as
TTM_PL_MASK_CACHINGwhich enables all caching modes.So I end up with, for example, my System memory BOs having
TTM_PL_FLAG_CACHEDnot set (though they also don't haveTTM_PL_FLAG_UNCACHED) andTTM_PL_FLAG_WC.We don't seem to use the
man->default_caching(which will haveTTM_PL_FLAG_CACHED) unless there is no matching bit at all between the proposed placement and the existing caching mode.Now this is a problem for several reason that I can think of:
- On a number of powerpc platforms, such as all our server 64-bit one
for example, it's actually illegal to map system memory non-cached. The system is fully cache coherent for all possible DMA originators (that we care about at least) and mapping memory non-cachable while it's mapped cachable in the linear mapping can cause nasty cache paradox which, when detected by HW, can checkstop the system.
Quoted 7 lines
- A similar issue exists, afaik, on ARM >= v7, so anything mapped
non-cachable must be removed from the linear mapping explicitly since otherwise it can be speculatively prefetched into the cache.- I don't know about x86, but even then, it looks quite sub-optimal to
map the memory backing of the BOs and access it using a WC rather than a cachable mapping attribute.
Last time I tested, (and it seems like Michel is on the same track), writing with the CPU to write-combined memory was substantially faster than writing to cached memory, with the additional side-effect that CPU caches are left unpolluted.
Moreover (although only tested on Intel's embedded chipsets), texturing from cpu-cache-coherent PCI memory was a real GPU performance hog compared to texturing from non-snooped memory. Hence, whenever a buffer could be classified as GPU-read-only (or almost at least), it should be placed in write-combined memory.
Quoted 27 lines
Now, some folks on IRC mentioned that there might be reasons for the current behaviour as to not change the caching attributes when going in/out of the GTT on Intel, I don't know how that relates and how that works, but maybe that should be enforced by having a different placement mask specifically on those chipsets.
Dave, should we change the various PCI drivers for generally coherent devices such that the System memory type doesn't allow placements without CACHED attribute ? Or at least on coherent platforms ? How do detect that ? Should we have a TTM helper to establish the default memory placement attributes that "normal PCI" drivers call to set that up so we can have all the necessary arch ifdefs in one single place, at least for "classic PCI/PCIe" stuff (AGP might need additional tweaks) ?
Non-PCI and "special" drivers like Intel can use a different set of placement attributes to represent the requirements of those specific platforms (mostly thinking of embedded ARM here which under some circumstances might actually require non-cached mappings). Or am I missing another part of the puzzle ?
As it-is, things are broken for me even for dumb drivers, and I suspect to a large extent with radeon and nouveau too, though in some case we might get away with it most of the time ... until the machine locks up for some unexplainable reason... This might cause problems on existing distros such as RHEL7 with our radeon adapters even.
Quoted 3 lines
Any suggestion of what's the best approach to fix it ? I'm happy to produce the patches but I'm not that familiar with the TTM so I would like to make sure I'm the right track first :-)
I dislike the approach of rewriting placements. In some cases I think it won't even work, because placements are declared 'static const'
What I'd suggest is instead to intercept the driver response from init_mem_type() and filter out undesired caching modes from available_caching and default_caching, perhaps also looking at whether the memory type is mappable or not. This should have the additional benefit of working everywhere, and if a caching mode is selected that's not available on the platform, you'll simply get an error. (I guess?)
/Thomas
Quoted 9 lines
Cheers,
Ben._______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Quoted 11 lines · Thomas Hellstrom
Quoted 8 lines
This will, from what I can tell, try to use the same caching mode as the original object:
if ((cur_placement & caching) != 0) result |= (cur_placement & caching);And
cur_placementcomes frombo->mem.placementwhich as far as I can tell is based on the placement array which the drivers set up.This originates from the fact that when evicting GTT memory, on x86 it's unnecessary and undesirable to switch caching mode when going to system.
But that's what I don't quite understand. We have two different mappings here. The VRAM and the memory object. We wouldn't be "switching"... we are creating a temporary mapping for the memory object in order to do the memcpy, but we seem to be doing it by using the caching attributes of the VRAM object.... or am I missing something ? I don't see how that makes sense so I suppose I'm missing something here :-)
Quoted 4 lines
Last time I tested, (and it seems like Michel is on the same track), writing with the CPU to write-combined memory was substantially faster than writing to cached memory, with the additional side-effect that CPU caches are left unpolluted.
That's very strange indeed. It's certainly an x86 specific artifact, even if we were allowed by our hypervisor to map memory non-cachable (the HW somewhat can), we tend to have a higher throughput by going cachable, but that could be due to the way the PowerBus works (it's basically very biased toward cachable transactions).
Quoted 6 lines
I dislike the approach of rewriting placements. In some cases I think it won't even work, because placements are declared 'static const'
What I'd suggest is instead to intercept the driver response from
init_mem_type()and filter out undesired caching modes fromavailable_cachinganddefault_caching,
This was my original intent but Jerome seems to have different ideas (see his proposed patches). I'm happy to revive mine as well and post it as an alternative after I've tested it a bit more (tomorrow).
Quoted 4 lines
perhaps also looking at whether
the memory type is mappable or not. This should have the additional benefit of working everywhere, and if a caching mode is selected that's not available on the platform, you'll simply get an error. (I guess?)
You mean that if not mappable we don't bother filtering ?
The rule is really for me pretty simple:
- If it's system memory (PL_SYSTEM/PL_TT), it MUST be cachable
- If it's PCIe memory space (VRAM, registers, ...) it MUST be
non-cachable.
Cheers,
Ben.
Quoted 12 lines
/Thomas
Quoted 9 lines
Cheers,
Ben._______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines · Thomas Hellstrom
Quoted 8 lines
This will, from what I can tell, try to use the same caching mode as the original object:
if ((cur_placement & caching) != 0) result |= (cur_placement & caching);And
cur_placementcomes frombo->mem.placementwhich as far as I can tell is based on the placement array which the drivers set up.
Quoted 8 lines
Quoted 2 lines
This originates from the fact that when evicting GTT memory, on x86 it's unnecessary and undesirable to switch caching mode when going to system.
But that's what I don't quite understand. We have two different mappings here. The VRAM and the memory object. We wouldn't be "switching"... we are creating a temporary mapping for the memory object in order to do the memcpy, but we seem to be doing it by using the caching attributes of the VRAM object.... or am I missing something ? I don't see how that makes sense so I suppose I'm missing something here :-)
Well, the intention when TTM was written was that the driver writer should be smart enough that when he wanted a move from unached VRAM to system, he'd request cached system in the placement flags in the first place. If TTM somehow overrides such a request, that's a bug in TTM.
If the move, for example, is a result of an eviction, then the driver evict_flags() function should ideally look at the current placement and decide about a suitable placement based on that: vram-to-system moves should generally request cacheable memory if the next access is expected by the CPU. Probably write-combined otherwise.
If the move is the result of a TTM swapout, TTM will automatically select cachable system, and for most other moves, I think the driver writer is in full control.
Quoted 25 lines
Quoted 5 lines
Last time I tested, (and it seems like Michel is on the same track), writing with the CPU to write-combined memory was substantially faster than writing to cached memory, with the additional side-effect that CPU caches are left unpolluted.
That's very strange indeed. It's certainly an x86 specific artifact, even if we were allowed by our hypervisor to map memory non-cachable (the HW somewhat can), we tend to have a higher throughput by going cachable, but that could be due to the way the PowerBus works (it's basically very biased toward cachable transactions).
Quoted 6 lines
I dislike the approach of rewriting placements. In some cases I think it won't even work, because placements are declared 'static const'
What I'd suggest is instead to intercept the driver response from
init_mem_type()and filter out undesired caching modes fromavailable_cachinganddefault_caching,This was my original intent but Jerome seems to have different ideas (see his proposed patches). I'm happy to revive mine as well and post it as an alternative after I've tested it a bit more (tomorrow).
Quoted 4 lines
perhaps also looking at whether
the memory type is mappable or not. This should have the additional benefit of working everywhere, and if a caching mode is selected that's not available on the platform, you'll simply get an error. (I guess?)
Quoted 8 lines
You mean that if not mappable we don't bother filtering ?
The rule is really for me pretty simple:
- If it's system memory (PL_SYSTEM/PL_TT), it MUST be cachable
- If it's PCIe memory space (VRAM, registers, ...) it MUST be
non-cachable.
Yes, something along these lines. I guess checking for VRAM or TTM_MEMTYPE_FLAG_FIXED would perhaps do the trick
/Thomas
Quoted 16 lines
Cheers,
Ben.Quoted 11 lines
/Thomas
Quoted 8 lines
Cheers,
Ben._______________________________________________
dri-devel mailing list
[email protected]
https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/dri-devel&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=l5Ago9ekmVFZ3c4M6eauqrJWGwjf6fTb%2BP3CxbBFkVM%3D%0A&m=C9AHL1VngKBOxe2UrNP2eCZo6FLqdlr6Y90rpfE5rUs%3D%0A&s=73da0633bafc5d54bf116bc861d48d13c39cf8f41832adfb739709e98ec05553
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Quoted 10 lines · Thomas Hellstrom
Last time I tested, (and it seems like Michel is on the same track), writing with the CPU to write-combined memory was substantially faster than writing to cached memory, with the additional side-effect that CPU caches are left unpolluted.
Moreover (although only tested on Intel's embedded chipsets), texturing from cpu-cache-coherent PCI memory was a real GPU performance hog compared to texturing from non-snooped memory. Hence, whenever a buffer could be classified as GPU-read-only (or almost at least), it should be placed in write-combined memory.
Just a quick comment since this explicitly referes to intel chips: On desktop/laptop chips with the big shared l3/l4 caches it's the other way round. Cached uploads are substantially faster than wc and not using coherent access is a severe perf hit for texturing. I guess the hw guys worked really hard to hide the snooping costs so that the gpu can benefit from the massive bandwidth these caches can provide.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 12 lines · Daniel Vetter
Quoted 10 lines · Thomas Hellstrom
Last time I tested, (and it seems like Michel is on the same track), writing with the CPU to write-combined memory was substantially faster than writing to cached memory, with the additional side-effect that CPU caches are left unpolluted.
Moreover (although only tested on Intel's embedded chipsets), texturing from cpu-cache-coherent PCI memory was a real GPU performance hog compared to texturing from non-snooped memory. Hence, whenever a buffer could be classified as GPU-read-only (or almost at least), it should be placed in write-combined memory.
Quoted 6 lines
Just a quick comment since this explicitly referes to intel chips: On desktop/laptop chips with the big shared l3/l4 caches it's the other way round. Cached uploads are substantially faster than wc and not using coherent access is a severe perf hit for texturing. I guess the hw guys worked really hard to hide the snooping costs so that the gpu can benefit from the massive bandwidth these caches can provide.
This is similar to modern POWER chips as well. We have pretty big L3's (though not technically shared they are in a separate quadrant and we have a shared L4 in the memory buffer) and our fabric is generally optimized for cachable/coherent access performance. In fact, we only have so many credits for NC accesses on the bus...
What that tells me is that when setting up the desired cachability attributes for the mapping of a memory object, we need to consider these things here:
- The hard requirement of the HW (non-coherent GPUs require NC, AGP
does in some cases, etc...) which I think is basically already handled using the placement attributes set by the GPU driver for the memory type
- The optimal attributes (and platform hard requirements) for fast
memory accesses to an object by the processor. From what I read here, this can be NC+WC on older Intel, cachable on newer, etc...)
- The optimal attributes for fast GPU DMA accesses to the object in
system memory. Here too, this is fairly platform/chipset dependent.
Do we have flags in the DRM that tell us whether an object in memory is more likely to be used by the GPU via DMA vs by the CPU via MMIO ? On powerpc (except in the old AGP case), I wouldn't care about require cachable in both case, but I can see the low latency crowd wanting the former to be non-cachable while the dumb GPUs like AST who don't do DMA would benefit greatly from the latter...
Cheers,
Ben.
Quoted 18 lines · Benjamin Herrenschmidt
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Thomas Hellstrom
Last time I tested, (and it seems like Michel is on the same track), writing with the CPU to write-combined memory was substantially faster than writing to cached memory, with the additional side-effect that CPU caches are left unpolluted.
Moreover (although only tested on Intel's embedded chipsets), texturing from cpu-cache-coherent PCI memory was a real GPU performance hog compared to texturing from non-snooped memory. Hence, whenever a buffer could be classified as GPU-read-only (or almost at least), it should be placed in write-combined memory.
Quoted 6 lines
Just a quick comment since this explicitly referes to intel chips: On desktop/laptop chips with the big shared l3/l4 caches it's the other way round. Cached uploads are substantially faster than wc and not using coherent access is a severe perf hit for texturing. I guess the hw guys worked really hard to hide the snooping costs so that the gpu can benefit from the massive bandwidth these caches can provide.
Quoted 6 lines
This is similar to modern POWER chips as well. We have pretty big L3's (though not technically shared they are in a separate quadrant and we have a shared L4 in the memory buffer) and our fabric is generally optimized for cachable/coherent access performance. In fact, we only have so many credits for NC accesses on the bus...
Thanks both of you for the update. I haven't dealt with real hardware for a while..
/Thomas
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev