[PATCH v2 7/7] drm/amdkfd: Changing range granularity update bitmap_mapped

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When changing the svm range granularity, update the svm range
bitmap_mapped accordingly.

Signed-off-by: Philip Yang <Philip.Yang@xxxxxxx>
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 49 +++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index e1392b277399..55b806048925 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -739,6 +739,53 @@ svm_range_check_attr(struct kfd_process *p,
 	return 0;
 }
 
+static void
+svm_range_change_granularity(struct svm_range *prange, uint8_t value)
+{
+	struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms);
+	unsigned int nbits_new, nbits_old, i, n;
+	unsigned long *bits_new, *bits_old;
+	int gpuidx;
+
+	if (prange->granularity == value)
+		return;
+
+	nbits_old = svm_range_mapped_nbits(prange->start, prange->last, prange->granularity);
+	nbits_new = svm_range_mapped_nbits(prange->start, prange->last, value);
+	if (nbits_new > nbits_old) {
+		n = nbits_new / nbits_old;
+		if (nbits_new % nbits_old)
+			n++;
+	} else {
+		n = nbits_old / nbits_new;
+		if (nbits_old % nbits_new)
+			n++;
+	}
+
+	pr_debug("prange 0x%p [0x%lx 0x%lx] bitmap_mapped nbits %d -> %d\n",
+		 prange, prange->start, prange->last, nbits_old, nbits_new);
+
+	for_each_set_bit(gpuidx, p->svms.bitmap_supported, p->n_pdds) {
+		bits_old = prange->bitmap_mapped[gpuidx];
+		if (bitmap_empty(bits_old, nbits_old))
+			continue;
+
+		bits_new = bitmap_zalloc(nbits_new, GFP_KERNEL);
+		if (!bits_new)
+			return;
+
+		for_each_set_bit(i, bits_old, nbits_old) {
+			if (nbits_new > nbits_old)
+				bitmap_set(bits_new, i * n, n);
+			else
+				bitmap_set(bits_new, i / n, 1);
+		}
+		bitmap_free(bits_old);
+		prange->bitmap_mapped[gpuidx] = bits_new;
+	}
+	prange->granularity = value;
+}
+
 static void
 svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange,
 		      uint32_t nattr, struct kfd_ioctl_svm_attribute *attrs,
@@ -783,7 +830,7 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange,
 			prange->flags &= ~attrs[i].value;
 			break;
 		case KFD_IOCTL_SVM_ATTR_GRANULARITY:
-			prange->granularity = attrs[i].value;
+			svm_range_change_granularity(prange, attrs[i].value);
 			break;
 		default:
 			WARN_ONCE(1, "svm_range_check_attrs wasn't called?");
-- 
2.35.1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux