Skip to contentSkip to conversation

drm/gpu: Add comment for memory barrier

PATCH Superseded Bhanusree 2 participants 2 messages Oct 23, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bhanusree

author
#0 lore raw

PATCH 1/1 drm/gpu: Add comment for memory barrier

-Add comment for memory barrier
-Issue found using checkpatch.pl

---
 drivers/gpu/drm/drm_cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_cache.c +2 -2
index 3bd76e9..39910f2 100644
@@ -62,10 +62,10 @@ static void drm_cache_flush_clflush(struct page *pages[],
 {
 	unsigned long i;
 
-	mb();
+	mb(); /*make sure page address is read*/
 	for (i = 0; i < num_pages; i++)
 		drm_clflush_page(*pages++);
-	mb();
+	mb(); /*make sure all addresses of pages are read sequentially*/
 }
 #endif
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 14 lines · Bhanusree
(quoted diff) +0 -2
-Add comment for memory barrier
-Issue found using checkpatch.pl
---
 drivers/gpu/drm/drm_cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_cache.c +0 -0
index 3bd76e9..39910f2 100644

drivers/gpu/drm/drm_cache.c static void drm_cache_flush_clflush(struct page *pages[], · line 65

Quoted 5 lines
drivers/gpu/drm/drm_cache.c +1 -1
@@ -62,10 +62,10 @@ static void drm_cache_flush_clflush(struct page *pages[],
 {
        unsigned long i;
 
-       mb();
+       mb(); /*make sure page address is read*/

That's not what's going on here. We need the barriers because:
- clflush is an unordered instruction (very rare on x86, but they exist)
- hence we need t have a barrier before&after to make sure the clflush actually happens when we want it to happen.
- clflush flushes the cpu cache, _that_ is what we want to synchronize against. not the memory address itself. Hence we need to make sure that before all reads/writes have hit the cpu cache, and afterwards that all the cache lines we wanted to flush are flushed.
- https://c9x.me/x86/html/file_module_x86_id_30.html for more info on clflush

So useful comment (see also the link) would be:

/* CLFLUSH is only ordered with a full memory mbarrier (MFENCE instruction) before ...*/

drivers/gpu/drm/drm_cache.c static void drm_cache_flush_clflush(struct page *pages[], · line 68

Quoted 4 lines
drivers/gpu/drm/drm_cache.c +1 -1
        for (i = 0; i < num_pages; i++)
                drm_clflush_page(*pages++);
-       mb();
+       mb(); /*make sure all addresses of pages are read sequentially*/

/* ... and after the CLFLUSH instruction itself */

If you dig through all the macros for mb() eventually you should find the inline assembler for MFENCE. That's also why we need to have this barrier even on single-processor builds (so no smp_mb()).

Can you pls respin?

Thanks, Daniel

Quoted 6 lines
drivers/gpu/drm/drm_cache.c +0 -1
 }
 #endif
 
--

2.7.4

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel