[PATCH v4 5/7] drm/amdkfd: Change range granularity update bitmap_map

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

 



When changing the svm range granularity, update the svm range
bitmap_map based on new range granularity.

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 7a30c3e58234..ebc4cce801bf 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -757,6 +757,53 @@ svm_range_check_attr(struct kfd_process *p,
 	return 0;
 }
 
+static void
+svm_range_change_granularity(struct svm_range *prange, u8 value)
+{
+	struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms);
+	u32 new_nbits, old_nbits, i, n;
+	unsigned long *new_bits, *old_bits;
+	u32 gpuidx;
+
+	if (prange->granularity == value)
+		return;
+
+	old_nbits = svm_range_map_nbits(prange->start, prange->last, prange->granularity);
+	new_nbits = svm_range_map_nbits(prange->start, prange->last, value);
+	if (new_nbits > old_nbits) {
+		n = new_nbits / old_nbits;
+		if (new_nbits % old_nbits)
+			n++;
+	} else {
+		n = old_nbits / new_nbits;
+		if (old_nbits % new_nbits)
+			n++;
+	}
+
+	pr_debug("prange 0x%p [0x%lx 0x%lx] bitmap_map nbits %d -> %d\n",
+		 prange, prange->start, prange->last, old_nbits, new_nbits);
+
+	for_each_set_bit(gpuidx, p->svms.bitmap_supported, p->n_pdds) {
+		old_bits = prange->bitmap_map[gpuidx];
+		if (bitmap_empty(old_bits, old_nbits))
+			continue;
+
+		new_bits = bitmap_zalloc(new_nbits, GFP_KERNEL);
+		if (!new_bits)
+			return;
+
+		for_each_set_bit(i, old_bits, old_nbits) {
+			if (new_nbits > old_nbits)
+				bitmap_set(new_bits, i * n, n);
+			else
+				bitmap_set(new_bits, i / n, 1);
+		}
+		prange->bitmap_map[gpuidx] = new_bits;
+		bitmap_free(old_bits);
+	}
+	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,
@@ -801,7 +848,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 = min_t(uint32_t, attrs[i].value, 0x3F);
+			svm_range_change_granularity(prange, min_t(u32, attrs[i].value, 0x3F));
 			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