From patchwork Fri Jul 8 15:44:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9221241 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 A5CAA6089D for ; Fri, 8 Jul 2016 15:45:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97208288B8 for ; Fri, 8 Jul 2016 15:45:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A861288C6; Fri, 8 Jul 2016 15:45:16 +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 17416288B8 for ; Fri, 8 Jul 2016 15:45:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DF4776E963; Fri, 8 Jul 2016 15:45:01 +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 37D596E05B for ; Fri, 8 Jul 2016 15:45:00 +0000 (UTC) Received: by mail-yw0-f196.google.com with SMTP id l125so8961301ywb.1 for ; Fri, 08 Jul 2016 08:45:00 -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; bh=YkZd86+Xe7eq5+aPwwnexWeLp4IZiZV3lP3v4SDvGkY=; b=PYvR3wxXUb6jboC2m4H8dm3qfY3O098CQrnMAaarityEDZP/sy9ZHZZg2zcm8sQeAd qkCNgi3pfGXDTOGYLgNotuoqGOqv8ILRnTap/eyfgSUQGYG7oXRFhjcJOyDYxercdw+M Jrdf4qcRc2HAeKS+Hy+O19p53GJGr7y3ah5BNrduT97N23UGOxQneKBg4F1fzqeVVKy/ 0Nnsque36RSLUnmt73lt1X6X7zjdzmHcm+LYdJVZ0R19Ssz/KibbDI3vkbRuKOLLY3CX QruiWJZOw9PaUiA/vJwBhQd3odVZ/0GoVpXCopPQ/i6FJisikwrgQskiiJri0qwU6PHG fN7A== X-Gm-Message-State: ALyK8tL91R9unTp9V1pQnJno3jfBK5NB0pie6N0Og/FuPubbIW3RFfCaeirbsqJ5yZ2fOw== X-Received: by 10.129.55.193 with SMTP id e184mr4889051ywa.243.1467992698983; Fri, 08 Jul 2016 08:44:58 -0700 (PDT) Received: from jade.localdomain ([201.82.26.135]) by smtp.gmail.com with ESMTPSA id p198sm16114920ywg.12.2016.07.08.08.44.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Jul 2016 08:44:57 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH] dma-buf/sync_file: only enable fence signalling during wait Date: Fri, 8 Jul 2016 12:44:51 -0300 Message-Id: <1467992691-12442-1-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 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 Signed-off-by: Gustavo Padovan --- This patch applies on top of my latest sync_file changes to support fence_array: https://lkml.org/lkml/2016/7/4/534 drivers/dma-buf/sync_file.c | 23 ++++++++++++++--------- include/linux/sync_file.h | 2 ++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 61a687c..1db4a64 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,6 @@ 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); fence_put(sync_file->fence); kfree(sync_file); } @@ -306,13 +300,24 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait) poll_wait(file, &sync_file->wq, wait); + if (!sync_file->enabled) { + fence_add_callback(sync_file->fence, &sync_file->cb, + fence_check_cb_func); + sync_file->enabled = true; + } + status = fence_is_signaled(sync_file->fence); - if (status) - return POLLIN; + if (!status) + return 0; + + fence_remove_callback(sync_file->fence, &sync_file->cb); + sync_file->enabled = false; + 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..16cbafd 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; + bool enabled; struct fence *fence; struct fence_cb cb;