From patchwork Tue Nov 14 14:24:35 2017 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: 10057719 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 B1D1160231 for ; Tue, 14 Nov 2017 14:24:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F4D22856B for ; Tue, 14 Nov 2017 14:24:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93B342851D; Tue, 14 Nov 2017 14:24:45 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 16E852851D for ; Tue, 14 Nov 2017 14:24:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EEC186E03C; Tue, 14 Nov 2017 14:24:42 +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 87A036E02E; Tue, 14 Nov 2017 14:24:41 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id r68so22414407wmr.3; Tue, 14 Nov 2017 06:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=0RVZ7WTexFXoSz5V5phmV7xuSoQ9Rfi0y4RurpI3rNg=; b=NzHyc4Z/2jUg2oP0P6b3OseFoh0NefDLJPmiJbi/ek/vFaITrMW9aNTghNwaNrW9OW Oz8DhBq8VhgAH1jHy2XI7L01a1P6xmdipM/lCm1vTJkmA0Gxs5QtUys300m2YYASchNI B7PWSRuVLgbN625xMCvWVMaqIiLTm6w9kiF2XqpROytgHO7DazcpzujZ/JMQ4XDbqrGf FXDhxFPyClDYl4lCXmVNZmlHVoBEPBlgrGJkFtoH4Z7yxPS8awq3V+vWr6YnH+tjj3yD ymMeAB767+sokwb3rSzWkdwUb/Zq6KYxvWfARhDCpSgJXmos/TQA2L5e3RcVybMy1mpp XH5w== 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:mime-version :content-transfer-encoding; bh=0RVZ7WTexFXoSz5V5phmV7xuSoQ9Rfi0y4RurpI3rNg=; b=WM36x1xpSetxlmWukvU9oR6lIOV0V45Lc+lUQrWeHmYHN0HdkwVJHifiI9bdD/K/5x N1hY6fsU0g5HeQ/VjEg47rAgE49HoFCvQ2FH/NShcpsBru/OhVgVaZKRBq6TG12OuUSc h6lNT753d7ua7XU/6/GHXBMKig8f/fIihJ0huSrOmRc8dQsTuEaF8rOqZG+ovEDl4qYp 867t8kn7O4uqzobrW/ThM1t2W+kr3TbNQI3a0VoJrSzKO99okIhAmTT3RUpAepEFPAuN AVryAFJC01EWP2raKGSnyZtPzEpDYRy2+QIJbeRTvzzMf2aEnqbVzi1QW2zQy3v22rK1 X3ug== X-Gm-Message-State: AJaThX5ZaEGxDQ4dSTQUNBMzwunHr+8RnLLplK3+mLMl90ZetTWW35gF bGdiVHmuMVitvP7fhZilHvumGA== X-Google-Smtp-Source: AGs4zMYsuGtbi1sNIW9RpKqKMX1UlN75VEZd3uXf5vmJeQO29txVPBVvGMQTbM/l9guUmmTD7pyO1Q== X-Received: by 10.28.55.78 with SMTP id e75mr8245062wma.112.1510669480113; Tue, 14 Nov 2017 06:24:40 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:50c0:8c4d:16f4:878b]) by smtp.gmail.com with ESMTPSA id 185sm11246938wmj.33.2017.11.14.06.24.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Nov 2017 06:24:39 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: chris@chris-wilson.co.uk, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 1/2] dma-buf: keep only not signaled fence in reservation_object_add_shared_replace v3 Date: Tue, 14 Nov 2017 15:24:35 +0100 Message-Id: <20171114142436.1360-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 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 The amdgpu issue to also need signaled fences in the reservation objects should be fixed by now. Optimize the list by keeping only the not signaled yet fences around. v2: temporary put the signaled fences at the end of the new container v3: put the old fence at the end of the new container as well. Signed-off-by: Christian König Reviewed-by: Chris Wilson Tested-by: Chris Wilson --- drivers/dma-buf/reservation.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index b44d9d7db347..6d7a53dadf77 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -145,8 +145,7 @@ reservation_object_add_shared_replace(struct reservation_object *obj, struct reservation_object_list *fobj, struct dma_fence *fence) { - unsigned i; - struct dma_fence *old_fence = NULL; + unsigned i, j, k; dma_fence_get(fence); @@ -162,24 +161,21 @@ reservation_object_add_shared_replace(struct reservation_object *obj, * references from the old struct are carried over to * the new. */ - fobj->shared_count = old->shared_count; - - for (i = 0; i < old->shared_count; ++i) { + for (i = 0, j = 0, k = fobj->shared_max; i < old->shared_count; ++i) { struct dma_fence *check; check = rcu_dereference_protected(old->shared[i], reservation_object_held(obj)); - if (!old_fence && check->context == fence->context) { - old_fence = check; - RCU_INIT_POINTER(fobj->shared[i], fence); - } else - RCU_INIT_POINTER(fobj->shared[i], check); - } - if (!old_fence) { - RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence); - fobj->shared_count++; + if (check->context == fence->context || + dma_fence_is_signaled(check)) + RCU_INIT_POINTER(fobj->shared[--k], check); + else + RCU_INIT_POINTER(fobj->shared[j++], check); } + fobj->shared_count = j; + RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence); + fobj->shared_count++; done: preempt_disable(); @@ -192,10 +188,18 @@ reservation_object_add_shared_replace(struct reservation_object *obj, write_seqcount_end(&obj->seq); preempt_enable(); - if (old) - kfree_rcu(old, rcu); + if (!old) + return; - dma_fence_put(old_fence); + /* Drop the references to the signaled fences */ + for (i = k; i < fobj->shared_max; ++i) { + struct dma_fence *f; + + f = rcu_dereference_protected(fobj->shared[i], + reservation_object_held(obj)); + dma_fence_put(f); + } + kfree_rcu(old, rcu); } /**