From patchwork Tue Jul 12 18:08:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9225897 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 204C660868 for ; Tue, 12 Jul 2016 18:09:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E686527F9E for ; Tue, 12 Jul 2016 18:09:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6C6426220; Tue, 12 Jul 2016 18:09:24 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B8122808C for ; Tue, 12 Jul 2016 18:09:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1648C6E5CD; Tue, 12 Jul 2016 18:09:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f195.google.com (mail-yw0-f195.google.com [209.85.161.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4845F6E5CC for ; Tue, 12 Jul 2016 18:09:19 +0000 (UTC) Received: by mail-yw0-f195.google.com with SMTP id i12so1499540ywa.0 for ; Tue, 12 Jul 2016 11:09:19 -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=SdBKMDeGsRtciFvx5kagf7P2J+WZSwupOapmedaxNTo=; b=JXQQFcxA1Gd1qdQlAbP/HwVuazkffUrJoVK3C5QSOFW7Xe4Y4WJXVa9tuJ6WX7PdZd fpltkGGrv/lifJ8qHSpdvbiBGpAxTOX1cZJpAavam36X5SXPsC8DscAjs2nwm60dcS2E R4dFIAiR+sFBuPhyypqGHN2sG+L5H6vI5NGNH+f6zuaZQ35uPb9EP0VfnmdFvAd51UER VIQ5Nhx01WzQ6IxLCAb3anBkFqBsBTXGg2S8s8SESmaHjvQBpbSTPYiCreTQIG9Lapb+ mXLnmLSx2kZf0bioMYqruX1LAwU8xf2cCzKNhwCLeshgnhPgJRONPRhuGbzc/ilM3OvM NyAg== X-Gm-Message-State: ALyK8tK4PXrrHHLKHHojlNZLZ9AE3AkQ3sFw6F+vqtmcqw08RZv0FA+VknQ/v9G102Y9Wg== X-Received: by 10.37.72.193 with SMTP id v184mr2513732yba.99.1468346958177; Tue, 12 Jul 2016 11:09:18 -0700 (PDT) Received: from jade.localdomain ([189.61.225.79]) by smtp.gmail.com with ESMTPSA id v68sm196062ywg.31.2016.07.12.11.09.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 11:09:17 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 5/5] dma-buf/sync_file: only enable fence signalling on poll() Date: Tue, 12 Jul 2016 15:08:45 -0300 Message-Id: <1468346925-12774-5-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468346925-12774-1-git-send-email-gustavo@padovan.org> References: <1468346925-12774-1-git-send-email-gustavo@padovan.org> Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , linux-kernel@vger.kernel.org, laurent.pinchart@ideasonboard.com, Gustavo Padovan , John Harrison , m.chehab@samsung.com 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 Signalling doesn't need to be enabled at sync_file creation, it is only required if userspace waiting the fence to signal through poll(). Thus we delay fence_add_callback() until poll is called. It only adds the callback the first time poll() is called. This avoid re-adding the same callback multiple times. v2: rebase and update to work with new fence support for sync_file v3: use atomic operation to set enabled and protect fence_add_callback() Signed-off-by: Gustavo Padovan --- drivers/dma-buf/sync_file.c | 22 +++++++++++++--------- include/linux/sync_file.h | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 61a687c..240ef22 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -86,8 +86,6 @@ struct sync_file *sync_file_create(struct fence *fence) fence->ops->get_timeline_name(fence), fence->context, fence->seqno); - fence_add_callback(fence, &sync_file->cb, fence_check_cb_func); - return sync_file; } EXPORT_SYMBOL(sync_file_create); @@ -269,9 +267,6 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a, goto err; } - fence_add_callback(sync_file->fence, &sync_file->cb, - fence_check_cb_func); - strlcpy(sync_file->name, name, sizeof(sync_file->name)); return sync_file; @@ -286,7 +281,8 @@ static void sync_file_free(struct kref *kref) struct sync_file *sync_file = container_of(kref, struct sync_file, kref); - fence_remove_callback(sync_file->fence, &sync_file->cb); + if (atomic_read(&sync_file->enabled)) + fence_remove_callback(sync_file->fence, &sync_file->cb); fence_put(sync_file->fence); kfree(sync_file); } @@ -306,13 +302,21 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait) poll_wait(file, &sync_file->wq, wait); + if (!atomic_xchg(&sync_file->enabled, 1)) { + if (fence_add_callback(sync_file->fence, &sync_file->cb, + fence_check_cb_func) < 0) + wake_up_all(&sync_file->wq); + } + status = fence_is_signaled(sync_file->fence); - if (status) - return POLLIN; + if (!status) + return 0; + if (status < 0) return POLLERR; - return 0; + + return POLLIN; } static long sync_file_ioctl_merge(struct sync_file *sync_file, diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h index f7de5a0..4ced13b 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -28,6 +28,7 @@ * @name: name of sync_file. Useful for debugging * @sync_file_list: membership in global file list * @wq: wait queue for fence signaling + * @enabled: wether fence signal is enabled or not * @fence: fence with the fences in the sync_file * @cb: fence callback information */ @@ -40,6 +41,7 @@ struct sync_file { #endif wait_queue_head_t wq; + atomic_t enabled; struct fence *fence; struct fence_cb cb;