From patchwork Sat Feb 18 21:15:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145706 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDF56C64ED9 for ; Sat, 18 Feb 2023 21:15:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbjBRVPw (ORCPT ); Sat, 18 Feb 2023 16:15:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbjBRVPv (ORCPT ); Sat, 18 Feb 2023 16:15:51 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 446CE12070; Sat, 18 Feb 2023 13:15:50 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id o9so1553648plk.12; Sat, 18 Feb 2023 13:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+1OrC8Qn2ZJKlzQr5VPD0V+OBV4kyv6Pm4LEmbHRWBY=; b=ZkdbOU+WUTXbXuy+edMoJBjcaH2pmGSWOPbAWIOHb+1uil8B7cZRAXaxpt2UzBVglS K9D42mFhZUJcG+CpOfomRVhFsdfvtao4eWTFV3/+UwBd/316jEIHmEWPTlOa0RssKCj1 q6+JqVhrNYTe37sHAGTzgDmWHe7IAo585bi5HTzHmLnbqpizohUqvGrmEN6//nmpjn+I tFz7J4QCJ2M+hzuOgu5IwJPfJ6OAxIQDVrn5ObNQd/YyMKOG3wF0TXHse6PkE5PFTOo/ UCKE9AF4BrQl4QisNCpjzkr8PAcEaMAj8rLMQPzDN2Hyci+wm2KiAB2Nef7AnBgp3v2u IzjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+1OrC8Qn2ZJKlzQr5VPD0V+OBV4kyv6Pm4LEmbHRWBY=; b=v5OOFhvC1QsgleSCdN2DzsZ+HsCbE47C65DnedPT47rKZNk/rSmi/R2+g5r4t8JvFz QmtYAWtdGuNSJifXtKjPxAeYAGZ8IGnUvWbwgDhncOexoYRficVvvis+VbT6qsMK8zoX 4tQRApVXTxv9pdFAfHCUwHDfMcA9W6YiK2pPouZtuUSF1p35QQPUcE7pMZYvCWN11pxG T29P9FZrQJB9wQ27Vt9V9LGVUuErVhYSL0wu+Ryr5Qb8Lo4GK74dOSN5/oPbzaOuhevJ gLlsPbYiUNu01PiZXd+moLXspJ5quNZS2gfBfwdA5FRmAfjUI53oEBITtcvkKslVNM33 4hOQ== X-Gm-Message-State: AO0yUKW08EcbHZx104u2K2nAoSu15qoL8tqCgOHK8MLou1jjRBjcrBn7 ERWFuMho1xuJptUQ+tCoaYE= X-Google-Smtp-Source: AK7set/oYuhKvXuo3/h/Qa5avadZ9tVCfGZN140IDlH5L063jOweVl04kKTFFu939dYcCEm0rB2r/Q== X-Received: by 2002:a17:902:ec81:b0:199:26b1:17b3 with SMTP id x1-20020a170902ec8100b0019926b117b3mr610623plg.28.1676754949710; Sat, 18 Feb 2023 13:15:49 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id x1-20020a1709029a4100b0019a97a4324dsm5059856plv.5.2023.02.18.13.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:49 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , =?utf-8?q?Christian_K=C3=B6nig?= , Sumit Semwal , Gustavo Padovan , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 01/14] dma-buf/dma-fence: Add deadline awareness Date: Sat, 18 Feb 2023 13:15:44 -0800 Message-Id: <20230218211608.1630586-2-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark Add a way to hint to the fence signaler of an upcoming deadline, such as vblank, which the fence waiter would prefer not to miss. This is to aid the fence signaler in making power management decisions, like boosting frequency as the deadline approaches and awareness of missing deadlines so that can be factored in to the frequency scaling. v2: Drop dma_fence::deadline and related logic to filter duplicate deadlines, to avoid increasing dma_fence size. The fence-context implementation will need similar logic to track deadlines of all the fences on the same timeline. [ckoenig] v3: Clarify locking wrt. set_deadline callback Signed-off-by: Rob Clark Reviewed-by: Christian König --- drivers/dma-buf/dma-fence.c | 20 ++++++++++++++++++++ include/linux/dma-fence.h | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 0de0482cd36e..763b32627684 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -912,6 +912,26 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, } EXPORT_SYMBOL(dma_fence_wait_any_timeout); + +/** + * dma_fence_set_deadline - set desired fence-wait deadline + * @fence: the fence that is to be waited on + * @deadline: the time by which the waiter hopes for the fence to be + * signaled + * + * Inform the fence signaler of an upcoming deadline, such as vblank, by + * which point the waiter would prefer the fence to be signaled by. This + * is intended to give feedback to the fence signaler to aid in power + * management decisions, such as boosting GPU frequency if a periodic + * vblank deadline is approaching. + */ +void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline) +{ + if (fence->ops->set_deadline && !dma_fence_is_signaled(fence)) + fence->ops->set_deadline(fence, deadline); +} +EXPORT_SYMBOL(dma_fence_set_deadline); + /** * dma_fence_describe - Dump fence describtion into seq_file * @fence: the 6fence to describe diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 775cdc0b4f24..d77f6591c453 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -99,6 +99,7 @@ enum dma_fence_flag_bits { DMA_FENCE_FLAG_SIGNALED_BIT, DMA_FENCE_FLAG_TIMESTAMP_BIT, DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, + DMA_FENCE_FLAG_HAS_DEADLINE_BIT, DMA_FENCE_FLAG_USER_BITS, /* must always be last member */ }; @@ -257,6 +258,23 @@ struct dma_fence_ops { */ void (*timeline_value_str)(struct dma_fence *fence, char *str, int size); + + /** + * @set_deadline: + * + * Callback to allow a fence waiter to inform the fence signaler of + * an upcoming deadline, such as vblank, by which point the waiter + * would prefer the fence to be signaled by. This is intended to + * give feedback to the fence signaler to aid in power management + * decisions, such as boosting GPU frequency. + * + * This is called without &dma_fence.lock held, it can be called + * multiple times and from any context. Locking is up to the callee + * if it has some state to manage. + * + * This callback is optional. + */ + void (*set_deadline)(struct dma_fence *fence, ktime_t deadline); }; void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, @@ -583,6 +601,8 @@ static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr) return ret < 0 ? ret : 0; } +void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline); + struct dma_fence *dma_fence_get_stub(void); struct dma_fence *dma_fence_allocate_private_stub(void); u64 dma_fence_context_alloc(unsigned num); From patchwork Sat Feb 18 21:15:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81C46C636CC for ; Sat, 18 Feb 2023 21:15:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229830AbjBRVPy (ORCPT ); Sat, 18 Feb 2023 16:15:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbjBRVPw (ORCPT ); Sat, 18 Feb 2023 16:15:52 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C9ED13D5F; Sat, 18 Feb 2023 13:15:51 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id cn10so1525118pjb.3; Sat, 18 Feb 2023 13:15:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MohZmh6ZcfzJn1OmRfs/o8+oM4ZPKLi2FB+4LPpL34o=; b=JKPBLpJuYtLP9cldFiCcQBESYKJDPCCdxK2p8Ufr/e7ac14X4XAWa/I6jS0fPcj37e mhzcsytchZq64j98/Us4f7wzBg+VXTi9kp+Pj/z+xtBTZuKHhnwMzlDgvm0NGFuD54vP mmQswfaDmO6rYjuZSDKBgBjdq0vsXkie19jhYNv5i1BGWHBWM7NX/4ETw6yeOF7xB3GN FrwTqOjuiorsAywFwh1DQOYvaS+co3s4W2mzUtcHg0bSQVy1W3TUeSCSkuPmMlttZ+Wr hHNWbwf4g+DyHKjq/TFRzJ377BMMdS4VH1igUJ9gBhzQOBjfsepQgOj3FLty/WL/fu7f v+Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MohZmh6ZcfzJn1OmRfs/o8+oM4ZPKLi2FB+4LPpL34o=; b=Hs4sdWJcs3S26P0VXXf5su7WPoeqZ4c+Y/gsjoo+dndMJInQRO4p89dWf9W24H/WmY LKrUTd1RtU8ce7Jpi75KNhkiIiOf7SeaHJjmxdbWXQUz9xEVu7GAufRA8UmUl+M6aEJb SCrftPGA7kN3ygezwZF9jY0b3X4dz/FJyFnoo9mzTZqjEKsKe1Q/Qg8El4c8vmXAipLw 4A9snxkizUYOJnlIYnNtV9PccVqxcfNduM5AalJNM+nAasB+nsiaPYsz0qlfbJkhPddZ dbgfEHT2AKD/5Pw3dsz086LCsjK5eHlHBb//cZWLEmb1JcX8ACClntzevO/sd6tK4RDN /OXA== X-Gm-Message-State: AO0yUKUR/1NbDMJhUKf4yv0+arwfZ+F1beXhaVoGAnjY9dbS+X8sGPZ0 RnWQFf/oMemFQ54qD2QfZu8= X-Google-Smtp-Source: AK7set+pq4QfLfFdfKgM6Wa+2NuPdUfpQy5kKDnaTLTht3wfRp9ww2c0n1JEFd40cSQfgefDzy4Kyw== X-Received: by 2002:a17:902:8601:b0:199:e58a:61c2 with SMTP id f1-20020a170902860100b00199e58a61c2mr4201310plo.29.1676754951096; Sat, 18 Feb 2023 13:15:51 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id x17-20020a170902ea9100b0019a6cce2060sm5104473plb.57.2023.02.18.13.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:50 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , =?utf-8?q?Christian_K=C3=B6nig?= , Sumit Semwal , Gustavo Padovan , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 02/14] dma-buf/fence-array: Add fence deadline support Date: Sat, 18 Feb 2023 13:15:45 -0800 Message-Id: <20230218211608.1630586-3-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark Propagate the deadline to all the fences in the array. Signed-off-by: Rob Clark Reviewed-by: Christian König --- drivers/dma-buf/dma-fence-array.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index 5c8a7084577b..9b3ce8948351 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -123,12 +123,23 @@ static void dma_fence_array_release(struct dma_fence *fence) dma_fence_free(fence); } +static void dma_fence_array_set_deadline(struct dma_fence *fence, + ktime_t deadline) +{ + struct dma_fence_array *array = to_dma_fence_array(fence); + unsigned i; + + for (i = 0; i < array->num_fences; ++i) + dma_fence_set_deadline(array->fences[i], deadline); +} + const struct dma_fence_ops dma_fence_array_ops = { .get_driver_name = dma_fence_array_get_driver_name, .get_timeline_name = dma_fence_array_get_timeline_name, .enable_signaling = dma_fence_array_enable_signaling, .signaled = dma_fence_array_signaled, .release = dma_fence_array_release, + .set_deadline = dma_fence_array_set_deadline, }; EXPORT_SYMBOL(dma_fence_array_ops); From patchwork Sat Feb 18 21:15:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE64FC64EC4 for ; Sat, 18 Feb 2023 21:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbjBRVQH (ORCPT ); Sat, 18 Feb 2023 16:16:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbjBRVPy (ORCPT ); Sat, 18 Feb 2023 16:15:54 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B051421C; Sat, 18 Feb 2023 13:15:52 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id w1so1556887plq.10; Sat, 18 Feb 2023 13:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5If47abMxVvdOGe/2jH89dN5UVVTGLmcg6EQzMCdPac=; b=CNTa3icUd804RiMnh5GApmZCXhp0f7037aAPuvfSQytTW0npuSY78gEtlHqHCmn8NW 5eyb8k4NDi+V7FS2GFNTsCMCbwtF/ltNdJ1R8lKpXjwlSuW/xA05CvMqFBhSSu07MEsU JH2yxu12s/Sag2BEmE1hSCDB+qldNLfSTvnE6oWJFCK0Mmjy4N6LpwoNiHLpYA46vDhq FKyzDBMCupniEDosM2D/oX5huHqWv+fGKFcFhLGvsIObJuL5txuSIxuJcq6Ha7jB3e5N 8lvmchf4xOKnqQmPJFYTIwbQW4VQVAXjRPv2OhBvHAUvo9YyVyaFKXVLfvp2bURupKsZ whYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5If47abMxVvdOGe/2jH89dN5UVVTGLmcg6EQzMCdPac=; b=1TunnlKQ7+DPFjBFegJL80VVTLUFzQkPzyHKgKHlf34e4lcb0nPcQO/aHTtad1IoC8 Qwzz9fXKtGc8NxRfiLbRfjLLScwzdYTBJn3XC2cXLnSyyhIn0xcom3jw2XOVmIh3fy4I ykknZFGk74Rjh5ZjoFva1Ovu/uhZZVm33BA5ZD1X62NZDFXGxE3OYURU+YkLkksxqOzD rz3JalsUWQny8mmJhOjtd2m9tIPTtRI3EjVQPchfE33HtKPKoSZzDC45JXHRXGFRdoLF LhSlWBWvjEZGFLpkkD4eDDnkmgMnpEJ2qukAa1/CB//VUnmpbytOkBw5Oh6pZWDcRh5J ZsQA== X-Gm-Message-State: AO0yUKXRHCOiU0gCB2D86m2tfZjfBM2cv8tHa4GLkrfv0f9VaT1raSyT DwDq0uMGVka9l7SUJzh7Cd4= X-Google-Smtp-Source: AK7set8+pwmvlN4/RTpTbvPrSu6bTCkr/ysSnaWTuvTnV/TRfDp/g41/uigNU2EfzQvt83CM+JnvNw== X-Received: by 2002:a17:902:f9cc:b0:19a:fd85:1891 with SMTP id kz12-20020a170902f9cc00b0019afd851891mr1808045plb.14.1676754952290; Sat, 18 Feb 2023 13:15:52 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b0019aafc42328sm236770plc.153.2023.02.18.13.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:51 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , =?utf-8?q?Christian_K=C3=B6nig?= , Sumit Semwal , Gustavo Padovan , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 03/14] dma-buf/fence-chain: Add fence deadline support Date: Sat, 18 Feb 2023 13:15:46 -0800 Message-Id: <20230218211608.1630586-4-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark Propagate the deadline to all the fences in the chain. Signed-off-by: Rob Clark Reviewed-by: Christian König for this one. --- drivers/dma-buf/dma-fence-chain.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index a0d920576ba6..4684874af612 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -206,6 +206,18 @@ static void dma_fence_chain_release(struct dma_fence *fence) dma_fence_free(fence); } + +static void dma_fence_chain_set_deadline(struct dma_fence *fence, + ktime_t deadline) +{ + dma_fence_chain_for_each(fence, fence) { + struct dma_fence_chain *chain = to_dma_fence_chain(fence); + struct dma_fence *f = chain ? chain->fence : fence; + + dma_fence_set_deadline(f, deadline); + } +} + const struct dma_fence_ops dma_fence_chain_ops = { .use_64bit_seqno = true, .get_driver_name = dma_fence_chain_get_driver_name, @@ -213,6 +225,7 @@ const struct dma_fence_ops dma_fence_chain_ops = { .enable_signaling = dma_fence_chain_enable_signaling, .signaled = dma_fence_chain_signaled, .release = dma_fence_chain_release, + .set_deadline = dma_fence_chain_set_deadline, }; EXPORT_SYMBOL(dma_fence_chain_ops); From patchwork Sat Feb 18 21:15:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70D04C677F1 for ; Sat, 18 Feb 2023 21:16:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjBRVQI (ORCPT ); Sat, 18 Feb 2023 16:16:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbjBRVPz (ORCPT ); Sat, 18 Feb 2023 16:15:55 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2280015C8C; Sat, 18 Feb 2023 13:15:54 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id a5-20020a17090a70c500b00236679bc70cso13689pjm.4; Sat, 18 Feb 2023 13:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=792an2SD05nhQRGBlD0Pg2RQ7VfR74mQEP4A4mqZ6Pk=; b=HM20qQN2yIU6PxWiMZEoSu3nueB6cRdZunRf/0WsasLxrWwG6jTJzi54FYZ5B5NZGd oiDKEt41GpKHkAkJ5gTVtA1j+PltUu0tI95VttL8G5W+qQnSbySKu7+cSjvKNge6QQ5J Pj2F3mRJmuteKR/t3CJoExZNh0GN57mlIvR6bySQe8r5eZLlOCXNqZxX5bjf/dupH9z3 IXqeOipa7lBiO9XbbbNImG/WCaemmgM46GgIE8Xh55pnP/LLLgxjXjr+DHt1NcdxFObQ 14PQ97rq81/QGaBdPs+HGfOyKwPzT8UnCAi8zNIuZLDmVStTVtSKfIFcJehu18xb5BVp cE9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=792an2SD05nhQRGBlD0Pg2RQ7VfR74mQEP4A4mqZ6Pk=; b=XmkjRTJUMuQzArRsYXYU+r3c9jw5UfF6rsTbn/sri85sibNdmoOzRFssTXU0cl4J2W BKqioXKYAkiT2mLOnHKYpLTZ4QS5RCWcRvhhmG8ZdS+rbxE9KQeNVofrWMEo4u6oL8mt awB+MsNmNQmjM41pkoqsCRDG458NJgsITQPKnFn2VZ6L9MHEKi89V9zNRsqjwE1yFQZI 8N1J+uduDsYiWGbc7OU1SiS+5uDU3aBNA/WB252mRSisZyE1Pp7iwpipMDxtuST4jcXy jI/e5drvU5l68Sr/QLM56zvBLqTHZZ3oZ/+kd/SOwvR6diwShDYh4MUvewU+MpXoF3jI ZNiA== X-Gm-Message-State: AO0yUKUj+K6wHyY473ZTULIS/PG4Xv8t0MhoodRJi3gFk7HcovHn5Mif L49ojjq/waezaNh6jM2s+Ck= X-Google-Smtp-Source: AK7set/QRHtfFq0gaLBBtupUc42V0jJFczyxE24VpZirzrpITI3ga4mB8wxlcDavsOCQ4hY8/UcUUA== X-Received: by 2002:a17:90a:357:b0:233:f990:d646 with SMTP id 23-20020a17090a035700b00233f990d646mr1577488pjf.35.1676754953521; Sat, 18 Feb 2023 13:15:53 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id bv21-20020a17090af19500b00231261061a5sm1254130pjb.5.2023.02.18.13.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:53 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org (open list:DMA BUFFER SHARING FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 04/14] dma-buf/dma-resv: Add a way to set fence deadline Date: Sat, 18 Feb 2023 13:15:47 -0800 Message-Id: <20230218211608.1630586-5-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark Add a way to set a deadline on remaining resv fences according to the requested usage. Signed-off-by: Rob Clark --- drivers/dma-buf/dma-resv.c | 19 +++++++++++++++++++ include/linux/dma-resv.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index 1c76aed8e262..0c86f6d577ab 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -684,6 +684,25 @@ long dma_resv_wait_timeout(struct dma_resv *obj, enum dma_resv_usage usage, } EXPORT_SYMBOL_GPL(dma_resv_wait_timeout); +/** + * dma_resv_set_deadline - Set a deadline on reservation's objects fences + * @obj: the reservation object + * @usage: controls which fences to include, see enum dma_resv_usage. + * @deadline: the requested deadline (MONOTONIC) + */ +void dma_resv_set_deadline(struct dma_resv *obj, enum dma_resv_usage usage, + ktime_t deadline) +{ + struct dma_resv_iter cursor; + struct dma_fence *fence; + + dma_resv_iter_begin(&cursor, obj, usage); + dma_resv_for_each_fence_unlocked(&cursor, fence) { + dma_fence_set_deadline(fence, deadline); + } + dma_resv_iter_end(&cursor); +} +EXPORT_SYMBOL_GPL(dma_resv_set_deadline); /** * dma_resv_test_signaled - Test if a reservation object's fences have been diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h index 0637659a702c..8d0e34dad446 100644 --- a/include/linux/dma-resv.h +++ b/include/linux/dma-resv.h @@ -479,6 +479,8 @@ int dma_resv_get_singleton(struct dma_resv *obj, enum dma_resv_usage usage, int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src); long dma_resv_wait_timeout(struct dma_resv *obj, enum dma_resv_usage usage, bool intr, unsigned long timeout); +void dma_resv_set_deadline(struct dma_resv *obj, enum dma_resv_usage usage, + ktime_t deadline); bool dma_resv_test_signaled(struct dma_resv *obj, enum dma_resv_usage usage); void dma_resv_describe(struct dma_resv *obj, struct seq_file *seq); From patchwork Sat Feb 18 21:15:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49F83C64ED8 for ; Sat, 18 Feb 2023 21:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbjBRVQK (ORCPT ); Sat, 18 Feb 2023 16:16:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229709AbjBRVQG (ORCPT ); Sat, 18 Feb 2023 16:16:06 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 975D715CB2; Sat, 18 Feb 2023 13:15:55 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id n1so1451380plc.11; Sat, 18 Feb 2023 13:15:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hI9qNsZmZouFqjT4Q7iKBhJP6Ch7PWCt+bcIXmzWxTA=; b=n8m0ik/8SEVtlt4tLy+1xKXcajLNDaoTcnObCr8qoX1kosoaMIoPX31NBzsj7seG30 TaPhmBInQnPnfd0sbBYcu2Sjd2IA6FxDGaZmCXZoXtGjZW6hFd+e9Xciqw/mNaEUFrq1 hjgq42bMdkekPwZy8PzTS6/Xq4JcoVNW50YdZjMsh/w+8uyRIy6w/+AWEK3pPnMvauwT wNnyWecM/dDofyumtFxiSCy6DM51SXQm97P8nGKVnoB2XUwupExO/xZ5cnsTPvxIDZIP qmCKeD3CtfUoaR56Ve0CFhe2vvZV/cLqVUjPQ858IZhTD5rfzOW9nQ9q1HUMtmg9/Zl0 ZfYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hI9qNsZmZouFqjT4Q7iKBhJP6Ch7PWCt+bcIXmzWxTA=; b=nWsKbyyIwWelqOmz6eJmexRq1iL+8On4/01gAZdYQq8td1ZoZB0FfzuekGR7JLMHVn e6iToVPLJpwEUvJrRNy01gsZQIJ9VNlz4YxHaEoyuCt0Jljc8W29JNQAsmM0l24/KnPU 2QPAyx0s6Jw6E3pEvbWbBjbN1x31tjGbhoF7FyD0R5rovH7VJXjM861CM+HLiQ6Um5yb wmGqWBSzhK1ZBGvvIuOKvSuQoBImayQNGvmAyc6YHn+UIXhAJ+PI+flcEmUabDp42tPr X6zXjMyTcW1T0+Mjb0vZ8frfNc2naeWdco8IHQsixs/ju5bRsypRxQ0v/ZFSrKoamLcl fJsQ== X-Gm-Message-State: AO0yUKVOi1Mcn11nXan6Toa06tEeupEueVOIYZvHBLHq+uU+4AR1TkF1 iOy4firbpNGxgtoEBXTgs8g= X-Google-Smtp-Source: AK7set9yuqIqkhJME2lpIvPyHaEjKyBB3ZOLwsVnLF62v/VV509uPfIKWgQ2ORuaU7W+EZTtXhgZJQ== X-Received: by 2002:a17:902:f98d:b0:19a:a647:1881 with SMTP id ky13-20020a170902f98d00b0019aa6471881mr3492159plb.62.1676754955043; Sat, 18 Feb 2023 13:15:55 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id a14-20020a170902ecce00b0019934030f46sm5057523plh.132.2023.02.18.13.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:54 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , Sumit Semwal , Gustavo Padovan , =?utf-8?q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 05/14] dma-buf/sync_file: Add SET_DEADLINE ioctl Date: Sat, 18 Feb 2023 13:15:48 -0800 Message-Id: <20230218211608.1630586-6-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark The initial purpose is for igt tests, but this would also be useful for compositors that wait until close to vblank deadline to make decisions about which frame to show. The igt tests can be found at: https://gitlab.freedesktop.org/robclark/igt-gpu-tools/-/commits/fence-deadline v2: Clarify the timebase, add link to igt tests Signed-off-by: Rob Clark --- drivers/dma-buf/sync_file.c | 19 +++++++++++++++++++ include/uapi/linux/sync_file.h | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index af57799c86ce..fb6ca1032885 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -350,6 +350,22 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, return ret; } +static int sync_file_ioctl_set_deadline(struct sync_file *sync_file, + unsigned long arg) +{ + struct sync_set_deadline ts; + + if (copy_from_user(&ts, (void __user *)arg, sizeof(ts))) + return -EFAULT; + + if (ts.pad) + return -EINVAL; + + dma_fence_set_deadline(sync_file->fence, ktime_set(ts.tv_sec, ts.tv_nsec)); + + return 0; +} + static long sync_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -362,6 +378,9 @@ static long sync_file_ioctl(struct file *file, unsigned int cmd, case SYNC_IOC_FILE_INFO: return sync_file_ioctl_fence_info(sync_file, arg); + case SYNC_IOC_SET_DEADLINE: + return sync_file_ioctl_set_deadline(sync_file, arg); + default: return -ENOTTY; } diff --git a/include/uapi/linux/sync_file.h b/include/uapi/linux/sync_file.h index ee2dcfb3d660..c8666580816f 100644 --- a/include/uapi/linux/sync_file.h +++ b/include/uapi/linux/sync_file.h @@ -67,6 +67,20 @@ struct sync_file_info { __u64 sync_fence_info; }; +/** + * struct sync_set_deadline - set a deadline on a fence + * @tv_sec: seconds elapsed since epoch + * @tv_nsec: nanoseconds elapsed since the time given by the tv_sec + * @pad: must be zero + * + * The timebase for the deadline is CLOCK_MONOTONIC (same as vblank) + */ +struct sync_set_deadline { + __s64 tv_sec; + __s32 tv_nsec; + __u32 pad; +}; + #define SYNC_IOC_MAGIC '>' /** @@ -95,4 +109,12 @@ struct sync_file_info { */ #define SYNC_IOC_FILE_INFO _IOWR(SYNC_IOC_MAGIC, 4, struct sync_file_info) + +/** + * DOC: SYNC_IOC_SET_DEADLINE - set a deadline on a fence + * + * Allows userspace to set a deadline on a fence, see dma_fence_set_deadline() + */ +#define SYNC_IOC_SET_DEADLINE _IOW(SYNC_IOC_MAGIC, 5, struct sync_set_deadline) + #endif /* _UAPI_LINUX_SYNC_H */ From patchwork Sat Feb 18 21:15:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEE44C64ED9 for ; Sat, 18 Feb 2023 21:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbjBRVQJ (ORCPT ); Sat, 18 Feb 2023 16:16:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbjBRVQG (ORCPT ); Sat, 18 Feb 2023 16:16:06 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91A713D7C; Sat, 18 Feb 2023 13:15:56 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id o9so1553787plk.12; Sat, 18 Feb 2023 13:15:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RYIkCiW1P3MTuGNaXnYInZXOL6oL98BTswmIrYI3+hc=; b=eQ/2i4WtARuumdk6wu3UFqAW69ZW8h3tfauASKVW6UiPkF3AV+YCLi3IsnRxxMwg0g CUIDHLV4BZqXknqttTtk+bXdQ6ljF08ejS9/UaWYQhGdaghr+KWH/71gNpnwDfzQ/UH5 nBW8tWukaXtSxhoyOsYUBlBageDHZMcz+vUTvBGG9/D5e4fM1azL9Vg9cP2p+UYvndt2 AHl5A36OpTJ8bpk7MfIg49zDicp0C2GaVHxplb2BU6oIc7LsUP5oMXTq3g1kIWHJce+H XGKorRr6oiJXunUlrDyMsUxILj9/VBJnJZI1d9zF9ycS3uV11lNRCp0g7026hwsHpCwE JhRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RYIkCiW1P3MTuGNaXnYInZXOL6oL98BTswmIrYI3+hc=; b=Cbf+1pS36nIWOhUBT7qVafeLUocqxkZ9ouS2pgEfesUdYU62aisMY47ys/j+crWR8x GJxGn9ZOkU0nfNaKgR8syXXLTerszhGSeiGFeaO6hoKRDxAUvuX+hj18GDoSAPybcZFK kpLPXGCJKLY/cHMRqc5yyebUs2GzSbyzK0gHANE5N3640yBjU1hjVHGoZW0dlzOyO3nl qGfNHq/jEqrCPolq3nr4NPWs8NofJyYyxgklM8W6siaCFFjO9LffAZ1I5w9NavcrVuxE 1XY5GO9RZbcid8fa6QeM+t47ShEKlBTdZg7/BOsuEfNfIkCne3jMaKT3DLz3qXLEwXMy iFiQ== X-Gm-Message-State: AO0yUKXQyYey09Q8aGcYvqgnaq+vWWbE9q90iGv7qv5U0V8niwXHaago Z9sEHK1Ag+YDFJpQqH+kAyk= X-Google-Smtp-Source: AK7set+6yJ/VIDgvzJ07sbwRoyqtX5Z4gVUluKE0+5jQloSvZWFq8eCN7xusPVn+H7cDq6VHJfZzWQ== X-Received: by 2002:a17:902:8504:b0:199:30a6:376c with SMTP id bj4-20020a170902850400b0019930a6376cmr3106041plb.68.1676754956327; Sat, 18 Feb 2023 13:15:56 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id h12-20020a170902eecc00b0019a96871e09sm5072653plb.211.2023.02.18.13.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:55 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , Sumit Semwal , Gustavo Padovan , =?utf-8?q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 06/14] dma-buf/sync_file: Support (E)POLLPRI Date: Sat, 18 Feb 2023 13:15:49 -0800 Message-Id: <20230218211608.1630586-7-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark Allow userspace to use the EPOLLPRI/POLLPRI flag to indicate an urgent wait (as opposed to a "housekeeping" wait to know when to cleanup after some work has completed). Usermode components of GPU driver stacks often poll() on fence fd's to know when it is safe to do things like free or reuse a buffer, but they can also poll() on a fence fd when waiting to read back results from the GPU. The EPOLLPRI/POLLPRI flag lets the kernel differentiate these two cases. Signed-off-by: Rob Clark --- drivers/dma-buf/sync_file.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index fb6ca1032885..c30b2085ee0a 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -192,6 +192,14 @@ static __poll_t sync_file_poll(struct file *file, poll_table *wait) { struct sync_file *sync_file = file->private_data; + /* + * The POLLPRI/EPOLLPRI flag can be used to signal that + * userspace wants the fence to signal ASAP, express this + * as an immediate deadline. + */ + if (poll_requested_events(wait) & EPOLLPRI) + dma_fence_set_deadline(sync_file->fence, ktime_get()); + poll_wait(file, &sync_file->wq, wait); if (list_empty(&sync_file->cb.node) && From patchwork Sat Feb 18 21:15:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CF34C64ED9 for ; Sat, 18 Feb 2023 21:16:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbjBRVQN (ORCPT ); Sat, 18 Feb 2023 16:16:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjBRVQI (ORCPT ); Sat, 18 Feb 2023 16:16:08 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96F62166D4; Sat, 18 Feb 2023 13:15:58 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id d19so677208pfo.9; Sat, 18 Feb 2023 13:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vB/jSDrgA8UtJvwy1x7JONuOUUbXDB++h6MnIk8ZgSw=; b=RY8338mvWxXiFN2CHg5+oaY5dszy2q7o07Qhnr55aOsSYI1UpZ9OwXPS4r6AC+zw0z AHFmOk3Hbxodz45mKpw3txyokHhLFObqsRYOESIkanEVGU/zO88ihBC4hKU+bmDz6UHo /Stah/9tCU3K9tUengKlhXc60ylZa5igR/9a5B3Ys7ne8+MuuFKhsT/G8INfSUMoHfln 7WKg3kwZOtwrLINCcgYDeUEE/+QSIojQUExKwBB1tVV4A8i7KCSoOFYLac70ytSfNu9j J8dpgpRM6lhjZ/U7MopMI1DjfnFLJKrNH2Vji6fkIhV8NP5Z8ePJHwUxigmCaL3i2O14 HnSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vB/jSDrgA8UtJvwy1x7JONuOUUbXDB++h6MnIk8ZgSw=; b=xQEuDZO9WGkAOFcuQXCxS1XJ6iDqLU69XSXMgbR/MHwhDLklGekP2XNuaSUrl1Aqsi e89CeaYGOrhWWFQTbQ4z7gl8C/tXqXOh3F9yHRr3wGv5K5xrIWNuWuoNdwk2EsAxAtYh zWs+hscsZAIw1bWk+NDGbUbobbQluHQcIUKYQfrGTdnt7YTjiCDWdo63JciqULepoEzZ e+d+WIDTLjxjzqQMtykVXf+YVimHGXqEw67665nGF0JB7of6KmljI5f6/yhKuKUqV8yk ldxOG+d2oLugx2qIQgJsUsTuCEg447cspZmd8p6G3uaO5GUmQ0EbD/c2iq1Beb/R9tLe yjfw== X-Gm-Message-State: AO0yUKXPVDGWEDzeUdq96xUw9GhIoVJKurn8A4PtEuRAECx1IWQPhj/V V+Xo+MCRBpVs4r4pMMYsLAA= X-Google-Smtp-Source: AK7set8gwg9RY9ZxDGIcTqNc4nJv6+AbCIJFIayFXX1sjc6F4gyeFD+K5gkUhaBMvy5Kxx7y8xK0mQ== X-Received: by 2002:a62:180d:0:b0:5a8:4de2:e94e with SMTP id 13-20020a62180d000000b005a84de2e94emr4528311pfy.33.1676754958081; Sat, 18 Feb 2023 13:15:58 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id w2-20020aa78582000000b005a8cc32b23csm3810199pfn.20.2023.02.18.13.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:57 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , Sumit Semwal , Gustavo Padovan , =?utf-8?q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 07/14] dma-buf/sw_sync: Add fence deadline support Date: Sat, 18 Feb 2023 13:15:50 -0800 Message-Id: <20230218211608.1630586-8-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark This consists of simply storing the most recent deadline, and adding an ioctl to retrieve the deadline. This can be used in conjunction with the SET_DEADLINE ioctl on a fence fd for testing. Ie. create various sw_sync fences, merge them into a fence-array, set deadline on the fence-array and confirm that it is propagated properly to each fence. Signed-off-by: Rob Clark Reviewed-by: Christian König --- drivers/dma-buf/sw_sync.c | 58 ++++++++++++++++++++++++++++++++++++ drivers/dma-buf/sync_debug.h | 2 ++ 2 files changed, 60 insertions(+) diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c index 348b3a9170fa..50f2638cccd3 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c @@ -52,12 +52,26 @@ struct sw_sync_create_fence_data { __s32 fence; /* fd of new fence */ }; +/** + * struct sw_sync_get_deadline - get the deadline of a sw_sync fence + * @tv_sec: seconds elapsed since epoch (out) + * @tv_nsec: nanoseconds elapsed since the time given by the tv_sec (out) + * @fence_fd: the sw_sync fence fd (in) + */ +struct sw_sync_get_deadline { + __s64 tv_sec; + __s32 tv_nsec; + __s32 fence_fd; +}; + #define SW_SYNC_IOC_MAGIC 'W' #define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\ struct sw_sync_create_fence_data) #define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32) +#define SW_SYNC_GET_DEADLINE _IOWR(SW_SYNC_IOC_MAGIC, 2, \ + struct sw_sync_get_deadline) static const struct dma_fence_ops timeline_fence_ops; @@ -171,6 +185,13 @@ static void timeline_fence_timeline_value_str(struct dma_fence *fence, snprintf(str, size, "%d", parent->value); } +static void timeline_fence_set_deadline(struct dma_fence *fence, ktime_t deadline) +{ + struct sync_pt *pt = dma_fence_to_sync_pt(fence); + + pt->deadline = deadline; +} + static const struct dma_fence_ops timeline_fence_ops = { .get_driver_name = timeline_fence_get_driver_name, .get_timeline_name = timeline_fence_get_timeline_name, @@ -179,6 +200,7 @@ static const struct dma_fence_ops timeline_fence_ops = { .release = timeline_fence_release, .fence_value_str = timeline_fence_value_str, .timeline_value_str = timeline_fence_timeline_value_str, + .set_deadline = timeline_fence_set_deadline, }; /** @@ -387,6 +409,39 @@ static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg) return 0; } +static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long arg) +{ + struct sw_sync_get_deadline data; + struct timespec64 ts; + struct dma_fence *fence; + struct sync_pt *pt; + + if (copy_from_user(&data, (void __user *)arg, sizeof(data))) + return -EFAULT; + + if (data.tv_sec || data.tv_nsec) + return -EINVAL; + + fence = sync_file_get_fence(data.fence_fd); + if (!fence) + return -EINVAL; + + pt = dma_fence_to_sync_pt(fence); + if (!pt) + return -EINVAL; + + ts = ktime_to_timespec64(pt->deadline); + data.tv_sec = ts.tv_sec; + data.tv_nsec = ts.tv_nsec; + + dma_fence_put(fence); + + if (copy_to_user((void __user *)arg, &data, sizeof(data))) + return -EFAULT; + + return 0; +} + static long sw_sync_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -399,6 +454,9 @@ static long sw_sync_ioctl(struct file *file, unsigned int cmd, case SW_SYNC_IOC_INC: return sw_sync_ioctl_inc(obj, arg); + case SW_SYNC_GET_DEADLINE: + return sw_sync_ioctl_get_deadline(obj, arg); + default: return -ENOTTY; } diff --git a/drivers/dma-buf/sync_debug.h b/drivers/dma-buf/sync_debug.h index 6176e52ba2d7..2e0146d0bdbb 100644 --- a/drivers/dma-buf/sync_debug.h +++ b/drivers/dma-buf/sync_debug.h @@ -55,11 +55,13 @@ static inline struct sync_timeline *dma_fence_parent(struct dma_fence *fence) * @base: base fence object * @link: link on the sync timeline's list * @node: node in the sync timeline's tree + * @deadline: the most recently set fence deadline */ struct sync_pt { struct dma_fence base; struct list_head link; struct rb_node node; + ktime_t deadline; }; extern const struct file_operations sw_sync_debugfs_fops; From patchwork Sat Feb 18 21:15:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B653C6379F for ; Sat, 18 Feb 2023 21:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjBRVQb (ORCPT ); Sat, 18 Feb 2023 16:16:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjBRVQI (ORCPT ); Sat, 18 Feb 2023 16:16:08 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00CC413DC2; Sat, 18 Feb 2023 13:15:59 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id nv10-20020a17090b1b4a00b00233ba727724so1197569pjb.1; Sat, 18 Feb 2023 13:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VdB6EdjwMQL5Ibg3VUOmJdReWQo7i7tr5bIvZ40Y+70=; b=pDA9FLO9fgkMVEoWNcr9GB82wPyuwd6l2FqLVItakUuB+XiNMjIds3HFZkW2geSsF5 JniRckmdMx4FBrTxXEMzuuu0JRfMaQGjWaV5CR0PgBkbcewgNkSzjkPQn4db0AKxiVBV 2OgVLUMSDHOwXovpeU+Y+dP7pSsTdfSjbA7OpGooBtFsSm07TdnYKXnfj6okBFn0kjkm rwMNzyzGBe/E9RxTygAHj0qiclCrl9jRN4c0Sk2WZTTIFah2yv9oAE5xkAPLpjVluse8 kWLSzCd+d8X33I0KRZYt1rV0mB2ftjO6edVT9oDPgGezTsOvgS9EJWuT4ADkBpZfiLqk 5daA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VdB6EdjwMQL5Ibg3VUOmJdReWQo7i7tr5bIvZ40Y+70=; b=C3ZUHKRcaSNzliGwJwgGFXxXxzp1JPIkxx371a3hYQeW5FILFCj0GeYVoUPXVkbynv viSJN2AVtqbJYbL5pdcbJplTWeCvVhKX1jgvi2hfuX+G4S8kEFqTv8cWw38ZLQAPRvYf FujFSKJqkyKmKqsGtDh0IWBw6JQy/PcEwAIwAyXLMZlwPcVTTL7OPG4BYzUQ7Ngn6lo8 QLGh+x3Q48i3A2rGJztM7JHkFa5AvzCHH7N03srYpU21H9cgmHidMwZvqtWOya+8z98s rk3wvIIc5QYDVz1ZSjwrOz8HnZCCbFP3W5qhihSqwL1yLIWtRfvAHR3BdSe/tx3fvRme ffow== X-Gm-Message-State: AO0yUKWwqrnK6r/408a3dgElX0Qph/sRnZv+RgdaCBkdhYixAFw9oF33 IFPmRsvplxZdBoVTQt2yDjE= X-Google-Smtp-Source: AK7set/isq+fQ8sHwasEnl9uLEI6PlAThVYe7S8EE+VDv5IdGpz8tgeAC/idcodqkaUTeNRTzHseWw== X-Received: by 2002:a17:902:d48a:b0:19a:b6bf:1e16 with SMTP id c10-20020a170902d48a00b0019ab6bf1e16mr817197plg.51.1676754959377; Sat, 18 Feb 2023 13:15:59 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id 6-20020a170902c20600b00194d14d8e54sm5050777pll.96.2023.02.18.13.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:15:59 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , Rob Clark , Luben Tuikov , David Airlie , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-kernel@vger.kernel.org (open list), linux-media@vger.kernel.org (open list:DMA BUFFER SHARING FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK) Subject: [PATCH v4 08/14] drm/scheduler: Add fence deadline support Date: Sat, 18 Feb 2023 13:15:51 -0800 Message-Id: <20230218211608.1630586-9-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org As the finished fence is the one that is exposed to userspace, and therefore the one that other operations, like atomic update, would block on, we need to propagate the deadline from from the finished fence to the actual hw fence. v2: Split into drm_sched_fence_set_parent() (ckoenig) v3: Ensure a thread calling drm_sched_fence_set_deadline_finished() sees fence->parent set before drm_sched_fence_set_parent() does this test_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT). Signed-off-by: Rob Clark --- drivers/gpu/drm/scheduler/sched_fence.c | 46 +++++++++++++++++++++++++ drivers/gpu/drm/scheduler/sched_main.c | 2 +- include/drm/gpu_scheduler.h | 8 +++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/scheduler/sched_fence.c b/drivers/gpu/drm/scheduler/sched_fence.c index 7fd869520ef2..43e2d4f5fe3b 100644 --- a/drivers/gpu/drm/scheduler/sched_fence.c +++ b/drivers/gpu/drm/scheduler/sched_fence.c @@ -123,6 +123,37 @@ static void drm_sched_fence_release_finished(struct dma_fence *f) dma_fence_put(&fence->scheduled); } +static void drm_sched_fence_set_deadline_finished(struct dma_fence *f, + ktime_t deadline) +{ + struct drm_sched_fence *fence = to_drm_sched_fence(f); + struct dma_fence *parent; + unsigned long flags; + + spin_lock_irqsave(&fence->lock, flags); + + /* If we already have an earlier deadline, keep it: */ + if (test_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT, &f->flags) && + ktime_before(fence->deadline, deadline)) { + spin_unlock_irqrestore(&fence->lock, flags); + return; + } + + fence->deadline = deadline; + set_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT, &f->flags); + + spin_unlock_irqrestore(&fence->lock, flags); + + /* + * smp_load_aquire() to ensure that if we are racing another + * thread calling drm_sched_fence_set_parent(), that we see + * the parent set before it calls test_bit(HAS_DEADLINE_BIT) + */ + parent = smp_load_acquire(&fence->parent); + if (parent) + dma_fence_set_deadline(parent, deadline); +} + static const struct dma_fence_ops drm_sched_fence_ops_scheduled = { .get_driver_name = drm_sched_fence_get_driver_name, .get_timeline_name = drm_sched_fence_get_timeline_name, @@ -133,6 +164,7 @@ static const struct dma_fence_ops drm_sched_fence_ops_finished = { .get_driver_name = drm_sched_fence_get_driver_name, .get_timeline_name = drm_sched_fence_get_timeline_name, .release = drm_sched_fence_release_finished, + .set_deadline = drm_sched_fence_set_deadline_finished, }; struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f) @@ -147,6 +179,20 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f) } EXPORT_SYMBOL(to_drm_sched_fence); +void drm_sched_fence_set_parent(struct drm_sched_fence *s_fence, + struct dma_fence *fence) +{ + /* + * smp_store_release() to ensure another thread racing us + * in drm_sched_fence_set_deadline_finished() sees the + * fence's parent set before test_bit() + */ + smp_store_release(&s_fence->parent, dma_fence_get(fence)); + if (test_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT, + &s_fence->finished.flags)) + dma_fence_set_deadline(fence, s_fence->deadline); +} + struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity, void *owner) { diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index 4e6ad6e122bc..007f98c48f8d 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -1019,7 +1019,7 @@ static int drm_sched_main(void *param) drm_sched_fence_scheduled(s_fence); if (!IS_ERR_OR_NULL(fence)) { - s_fence->parent = dma_fence_get(fence); + drm_sched_fence_set_parent(s_fence, fence); /* Drop for original kref_init of the fence */ dma_fence_put(fence); diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 9db9e5e504ee..8b31a954a44d 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -280,6 +280,12 @@ struct drm_sched_fence { */ struct dma_fence finished; + /** + * @deadline: deadline set on &drm_sched_fence.finished which + * potentially needs to be propagated to &drm_sched_fence.parent + */ + ktime_t deadline; + /** * @parent: the fence returned by &drm_sched_backend_ops.run_job * when scheduling the job on hardware. We signal the @@ -568,6 +574,8 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity, enum drm_sched_priority priority); bool drm_sched_entity_is_ready(struct drm_sched_entity *entity); +void drm_sched_fence_set_parent(struct drm_sched_fence *s_fence, + struct dma_fence *fence); struct drm_sched_fence *drm_sched_fence_alloc( struct drm_sched_entity *s_entity, void *owner); void drm_sched_fence_init(struct drm_sched_fence *fence, From patchwork Sat Feb 18 21:15:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 614F5C61DA4 for ; Sat, 18 Feb 2023 21:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbjBRVRb (ORCPT ); Sat, 18 Feb 2023 16:17:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbjBRVQd (ORCPT ); Sat, 18 Feb 2023 16:16:33 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD78A15C82; Sat, 18 Feb 2023 13:16:05 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id 21so319343plg.8; Sat, 18 Feb 2023 13:16:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JsqKhysyjry5mR87QHTfoSePPgw92sCbt0Ck69L5/uk=; b=fdqRVzGUTW2Lylj8ptJ8toY2v6E2ELgrc8C8ilcJUZ/kWsyPrOCCgQdLF+kfCIID3d 1yO9rav+tObLxcCflTXMXXJl/q5dB+0YsloZdSqf45hZF7HC9gHfhGaw+mPtrlO+bt4m iEwSaUeDE//+Jw2o8V4PDqoX/9WP7WqY57r4BlulvwXO+2mGolrHFjLYLfG6SE5rsCWd FUbiWHBPoS0KTibR65rb2rP9Sqx/RFWW8FBI7AZiXRVMQCVLfUFFHAQF00Gqw6+Oynw0 uG7o6WGK7t/sfWs8eSza5ClmJ69N2tkQtrfznMed39wwS+8P4C56iZZfSK/TXUUvMIUL jrVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JsqKhysyjry5mR87QHTfoSePPgw92sCbt0Ck69L5/uk=; b=Lt03KKYxl2LKp3JcmeV5eE2MXqokQfM1FRlC2YNrJKoTsU+g5qf/P1y+smn6YLrm1v m2Fspn4GaWCNm1uNAg0i2gM+/3e3T/SR9+rNuv9US7K+SOdPlwQUa0KKEOmK+xRwobBH PMGgjBs+ZbqQQxfrbgShkeHoekTFmWGzMsFbgAjc4rzYl40y1c98ugCQznQw+jVoh+oO mZjTmw9Pj9JwhEhAwCLg1D9cL3pvv65VrLyRnd6Cz4HwEC1YhN5cIam31NLOQXnIpcKd YTn+Ccb3letXJwfmacCae9wvlW+bi/PpPq0ABWgQ7lSSLZAotmQv/kndQ5Bp09AlCgcr lPaA== X-Gm-Message-State: AO0yUKUYZ+/cHtTfJHKd3OcYCTWhA2o+uvErpc/l2HPxHYI+rUwsd4hC kfJrzRkSqzovoZASAD+vbBA= X-Google-Smtp-Source: AK7set+E5bi4hUVjrj1G0GZ5TsGbo0N5rmpLKCrZ3Kk67JhED8tmWFS6Fjjlgd7iA3PZt/W4m6gieA== X-Received: by 2002:a17:902:ea12:b0:199:4be8:be48 with SMTP id s18-20020a170902ea1200b001994be8be48mr2315956plg.19.1676754965011; Sat, 18 Feb 2023 13:16:05 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id z13-20020a1709027e8d00b00198fe021f93sm5047709pla.77.2023.02.18.13.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:16:04 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-msm@vger.kernel.org (open list:DRM DRIVER FOR MSM ADRENO GPU), linux-kernel@vger.kernel.org (open list), linux-media@vger.kernel.org (open list:DMA BUFFER SHARING FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK) Subject: [PATCH v4 12/14] drm/msm: Add deadline based boost support Date: Sat, 18 Feb 2023 13:15:55 -0800 Message-Id: <20230218211608.1630586-13-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark Track the nearest deadline on a fence timeline and set a timer to expire shortly before to trigger boost if the fence has not yet been signaled. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_drv.c | 4 +- drivers/gpu/drm/msm/msm_fence.c | 74 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/msm/msm_fence.h | 20 +++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index aca48c868c14..be2a68f8e78d 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1065,7 +1065,9 @@ static const struct drm_driver msm_driver = { DRIVER_RENDER | DRIVER_ATOMIC | DRIVER_MODESET | - DRIVER_SYNCOBJ, + DRIVER_SYNCOBJ | + DRIVER_SYNCOBJ_DEADLINE | + 0, .open = msm_open, .postclose = msm_postclose, .lastclose = drm_fb_helper_lastclose, diff --git a/drivers/gpu/drm/msm/msm_fence.c b/drivers/gpu/drm/msm/msm_fence.c index 56641408ea74..51b461f32103 100644 --- a/drivers/gpu/drm/msm/msm_fence.c +++ b/drivers/gpu/drm/msm/msm_fence.c @@ -8,6 +8,35 @@ #include "msm_drv.h" #include "msm_fence.h" +#include "msm_gpu.h" + +static struct msm_gpu *fctx2gpu(struct msm_fence_context *fctx) +{ + struct msm_drm_private *priv = fctx->dev->dev_private; + return priv->gpu; +} + +static enum hrtimer_restart deadline_timer(struct hrtimer *t) +{ + struct msm_fence_context *fctx = container_of(t, + struct msm_fence_context, deadline_timer); + + kthread_queue_work(fctx2gpu(fctx)->worker, &fctx->deadline_work); + + return HRTIMER_NORESTART; +} + +static void deadline_work(struct kthread_work *work) +{ + struct msm_fence_context *fctx = container_of(work, + struct msm_fence_context, deadline_work); + + /* If deadline fence has already passed, nothing to do: */ + if (msm_fence_completed(fctx, fctx->next_deadline_fence)) + return; + + msm_devfreq_boost(fctx2gpu(fctx), 2); +} struct msm_fence_context * @@ -36,6 +65,13 @@ msm_fence_context_alloc(struct drm_device *dev, volatile uint32_t *fenceptr, fctx->completed_fence = fctx->last_fence; *fctx->fenceptr = fctx->last_fence; + hrtimer_init(&fctx->deadline_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); + fctx->deadline_timer.function = deadline_timer; + + kthread_init_work(&fctx->deadline_work, deadline_work); + + fctx->next_deadline = ktime_get(); + return fctx; } @@ -62,6 +98,8 @@ void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence) spin_lock_irqsave(&fctx->spinlock, flags); if (fence_after(fence, fctx->completed_fence)) fctx->completed_fence = fence; + if (msm_fence_completed(fctx, fctx->next_deadline_fence)) + hrtimer_cancel(&fctx->deadline_timer); spin_unlock_irqrestore(&fctx->spinlock, flags); } @@ -92,10 +130,46 @@ static bool msm_fence_signaled(struct dma_fence *fence) return msm_fence_completed(f->fctx, f->base.seqno); } +static void msm_fence_set_deadline(struct dma_fence *fence, ktime_t deadline) +{ + struct msm_fence *f = to_msm_fence(fence); + struct msm_fence_context *fctx = f->fctx; + unsigned long flags; + ktime_t now; + + spin_lock_irqsave(&fctx->spinlock, flags); + now = ktime_get(); + + if (ktime_after(now, fctx->next_deadline) || + ktime_before(deadline, fctx->next_deadline)) { + fctx->next_deadline = deadline; + fctx->next_deadline_fence = + max(fctx->next_deadline_fence, (uint32_t)fence->seqno); + + /* + * Set timer to trigger boost 3ms before deadline, or + * if we are already less than 3ms before the deadline + * schedule boost work immediately. + */ + deadline = ktime_sub(deadline, ms_to_ktime(3)); + + if (ktime_after(now, deadline)) { + kthread_queue_work(fctx2gpu(fctx)->worker, + &fctx->deadline_work); + } else { + hrtimer_start(&fctx->deadline_timer, deadline, + HRTIMER_MODE_ABS); + } + } + + spin_unlock_irqrestore(&fctx->spinlock, flags); +} + static const struct dma_fence_ops msm_fence_ops = { .get_driver_name = msm_fence_get_driver_name, .get_timeline_name = msm_fence_get_timeline_name, .signaled = msm_fence_signaled, + .set_deadline = msm_fence_set_deadline, }; struct dma_fence * diff --git a/drivers/gpu/drm/msm/msm_fence.h b/drivers/gpu/drm/msm/msm_fence.h index 7f1798c54cd1..cdaebfb94f5c 100644 --- a/drivers/gpu/drm/msm/msm_fence.h +++ b/drivers/gpu/drm/msm/msm_fence.h @@ -52,6 +52,26 @@ struct msm_fence_context { volatile uint32_t *fenceptr; spinlock_t spinlock; + + /* + * TODO this doesn't really deal with multiple deadlines, like + * if userspace got multiple frames ahead.. OTOH atomic updates + * don't queue, so maybe that is ok + */ + + /** next_deadline: Time of next deadline */ + ktime_t next_deadline; + + /** + * next_deadline_fence: + * + * Fence value for next pending deadline. The deadline timer is + * canceled when this fence is signaled. + */ + uint32_t next_deadline_fence; + + struct hrtimer deadline_timer; + struct kthread_work deadline_work; }; struct msm_fence_context * msm_fence_context_alloc(struct drm_device *dev, From patchwork Sat Feb 18 21:15:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13145715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0C0DC61DA4 for ; Sat, 18 Feb 2023 21:18:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbjBRVSR (ORCPT ); Sat, 18 Feb 2023 16:18:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbjBRVRd (ORCPT ); Sat, 18 Feb 2023 16:17:33 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3318193E9; Sat, 18 Feb 2023 13:16:19 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id a20so1691798pls.2; Sat, 18 Feb 2023 13:16:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LJRWjyogOQnJ+5yTXZeR/CA8uKgjfGlQ9M7/4cay494=; b=HlVIEobOB1fK4orz/vfjScfvfTmsM2Ff4tRZMVa4xdM5sCf4zF5X+pa/NEvV0jRFap d96y+vkl2FVlKyaS9S7zCK5ePnuhaaEY0SmBx5WF6VNh/A+Ddw4lzPwCsRykF7v5tW+G j6OTAh+IKDR2F+7ntwLsA2YAPfoL15U9CCJgJRqqpH77DSuZ6QgB7jeDf4EuDi1zovoz WqdVKpv8e/55Xn9GYpUy3oewxQ91CfDFS/Ljoeg0C7AuiGQkPCu8IGY7ptZcCfOFyu0F 3XanlgorSS20WKL00Ktx8XMMNFwITyfSWzjmfWs+jSzPH1rSFkjSLEdZ6yYHveznktpt eclw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LJRWjyogOQnJ+5yTXZeR/CA8uKgjfGlQ9M7/4cay494=; b=Dvcu7kZ+FlsBZPkbv7u1oRfTis3sKsfHlMIsvQoxTfI57zbgb2Ek6Xcp6uwftkPXjl z8mGCfwXLuxDOqtfnNzFr0gyOhwbu1zOIjBmn8pMOT9h31JLalSQAObSSAdIRr9EK4Ja skr3EDqKZUjHbHBxjLwr5Ra450+yNvlRhfi2S0MbJc0338QwDFPy7x1sxFtZ2Jl3/cMl Et0rfaXiYGMmfKrd6hhXB67YIc1mwFls5zlvVOo4eHCoo0mR7BrSSxduTU/vp5SnWYUN JCjN48DxeVpGzuxyrtHTxdUgsjPOBT/rKmpeZ17Q9NxIs0hCPlMOZcxx2kzfsvj+ai2Z nN3g== X-Gm-Message-State: AO0yUKUtSFed5nCevRdP6Tbx/WfyVMzIn1lLb6DohWtDH3DGbiVD1778 q5+qKDLNH9yy/cZaL4IIfbE= X-Google-Smtp-Source: AK7set/0yqp/q3/jslTp6QxBhdRo+Dy4M24xdmTIftytbmsLtB5hmbelVCK/TX7kEgjPGP3InbTQCA== X-Received: by 2002:a17:903:2447:b0:194:5c63:364c with SMTP id l7-20020a170903244700b001945c63364cmr1849203pls.62.1676754978760; Sat, 18 Feb 2023 13:16:18 -0800 (PST) Received: from localhost (c-73-67-135-195.hsd1.or.comcast.net. [73.67.135.195]) by smtp.gmail.com with ESMTPSA id ji11-20020a170903324b00b0019afb7a02a1sm4785944plb.218.2023.02.18.13.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 13:16:18 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Rob Clark , Jani Nikula , Joonas Lahtinen , Tvrtko Ursulin , David Airlie , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org (open list), linux-media@vger.kernel.org (open list:DMA BUFFER SHARING FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK) Subject: [PATCH v4 14/14] drm/i915: Add deadline based boost support Date: Sat, 18 Feb 2023 13:15:57 -0800 Message-Id: <20230218211608.1630586-15-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230218211608.1630586-1-robdclark@gmail.com> References: <20230218211608.1630586-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark Signed-off-by: Rob Clark --- This should probably be re-written by someone who knows the i915 request/timeline stuff better, to deal with non-immediate deadlines. But as-is I think this should be enough to handle the case where we want syncobj waits to trigger boost. drivers/gpu/drm/i915/i915_driver.c | 2 +- drivers/gpu/drm/i915/i915_request.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index cf1c0970ecb4..bd40b7bcb38a 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1781,7 +1781,7 @@ static const struct drm_driver i915_drm_driver = { .driver_features = DRIVER_GEM | DRIVER_RENDER | DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_SYNCOBJ | - DRIVER_SYNCOBJ_TIMELINE, + DRIVER_SYNCOBJ_TIMELINE | DRIVER_SYNCOBJ_DEADLINE, .release = i915_driver_release, .open = i915_driver_open, .lastclose = i915_driver_lastclose, diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c index 7503dcb9043b..44491e7e214c 100644 --- a/drivers/gpu/drm/i915/i915_request.c +++ b/drivers/gpu/drm/i915/i915_request.c @@ -97,6 +97,25 @@ static bool i915_fence_enable_signaling(struct dma_fence *fence) return i915_request_enable_breadcrumb(to_request(fence)); } +static void i915_fence_set_deadline(struct dma_fence *fence, ktime_t deadline) +{ + struct i915_request *rq = to_request(fence); + + if (i915_request_completed(rq)) + return; + + if (i915_request_started(rq)) + return; + + /* + * TODO something more clever for deadlines that are in the + * future. I think probably track the nearest deadline in + * rq->timeline and set timer to trigger boost accordingly? + */ + + intel_rps_boost(rq); +} + static signed long i915_fence_wait(struct dma_fence *fence, bool interruptible, signed long timeout) @@ -182,6 +201,7 @@ const struct dma_fence_ops i915_fence_ops = { .signaled = i915_fence_signaled, .wait = i915_fence_wait, .release = i915_fence_release, + .set_deadline = i915_fence_set_deadline, }; static void irq_execute_cb(struct irq_work *wrk)