From patchwork Fri Aug 11 22:39:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 9896699 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 EEA6D60351 for ; Fri, 11 Aug 2017 22:40:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E081728CAC for ; Fri, 11 Aug 2017 22:40:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D281E28CFE; Fri, 11 Aug 2017 22:40:01 +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_SIGNED, 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 4ECD828CAC for ; Fri, 11 Aug 2017 22:40:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 079AE6E76B; Fri, 11 Aug 2017 22:39:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0CE016E766 for ; Fri, 11 Aug 2017 22:39:51 +0000 (UTC) Received: by mail-pg0-x244.google.com with SMTP id u185so4058446pgb.0 for ; Fri, 11 Aug 2017 15:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j73Pkm9cLANoodBspfW5JSFy1IOiHmutWQnshfyrCA4=; b=maqiAxeIlaX5QjhphT5JR0QwWcLJzhsCr5cRvjq2E8eidfibNAfcOvgzSrAUQlsMEs Wo3iZF9jdcNSfGbe7YnFjDy9d39DGkcR4haHxivZiT24pmmQmugSQCoFC6mQqkS463/4 BF0+9Vhr6m1vXj6OzOpKJn4w4nqhC2EsOwJpvjX8KreUKwyzFKVtTuA8LzyhLGSoXMsr CATKM+bcWVI+PuOtkz5uu0koxkQvmW2JI6A3f2rVwfaalGWXke+C4mA7wGibrw5i7aWW BZwNxlZFaSwAFmKII9ueJ1y+d8Y3Jc8RmBCNJRaeR9GOgl84mj9umMWHqgIpQ+JNUYQ4 wNOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j73Pkm9cLANoodBspfW5JSFy1IOiHmutWQnshfyrCA4=; b=Y2XdDbWJmqVKFxYy93vnqWv0uU9oOrJBIeRxtBo5LIINAnw6t9vKWGnzt8nCHpt7iu feq967W19w/5zXsmPSKu/LVEXwZ9+/0ppSBiGacxviV6XbizChVYhnRnJSNchdZ0pNjD pUIXksdWxJBI/xei62aPGlxf/ovtxbMQixMvg6WVkmEntggIwRBu61zr8mdNLO9v+2l5 zm7Cp8lu0hu+qlz5aszPvngbcQoI65jujWDdPMKv7FX+7F874ldsWUNA4bHt6So3GQL2 Yhlwh1Zh0PcLxakzpT1+iH/PqXz91g/l8j6vHG0nWNUlpkbzadWVG/fX8JPisOeUIWX8 zoeA== X-Gm-Message-State: AHYfb5gRYJKGRqS6iEyU9sdW+zs5p2ZauVFo2k/PuBAtnTEyAcIzZJjh rgvvT63A5i4XXHze55yjBA== X-Received: by 10.84.217.70 with SMTP id e6mr19896073plj.414.1502491191179; Fri, 11 Aug 2017 15:39:51 -0700 (PDT) Received: from omlet.jf.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by smtp.gmail.com with ESMTPSA id p77sm3244484pfi.153.2017.08.11.15.39.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2017 15:39:50 -0700 (PDT) From: Jason Ekstrand X-Google-Original-From: Jason Ekstrand To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/9] dma-buf/dma-fence: Allow wait_any_timeout without default_wait (v2) Date: Fri, 11 Aug 2017 15:39:30 -0700 Message-Id: <1502491174-10913-6-git-send-email-jason.ekstrand@intel.com> X-Mailer: git-send-email 2.5.0.400.gff86faf In-Reply-To: <1502491174-10913-1-git-send-email-jason.ekstrand@intel.com> References: <1502232369-19753-1-git-send-email-jason.ekstrand@intel.com> <1502491174-10913-1-git-send-email-jason.ekstrand@intel.com> MIME-Version: 1.0 Cc: Jason Ekstrand , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jason Ekstrand 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 dma_fence_wait_any_timeout only relies on two things to work correctly: 1) The callback list to get called upon fence signal 2) The SIGNALED flag to be set upon fence signal The first if these is part of the core dma-fence API. The second is only mostly part of the core dma-fence API with the one issue that the flag may not be set and dma_fence_is_signaled may never return true if fence->ops->enable_signaling() has not been called. It's easy enough to work around that by always using dma_fence_is_signaled instead of manually checking the bit and falling through to a zero-timeout wait if none of the fences report that they are signaled. v2: - Use dma_fence_is_signaled in test_signaled_any - Fall through to a zero-timeout wait Cc: Christian König Signed-off-by: Jason Ekstrand --- drivers/dma-buf/dma-fence.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 9a30279..0cac367 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -437,8 +437,7 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count, int i; for (i = 0; i < count; ++i) { - struct dma_fence *fence = fences[i]; - if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { + if (dma_fence_is_signaled(fences[i])) { if (idx) *idx = i; return true; @@ -484,7 +483,13 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, return 1; } - return 0; + /* There's a very annoying laxness in the dma_fence API + * here, in that backends are not required to automatically + * report when a fence is signaled prior to + * fence->ops->enable_signaling() being called. So here if + * we fail to match signaled_count, we need to fallthough + * and try a 0 timeout wait! + */ } cb = kcalloc(count, sizeof(struct default_wait_cb), GFP_KERNEL); @@ -496,11 +501,6 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, for (i = 0; i < count; ++i) { struct dma_fence *fence = fences[i]; - if (fence->ops->wait != dma_fence_default_wait) { - ret = -EINVAL; - goto fence_rm_cb; - } - cb[i].task = current; if (dma_fence_add_callback(fence, &cb[i].base, dma_fence_default_wait_cb)) { @@ -511,7 +511,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, } } - while (ret > 0) { + do { if (intr) set_current_state(TASK_INTERRUPTIBLE); else @@ -524,7 +524,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, if (ret > 0 && intr && signal_pending(current)) ret = -ERESTARTSYS; - } + } while (ret > 0); __set_current_state(TASK_RUNNING);