From patchwork Tue Oct 31 08:43:05 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: 10033737 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 3FFF2602B9 for ; Tue, 31 Oct 2017 08:43:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EA9F289DE for ; Tue, 31 Oct 2017 08:43:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 232B7289E0; Tue, 31 Oct 2017 08:43:14 +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 964D7289E2 for ; Tue, 31 Oct 2017 08:43:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7AC2A6E511; Tue, 31 Oct 2017 08:43:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 22B806E511; Tue, 31 Oct 2017 08:43:11 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id b189so20630441wmd.4; Tue, 31 Oct 2017 01:43:10 -0700 (PDT) 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=7eXEVX8W8vB2OnQKwZ03tMv3ROC7BrbiWJYIo3auYRY=; b=ULjS+N0cPC5lRBtmAxA5Hq799tYXmhahUj2/Qc0m1eGUoJf1Of/OaTTPLetMcmJij5 ZuC0ZnNwNSFFrDMiNfFY606owEuxR4BYroSWPBICvMJrVz57UZnHm/NFi7qvbc+8uXZ1 7bq2uGP+QFRMJYxrYMJ8Hjz5yxszCbOru8UkjhsTv8JmyA30CahIEps2ail7ksZmkDJ1 XHbCG0Fc9rPtKAJb3BE5rWSBkTht+wFVvPGJ7N4i1GqZMCUGiPGuTPMMuQO3TECygX1l ppunPiUdWPnxG6P3iFp8J5TjCVuyhpYM7AQjwagZzfCpV4gh/kmbopnzNQkHAWf7V/9C Mfxg== 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=7eXEVX8W8vB2OnQKwZ03tMv3ROC7BrbiWJYIo3auYRY=; b=ISBVZRryvO7nupTuPSddcOH0yTQszvkcdSLg2ATDnjAp2Do1Tov3PN9U6jrNTTFhIl GBcJLFXOdaeE3rsZXtuYykYrmhijYIiMij9/YJgeoYIvz9vjnzxNdKWNKoGWbUTkcmfL kpuM/nmdchS+PGMcvEAKNSMDRvMza4H2z3BV7BiyN9tqpXqIwbub7mGNmfe0XK7ui0e3 V/hrytLYyi4qoFx5KKU4cK9lRbGlQKedOv4w8W67vNN5JVrK1ZyqTq2IqvTRfJ1VKVGi tkrL8jso7sfCbP3mP8utDBUumd0ItUNx09iz1WVxxDLD0IyX6TEeU8TI8fOS/I46qHbF gLuQ== X-Gm-Message-State: AMCzsaWRMv9uh4nmxRa4XZL+m1DihRT1hzjWvjzWSsrKr8tMvuAMimTU RouesHlyve7UZEQejG8g9QvQLA== X-Google-Smtp-Source: ABhQp+QAlOqsrr/dSy+tO/n5991DCRJrpczhbvepDRJ3ojrHwOmIQTYQ5v8JyNncNhTV7P3NCCu0ZQ== X-Received: by 10.28.73.9 with SMTP id w9mr1139726wma.3.1509439389478; Tue, 31 Oct 2017 01:43:09 -0700 (PDT) Received: from localhost.localdomain ([2a02:908:1251:7981:c0f4:45e6:8be5:ed97]) by smtp.gmail.com with ESMTPSA id c17sm1865109wrg.26.2017.10.31.01.43.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Oct 2017 01:43:09 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, sumit.semwal@linaro.org, christian.koenig@amd.com Subject: [PATCH 1/2] dma-buf: keep only not signaled fence in reservation_object_add_shared_replace v2 Date: Tue, 31 Oct 2017 09:43:05 +0100 Message-Id: <20171031084306.1986-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 Signed-off-by: Christian König --- drivers/dma-buf/reservation.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index b44d9d7db347..6fc794576997 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -145,8 +145,8 @@ 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,9 +162,7 @@ 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], @@ -172,10 +170,18 @@ reservation_object_add_shared_replace(struct reservation_object *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); + RCU_INIT_POINTER(fobj->shared[j++], fence); + } else if (!dma_fence_is_signaled(check)) { + RCU_INIT_POINTER(fobj->shared[j++], check); + } else { + /* + * Temporary save the signaled fences at the end of the + * new container + */ + RCU_INIT_POINTER(fobj->shared[--k], check); + } } + fobj->shared_count = j; if (!old_fence) { RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence); fobj->shared_count++; @@ -192,10 +198,20 @@ reservation_object_add_shared_replace(struct reservation_object *obj, write_seqcount_end(&obj->seq); preempt_enable(); - if (old) - kfree_rcu(old, rcu); - dma_fence_put(old_fence); + + if (!old) + return; + + /* 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); } /**