From patchwork Mon Oct 30 14:59:03 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: 10032727 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 31E48603B4 for ; Mon, 30 Oct 2017 14:59:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23E47284D2 for ; Mon, 30 Oct 2017 14:59:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 189F8288B1; Mon, 30 Oct 2017 14:59:12 +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 81BC4284D2 for ; Mon, 30 Oct 2017 14:59:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B77926E3A3; Mon, 30 Oct 2017 14:59:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 538DA6E3A3; Mon, 30 Oct 2017 14:59:09 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id y9so12905099wrb.2; Mon, 30 Oct 2017 07:59:09 -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=US8rC9uewqBSQG86SdFOQ8fPrgU1c30CAgFFXvP75yOxQdOFz8h0dUqB57EI75fHz5 O3FaBD7q3GTXqad5CZtdaS9+FiCp5SBSsfn0F5EYcjRe5HhBKh7agGn8WZLETQ2UHa5s mH/CStiawYrMQ9bMMcwud88XVVmwiYzvtXAu4DO0JfBW+M/OGpLcDMFITIw2Sb6PjfJb kgLuJarbQ+JHLlgqg853V6o9IEApwQD6Fr1pCEcQ1QtMQtzKM4m2BytFzMQkFLOPg9vT ef/Vh+vVsJ0iOq6lzOYcW9/CWUoskBcSe8UowXd/nUrXmL+roxXOVod3avuir8h/tO/V 6A6g== 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=pKSat05Hhd854aD+Y1lk9APl8SVL4Rtggi/O7n7TSDdlrm2YAgJdLiGLW+tP9vUe58 PFa/1F8tg7IosTBON1rinK/apjNetuO8CcZmKSUHWBJcdqxLINNMtitCfU0o9QC8DoY9 /erGcZxbdBkCJjmA6gogWbmH3FlO3EZSVxstj6GRNfhLzyq+SN6GHtKzAkygpyEUW7s6 TfVmoBWoHWkll88xX/Rg/OlAD8mSMN707yHXlXakZSLvccFcPHLwsYH5BQ/tMO3tPBc/ WcWZEYFwG7SzIy7JpYJjU+tB4X9CvoLsypFv1o/1Y9TFA5URhj/xz2lGDpGBTaz9LLIm bpwA== X-Gm-Message-State: AMCzsaVxGmHHvy3DJJAPlFKTGkO+98PNTFYis18I5JZrRtmF5iFy3J9I //ZwaIQOwkQ4W947fNEdIa5r6Q== X-Google-Smtp-Source: ABhQp+QMZIXpNZqapJUXv54ibxiCpF7gKSYMAIVQrNNIQhcrSiQc9eCNXTadlghgDG11xLuBkwEw+A== X-Received: by 10.223.135.90 with SMTP id 26mr1083325wrz.114.1509375547600; Mon, 30 Oct 2017 07:59:07 -0700 (PDT) Received: from localhost.localdomain ([2a02:908:1251:7981:7dea:e6ff:9c90:f1e3]) by smtp.gmail.com with ESMTPSA id o20sm14670147wro.6.2017.10.30.07.59.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Oct 2017 07:59:07 -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 Subject: [PATCH 1/2] dma-buf: keep only not signaled fence in reservation_object_add_shared_replace v2 Date: Mon, 30 Oct 2017 15:59:03 +0100 Message-Id: <20171030145904.18584-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); } /**