From patchwork Thu Dec 22 08:36:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484493 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 AE250601D3 for ; Thu, 22 Dec 2016 08:41:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA69927D64 for ; Thu, 22 Dec 2016 08:41:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F6BA283A6; Thu, 22 Dec 2016 08:41:43 +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 4493C281C3 for ; Thu, 22 Dec 2016 08:41:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5593F6F1A2; Thu, 22 Dec 2016 08:41:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x242.google.com (mail-wj0-x242.google.com [IPv6:2a00:1450:400c:c01::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id C38956F17B; Thu, 22 Dec 2016 08:37:20 +0000 (UTC) Received: by mail-wj0-x242.google.com with SMTP id kp2so35175142wjc.0; Thu, 22 Dec 2016 00:37:20 -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=iOpc4NkuK7FumSwYScioIe71UTiS820fWzJLuBo9zzk=; b=itjXqQcq1GSdanDB1S7myrEzTW/Gk/61Ie2OF3tbfdbjWIbPpf3M39auSrlp/wjV69 oI/1JhNy55wY4pQacDq2+laScKyDMQU6vU546Yj0mYiSCCpR65wKjewUhQ7p6LZppdvY GQzYJPuEnxj865d1kfQBL+VQCgSpzIURqNLFEbxCvqnABFQyUl0BY8EsHqlS37fZD9G6 TjY4AVPjJY+YdLn4rH2t/0hcRAz6xkZek3e0ZrCKt97HUhj6ogy9vp4lYL0n0ZI9n3Fa u9BXwaguEMSxW2VN6hXs0o8g2L8R/BPBMBiMBd3m7giHzmhEDQQ4P9IQenZDaW96wU5a zE6g== 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=iOpc4NkuK7FumSwYScioIe71UTiS820fWzJLuBo9zzk=; b=B9NkskOR8nwoIrI1/rLBZ68M6o5Nwx/lhCidofn2DBVo28dfq9QOhRS127+YQfwpIG bwTjTDER3K+WepLkMCG/IPe/Cvm4Dnw5D6UbnhPYfmvfyV9+vD2QKafg8VWkdXJ0TOxl tJg5VLE+9hMhc1kZBRk/f5Ob7RefzLUr/CT1GsDm0fNFe3qDhGckOEC6nropGEy/cEe6 rBb57381LpDGf2aIANvr2dovtYGqmt21wQXSSedgO115/Oa9y7F1oPgktInj2uQYxs6o 6ajXLWjJI4knHW8oRXGCb96YshOijFV48HKg7oHIageLgJRxSiA0L5NmZ3GsfKrLwXr4 jFRA== X-Gm-Message-State: AIkVDXLFrthXGRhsLgyUZ3gsJfuyCZf+N/ds0T+LKkUxobOtSay0mT8rtbLyBxJnor/8ng== X-Received: by 10.194.222.202 with SMTP id qo10mr7987172wjc.115.1482395838579; Thu, 22 Dec 2016 00:37:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:37:17 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 32/38] drm: Simplify drm_mm scan-list manipulation Date: Thu, 22 Dec 2016 08:36:35 +0000 Message-Id: <20161222083641.2691-33-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 Since we mandate a strict reverse-order of drm_mm_scan_remove_block() after drm_mm_scan_add_block() we can further simplify the list manipulations when generating the temporary scan-hole. v2: Highlight the games being played with the lists to track the scan holes without allocation. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/drm_mm.c | 35 ++++++++++++++++++----------------- include/drm/drm_mm.h | 7 +------ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 0441d84fba74..ccca8dafb7fc 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -518,9 +518,7 @@ void drm_mm_remove_node(struct drm_mm_node *node) struct drm_mm_node *prev_node; DRM_MM_BUG_ON(!node->allocated); - DRM_MM_BUG_ON(node->scanned_block || - node->scanned_prev_free || - node->scanned_next_free); + DRM_MM_BUG_ON(node->scanned_block); prev_node = list_entry(node->node_list.prev, struct drm_mm_node, node_list); @@ -757,8 +755,6 @@ void drm_mm_scan_init_with_range(struct drm_mm_scan *scan, scan->hit_start = U64_MAX; scan->hit_end = 0; - - scan->prev_scanned_node = NULL; } EXPORT_SYMBOL(drm_mm_scan_init_with_range); @@ -787,14 +783,14 @@ bool drm_mm_scan_add_block(struct drm_mm_scan *scan, node->scanned_block = true; mm->scan_active++; + /* Remove this block from the node_list so that we enlarge the hole + * (distance between the end of our previous node and the start of + * or next), without poisoning the link so that we can restore it + * later in drm_mm_scan_remove_block(). + */ hole = list_prev_entry(node, node_list); - - node->scanned_preceeds_hole = hole->hole_follows; - hole->hole_follows = 1; - list_del(&node->node_list); - node->node_list.prev = &hole->node_list; - node->node_list.next = &scan->prev_scanned_node->node_list; - scan->prev_scanned_node = node; + DRM_MM_BUG_ON(list_next_entry(hole, node_list) != node); + __list_del_entry(&node->node_list); hole_start = __drm_mm_hole_node_start(hole); hole_end = __drm_mm_hole_node_end(hole); @@ -888,9 +884,17 @@ bool drm_mm_scan_remove_block(struct drm_mm_scan *scan, DRM_MM_BUG_ON(!node->mm->scan_active); node->mm->scan_active--; + /* During drm_mm_scan_add_block() we decoupled this node leaving + * its pointers intact. Now that the caller is walking back along + * the eviction list we can restore this block into its rightful + * place on the full node_list. To confirm that the caller is walking + * backwards correctly we check that prev_node->next == node->next, + * i.e. both believe the same node should be on the other side of the + * hole. + */ prev_node = list_prev_entry(node, node_list); - - prev_node->hole_follows = node->scanned_preceeds_hole; + DRM_MM_BUG_ON(list_next_entry(prev_node, node_list) != + list_next_entry(node, node_list)); list_add(&node->node_list, &prev_node->node_list); return (node->start + node->size > scan->hit_start && @@ -917,9 +921,6 @@ void drm_mm_init(struct drm_mm *mm, u64 start, u64 size) INIT_LIST_HEAD(&mm->head_node.node_list); mm->head_node.allocated = 0; mm->head_node.hole_follows = 1; - mm->head_node.scanned_block = 0; - mm->head_node.scanned_prev_free = 0; - mm->head_node.scanned_next_free = 0; mm->head_node.mm = mm; mm->head_node.start = start + size; mm->head_node.size = start - mm->head_node.start; diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h index d6701d56ea74..ff120b7d0f85 100644 --- a/include/drm/drm_mm.h +++ b/include/drm/drm_mm.h @@ -74,11 +74,8 @@ struct drm_mm_node { struct list_head hole_stack; struct rb_node rb; unsigned hole_follows : 1; - unsigned scanned_block : 1; - unsigned scanned_prev_free : 1; - unsigned scanned_next_free : 1; - unsigned scanned_preceeds_hole : 1; unsigned allocated : 1; + bool scanned_block : 1; unsigned long color; u64 start; u64 size; @@ -118,8 +115,6 @@ struct drm_mm_scan { u64 hit_start; u64 hit_end; - struct drm_mm_node *prev_scanned_node; - unsigned long color; unsigned int flags; };