From patchwork Wed Oct 19 17:48:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9384983 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 C1C5560487 for ; Wed, 19 Oct 2016 17:48:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B62A528C52 for ; Wed, 19 Oct 2016 17:48:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAE7728CAD; Wed, 19 Oct 2016 17:48:50 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 4B50128C52 for ; Wed, 19 Oct 2016 17:48:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E57256E995; Wed, 19 Oct 2016 17:48:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-vk0-f65.google.com (mail-vk0-f65.google.com [209.85.213.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9376F6E990 for ; Wed, 19 Oct 2016 17:48:41 +0000 (UTC) Received: by mail-vk0-f65.google.com with SMTP id b186so1472509vkb.3 for ; Wed, 19 Oct 2016 10:48:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YArirB6JLaMAZQJcwUDEXXwwHPO+ig0C1wW8tlgbdWo=; b=hwuF1InJ1Mc3xgd9SrNVUD9taOEH1BiMro2u9ANGTM1NAx4BTooAQpLYWec1pb0oit syuM3RSdB7O0rANzHER1zb4tJxGd40wDAyfD/YGAogJdb+attcHo5OubCirfxeUTKQsd KuwS8tFJ8vgCTlL7yc1ytQRf9JIJiUHYOT6AECtux6RiRdwH5UhWU3drRMEbgGf4EfGo 0nthQuPjPZqOw5LLnQqZrpPgHVrIroefGO3K2FZu6sq8kIAyxl9NqV8343mZ0t0PW2X5 LcYgXkiejeEhAEeW0HILhahGkQieySb5Z8G3pnZ3eNtgTV54GqEjx4lnYc0+Pt6teN98 oVhQ== X-Gm-Message-State: AA6/9RnyXmiEhe2La3OHOj4ojAzDoWnhAXTNeJQfLym0J8fb31X3yAQAmqaTocECyH66Pg== X-Received: by 10.31.160.141 with SMTP id j135mr6184393vke.18.1476899320325; Wed, 19 Oct 2016 10:48:40 -0700 (PDT) Received: from jade.localdomain ([187.64.228.41]) by smtp.gmail.com with ESMTPSA id y72sm15917302vky.9.2016.10.19.10.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 10:48:39 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] dma-buf/fence-array: hold fences reference when creating an array Date: Wed, 19 Oct 2016 15:48:33 -0200 Message-Id: <1476899313-22241-2-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1476899313-22241-1-git-send-email-gustavo@padovan.org> References: <1476899313-22241-1-git-send-email-gustavo@padovan.org> Cc: Gustavo Padovan 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 From: Gustavo Padovan When creating fence arrays we were not holding references to the fences in the array, however when destroy the array we were putting away a reference to these fences. This patch hold the ref for all fences in the array when creating the array. It then removes the code that was holding the fences on both amdgpu_vm and sync_file. For sync_file, specially, we worked on small referencing refactor for sync_file_merge(). Signed-off-by: Gustavo Padovan --- drivers/dma-buf/fence-array.c | 8 ++++---- drivers/dma-buf/sync_file.c | 14 +++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 --- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/dma-buf/fence-array.c b/drivers/dma-buf/fence-array.c index f1989fc..598737f 100644 --- a/drivers/dma-buf/fence-array.c +++ b/drivers/dma-buf/fence-array.c @@ -112,10 +112,6 @@ EXPORT_SYMBOL(fence_array_ops); * Allocate a fence_array object and initialize the base fence with fence_init(). * In case of error it returns NULL. * - * The caller should allocate the fences array with num_fences size - * and fill it with the fences it wants to add to the object. Ownership of this - * array is taken and fence_put() is used on each fence on release. - * * If @signal_on_any is true the fence array signals if any fence in the array * signals, otherwise it signals when all fences in the array signal. */ @@ -125,6 +121,7 @@ struct fence_array *fence_array_create(int num_fences, struct fence **fences, { struct fence_array *array; size_t size = sizeof(*array); + int i; /* Allocate the callback structures behind the array. */ size += num_fences * sizeof(struct fence_array_cb); @@ -140,6 +137,9 @@ struct fence_array *fence_array_create(int num_fences, struct fence **fences, atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences); array->fences = fences; + for (i = 0; i < array->num_fences; ++i) + fence_get(array->fences[i]); + return array; } EXPORT_SYMBOL(fence_array_create); diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 235f8ac..678baaf 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -142,14 +142,8 @@ static int sync_file_set_fence(struct sync_file *sync_file, { struct fence_array *array; - /* - * The reference for the fences in the new sync_file and held - * in add_fence() during the merge procedure, so for num_fences == 1 - * we already own a new reference to the fence. For num_fence > 1 - * we own the reference of the fence_array creation. - */ if (num_fences == 1) { - sync_file->fence = fences[0]; + sync_file->fence = fence_get(fences[0]); kfree(fences); } else { array = fence_array_create(num_fences, fences, @@ -180,10 +174,8 @@ static void add_fence(struct fence **fences, int *i, struct fence *fence) { fences[*i] = fence; - if (!fence_is_signaled(fence)) { - fence_get(fence); + if (!fence_is_signaled(fence)) (*i)++; - } } /** @@ -255,7 +247,7 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a, add_fence(fences, &i, b_fences[i_b]); if (i == 0) - fences[i++] = fence_get(a_fences[0]); + fences[i++] = a_fences[0]; if (num_fences > i) { nfences = krealloc(fences, i * sizeof(*fences), diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index bc4b22c..4ee7988 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -228,9 +228,6 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, struct fence_array *array; unsigned j; - for (j = 0; j < i; ++j) - fence_get(fences[j]); - array = fence_array_create(i, fences, fence_context, seqno, true); if (!array) {