From patchwork Wed Sep 21 11:36:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9343347 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 C8DB1607D0 for ; Wed, 21 Sep 2016 11:37:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9B712A55E for ; Wed, 21 Sep 2016 11:37:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE44B2A57F; Wed, 21 Sep 2016 11:37:18 +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 EFE232A55E for ; Wed, 21 Sep 2016 11:37:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2AFF46E813; Wed, 21 Sep 2016 11:37:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-f66.google.com (mail-lf0-f66.google.com [209.85.215.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1ED256E811 for ; Wed, 21 Sep 2016 11:36:11 +0000 (UTC) Received: by mail-lf0-f66.google.com with SMTP id s29so2270132lfg.3 for ; Wed, 21 Sep 2016 04:36:11 -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=d0g6AypoxxxYtk0u8muDjgEwsCihTMhcSNZm0O+Sk0c=; b=SCnK048zefysrnPTdZJq+TzkBvrEgFkiWkLfZ+9dzAnUy+cGuRon4LbvEZuGWXVfJq RXiyLKovyDCXWIh2rF6WAE4FKN+5Wtpph2JbyD6qCUxOD/BdXykKZmTLA/Yl+H156ZhZ DEoumUkc1SXEut5KupybxazRexewNN8OfA3qCdMQo33z5kfL9wLEayaNxeyPHXQmEpNX cQyutclFHUXkD/ButZ/Da+a4WL5LTdENVOH2zHfgETKGQfJ6JPMnkHG3MDg5X0UQgPFX 9IJm01zDFhFhqUa4kXLYAJN014AEqVKMUMEV1Xlst2VwytF53PokTqIQGMlRXaxeaVOl GMWw== X-Gm-Message-State: AE9vXwPcsRXZX0v4CXBwKbLdBFNec4OREgFDRFZ/1m+TzwfFqJgJr70UskMGR2PcNy6FBg== X-Received: by 10.46.71.17 with SMTP id u17mr14825738lja.49.1474457769326; Wed, 21 Sep 2016 04:36:09 -0700 (PDT) Received: from jade.haaga-helia.fi (pub-nat.haaga-helia.fi. [193.166.13.253]) by smtp.gmail.com with ESMTPSA id f64sm6746836lji.29.2016.09.21.04.36.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Sep 2016 04:36:08 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH] dma-buf/fence-array: get signaled state when signaling is disabled Date: Wed, 21 Sep 2016 14:36:07 +0300 Message-Id: <1474457767-26195-1-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 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 If the fences in the fence_array signal on the fence_array does not have signalling enabled num_pending will not be updated accordingly. So when signaling is disabled check the signal of every fence with fence_is_signaled() and then compare with num_pending to learn if the fence_array was signalled or not. If we want to keep the poll_does_not_wait optimization I think we need something like this. It keeps the same behaviour if signalling is enabled but tries to calculated the state otherwise. Signed-off-by: Gustavo Padovan Reviewed-by: Chris Wilson Reviewed-by: Chunming Zhou --- drivers/dma-buf/fence-array.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/fence-array.c b/drivers/dma-buf/fence-array.c index f1989fc..1eec271 100644 --- a/drivers/dma-buf/fence-array.c +++ b/drivers/dma-buf/fence-array.c @@ -75,8 +75,25 @@ static bool fence_array_enable_signaling(struct fence *fence) static bool fence_array_signaled(struct fence *fence) { struct fence_array *array = to_fence_array(fence); + int i, num_pending; + + num_pending = atomic_read(&array->num_pending); + + /* + * Before signaling is enabled, num_pending is static (set during array + * construction as a count of all fences or set to 1 if signal_on_any + * flag is passed. To ensure forward progress, i.e. a while + * (!fence_is_signaled()) ; busy-loop eventually proceeds, we need to + * check the current status of our fences. + */ + if (!test_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) { + for (i = 0 ; i < array->num_fences; ++i) { + if (fence_is_signaled(array->fences[i])) + num_pending--; + } + } - return atomic_read(&array->num_pending) <= 0; + return num_pending <= 0; } static void fence_array_release(struct fence *fence)