From patchwork Mon Sep 12 18:59:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Deucher X-Patchwork-Id: 9327605 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 352786077F for ; Mon, 12 Sep 2016 18:59:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FEC928E8F for ; Mon, 12 Sep 2016 18:59:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1352A28E91; Mon, 12 Sep 2016 18:59: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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 07D3228E8F for ; Mon, 12 Sep 2016 18:59:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DF3C56E561; Mon, 12 Sep 2016 18:59:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-x242.google.com (mail-qk0-x242.google.com [IPv6:2607:f8b0:400d:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C10A6E55F; Mon, 12 Sep 2016 18:59:15 +0000 (UTC) Received: by mail-qk0-x242.google.com with SMTP id n66so12435296qkf.0; Mon, 12 Sep 2016 11:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=uQ5aZ0FYXYC30VgK0+Umtew1qwgnbQLum1HiK+OoUdc=; b=I9vCatq7wlvglDLC/kHuX/SthxrxAuSwy4OV5J8+t3UDiJ7Ht2SIfPu2PTTAA/M+h4 uud7WbYjvgPWlMBQjFj8u8+d8is1QBDccnsRw4u2uDPAYIpOlRC+5P8IVbGqbg3Qm5Ze lc2X+Ezx0S58acW1fvnTS/47aVpPAnxl1tz2sHN3bA41o1wtPUeemRjbtp0AP/AcL9ou 4hCW12KFpQneFlG7o/G46zPsntpL/7AKy9XzU3c6JFUvmMABfqzYkf5l5PIKgniRb/LJ h56WMEBXKVus60/ZDzCLGrD4/Fadnuw3qUUNO+p4K9xn6hh6HNTAuUlBSXSB4TsACP1S 7wyw== 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=uQ5aZ0FYXYC30VgK0+Umtew1qwgnbQLum1HiK+OoUdc=; b=XZtbBh/m+BIqMCzaUKb3B9vnYpbJKq4gC3vKRB1vfICOaV/Qe6IDrJqlKNTorCDVLf C8HwJ9zmE+kjZLGSLsh7qEvP/Tgg7P452v+ESYLFA2HgLqqbu3qxXfMN5CIyyF1wRsld UDKQJNFC8wPQjXvFlw2hhSeFKBIkCM/MaPD4JplE5FPL/uGrbI4KqEj7ogzkcn6753Ez 0sS7FoVCNIPn0ox1MRqL9lgg5BpKA/2QXLCNU0OqFaoGSPlmyRIXw5gQM0LoTHKHSVfH +GJ8ZxUjyc+eCVCVFdaNkczf7yIJoG1ontHnhqW80dlW2cdswe83RVwy/bqtjhxli3sH Gidg== X-Gm-Message-State: AE9vXwMUOIPtMqsCvC8kcwq1ykZK7I2qPrKlwr/4GflMp52/5eJb9zrUUVOLppdulGZCjQ== X-Received: by 10.55.204.28 with SMTP id r28mr20990919qki.219.1473706754810; Mon, 12 Sep 2016 11:59:14 -0700 (PDT) Received: from cm.localdomain (va-67-76-166-195.sta.embarqhsd.net. [67.76.166.195]) by smtp.gmail.com with ESMTPSA id o65sm11261083qkc.48.2016.09.12.11.59.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Sep 2016 11:59:14 -0700 (PDT) From: Alex Deucher X-Google-Original-From: Alex Deucher To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, sumit.semwal@linaro.org Subject: [PATCH 1/2] dma-buf: return index of the first signaled fence Date: Mon, 12 Sep 2016 14:59:06 -0400 Message-Id: <1473706747-31065-1-git-send-email-alexander.deucher@amd.com> X-Mailer: git-send-email 2.5.5 Cc: Alex Deucher , "monk.liu" 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: "monk.liu" Return the index of the first signaled fence. This information is useful in some APIs like Vulkan. Signed-off-by: monk.liu Signed-off-by: Alex Deucher --- drivers/dma-buf/fence.c | 19 ++++++++++++++----- include/linux/fence.h | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c index 4d51f9e..90b7d27 100644 --- a/drivers/dma-buf/fence.c +++ b/drivers/dma-buf/fence.c @@ -398,14 +398,17 @@ out: EXPORT_SYMBOL(fence_default_wait); static bool -fence_test_signaled_any(struct fence **fences, uint32_t count) +fence_test_signaled_any(struct fence **fences, uint32_t count, uint32_t *idx) { int i; for (i = 0; i < count; ++i) { struct fence *fence = fences[i]; - if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) + if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { + if (idx) + *idx = i; return true; + } } return false; } @@ -417,6 +420,7 @@ fence_test_signaled_any(struct fence **fences, uint32_t count) * @count: [in] number of fences to wait on * @intr: [in] if true, do an interruptible wait * @timeout: [in] timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT + * @idx: [out] the first signaled fence index, meaninful only on Returns positive * * Returns -EINVAL on custom fence wait implementation, -ERESTARTSYS if * interrupted, 0 if the wait timed out, or the remaining timeout in jiffies @@ -428,7 +432,7 @@ fence_test_signaled_any(struct fence **fences, uint32_t count) */ signed long fence_wait_any_timeout(struct fence **fences, uint32_t count, - bool intr, signed long timeout) + bool intr, signed long timeout, uint32_t *idx) { struct default_wait_cb *cb; signed long ret = timeout; @@ -439,8 +443,11 @@ fence_wait_any_timeout(struct fence **fences, uint32_t count, if (timeout == 0) { for (i = 0; i < count; ++i) - if (fence_is_signaled(fences[i])) + if (fence_is_signaled(fences[i])) { + if (idx) + *idx = i; return 1; + } return 0; } @@ -463,6 +470,8 @@ fence_wait_any_timeout(struct fence **fences, uint32_t count, if (fence_add_callback(fence, &cb[i].base, fence_default_wait_cb)) { /* This fence is already signaled */ + if (idx) + *idx = i; goto fence_rm_cb; } } @@ -473,7 +482,7 @@ fence_wait_any_timeout(struct fence **fences, uint32_t count, else set_current_state(TASK_UNINTERRUPTIBLE); - if (fence_test_signaled_any(fences, count)) + if (fence_test_signaled_any(fences, count, idx)) break; ret = schedule_timeout(ret); diff --git a/include/linux/fence.h b/include/linux/fence.h index 8cc719a..2d21113 100644 --- a/include/linux/fence.h +++ b/include/linux/fence.h @@ -325,7 +325,7 @@ static inline struct fence *fence_later(struct fence *f1, struct fence *f2) signed long fence_wait_timeout(struct fence *, bool intr, signed long timeout); signed long fence_wait_any_timeout(struct fence **fences, uint32_t count, - bool intr, signed long timeout); + bool intr, signed long timeout, uint32_t *idx); /** * fence_wait - sleep until the fence gets signaled