From: Xiaogang.Chen <xiaogang.chen@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Philip.Yang@amd.com>, <Emily.Deng@amd.com>,
<felix.kuehling@amd.com>, Xiaogang Chen <xiaogang.chen@amd.com>,
Xiaogang Chen <Xiaogang.Chen@amd.com>
Subject: [PATCH] drm/amdkfd: Change page discontinuity handling at svm_migrate_copy_to_vram
Date: Wed, 15 Jan 2025 15:40:01 -0600 [thread overview]
Message-ID: <20250115214001.335607-1-xiaogang.chen@amd.com> (raw)
From: Xiaogang Chen <xiaogang.chen@amd.com>
Current svm_migrate_copy_to_vram handles sys pages(src) and dst pages (vram)
discontinuation in different way. When src got discontinuity migrates j pages
that ith page is not migrated; When dst got discontinuity migrates j+1 pages
that ith page is migrated. That cause error path have to iterate all pages to
find which page got migrated before error happened. Also makes code more
difficult to read.
This patch handles src and dst page discontinuity in consistent way, has its
logic and error recovery straight forward.
Signed-off-by: Xiaogang Chen<Xiaogang.Chen@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 68 ++++++++++++------------
1 file changed, 35 insertions(+), 33 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
index d05d199b5e44..2ce78c77f203 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
@@ -299,6 +299,19 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,
for (i = j = 0; (i < npages) && (mpages < migrate->cpages); i++) {
struct page *spage;
+ /* accumulated pages more than current cursor's block has */
+ if (j >= (cursor.size >> PAGE_SHIFT)) {
+ r = svm_migrate_copy_memory_gart(adev, src + i - j,
+ dst + i - j, j,
+ FROM_RAM_TO_VRAM,
+ mfence);
+ if (r)
+ goto out_free_vram_pages;
+
+ amdgpu_res_next(&cursor, j * PAGE_SIZE);
+ j = 0;
+ }
+
if (migrate->src[i] & MIGRATE_PFN_MIGRATE) {
dst[i] = cursor.start + (j << PAGE_SHIFT);
migrate->dst[i] = svm_migrate_addr_to_pfn(adev, dst[i]);
@@ -306,17 +319,10 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,
migrate->dst[i] = migrate_pfn(migrate->dst[i]);
mpages++;
}
+
spage = migrate_pfn_to_page(migrate->src[i]);
- if (spage && !is_zone_device_page(spage)) {
- src[i] = dma_map_page(dev, spage, 0, PAGE_SIZE,
- DMA_BIDIRECTIONAL);
- r = dma_mapping_error(dev, src[i]);
- if (r) {
- dev_err(dev, "%s: fail %d dma_map_page\n",
- __func__, r);
- goto out_free_vram_pages;
- }
- } else {
+ if (!spage || is_zone_device_page(spage)) {
+ /* sdma accumulated pages before src got gap */
if (j) {
r = svm_migrate_copy_memory_gart(
adev, src + i - j,
@@ -325,29 +331,26 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,
mfence);
if (r)
goto out_free_vram_pages;
- amdgpu_res_next(&cursor, (j + 1) << PAGE_SHIFT);
+
+ amdgpu_res_next(&cursor, (j+1) << PAGE_SHIFT);
j = 0;
- } else {
+ } else
amdgpu_res_next(&cursor, PAGE_SIZE);
- }
+
continue;
}
- pr_debug_ratelimited("dma mapping src to 0x%llx, pfn 0x%lx\n",
- src[i] >> PAGE_SHIFT, page_to_pfn(spage));
-
- if (j >= (cursor.size >> PAGE_SHIFT) - 1 && i < npages - 1) {
- r = svm_migrate_copy_memory_gart(adev, src + i - j,
- dst + i - j, j + 1,
- FROM_RAM_TO_VRAM,
- mfence);
- if (r)
- goto out_free_vram_pages;
- amdgpu_res_next(&cursor, (j + 1) * PAGE_SIZE);
- j = 0;
- } else {
- j++;
+ src[i] = dma_map_page(dev, spage, 0, PAGE_SIZE,
+ DMA_BIDIRECTIONAL);
+ r = dma_mapping_error(dev, src[i]);
+ if (r) {
+ dev_err(dev, "%s: fail %d dma_map_page\n", __func__, r);
+ goto out_free_vram_pages;
}
+
+ pr_debug_ratelimited("dma mapping src to 0x%llx, pfn 0x%lx\n",
+ src[i] >> PAGE_SHIFT, page_to_pfn(spage));
+ j++;
}
r = svm_migrate_copy_memory_gart(adev, src + i - j, dst + i - j, j,
@@ -356,12 +359,11 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,
out_free_vram_pages:
if (r) {
pr_debug("failed %d to copy memory to vram\n", r);
- for (i = 0; i < npages && mpages; i++) {
- if (!dst[i])
- continue;
- svm_migrate_put_vram_page(adev, dst[i]);
- migrate->dst[i] = 0;
- mpages--;
+ while (i--) {
+ if (migrate->dst[i]) {
+ svm_migrate_put_vram_page(adev, dst[i]);
+ migrate->dst[i] = 0;
+ }
}
}
--
2.25.1
next reply other threads:[~2025-01-15 21:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-15 21:40 Xiaogang.Chen [this message]
2025-01-20 16:13 ` [PATCH] drm/amdkfd: Change page discontinuity handling at svm_migrate_copy_to_vram Philip Yang
2025-01-20 16:30 ` Chen, Xiaogang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250115214001.335607-1-xiaogang.chen@amd.com \
--to=xiaogang.chen@amd.com \
--cc=Emily.Deng@amd.com \
--cc=Philip.Yang@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=felix.kuehling@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox