[PATCH 30/34] drm: Optimise power-of-two alignments in drm_mm_scan_add_block()

Chris Wilson chris at chris-wilson.co.uk
Mon Dec 12 11:53:46 UTC 2016


For power-of-two alignments, we can avoid the 64bit divide and do a
simple bitwise add instead.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/drm_mm.c | 9 ++++++++-
 include/drm/drm_mm.h     | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index eec0a46f5b38..7245483f1111 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -741,8 +741,12 @@ void drm_mm_scan_init_with_range(struct drm_mm_scan *scan,
 
 	scan->mm = mm;
 
+	if (alignment <= 1)
+		alignment = 0;
+
 	scan->color = color;
 	scan->alignment = alignment;
+	scan->alignment_mask = is_power_of_2(alignment) ? alignment - 1 : 0;
 	scan->size = size;
 	scan->flags = flags;
 
@@ -810,7 +814,10 @@ bool drm_mm_scan_add_block(struct drm_mm_scan *scan,
 	if (scan->alignment) {
 		u64 rem;
 
-		div64_u64_rem(adj_start, scan->alignment, &rem);
+		if (scan->alignment_mask)
+			rem = adj_start & scan->alignment_mask;
+		else
+			div64_u64_rem(adj_start, scan->alignment, &rem);
 		if (rem) {
 			adj_start -= rem;
 			if (scan->flags != DRM_MM_CREATE_TOP)
diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h
index 5e8350b91fcf..90d607e31301 100644
--- a/include/drm/drm_mm.h
+++ b/include/drm/drm_mm.h
@@ -109,6 +109,7 @@ struct drm_mm_scan {
 
 	u64 size;
 	u64 alignment;
+	u64 alignment_mask;
 
 	u64 range_start;
 	u64 range_end;
-- 
2.11.0



More information about the dri-devel mailing list