Commit 9a956b15 authored by Chris Wilson's avatar Chris Wilson Committed by Daniel Vetter

drm: Optimise power-of-two alignments in drm_mm_scan_add_block()

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

v2: s/alignment_mask/remainder_mask/
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161222083641.2691-32-chris@chris-wilson.co.uk
parent 0b04d474
...@@ -742,8 +742,12 @@ void drm_mm_scan_init_with_range(struct drm_mm_scan *scan, ...@@ -742,8 +742,12 @@ void drm_mm_scan_init_with_range(struct drm_mm_scan *scan,
scan->mm = mm; scan->mm = mm;
if (alignment <= 1)
alignment = 0;
scan->color = color; scan->color = color;
scan->alignment = alignment; scan->alignment = alignment;
scan->remainder_mask = is_power_of_2(alignment) ? alignment - 1 : 0;
scan->size = size; scan->size = size;
scan->flags = flags; scan->flags = flags;
...@@ -811,7 +815,10 @@ bool drm_mm_scan_add_block(struct drm_mm_scan *scan, ...@@ -811,7 +815,10 @@ bool drm_mm_scan_add_block(struct drm_mm_scan *scan,
if (scan->alignment) { if (scan->alignment) {
u64 rem; u64 rem;
div64_u64_rem(adj_start, scan->alignment, &rem); if (likely(scan->remainder_mask))
rem = adj_start & scan->remainder_mask;
else
div64_u64_rem(adj_start, scan->alignment, &rem);
if (rem) { if (rem) {
adj_start -= rem; adj_start -= rem;
if (scan->flags != DRM_MM_CREATE_TOP) if (scan->flags != DRM_MM_CREATE_TOP)
......
...@@ -110,6 +110,7 @@ struct drm_mm_scan { ...@@ -110,6 +110,7 @@ struct drm_mm_scan {
u64 size; u64 size;
u64 alignment; u64 alignment;
u64 remainder_mask;
u64 range_start; u64 range_start;
u64 range_end; u64 range_end;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment