From patchwork Fri Dec 16 19:25:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9478441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B689601C2 for ; Fri, 16 Dec 2016 19:32:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DD9428772 for ; Fri, 16 Dec 2016 19:32:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 126DC287DB; Fri, 16 Dec 2016 19:32:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD51228772 for ; Fri, 16 Dec 2016 19:32:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 709E96ED06; Fri, 16 Dec 2016 19:32:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id E8B5E6ECE0; Fri, 16 Dec 2016 19:26:26 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id g23so7268585wme.1; Fri, 16 Dec 2016 11:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=61yLsTanbxnWrXR/l8PNeIK7QaXsFNLxuCPuD7NJRQw=; b=m+ZLsne9+zle+3FdingEE3gs2zZZQY0yBab0hbpwrWp502IfnqpqO9Lcn/z6STGDe5 9niv4TlYEaPWty7FstazOuXFUf95E2YFiElrCKsZRxwQoCen6w1MhSKUl+yfovleorwE S6gV2/wBEKafsvIjo+FtmiJSU/xAnV3kedAa+HP4QRPfF+3xx781SuBnVZJ3Bn9gdGQM mgtENCYfhVFXyjkHIcs44LnA8+svn2e+lEfdAes3bCYQRwIHm+6NqfNjxDQT6juG94pH 3HYFEGxprYZUpJtly4fNAam5H7TEb+feRoGD327PCcWihaYPQ6bcMdRweYYtunIFkusB f1tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=61yLsTanbxnWrXR/l8PNeIK7QaXsFNLxuCPuD7NJRQw=; b=NyJ6QYRASnp1WtHddtDrz/HJ8Mh5EwPsMg+RsnHhiqd2+lAC+zU62Yg/v8EWpLQ006 XbcBAyscUOVMWti7MpOxVhbU/9VfSKHMwKt68w9uVW2fgDCDO7vYSYbkBPyyWa+i55M0 XA5MHPHCgP8LDexsO3AQhWAQepmyL6OIOUgoKw+ossUbtbkxAi6C8QAPw283vnn6vw4T 6NCFvXnQosDdHLyQEQE4qsDiYKQu0zXE96B7xFAokW6Fz5e2+oK2zoI9/AVxR9HR1Zgc UZamlk6yGhDVuR4zZ6mEKqTNAoYG5ScU5Bj7l3OI4Xv969stf1woVghBlsowZqUm/Xkq oeyg== X-Gm-Message-State: AIkVDXJUVjGR8q635QalWl9RkoekS9tf5SiAuAZwjMRgscqEfXchqE+/ZisVOHELqrO0uw== X-Received: by 10.28.49.193 with SMTP id x184mr3928622wmx.44.1481916383377; Fri, 16 Dec 2016 11:26:23 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id v2sm8125856wja.41.2016.12.16.11.26.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 11:26:22 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 31/38] drm: Optimise power-of-two alignments in drm_mm_scan_add_block() Date: Fri, 16 Dec 2016 19:25:43 +0000 Message-Id: <20161216192550.8352-32-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161216192550.8352-1-chris@chris-wilson.co.uk> References: <20161216192550.8352-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Joonas Lahtinen --- 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 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) diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h index 606336fc229a..d6701d56ea74 100644 --- a/include/drm/drm_mm.h +++ b/include/drm/drm_mm.h @@ -110,6 +110,7 @@ struct drm_mm_scan { u64 size; u64 alignment; + u64 remainder_mask; u64 range_start; u64 range_end;