From patchwork Fri Aug 5 13:39:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9265413 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 BE28F60760 for ; Fri, 5 Aug 2016 13:40:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0A9428440 for ; Fri, 5 Aug 2016 13:40:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4DE128444; Fri, 5 Aug 2016 13:40:22 +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]) (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 6A94C28443 for ; Fri, 5 Aug 2016 13:40:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B6EA36EBAD; Fri, 5 Aug 2016 13:40:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f196.google.com (mail-yw0-f196.google.com [209.85.161.196]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9492E6EBAD for ; Fri, 5 Aug 2016 13:40:13 +0000 (UTC) Received: by mail-yw0-f196.google.com with SMTP id u134so21599293ywg.3 for ; Fri, 05 Aug 2016 06:40:13 -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=NSF6Kyqqaz2zoJswrLmXxIxbXM4LSKNvqV6cBZf9zEM=; b=HjzFYnSiR+ggeVn1Tueoa5+SeqhhiPOfqOeJ3Gq3ggKDy1C5l0bhVcN4hMzVP70Zx5 YOAoyXpyrcld6V85XYb3shsaChhh7fz0yzYtBDrDV1xVBLjOE79zUgb3hKuqwhWrOkmZ EywncbLA8npOAfZOpLHmJygB9dS8OTpdI7wcp9fzixdo4ArD0J3Uk1D+txxMBZf/hu42 HxGA9k7Gp/64Qw3kSM5fNVOZETAtA6+G5nKbOVkt8YqC+9odEZsrpf0dSgCf7Yi+uPHr 5rRWRawzDBRl8SJtHUwtHq86ppFhisJI2pQ8Z8MNia1FaCpb/9lX9z2YRB20+lBEm5Wz GmDg== X-Gm-Message-State: AEkooutaG4qRU0FwsYHIQPFeNKJpePXE7TXAE5PO5DoUBdOokY3zqg6e6qfrdgFhcwpciw== X-Received: by 10.13.214.146 with SMTP id y140mr58128845ywd.0.1470404412824; Fri, 05 Aug 2016 06:40:12 -0700 (PDT) Received: from jade.localdomain ([201.82.189.183]) by smtp.gmail.com with ESMTPSA id a11sm7801449ywa.37.2016.08.05.06.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Aug 2016 06:40:12 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH v6 5/5] dma-buf/sync_file: only enable fence signalling on poll() Date: Fri, 5 Aug 2016 10:39:38 -0300 Message-Id: <1470404378-27961-5-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1470404378-27961-1-git-send-email-gustavo@padovan.org> References: <1470404378-27961-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() v4: use user bit from fence flags (comment from Chris Wilson) v5: use ternary if on poll return (comment from Chris Wilson) Signed-off-by: Gustavo Padovan Reviewed-by: Chris Wilson --- drivers/dma-buf/sync_file.c | 20 ++++++++------------ include/linux/sync_file.h | 2 ++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 2873760..82b5334 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); @@ -274,9 +272,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; @@ -291,7 +286,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 (test_bit(POLL_ENABLED, &sync_file->fence->flags)) + fence_remove_callback(sync_file->fence, &sync_file->cb); fence_put(sync_file->fence); kfree(sync_file); } @@ -311,13 +307,13 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait) poll_wait(file, &sync_file->wq, wait); - status = fence_is_signaled(sync_file->fence); + if (!test_and_set_bit(POLL_ENABLED, &sync_file->fence->flags)) { + if (fence_add_callback(sync_file->fence, &sync_file->cb, + fence_check_cb_func) < 0) + wake_up_all(&sync_file->wq); + } - if (status) - return POLLIN; - if (status < 0) - return POLLERR; - return 0; + return fence_is_signaled(sync_file->fence) ? POLLIN : 0; } 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..aa17ccf 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -45,6 +45,8 @@ struct sync_file { struct fence_cb cb; }; +#define POLL_ENABLED FENCE_FLAG_USER_BITS + struct sync_file *sync_file_create(struct fence *fence); struct fence *sync_file_get_fence(int fd);