From patchwork Tue Oct 31 08:41:36 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: 10033733 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 E1E04602B9 for ; Tue, 31 Oct 2017 08:41:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CED5A289D7 for ; Tue, 31 Oct 2017 08:41:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1F11289DA; Tue, 31 Oct 2017 08:41:46 +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 C298E289D7 for ; Tue, 31 Oct 2017 08:41:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8433F6E1A1; Tue, 31 Oct 2017 08:41:43 +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 0966E6E1A1; Tue, 31 Oct 2017 08:41:41 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id z3so21344365wme.5; Tue, 31 Oct 2017 01:41:41 -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=9uiu4pF2rIjdNz3EuIRBSY+NeU7ktuIXt3q9kWO4/Po=; b=IH9l3T2hz80PoPHcy5Dtxo1ZkJ3Q4IAcdfsNAJ4fgmGi6VYbaXajFdrS6q0wbgTUvn BdG8R7m9we4pc3sKEkjVhwGtirkESoC4LS3rqaE245zj38N7UfVuM48RyvmE59mzuUvM PeomjgBvo5pYoWy76Rv8RMOO8QCFnbdcpmGitFtB3U5oMN6eBHm5H4N399RV+1VFgmlE yQ7OTytfuCGTAJYbVqHlUTZbNigSMjZYSYhJvHDbOTyj0XKhofgaebu7vZmbef/+xbhC rwYMDqVzYz1FgwUAIvW61HTP/aarzUVnHXrXPPgK9Q/vxNVSwLBJGkgJMrElu9HvSNql kogQ== 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=9uiu4pF2rIjdNz3EuIRBSY+NeU7ktuIXt3q9kWO4/Po=; b=X2RhGln0w44wVECBMuuX/zz0QqiqpFHQu+qqbI7crAkBrB1xe2Kg5Xc2vzxSZvuUoY 9O8id3bwQCZ9Ba6vyxVI/zFzS7TKwZAs16Y8pd7fJUm/TLYFd5kIxvpLwHxvlAazOg82 FoeDUE4fnDBZvlZ5ZLgEgXQ0u10qoqqaRANnCR0n08u5k8c9mAfsXsZIsuvzu6Z8ALzB Fu9oFqhjk02l/ChhYYcPQmIwKtXXTn1QJ1PiEHeKlBjd/II6efY6KR3Kn5nGAlSunVAy /2kD2VnjZFPO5Ed+j8FbMSGSr+48L7DF5fgGdZ+hDPq4c/Hd/slYNOXoxkiI3Kf7u/y0 Vgzg== X-Gm-Message-State: AMCzsaVlf1W1qaik4/vpk0+8aXHkRZmRh9Q/bquEl4DhaeT9vQpwnMbs B3eOxh4ACmI4os2VY4wduj/aBw== X-Google-Smtp-Source: ABhQp+Si3JQMiKK7cho9FRv2J+iDwG93JWJyny8rR/amKo/JAJ1R9SqfidGmYI9F3ux7eETDNafUxg== X-Received: by 10.28.63.134 with SMTP id m128mr1236110wma.137.1509439300333; Tue, 31 Oct 2017 01:41:40 -0700 (PDT) Received: from localhost.localdomain ([2a02:908:1251:7981:c0f4:45e6:8be5:ed97]) by smtp.gmail.com with ESMTPSA id v35sm2690908wrc.13.2017.10.31.01.41.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Oct 2017 01:41:39 -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:41:36 +0100 Message-Id: <20171031084137.1925-1-deathsimple@vodafone.de> 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 From: Christian König 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); } /**