summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_mm.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2016-12-22 09:36:34 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2016-12-28 11:51:52 +0100
commit9a956b1548794033d5b893d6d6fcc00b197cfc9b (patch)
tree8b8cfbe1b61e48ac2a8a7aca0620a16bc29fcd15 /drivers/gpu/drm/drm_mm.c
parentdrm: Compute tight evictions for drm_mm_scan (diff)
downloadlinux-9a956b1548794033d5b893d6d6fcc00b197cfc9b.tar.xz
linux-9a956b1548794033d5b893d6d6fcc00b197cfc9b.zip
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: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/20161222083641.2691-32-chris@chris-wilson.co.uk
Diffstat (limited to 'drivers/gpu/drm/drm_mm.c')
-rw-r--r--drivers/gpu/drm/drm_mm.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 189ab84c5a59..0441d84fba74 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -742,8 +742,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->remainder_mask = is_power_of_2(alignment) ? alignment - 1 : 0;
scan->size = size;
scan->flags = flags;
@@ -811,7 +815,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 (likely(scan->remainder_mask))
+ rem = adj_start & scan->remainder_mask;
+ else
+ div64_u64_rem(adj_start, scan->alignment, &rem);
if (rem) {
adj_start -= rem;
if (scan->flags != DRM_MM_CREATE_TOP)