Skip to contentSkip to conversation

drm/ttm: Set CPU caching mode to cached for BOs being swapped out

PATCH In review Michel Dänzer 2 participants 5 messages Nov 5, 2015 – Nov 9, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/ttm: Set CPU caching mode to cached for BOs being swapped out

From: Michel Dänzer <[email protected]>

I ran into the BUG_ON in ttm_tt_swapout, presumably the BO being swapped out was using a write-combined CPU mapping.

Instead of BUGging out, just set the caching mode to what's needed.

---
 drivers/gpu/drm/ttm/ttm_tt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -1
index 4e19d0f..c2794eb 100644
@@ -334,7 +334,8 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	int ret = -ENOMEM;
 
 	BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
-	BUG_ON(ttm->caching_state != tt_cached);
+
+	ttm_tt_set_caching(ttm, tt_cached);
 
 	if (!persistent_swap_storage) {
 		swap_storage = shmem_file_setup("ttm swap",
Signature · 6 lines
2.6.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Hi, Michel,

Quoted 17 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

I ran into the BUG_ON in ttm_tt_swapout, presumably the BO being swapped out was using a write-combined CPU mapping.

Instead of BUGging out, just set the caching mode to what's needed.

---
 drivers/gpu/drm/ttm/ttm_tt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -0
index 4e19d0f..c2794eb 100644

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage) · line 341

Quoted 9 lines
drivers/gpu/drm/ttm/ttm_tt.c +2 -1
@@ -334,7 +334,8 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	int ret = -ENOMEM;
 
 	BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
-	BUG_ON(ttm->caching_state != tt_cached);
+
+	ttm_tt_set_caching(ttm, tt_cached);
 
 	if (!persistent_swap_storage) {
 		swap_storage = shmem_file_setup("ttm swap",

This *is* actually a bug somewhere, since before ttm_tt_swapout, ttm_bo_swapout should have moved out the bo to system and set the correct caching. A WARN_ON_ONCE instead of BUG_ON is ok, but this should never happen.

/Thomas

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 27 lines · Thomas Hellstrom

Hi, Michel,

Quoted 24 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

I ran into the BUG_ON in ttm_tt_swapout, presumably the BO being swapped out was using a write-combined CPU mapping.

Instead of BUGging out, just set the caching mode to what's needed.

---
 drivers/gpu/drm/ttm/ttm_tt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -1
index 4e19d0f..c2794eb 100644
@@ -334,7 +334,8 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	int ret = -ENOMEM;
 
 	BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
-	BUG_ON(ttm->caching_state != tt_cached);
+
+	ttm_tt_set_caching(ttm, tt_cached);
 
Quoted 6 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage) · line 341

Quoted 2 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -0
 	if (!persistent_swap_storage) {
 		swap_storage = shmem_file_setup("ttm swap",

This *is* actually a bug somewhere, since before ttm_tt_swapout, ttm_bo_swapout should have moved out the bo to system and set the correct caching.

Maybe ttm_bo_swapout needs to check ttm->caching_state explicitly? AFAICT it only checks the placement flags, but we allow all caching modes for GTT.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
Quoted 28 lines · Michel Dänzer
Quoted 27 lines · Thomas Hellstrom

Hi, Michel,

Quoted 24 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

I ran into the BUG_ON in ttm_tt_swapout, presumably the BO being swapped out was using a write-combined CPU mapping.

Instead of BUGging out, just set the caching mode to what's needed.

---
 drivers/gpu/drm/ttm/ttm_tt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -1
index 4e19d0f..c2794eb 100644
@@ -334,7 +334,8 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	int ret = -ENOMEM;
 
 	BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
-	BUG_ON(ttm->caching_state != tt_cached);
+
+	ttm_tt_set_caching(ttm, tt_cached);
 
Quoted 9 lines
Quoted 5 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage) · line 341

Quoted 2 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -0
 	if (!persistent_swap_storage) {
 		swap_storage = shmem_file_setup("ttm swap",

This *is* actually a bug somewhere, since before ttm_tt_swapout, ttm_bo_swapout should have moved out the bo to system and set the correct caching.

Maybe ttm_bo_swapout needs to check ttm->caching_state explicitly? AFAICT it only checks the placement flags, but we allow all caching modes for GTT.

bo->mem.placement should only have two flags set, one for the current memory type corresponding to bo->mem.mem_type, the other for the current caching. If there are more than one caching flag set at this point, that's a bug. The preferred caching mode is chosen from a set of modes in ttm_bo_select_caching(), and bo->mem is reassigned to incorporate the current caching mode after a successful move.

I quickly eyed through the TTM default move functions and they seem to do the correct thing from what I can tell. Is the radeon ttm driver assigning bo->mem in a move callback perhaps?

/Thomas

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 46 lines · Thomas Hellstrom
Quoted 28 lines · Michel Dänzer
Quoted 27 lines · Thomas Hellstrom

Hi, Michel,

Quoted 24 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

I ran into the BUG_ON in ttm_tt_swapout, presumably the BO being swapped out was using a write-combined CPU mapping.

Instead of BUGging out, just set the caching mode to what's needed.

---
 drivers/gpu/drm/ttm/ttm_tt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -1
index 4e19d0f..c2794eb 100644
@@ -334,7 +334,8 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	int ret = -ENOMEM;
 
 	BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
-	BUG_ON(ttm->caching_state != tt_cached);
+
+	ttm_tt_set_caching(ttm, tt_cached);
 
Quoted 9 lines
Quoted 5 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage) · line 341

Quoted 2 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -0
 	if (!persistent_swap_storage) {
 		swap_storage = shmem_file_setup("ttm swap",

This *is* actually a bug somewhere, since before ttm_tt_swapout, ttm_bo_swapout should have moved out the bo to system and set the correct caching.

Maybe ttm_bo_swapout needs to check ttm->caching_state explicitly? AFAICT it only checks the placement flags, but we allow all caching modes for GTT.

bo->mem.placement should only have two flags set, one for the current memory type corresponding to bo->mem.mem_type, the other for the current caching. If there are more than one caching flag set at this point, that's a bug. The preferred caching mode is chosen from a set of modes in ttm_bo_select_caching(), and bo->mem is reassigned to incorporate the current caching mode after a successful move.

Quoted 3 lines

I quickly eyed through the TTM default move functions and they seem to do the correct thing from what I can tell. Is the radeon ttm driver assigning bo->mem in a move callback perhaps?

Only via ttm_bo_move_ttm / to the values passed into the move callback AFAICT.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel