From patchwork Sat Feb 4 11:19:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9555591 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 DD0D1602B5 for ; Sat, 4 Feb 2017 11:19:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A567226E4D for ; Sat, 4 Feb 2017 11:19:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87DE927D29; Sat, 4 Feb 2017 11:19:21 +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 0517026E4D for ; Sat, 4 Feb 2017 11:19:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA41D6E182; Sat, 4 Feb 2017 11:19:18 +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 36D1E6E182 for ; Sat, 4 Feb 2017 11:19:18 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id u63so10443215wmu.2 for ; Sat, 04 Feb 2017 03:19:18 -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; bh=4YKmxXoapnyVvYwo3Cirh8TQxCcTV+ED69jHsmtyneQ=; b=nZOvVNGtjiPGaowMxjDmYAiOIjac61D3VFkYOf3lB3foVU3Q6hmE+h6CfyRCSIJhCb jgSlhKFkketFdRE7AnllE9UoVB7TM1yEpEOYI4tn03L9VU7g8kq1GciO1JYxIfDj418R Rvm82eIlygtx6m1mcX6r6c/6gUq6yfDDUcLMJy35OJXlfKyp0W62cLkuzz+1YKQa+rR3 LasLTHYj8E8JpCUdn+B+4z83o2eNOPwZrEeuSCQAmhQcsFWbybLCi9n0n6g8Bim0Ww+f PopbiBhVD4iorEhpct6VlCLX+H942JpqT848EQpZKPFh+uRnPTJqk++PhP0az245nj1h mXrQ== 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; bh=4YKmxXoapnyVvYwo3Cirh8TQxCcTV+ED69jHsmtyneQ=; b=KYPihG+xjKn336wU/qDtfkXXT54eu/O2+comGyAztnz775bk1Uaj6vE7m/bsaLQQQX c+pGEpUH8x7ZBDzX2wRt6sALiridZvWTI6annI4ROQxdmcUTtZJAXir6wsOTpv6pxg9o hgN/FzM13706/d3aib0MQDD3dJh2ClQ7loyHCDwIi64QU2GnsnkCjDkLu2Kws6e+A3HR nkximohqWcxWyr2TbUm+wOgTafgfGn1eWB6GTp7Lo3ah3YwEEsfNSIwzn899wjP5nqxL di3SdvoW4Nzt022YyrHz1oW1PFmgTPv/S9CiWybUzILZgT7hKtiQhoRurVq0U8A6M7sr gfqA== X-Gm-Message-State: AMke39nB/GrcB9U94MFEZiuG62LZx0MeJoLxjIKowLVxR7LYQXcOYybCz2vk8bUHsE7AeA== X-Received: by 10.28.95.4 with SMTP id t4mr1680151wmb.87.1486207156564; Sat, 04 Feb 2017 03:19:16 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id l140sm2128787wmg.12.2017.02.04.03.19.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Feb 2017 03:19:15 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm: Micro-optimise drm_mm_for_each_node_in_range() Date: Sat, 4 Feb 2017 11:19:13 +0000 Message-Id: <20170204111913.12416-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 Cc: Joonas Lahtinen 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 As we require valid start/end parameters, we can replace the initial potential NULL with a pointer to the drm_mm.head_node and so reduce the test on every iteration from a NULL + address comparison to just an address comparison. add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-26 (-26) function old new delta i915_gem_evict_for_node 719 693 -26 (No other users outside of the test harness.) Signed-off-by: Chris Wilson Cc: Joonas Lahtinen Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/drm_mm.c | 2 +- drivers/gpu/drm/selftests/test-drm_mm.c | 10 ++++++---- include/drm/drm_mm.h | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 8bfb0b327267..f794089d30ac 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -170,7 +170,7 @@ struct drm_mm_node * __drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last) { return drm_mm_interval_tree_iter_first((struct rb_root *)&mm->interval_tree, - start, last); + start, last) ?: (struct drm_mm_node *)&mm->head_node; } EXPORT_SYMBOL(__drm_mm_interval_first); diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 1e71bc182ca9..2958f596081e 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -839,16 +839,18 @@ static bool assert_contiguous_in_range(struct drm_mm *mm, n++; } - drm_mm_for_each_node_in_range(node, mm, 0, start) { - if (node) { + if (start > 0) { + node = __drm_mm_interval_first(mm, 0, start - 1); + if (node->allocated) { pr_err("node before start: node=%llx+%llu, start=%llx\n", node->start, node->size, start); return false; } } - drm_mm_for_each_node_in_range(node, mm, end, U64_MAX) { - if (node) { + if (end < U64_MAX) { + node = __drm_mm_interval_first(mm, end, U64_MAX); + if (node->allocated) { pr_err("node after end: node=%llx+%llu, end=%llx\n", node->start, node->size, end); return false; diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h index d81b0ba9921f..f262da180117 100644 --- a/include/drm/drm_mm.h +++ b/include/drm/drm_mm.h @@ -459,10 +459,13 @@ __drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last); * but using the internal interval tree to accelerate the search for the * starting node, and so not safe against removal of elements. It assumes * that @end is within (or is the upper limit of) the drm_mm allocator. + * If [@start, @end] are beyond the range of the drm_mm, the iterator may walk + * over the special _unallocated_ &drm_mm.head_node, and may even continue + * indefinitely. */ #define drm_mm_for_each_node_in_range(node__, mm__, start__, end__) \ for (node__ = __drm_mm_interval_first((mm__), (start__), (end__)-1); \ - node__ && node__->start < (end__); \ + node__->start < (end__); \ node__ = list_next_entry(node__, node_list)) void drm_mm_scan_init_with_range(struct drm_mm_scan *scan,