Skip to contentSkip to conversation

drm/ttm: Merge hugepage attr changes in ttm_dma_page_put.

PATCH In review Bas Nieuwenhuizen 5 participants 6 messages Jul 25, 2018 – Jul 26, 2018 2 messages not in the archive

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

PATCH 1/1 drm/ttm: Merge hugepage attr changes in ttm_dma_page_put.

Every set_pages_array_wb call resulted in cross-core interrupts and TLB flushes. Merge more of them for less overhead.

This reduces the time needed to free a 1.6 GiB GTT WC buffer as part of Vulkan CTS from ~2 sec to < 0.25 sec. (Allocation still takes more than 2 sec though)

---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 31 ++++++++++++++++++------
 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +24 -7
index 4c659405a008a..9440ba0a55116 100644
@@ -299,6 +299,25 @@ static int set_pages_array_uc(struct page **pages, int addrinarray)
 #endif
 	return 0;
 }
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+#if IS_ENABLED(CONFIG_AGP)
+        unsigned long i;
+
+        for (i = 0; i < numpages; i++)
+                unmap_page_from_agp(p + i);
+#endif
+	return 0;
+}
+
+#else /* for !CONFIG_X86 */
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+	return set_memory_wb((unsigned long)page_address(p), numpages);
+}
+
 #endif /* for !CONFIG_X86 */
 
 static int ttm_set_pages_caching(struct dma_pool *pool,
@@ -387,18 +406,16 @@ static void ttm_pool_update_free_locked(struct dma_pool *pool,
 static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
 {
 	struct page *page = d_page->p;
-	unsigned i, num_pages;
+	unsigned num_pages;
 	int ret;
 
 	/* Don't set WB on WB page pool. */
 	if (!(pool->type & IS_CACHED)) {
 		num_pages = pool->size / PAGE_SIZE;
-		for (i = 0; i < num_pages; ++i, ++page) {
-			ret = set_pages_array_wb(&page, 1);
-			if (ret) {
-				pr_err("%s: Failed to set %d pages to wb!\n",
-				       pool->dev_name, 1);
-			}
+		ret = ttm_set_page_range_wb(page, num_pages);
+		if (ret) {
+			pr_err("%s: Failed to set %d pages to wb!\n",
+			       pool->dev_name, num_pages);
 		}
 	}
 
Signature · 6 lines
2.18.0.233.g985f88cf7e-goog

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20180725202950.51216-1-basni-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org

Reviewed-by
#2 lore raw
Quoted 9 lines · Bas Nieuwenhuizen

Every set_pages_array_wb call resulted in cross-core interrupts and TLB flushes. Merge more of them for less overhead.

This reduces the time needed to free a 1.6 GiB GTT WC buffer as part of Vulkan CTS from ~2 sec to < 0.25 sec. (Allocation still takes more than 2 sec though)

Quoted 65 lines
---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 31 ++++++++++++++++++------
 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +24 -7
index 4c659405a008a..9440ba0a55116 100644
@@ -299,6 +299,25 @@ static int set_pages_array_uc(struct page **pages, int addrinarray)
 #endif
 	return 0;
 }
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+#if IS_ENABLED(CONFIG_AGP)
+        unsigned long i;
+
+        for (i = 0; i < numpages; i++)
+                unmap_page_from_agp(p + i);
+#endif
+	return 0;
+}
+
+#else /* for !CONFIG_X86 */
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+	return set_memory_wb((unsigned long)page_address(p), numpages);
+}
+
 #endif /* for !CONFIG_X86 */
 
 static int ttm_set_pages_caching(struct dma_pool *pool,
@@ -387,18 +406,16 @@ static void ttm_pool_update_free_locked(struct dma_pool *pool,
 static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
 {
 	struct page *page = d_page->p;
-	unsigned i, num_pages;
+	unsigned num_pages;
 	int ret;
 
 	/* Don't set WB on WB page pool. */
 	if (!(pool->type & IS_CACHED)) {
 		num_pages = pool->size / PAGE_SIZE;
-		for (i = 0; i < num_pages; ++i, ++page) {
-			ret = set_pages_array_wb(&page, 1);
-			if (ret) {
-				pr_err("%s: Failed to set %d pages to wb!\n",
-				       pool->dev_name, 1);
-			}
+		ret = ttm_set_page_range_wb(page, num_pages);
+		if (ret) {
+			pr_err("%s: Failed to set %d pages to wb!\n",
+			       pool->dev_name, num_pages);
 		}
 	}
 
Signature · 6 lines
2.18.0.233.g985f88cf7e-goog

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw
In reply to a message not in the archive
Quoted 51 lines · Bas Nieuwenhuizen

Every set_pages_array_wb call resulted in cross-core interrupts and TLB flushes. Merge more of them for less overhead.

This reduces the time needed to free a 1.6 GiB GTT WC buffer as part of Vulkan CTS from ~2 sec to < 0.25 sec. (Allocation still takes more than 2 sec though)

---
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 31 ++++++++++++++++++------
  1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +20 -1
index 4c659405a008a..9440ba0a55116 100644
@@ -299,6 +299,25 @@ static int set_pages_array_uc(struct page **pages, int addrinarray)
  #endif
  	return 0;
  }
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+#if IS_ENABLED(CONFIG_AGP)
+        unsigned long i;
+
+        for (i = 0; i < numpages; i++)
+                unmap_page_from_agp(p + i);
+#endif
+	return 0;
+}
+
+#else /* for !CONFIG_X86 */
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+	return set_memory_wb((unsigned long)page_address(p), numpages);
+}
+
  #endif /* for !CONFIG_X86 */
 
  static int ttm_set_pages_caching(struct dma_pool *pool,
@@ -387,18 +406,16 @@ static void ttm_pool_update_free_locked(struct dma_pool *pool,
  static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
  {
  	struct page *page = d_page->p;
-	unsigned i, num_pages;
+	unsigned num_pages;
  	int ret;
 

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c static void ttm_pool_update_free_locked(struct dma_pool *pool, · line 415

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -6
  	/* Don't set WB on WB page pool. */
  	if (!(pool->type & IS_CACHED)) {
  		num_pages = pool->size / PAGE_SIZE;
-		for (i = 0; i < num_pages; ++i, ++page) {
-			ret = set_pages_array_wb(&page, 1);
-			if (ret) {
-				pr_err("%s: Failed to set %d pages to wb!\n",
-				       pool->dev_name, 1);
-			}
+		ret = ttm_set_page_range_wb(page, num_pages);

For AGP enabled, set_pages_array_wc() could works like that by passing "num_pages" instead of "1" In X86 case, we may use set_pages_array_wb() in arch/x86/mm/pageattr.c.

so, does it work as below?

ret = set_pages_array_wb(page, num_pages);

Jerry

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c static void ttm_pool_update_free_locked(struct dma_pool *pool, · line 421

Quoted 7 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +3 -0
+		if (ret) {
+			pr_err("%s: Failed to set %d pages to wb!\n",
+			       pool->dev_name, num_pages);
  		}
  	}
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
Quoted 74 lines · Jerry (Junwei)
Quoted 57 lines · Bas Nieuwenhuizen

Every set_pages_array_wb call resulted in cross-core interrupts and TLB flushes. Merge more of them for less overhead.

This reduces the time needed to free a 1.6 GiB GTT WC buffer as part of Vulkan CTS from ~2 sec to < 0.25 sec. (Allocation still takes more than 2 sec though)

---
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 31 ++++++++++++++++++------
  1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +19 -0
index 4c659405a008a..9440ba0a55116 100644
@@ -299,6 +299,25 @@ static int set_pages_array_uc(struct page **pages,
 int addrinarray)
  #endif
        return 0;
  }
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+#if IS_ENABLED(CONFIG_AGP)
+        unsigned long i;
+
+        for (i = 0; i < numpages; i++)
+                unmap_page_from_agp(p + i);
+#endif
+       return 0;
+}
+
+#else /* for !CONFIG_X86 */
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+       return set_memory_wb((unsigned long)page_address(p), numpages);
+}
+
  #endif /* for !CONFIG_X86 */
 

static int ttm_set_pages_caching(struct dma_pool *pool,

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -1
@@ -387,18 +406,16 @@ static void ttm_pool_update_free_locked(struct
 dma_pool *pool,
  static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page
 *d_page)
  {
        struct page *page = d_page->p;
-       unsigned i, num_pages;
+       unsigned num_pages;
        int ret;
 
        /* Don't set WB on WB page pool. */

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c static void ttm_pool_update_free_locked(struct · line 418

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -6
        if (!(pool->type & IS_CACHED)) {
                num_pages = pool->size / PAGE_SIZE;
-               for (i = 0; i < num_pages; ++i, ++page) {
-                       ret = set_pages_array_wb(&page, 1);
-                       if (ret) {
-                               pr_err("%s: Failed to set %d pages to
 wb!\n",
-                                      pool->dev_name, 1);
-                       }
+               ret = ttm_set_page_range_wb(page, num_pages);

For AGP enabled, set_pages_array_wc() could works like that by passing "num_pages" instead of "1"
In X86 case, we may use set_pages_array_wb() in arch/x86/mm/pageattr.c.

Quoted 3 lines

so, does it work as below?

ret = set_pages_array_wb(page, num_pages);

No that would not work. Note that we have an array of page structs, while set_pages_array_wb() wants an array of pointers to page structs. We could allocate a temporary array and write the pointers but that seems unnecessarily inefficient to me, and probably also does not achieve a reduction in code.

Quoted 12 lines

Jerry

Quoted 7 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +3 -0
+               if (ret) {
+                       pr_err("%s: Failed to set %d pages to wb!\n",
+                              pool->dev_name, num_pages);
                }
        }

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

#5 lore raw
In reply to a message not in the archive

Am 25.07.2018 um 22:29 schrieb Bas Nieuwenhuizen:

Quoted 7 lines

Every set_pages_array_wb call resulted in cross-core interrupts and TLB flushes. Merge more of them for less overhead.

This reduces the time needed to free a 1.6 GiB GTT WC buffer as part of Vulkan CTS from ~2 sec to < 0.25 sec. (Allocation still takes more than 2 sec though)

Yeah, I was already wondering when I originally implemented this if there isn't a better approach.

This needs a bit of cleanup I think, e.g. use set_pages_wb() instead of set_memory_wb() and we should move the non-x86 abstraction into a common header for both ttm_page_alloc_dma.c and ttm_page_alloc.c.

Bas, do you want to tackle this or should just I take a look?

Christian.

Quoted 50 lines
---
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 31 ++++++++++++++++++------
  1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +20 -4
index 4c659405a008a..9440ba0a55116 100644
@@ -299,6 +299,25 @@ static int set_pages_array_uc(struct page **pages, int addrinarray)
  #endif
  	return 0;
  }
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+#if IS_ENABLED(CONFIG_AGP)
+        unsigned long i;
+
+        for (i = 0; i < numpages; i++)
+                unmap_page_from_agp(p + i);
+#endif
+	return 0;
+}
+
+#else /* for !CONFIG_X86 */
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+	return set_memory_wb((unsigned long)page_address(p), numpages);
+}
+
  #endif /* for !CONFIG_X86 */
 
  static int ttm_set_pages_caching(struct dma_pool *pool,
@@ -387,18 +406,16 @@ static void ttm_pool_update_free_locked(struct dma_pool *pool,
  static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
  {
  	struct page *page = d_page->p;
-	unsigned i, num_pages;
+	unsigned num_pages;
  	int ret;
 
  	/* Don't set WB on WB page pool. */
  	if (!(pool->type & IS_CACHED)) {
  		num_pages = pool->size / PAGE_SIZE;
-		for (i = 0; i < num_pages; ++i, ++page) {
-			ret = set_pages_array_wb(&page, 1);
-			if (ret) {

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c static void ttm_pool_update_free_locked(struct dma_pool *pool, · line 421

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4 -3
-				pr_err("%s: Failed to set %d pages to wb!\n",
-				       pool->dev_name, 1);
-			}
+		ret = ttm_set_page_range_wb(page, num_pages);
+		if (ret) {
+			pr_err("%s: Failed to set %d pages to wb!\n",
+			       pool->dev_name, num_pages);
  		}
  	}
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): c76533c0-402e-4137-705e-cd5c2b3ae792-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#7 lore raw
Quoted 9 lines · Christian König

Am 25.07.2018 um 22:29 schrieb Bas Nieuwenhuizen:

Quoted 7 lines

Every set_pages_array_wb call resulted in cross-core interrupts and TLB flushes. Merge more of them for less overhead.

This reduces the time needed to free a 1.6 GiB GTT WC buffer as part of Vulkan CTS from ~2 sec to < 0.25 sec. (Allocation still takes more than 2 sec though)

Quoted 7 lines

Yeah, I was already wondering when I originally implemented this if there isn't a better approach.

This needs a bit of cleanup I think, e.g. use set_pages_wb() instead of set_memory_wb() and we should move the non-x86 abstraction into a common header for both ttm_page_alloc_dma.c and ttm_page_alloc.c.

Agree, at the first glance, I almost got it wrong to miss-read "#ifndef CONFIG_X86". So it make sense to move non-x86 definition into another header.

Thanks,
Ray

Quoted 58 lines

Bas, do you want to tackle this or should just I take a look?

Christian.

Quoted 54 lines
---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 31 ++++++++++++++++++------
 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +23 -7
index 4c659405a008a..9440ba0a55116 100644
@@ -299,6 +299,25 @@ static int set_pages_array_uc(struct page **pages, int addrinarray)
 #endif
 	return 0;
 }
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+#if IS_ENABLED(CONFIG_AGP)
+        unsigned long i;
+
+        for (i = 0; i < numpages; i++)
+                unmap_page_from_agp(p + i);
+#endif
+	return 0;
+}
+
+#else /* for !CONFIG_X86 */
+
+static int ttm_set_page_range_wb(struct page *p, unsigned long numpages)
+{
+	return set_memory_wb((unsigned long)page_address(p), numpages);
+}
+
 #endif /* for !CONFIG_X86 */
 static int ttm_set_pages_caching(struct dma_pool *pool,
@@ -387,18 +406,16 @@ static void ttm_pool_update_free_locked(struct dma_pool *pool,
 static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
 {
 	struct page *page = d_page->p;
-	unsigned i, num_pages;
+	unsigned num_pages;
 	int ret;
 	/* Don't set WB on WB page pool. */
 	if (!(pool->type & IS_CACHED)) {
 		num_pages = pool->size / PAGE_SIZE;
-		for (i = 0; i < num_pages; ++i, ++page) {
-			ret = set_pages_array_wb(&page, 1);
-			if (ret) {
-				pr_err("%s: Failed to set %d pages to wb!\n",
-				       pool->dev_name, 1);
-			}
+		ret = ttm_set_page_range_wb(page, num_pages);
+		if (ret) {
+			pr_err("%s: Failed to set %d pages to wb!\n",
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c static void ttm_pool_update_free_locked(struct dma_pool *pool, · line 420

Quoted 3 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -0
+			       pool->dev_name, num_pages);
 		}
 	}

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx