From patchwork Mon Jun 15 14:54:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11605301 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03ECF14DD for ; Mon, 15 Jun 2020 15:05:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D637920739 for ; Mon, 15 Jun 2020 15:05:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hARkJctl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D637920739 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B7B46E34B; Mon, 15 Jun 2020 15:05:07 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by gabe.freedesktop.org (Postfix) with ESMTPS id E6BDF6E330; Mon, 15 Jun 2020 14:54:20 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id r15so15140090wmh.5; Mon, 15 Jun 2020 07:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=k09U0VG1ixp4ZkjUC6lkt8f6MU6uFqrJ3qqTzv3/HJY=; b=hARkJctlAC8+yGOj6dpu0fz7YlhrZrQNiJYN6/ccdlxyb54Qy3cFuOCmA6eHaFYwYX zANsaaV/5cMjh0IWncnZDPFxPezHASG9NOQJDlSq/CUqMHCJEky0rCi3VgxsJYogGocx u5fmuFgUg4DNiFUJvIz905VwSnfJDXXvkrtyUN9XLHWEksq60mcmTS1MjNu80v4N3UFT 1ZCv0icCJMukEDlyCwqJxr35pppsvpzdbSJpa3bnOGTWV5BhGDgS2MYEbhFO4Vtlccv1 htZIUlqbXlq/JTHT+GhuJx+ebe2mLOx5yNwlwNA8ZNE1GUf25MV4IFymA5k45C7jhPdh NEHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k09U0VG1ixp4ZkjUC6lkt8f6MU6uFqrJ3qqTzv3/HJY=; b=Dn46baxJjQk2pxL4K8QsdXeLxSXZi5vaBq5l3W2kkY/EZemdbqZ0iOIy+IKEOh6/1K UK+Q/3jLnDEsFKe+oTLpoistYQ9uLyyQa4RzrbKVUvkkeyD3DI3ErLl2LdGAbn4Zq/IQ CkM/PojEMOtRO10jiufAbTUsKvv9BBYqw6FR3bJD4tkEdAFEyHaB+eJUb5cZt/alwyOM I5SyjKbWMlvxhoC6ysduPl3GUvler+yHm4NBl1YHowTKhYYWYzl5JEK1U5C5K4z0Br0Z HzhfSxSkckonLfIodLcg4nTEWGglff+XdbAdzX7CY/DWHUWIB/HkYbNjEy5xMR0ws7oa cMtw== X-Gm-Message-State: AOAM532c8JavQzGffJ34SqkAfYCOb8tbYkHQZHnmFv3wJx3DCKnvwGBs a4TXII26QbpemlCILZssb//Xk4Aq X-Google-Smtp-Source: ABdhPJxzrizoSk90HuvD8yGlAKVZGJ1JOZKoLLvE/jRValE3Qp3ktENr6Jj/CI7LFxJ+quqC/+FsZA== X-Received: by 2002:a1c:9d09:: with SMTP id g9mr13162436wme.31.1592232859603; Mon, 15 Jun 2020 07:54:19 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:a5ab:7330:3773:519a]) by smtp.gmail.com with ESMTPSA id j4sm24277442wma.7.2020.06.15.07.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 07:54:19 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, nirmoy.das@amd.com, dri-devel@lists.freedesktop.org Date: Mon, 15 Jun 2020 16:54:15 +0200 Message-Id: <20200615145415.1775-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200615145415.1775-1-christian.koenig@amd.com> References: <20200615145415.1775-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 15 Jun 2020 15:05:06 +0000 Subject: [Intel-gfx] [PATCH 3/3] drm/mm: cleanup and improve next_hole_*_addr() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Skipping just one branch of the tree is not the most effective approach. Instead use a macro to define the traversal functions and sort out both branch sides. This improves the performance of the unit tests by a factor of more than 4. Signed-off-by: Christian König Reviewed-by: Nirmoy Das --- drivers/gpu/drm/drm_mm.c | 106 +++++++++++++-------------------------- 1 file changed, 34 insertions(+), 72 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 177a5df0fe95..a4a04d246135 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -325,6 +325,11 @@ static struct drm_mm_node *best_hole(struct drm_mm *mm, u64 size) return best; } +static bool usable_hole_addr(struct rb_node *rb, u64 size) +{ + return rb && rb_hole_addr_to_node(rb)->subtree_max_hole >= size; +} + static struct drm_mm_node *find_hole_addr(struct drm_mm *mm, u64 addr, u64 size) { struct rb_node *rb = mm->holes_addr.rb_node; @@ -333,7 +338,7 @@ static struct drm_mm_node *find_hole_addr(struct drm_mm *mm, u64 addr, u64 size) while (rb) { u64 hole_start; - if (rb_hole_addr_to_node(rb)->subtree_max_hole < size) + if (!usable_hole_addr(rb, size)) break; node = rb_hole_addr_to_node(rb); @@ -374,82 +379,39 @@ first_hole(struct drm_mm *mm, } /** - * next_hole_high_addr - returns next hole for a DRM_MM_INSERT_HIGH mode request - * @entry: previously selected drm_mm_node - * @size: size of the a hole needed for the request - * - * This function will verify whether left subtree of @entry has hole big enough - * to fit the requtested size. If so, it will return previous node of @entry or - * else it will return parent node of @entry + * DECLARE_NEXT_HOLE_ADDR - macro to declare next hole functions + * @name: name of function to declare + * @first: first rb member to traverse (either rb_left or rb_right). + * @last: last rb member to traverse (either rb_right or rb_left). * - * It will also skip the complete left subtree if subtree_max_hole of that - * subtree is same as the subtree_max_hole of the @entry. - * - * Returns: - * previous node of @entry if left subtree of @entry can serve the request or - * else return parent of @entry + * This macro declares a function to return the next hole of the addr rb tree. + * While traversing the tree we take the searched size into account and only + * visit branches with potential big enough holes. */ -static struct drm_mm_node * -next_hole_high_addr(struct drm_mm_node *entry, u64 size) -{ - struct rb_node *rb_node, *left_rb_node, *parent_rb_node; - struct drm_mm_node *left_node; - - if (!entry) - return NULL; - rb_node = &entry->rb_hole_addr; - if (rb_node->rb_left) { - left_rb_node = rb_node->rb_left; - parent_rb_node = rb_parent(rb_node); - left_node = rb_entry(left_rb_node, - struct drm_mm_node, rb_hole_addr); - if (left_node->subtree_max_hole < size && - parent_rb_node && parent_rb_node->rb_left != rb_node) - return rb_hole_addr_to_node(parent_rb_node); - } - - return rb_hole_addr_to_node(rb_prev(rb_node)); +#define DECLARE_NEXT_HOLE_ADDR(name, first, last) \ +static struct drm_mm_node *name(struct drm_mm_node *entry, u64 size) \ +{ \ + struct rb_node *parent, *node = &entry->rb_hole_addr; \ + \ + if (!entry || RB_EMPTY_NODE(node)) \ + return NULL; \ + \ + if (usable_hole_addr(node->first, size)) { \ + node = node->first; \ + while (usable_hole_addr(node->last, size)) \ + node = node->last; \ + return rb_hole_addr_to_node(node); \ + } \ + \ + while ((parent = rb_parent(node)) && node == parent->first) \ + node = parent; \ + \ + return rb_hole_addr_to_node(parent); \ } -/** - * next_hole_low_addr - returns next hole for a DRM_MM_INSERT_LOW mode request - * @entry: previously selected drm_mm_node - * @size: size of the a hole needed for the request - * - * This function will verify whether right subtree of @entry has hole big enough - * to fit the requtested size. If so, it will return next node of @entry or - * else it will return parent node of @entry - * - * It will also skip the complete right subtree if subtree_max_hole of that - * subtree is same as the subtree_max_hole of the @entry. - * - * Returns: - * next node of @entry if right subtree of @entry can serve the request or - * else return parent of @entry - */ -static struct drm_mm_node * -next_hole_low_addr(struct drm_mm_node *entry, u64 size) -{ - struct rb_node *rb_node, *right_rb_node, *parent_rb_node; - struct drm_mm_node *right_node; - - if (!entry) - return NULL; - - rb_node = &entry->rb_hole_addr; - if (rb_node->rb_right) { - right_rb_node = rb_node->rb_right; - parent_rb_node = rb_parent(rb_node); - right_node = rb_entry(right_rb_node, - struct drm_mm_node, rb_hole_addr); - if (right_node->subtree_max_hole < size && - parent_rb_node && parent_rb_node->rb_right != rb_node) - return rb_hole_addr_to_node(parent_rb_node); - } - - return rb_hole_addr_to_node(rb_next(rb_node)); -} +DECLARE_NEXT_HOLE_ADDR(next_hole_high_addr, rb_left, rb_right) +DECLARE_NEXT_HOLE_ADDR(next_hole_low_addr, rb_right, rb_left) static struct drm_mm_node * next_hole(struct drm_mm *mm,