From patchwork Fri Dec 16 19:25:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9478445 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 7B7D4601C2 for ; Fri, 16 Dec 2016 19:32:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E252287A5 for ; Fri, 16 Dec 2016 19:32:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62FE4287CD; Fri, 16 Dec 2016 19:32:51 +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 D7FF1287B6 for ; Fri, 16 Dec 2016 19:32:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 530286ED25; Fri, 16 Dec 2016 19:32:46 +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 D09E46ECD7; Fri, 16 Dec 2016 19:26:16 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id a20so7274385wme.2; Fri, 16 Dec 2016 11:26:16 -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 :mime-version:content-transfer-encoding; bh=rup5buQJDyauhw5rdfhDagry2bWYG/d9wekOcptn9dg=; b=jSoILs4X97gMpIWVvUvZKaqQkI+2mtIEP6B/fJk1BfZqslNcGj4Nl6N2jK02CdcEER SbSLSIByQyh8ErriEsQYO24L+qGsdphrJhMrfnEjKxOgZRm+EQ/BlI4ZI7QZBlKvbop3 lO7+XaU7cXXh8JFg8GrZ7ZsFQwG+DNhb282mPOB0kKHaBiK1/v1dMTdG9Q3HHQPEY8kQ q979Mp0sAtv7bm80QjdH984eXEGR5w5aJZxNovxaiMY9/623y1OeP+A/O8tN8t0aIcel TZf/cyi3xDeViroZRSO0af1BsQs2SNQNgEotp7fzvAl/OZiQyABN9jzf64u8pHWgL0Nv e8IQ== 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:mime-version:content-transfer-encoding; bh=rup5buQJDyauhw5rdfhDagry2bWYG/d9wekOcptn9dg=; b=Onz1lF2mnfixrONyToxbpVWRr+mJBQVvuxalgKhm23Gs9wlcT+5vQKMmhCyM+hHlTK LTcSzGSq3ffkJR6i+VEh6lCHtaEgoRuA9fv33/Iiz1cTtfglctxo/yPVUhOqcI5F7+XQ XWSm1MP+gRiZAwajZybIvXj/25ilzzVxZ4ZY6KHCe8zaDoahyD4auppFNIdM4ERXb8Iw /cvyj0wL6PQKSvVErWGKwlL7Q06ZZ7LgOfXObxb1YbogzX27/1uWmBN+N6pwIPfvaMt8 1m5ieRRNB5Yu2HSYvD6fgcQunpUrb/XxfH3kKwqpRstOp4d9GZbNX15zsOTaoHp7Msis p1mw== X-Gm-Message-State: AIkVDXJi8rL50rfyqHtFaU76Qlo1+bt/wRN5ceuINep8amHuIQoNAy6N+OYgEM0s7BWo2w== X-Received: by 10.28.140.136 with SMTP id o130mr4682588wmd.76.1481916375005; Fri, 16 Dec 2016 11:26:15 -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.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 11:26:14 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 21/38] drm: Promote drm_mm alignment to u64 Date: Fri, 16 Dec 2016 19:25:33 +0000 Message-Id: <20161216192550.8352-22-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> MIME-Version: 1.0 Cc: intel-gfx@lists.freedesktop.org, Joonas Lahtinen , =?UTF-8?q?Christian=20K=C3=B6nig?= 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In places (e.g. i915.ko), the alignment is exported to userspace as u64 and there now exists hardware for which we can indeed utilize a u64 alignment. As such, we need to keep 64bit integers throughout when handling alignment. Testcase: igt/drm_mm/align64 Testcase: igt/gem_exec_alignment Signed-off-by: Chris Wilson Cc: Joonas Lahtinen Cc: Christian König Reviewed-by: Christian König --- drivers/gpu/drm/drm_mm.c | 37 +++++++++++++++------------------ drivers/gpu/drm/selftests/test-drm_mm.c | 4 ++-- include/drm/drm_mm.h | 16 +++++++------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 9756542abe4c..fd2667052c73 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -93,12 +93,12 @@ static struct drm_mm_node *drm_mm_search_free_generic(const struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, enum drm_mm_search_flags flags); static struct drm_mm_node *drm_mm_search_free_in_range_generic(const struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, u64 start, u64 end, @@ -227,7 +227,7 @@ static void drm_mm_interval_tree_add_node(struct drm_mm_node *hole_node, static void drm_mm_insert_helper(struct drm_mm_node *hole_node, struct drm_mm_node *node, - u64 size, unsigned alignment, + u64 size, u64 alignment, unsigned long color, enum drm_mm_allocator_flags flags) { @@ -246,10 +246,9 @@ static void drm_mm_insert_helper(struct drm_mm_node *hole_node, adj_start = adj_end - size; if (alignment) { - u64 tmp = adj_start; - unsigned rem; + u64 rem; - rem = do_div(tmp, alignment); + div64_u64_rem(adj_start, alignment, &rem); if (rem) { if (flags & DRM_MM_CREATE_TOP) adj_start -= rem; @@ -376,7 +375,7 @@ EXPORT_SYMBOL(drm_mm_reserve_node); * 0 on success, -ENOSPC if there's no suitable hole. */ int drm_mm_insert_node_generic(struct drm_mm *mm, struct drm_mm_node *node, - u64 size, unsigned alignment, + u64 size, u64 alignment, unsigned long color, enum drm_mm_search_flags sflags, enum drm_mm_allocator_flags aflags) @@ -398,7 +397,7 @@ EXPORT_SYMBOL(drm_mm_insert_node_generic); static void drm_mm_insert_helper_range(struct drm_mm_node *hole_node, struct drm_mm_node *node, - u64 size, unsigned alignment, + u64 size, u64 alignment, unsigned long color, u64 start, u64 end, enum drm_mm_allocator_flags flags) @@ -423,10 +422,9 @@ static void drm_mm_insert_helper_range(struct drm_mm_node *hole_node, adj_start = adj_end - size; if (alignment) { - u64 tmp = adj_start; - unsigned rem; + u64 rem; - rem = do_div(tmp, alignment); + div64_u64_rem(adj_start, alignment, &rem); if (rem) { if (flags & DRM_MM_CREATE_TOP) adj_start -= rem; @@ -482,7 +480,7 @@ static void drm_mm_insert_helper_range(struct drm_mm_node *hole_node, * 0 on success, -ENOSPC if there's no suitable hole. */ int drm_mm_insert_node_in_range_generic(struct drm_mm *mm, struct drm_mm_node *node, - u64 size, unsigned alignment, + u64 size, u64 alignment, unsigned long color, u64 start, u64 end, enum drm_mm_search_flags sflags, @@ -548,16 +546,15 @@ void drm_mm_remove_node(struct drm_mm_node *node) } EXPORT_SYMBOL(drm_mm_remove_node); -static int check_free_hole(u64 start, u64 end, u64 size, unsigned alignment) +static int check_free_hole(u64 start, u64 end, u64 size, u64 alignment) { if (end - start < size) return 0; if (alignment) { - u64 tmp = start; - unsigned rem; + u64 rem; - rem = do_div(tmp, alignment); + div64_u64_rem(start, alignment, &rem); if (rem) start += alignment - rem; } @@ -567,7 +564,7 @@ static int check_free_hole(u64 start, u64 end, u64 size, unsigned alignment) static struct drm_mm_node *drm_mm_search_free_generic(const struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, enum drm_mm_search_flags flags) { @@ -609,7 +606,7 @@ static struct drm_mm_node *drm_mm_search_free_generic(const struct drm_mm *mm, static struct drm_mm_node *drm_mm_search_free_in_range_generic(const struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, u64 start, u64 end, @@ -729,7 +726,7 @@ EXPORT_SYMBOL(drm_mm_replace_node); */ void drm_mm_init_scan(struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color) { mm->scan_color = color; @@ -762,7 +759,7 @@ EXPORT_SYMBOL(drm_mm_init_scan); */ void drm_mm_init_scan_with_range(struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, u64 start, u64 end) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 7e90886f5558..ea21c477837c 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1111,7 +1111,7 @@ static int igt_align64(void *ignored) static void show_scan(const struct drm_mm *scan) { - pr_info("scan: hit [%llx, %llx], size=%lld, align=%d, color=%ld\n", + pr_info("scan: hit [%llx, %llx], size=%lld, align=%lld, color=%ld\n", scan->scan_hit_start, scan->scan_hit_end, scan->scan_size, scan->scan_alignment, scan->scan_color); } @@ -1173,7 +1173,7 @@ static bool evict_nodes(struct drm_mm *mm, list_del(&e->link); } if (list_empty(evict_list)) { - pr_err("Failed to find eviction: size=%lld [avail=%d], align=%d (color=%lu)\n", + pr_err("Failed to find eviction: size=%lld [avail=%d], align=%lld (color=%lu)\n", mm->scan_size, count, mm->scan_alignment, mm->scan_color); diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h index 525543019896..0ce8c3678c11 100644 --- a/include/drm/drm_mm.h +++ b/include/drm/drm_mm.h @@ -98,12 +98,12 @@ struct drm_mm { struct rb_root interval_tree; unsigned int scan_check_range : 1; - unsigned scan_alignment; + unsigned int scanned_blocks; unsigned long scan_color; + u64 scan_alignment; u64 scan_size; u64 scan_hit_start; u64 scan_hit_end; - unsigned scanned_blocks; u64 scan_start; u64 scan_end; struct drm_mm_node *prev_scanned_node; @@ -261,7 +261,7 @@ int drm_mm_reserve_node(struct drm_mm *mm, struct drm_mm_node *node); int drm_mm_insert_node_generic(struct drm_mm *mm, struct drm_mm_node *node, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, enum drm_mm_search_flags sflags, enum drm_mm_allocator_flags aflags); @@ -284,7 +284,7 @@ int drm_mm_insert_node_generic(struct drm_mm *mm, static inline int drm_mm_insert_node(struct drm_mm *mm, struct drm_mm_node *node, u64 size, - unsigned alignment, + u64 alignment, enum drm_mm_search_flags flags) { return drm_mm_insert_node_generic(mm, node, size, alignment, 0, flags, @@ -294,7 +294,7 @@ static inline int drm_mm_insert_node(struct drm_mm *mm, int drm_mm_insert_node_in_range_generic(struct drm_mm *mm, struct drm_mm_node *node, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, u64 start, u64 end, @@ -321,7 +321,7 @@ int drm_mm_insert_node_in_range_generic(struct drm_mm *mm, static inline int drm_mm_insert_node_in_range(struct drm_mm *mm, struct drm_mm_node *node, u64 size, - unsigned alignment, + u64 alignment, u64 start, u64 end, enum drm_mm_search_flags flags) @@ -361,11 +361,11 @@ __drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last); void drm_mm_init_scan(struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color); void drm_mm_init_scan_with_range(struct drm_mm *mm, u64 size, - unsigned alignment, + u64 alignment, unsigned long color, u64 start, u64 end);