From patchwork Thu Dec 22 08:36:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484447 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 CDE45601D2 for ; Thu, 22 Dec 2016 08:39:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C932127D64 for ; Thu, 22 Dec 2016 08:39:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDF4928285; Thu, 22 Dec 2016 08:39:05 +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=ham 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 7783A27D64 for ; Thu, 22 Dec 2016 08:39:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E0AF6F195; Thu, 22 Dec 2016 08:38:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6F64D6F175; Thu, 22 Dec 2016 08:37:19 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id l2so9218746wml.2; Thu, 22 Dec 2016 00:37:19 -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=UTiVd+CczYjpB1TQQdSrarvFeKWwowhFOqYkT+W8K076OZ6YpUW4uUbPg+uE3OA/r9 GPAT6llVW3Wgjn0mYjywIRd1u2oskPqix8T8EQU9A3OmrGuANBIKkbnKgUBXTFAbzL28 tz8Fvc3cBHmPSf4uSScGwj0jDUb3sKxJX24uWSbAUZ+wL8Pgzkr8KBC067Mh0uuZwBcv Cgou5qi5a/h3irrbgFrbke2W1qMgVEO3FLTqAfjm8MxyETAwcQWiaCa2zolneipmcQ08 h0MgJdupcSf3gsviUZ+Q+jgIHMOuoBVgiVDAjG0eQ9d6N0sqq/xRFAZpGkO+oworWoJ+ 3RLQ== 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=KeqswDoB5xMTd7UUy6rla3j+XHhDUf0oqcDxtEE0+5HUZ8BT/uQJwRDpnolK1pQ4vL ZnhVKwm+OyNDObwV39jXqyE5Vo942vSBPUGpkmlPZChED/4i8+yBRQJSlDQB0/66Cw5L EdtPlhiE3HlGtjsA0RZnN101F7skdAyifT8xZtIP7iL7uXtWnbSYD095l5CEmIpOiRjm S+b01rvgybgCWXD6bcr00TgugSXiF+PCkp/QINgVGAlknw3fNarYTXoDknV2TJ0cVyFc TTPAGLPJZ/0krCgSTFpAVBxakvrdtxbycKb40oNkooQ45eKw4ebLa845zmonqyijmZGU pECg== X-Gm-Message-State: AIkVDXIMMShn1oSxbpFw2asAjMO8ebZ7znoDMSdtaYlVeviOVWbKGTDeN+G+G9H5GaETNw== X-Received: by 10.28.27.133 with SMTP id b127mr10966723wmb.59.1482395837386; Thu, 22 Dec 2016 00:37:17 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id di9sm34442318wjc.37.2016.12.22.00.37.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:37:16 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 31/38] drm: Optimise power-of-two alignments in drm_mm_scan_add_block() Date: Thu, 22 Dec 2016 08:36:34 +0000 Message-Id: <20161222083641.2691-32-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161222083641.2691-1-chris@chris-wilson.co.uk> References: <20161222083641.2691-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;