From patchwork Fri Dec 16 19:25:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9478451 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 F217C601C2 for ; Fri, 16 Dec 2016 19:33:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E449A287A5 for ; Fri, 16 Dec 2016 19:33:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D917D287CD; Fri, 16 Dec 2016 19:33:06 +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 601B2287A5 for ; Fri, 16 Dec 2016 19:33:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D7B4B6ED27; Fri, 16 Dec 2016 19:33:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x243.google.com (mail-wj0-x243.google.com [IPv6:2a00:1450:400c:c01::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 518126ECDB; Fri, 16 Dec 2016 19:26:23 +0000 (UTC) Received: by mail-wj0-x243.google.com with SMTP id xy5so15613414wjc.1; Fri, 16 Dec 2016 11:26:23 -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=QLsm1guvnIdVlOsm0WWCJrSMAtto9I6Z3JQAmQ+GThk=; b=F2kxPYZ7uKkX6gwPoQac/jU2MJT8zly0mGDRcUT0nSs89tsIWeDcllfSoxusUP6qnD tXx7F8F92NJGGIOxELH6ST2zT3qZSc0i3GRco4v5jfLpzWpBZP0fAF/G6tZ+aFP507X6 amYLyoO5VclwR7oZuknTZ83w7u/FqQCcODa6ZEulm5DQhOsoYSfPoU++Ic7VfaJMK3Yu iGIpURUFAhipVmTUFTGVQ0gKdxCPg44maDBxyggG980ZnOMPJysZuYODn4bcZwWFFykj 9QjrgUCZ3g2PcKVvaBibNm86OBBQtdMgZPUV0id2/rWb3wR4k9HoFTwgSsyrMW4T5gRV NPFQ== 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=QLsm1guvnIdVlOsm0WWCJrSMAtto9I6Z3JQAmQ+GThk=; b=CRoCZjtTov5FgPBJiCvhQ1uGMae/+2Z3bWrkF4j0Tky+5m+AnaTv2X4GcKKH62xzG4 hQ7k3SLblgbfaD2XiYnYviXnnvUsdPo1KCKmnfhn2PHnBBlsndpfDkpXkNhMJg+z46oR Bh1uSPSelcolW7FAy3dI2fJbLNustFMdopNrIAiF6R1fjzTgsnTMvG6BpF0o9tFS6p0G /HR/nl4c+Xbed87B4PfDdipjHoPwa4jQxzDTFl5Fgnq1QkoX1gkWpv/INOf1R4ORXm/3 J7O+RCKNXKjXCfF/bTbfzkyGdq1LQY+AYEUPljlM4eoAw6uypntE/I8QAEhzXeMaNv5W q6Sg== X-Gm-Message-State: AIkVDXIC4phEHzKiwtBMtZBnMI7sXej8yEGZcjhlxbN2P3I5F3ipG1Wmq43Z8Fv4q7af9g== X-Received: by 10.194.113.2 with SMTP id iu2mr4709239wjb.32.1481916380909; Fri, 16 Dec 2016 11:26:20 -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.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 11:26:20 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 28/38] drm: Unconditionally do the range check in drm_mm_scan_add_block() Date: Fri, 16 Dec 2016 19:25:40 +0000 Message-Id: <20161216192550.8352-29-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 Doing the check is trivial (low cost in comparison to overall eviction) and helps simplify the code. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/drm_mm.c | 53 +++-------------------------------- drivers/gpu/drm/i915/i915_gem_evict.c | 10 ++----- include/drm/drm_mm.h | 33 ++++++++++++++++++---- 3 files changed, 34 insertions(+), 62 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 459f10ca5714..c68f79149b9a 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -710,46 +710,6 @@ EXPORT_SYMBOL(drm_mm_replace_node); */ /** - * drm_mm_scan_init - initialize lru scanning - * @scan: scan state - * @mm: drm_mm to scan - * @size: size of the allocation - * @alignment: alignment of the allocation - * @color: opaque tag value to use for the allocation - * - * This simply sets up the scanning routines with the parameters for the desired - * hole. Note that there's no need to specify allocation flags, since they only - * change the place a node is allocated from within a suitable hole. - * - * Warning: - * As long as the scan list is non-empty, no other operations than - * adding/removing nodes to/from the scan list are allowed. - */ -void drm_mm_scan_init(struct drm_mm_scan *scan, - struct drm_mm *mm, - u64 size, - u64 alignment, - unsigned long color) -{ - DRM_MM_BUG_ON(!size); - DRM_MM_BUG_ON(mm->scan_active); - - scan->mm = mm; - - scan->color = color; - scan->alignment = alignment; - scan->size = size; - - scan->check_range = 0; - - scan->hit_start = U64_MAX; - scan->hit_end = 0; - - scan->prev_scanned_node = NULL; -} -EXPORT_SYMBOL(drm_mm_scan_init); - -/** * drm_mm_scan_init_with_range - initialize range-restricted lru scanning * @scan: scan state * @mm: drm_mm to scan @@ -788,7 +748,6 @@ void drm_mm_scan_init_with_range(struct drm_mm_scan *scan, DRM_MM_BUG_ON(end <= start); scan->range_start = start; scan->range_end = end; - scan->check_range = 1; scan->hit_start = U64_MAX; scan->hit_end = 0; @@ -830,15 +789,11 @@ bool drm_mm_scan_add_block(struct drm_mm_scan *scan, node->node_list.next = &scan->prev_scanned_node->node_list; scan->prev_scanned_node = node; - adj_start = hole_start = drm_mm_hole_node_start(hole); - adj_end = hole_end = drm_mm_hole_node_end(hole); + hole_start = drm_mm_hole_node_start(hole); + hole_end = drm_mm_hole_node_end(hole); - if (scan->check_range) { - if (adj_start < scan->range_start) - adj_start = scan->range_start; - if (adj_end > scan->range_end) - adj_end = scan->range_end; - } + adj_start = max(hole_start, scan->range_start); + adj_end = min(hole_end, scan->range_end); if (mm->color_adjust) mm->color_adjust(hole, scan->color, &adj_start, &adj_end); diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c index 6db0d73c0aa7..77ded288534b 100644 --- a/drivers/gpu/drm/i915/i915_gem_evict.c +++ b/drivers/gpu/drm/i915/i915_gem_evict.c @@ -126,13 +126,9 @@ i915_gem_evict_something(struct i915_address_space *vm, * On each list, the oldest objects lie at the HEAD with the freshest * object on the TAIL. */ - if (start != 0 || end != vm->total) { - drm_mm_scan_init_with_range(&scan, &vm->mm, min_size, - alignment, cache_level, - start, end); - } else - drm_mm_scan_init(&scan, &vm->mm, min_size, - alignment, cache_level); + drm_mm_scan_init_with_range(&scan, &vm->mm, + min_size, alignment, cache_level, + start, end); /* Retire before we search the active list. Although we have * reasonable accuracy in our retirement lists, we may have diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h index fcad718c5fb4..bae0f10da8e3 100644 --- a/include/drm/drm_mm.h +++ b/include/drm/drm_mm.h @@ -120,7 +120,6 @@ struct drm_mm_scan { struct drm_mm_node *prev_scanned_node; unsigned long color; - bool check_range : 1; }; /** @@ -387,11 +386,6 @@ __drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last); node__ && node__->start < (end__); \ node__ = list_next_entry(node__, node_list)) -void drm_mm_scan_init(struct drm_mm_scan *scan, - struct drm_mm *mm, - u64 size, - u64 alignment, - unsigned long color); void drm_mm_scan_init_with_range(struct drm_mm_scan *scan, struct drm_mm *mm, u64 size, @@ -399,6 +393,33 @@ void drm_mm_scan_init_with_range(struct drm_mm_scan *scan, unsigned long color, u64 start, u64 end); + +/** + * drm_mm_scan_init - initialize lru scanning + * @scan: scan state + * @mm: drm_mm to scan + * @size: size of the allocation + * @alignment: alignment of the allocation + * @color: opaque tag value to use for the allocation + * + * This simply sets up the scanning routines with the parameters for the desired + * hole. Note that there's no need to specify allocation flags, since they only + * change the place a node is allocated from within a suitable hole. + * + * Warning: + * As long as the scan list is non-empty, no other operations than + * adding/removing nodes to/from the scan list are allowed. + */ +static inline void drm_mm_scan_init(struct drm_mm_scan *scan, + struct drm_mm *mm, + u64 size, + u64 alignment, + unsigned long color) +{ + drm_mm_scan_init_with_range(scan, mm, size, alignment, color, + 0, U64_MAX); +} + bool drm_mm_scan_add_block(struct drm_mm_scan *scan, struct drm_mm_node *node); bool drm_mm_scan_remove_block(struct drm_mm_scan *scan,