From patchwork Mon Feb 20 20:18:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147041 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 45585C64ED9 for ; Mon, 20 Feb 2023 20:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232636AbjBTUTX (ORCPT ); Mon, 20 Feb 2023 15:19:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232613AbjBTUTW (ORCPT ); Mon, 20 Feb 2023 15:19:22 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99186CDFC; Mon, 20 Feb 2023 12:19:21 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id 16so1138978pfl.8; Mon, 20 Feb 2023 12:19:21 -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=bAzgDJUXjy9h0b3wWSJvQgc6EH9SI72PAik2xEzTc0A=; b=L3pLkaDHvEbV43iHZrzlIEV7OhTotYtHn/7GtNIJgutWGMGrnnN9lu6JzkyGk2eqtv gAeYOrSjmSd5R+JzfsJrDASD1KvwFIfmh+OtnGd/4B0aAFgLP4f01sK+arwiDDVngZNU b6tajlB2k+l07TTmVMJYoyWmqQhWwklrEhVKAsPnnpsrwWDRdG2JZjZPCcJLCDvCE1ZV zNvNGA0mww53jE5+oTomy4ePhhb1a7HPVS6NLi50cYWoZAduiH314mQnGHROPJfKIr/+ /CUxe1TvUq5paX+fqp7V/6REycY2S73V2owLVjcOyM/c5leU7xy/oiEJ5QpSbktFbQZH 0/sQ== 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=bAzgDJUXjy9h0b3wWSJvQgc6EH9SI72PAik2xEzTc0A=; b=mh1cprGM7crmhokMkMwLIcoRHCI4norZo8eIqGB8bv/wiQEEySA9euHVX3jQwypSaJ sCws350YmtdyH7K0jdI8m2E5LHA1m61VCv7j/CY2F2zqn+hnp3m64fHdNxyms6a5VNYC AGerah42aAefiw8AMnjMPBW6bTdCxtM2Oj/THEnNF74bnLtsZlhV6H3qiVIYMpY6gNVz /qxTVBEQnuq47RnEjAWsrSyMd9O5HsmP+jtC8tGaONxS0lSZUAOVslChElTW0bP5UNDo pqDeiYoA0vkxpZ7BCg73vunJVw0CyVhpbM5Z8WEfoWW5zRedlBASQXd/cK1yRokddepR IKTQ== X-Gm-Message-State: AO0yUKUgJ0znMSCTU7ATPdwlhsIvHZjslR3fX4PV9UQZ6+tkkzABEdLE jZJxOn1mXJkYPY1c4jgxAzg= X-Google-Smtp-Source: AK7set+T1ETLgiEQvfF2x6OGFtWpU1Whd0FMuM7my/yGNBBYPdgyZrdMLMOhVxHrUvhUAs/zc+udAA== X-Received: by 2002:a05:6a00:13a5:b0:5a8:c699:3eaa with SMTP id t37-20020a056a0013a500b005a8c6993eaamr3307609pfg.9.1676924361040; Mon, 20 Feb 2023 12:19:21 -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 v24-20020aa78518000000b005a9ea5d43ddsm6634377pfn.174.2023.02.20.12.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:20 -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 v5 01/14] dma-buf/dma-fence: Add deadline awareness Date: Mon, 20 Feb 2023 12:18:48 -0800 Message-Id: <20230220201916.1822214-2-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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 v4: Clarify in docs comment that this is a hint Signed-off-by: Rob Clark Reviewed-by: Christian König --- drivers/dma-buf/dma-fence.c | 21 +++++++++++++++++++++ include/linux/dma-fence.h | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 0de0482cd36e..e3331761384c 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -912,6 +912,27 @@ 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 + * + * Give the fence signaler a hint about 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 but the fence is not + * yet signaled.. + */ +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 Mon Feb 20 20:18:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147042 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 D72E5C6379F for ; Mon, 20 Feb 2023 20:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232643AbjBTUT0 (ORCPT ); Mon, 20 Feb 2023 15:19:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjBTUTY (ORCPT ); Mon, 20 Feb 2023 15:19:24 -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 D7BDBCDDD; Mon, 20 Feb 2023 12:19:22 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id x24so1263173pfn.7; Mon, 20 Feb 2023 12:19:22 -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=eNWnZdY7bb0sIPeM/dP+nfuIuObMIanncbZ+NRD8X1XJMJ3PtrtrWEi9KbjDnT/8w/ 4868uK4c3a+o7f87mCfBXFuvYydQ0cuDb9mH/m5cPTpxn/qovKcax5YMahSlLSjYQWnj cOhgi+GA0fYpdhHXJew7nHx03aK8aUQ8p5ZFGvXeOjgRTpbbfDaG4dcHiobo8k+1cZdr rdBw52ruPwcHMxTkGp2qw/JKV4NNoevhSbXnwZWXIRBNhlsTWdgG+NiAWOZqCVkeVTPm EKNybgNSFZ+jaB3UZq7n3CyDCiF7d7P5sjMF/me3F6e407AydxnfmvvF+ZJZ22/xu8M0 auhQ== 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=CPN4K3/0BnxjgG2IYQ8jvbFoEHvz5drnR62avxUgOV7usC/q+ZqbTNi2OaG7G91YAm hxBudnpqPzy3dguEDzvuz/HU8BtDJhTn4y7PKLwsoSRrZx6MEzRWgp+ZangG1elQAIqK 8zJlzgsUqqXs5OrPeaqp9hmvAFsb9DR0LykRBmGfGxl+mmUzoG6Q6GIoYxQ6LHOy0diD JxGtKMFf+ZDus418fsYTnDy/KmuwsNCSawtiecOLxBU/PH3bTv3coni4pto08iN6tp9T PmY3EWqUQJrprOLm2ZKMpV44oo44NLis3ZQ4pJR0c0rECi87boUP0YYfWR6aNma4Qb0U LHxg== X-Gm-Message-State: AO0yUKU8dxfyL8eqqhHdXUe5V8ZKg5PYFvSAK8+Jwaly+bb6OZGQDfFD mvr9yvakLa3G4n/3BQO10/4= X-Google-Smtp-Source: AK7set/IEnsknqrg1Kvv1r90ECUxuHVfyDcG96xSfQIiNKkRh0eFALUg+af5KU3PpovvGnGW2S9fJw== X-Received: by 2002:a62:52d7:0:b0:5a9:d4fa:d3c7 with SMTP id g206-20020a6252d7000000b005a9d4fad3c7mr2485352pfb.7.1676924362392; Mon, 20 Feb 2023 12:19:22 -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 g20-20020aa78754000000b005a9bf65b591sm7029643pfo.135.2023.02.20.12.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:22 -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 v5 02/14] dma-buf/fence-array: Add fence deadline support Date: Mon, 20 Feb 2023 12:18:49 -0800 Message-Id: <20230220201916.1822214-3-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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 Mon Feb 20 20:18: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: 13147043 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 01B6DC6379F for ; Mon, 20 Feb 2023 20:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232689AbjBTUTg (ORCPT ); Mon, 20 Feb 2023 15:19:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232647AbjBTUT1 (ORCPT ); Mon, 20 Feb 2023 15:19:27 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4989518B3A; Mon, 20 Feb 2023 12:19:24 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id c32so1341124pgc.7; Mon, 20 Feb 2023 12:19:24 -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=YzeOmopCn0gh++/gAGcFEfcXWPP1jVMzasozIMD7Gnkw8K3NyhlEHe1zc8el3aD0Vx CIjGOhfZLHb/eeQuNytwDrZu2MoSPDSzBx0NkJozDbP/hff1JNpcf2JBAIZfOu4xeUEk +zOyP81obkNmacqYNnkI/8yrUexPNt23g3fRPvuMaEXgoQIpCMGtdvsH2gFRg7OLk4HQ DlyJkIqao3kfB+qsI6mVx2PKcGPpW6oE1VQU/ZgJ4BErwqSEE0o8LhrAJChvdIFMFXmY FFXESxU7CgmFAJRaj8/2sXKYQmNzH+0DmG3t+TEr8o4FPil3h4k4nq2uUgFAqGXt3R3M 6feg== 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=cV9WMwpx/JmzxJXfTZC+76cmvnKxjfXjeQaelB5iQqDRcrXgi8eCgwx9T1x4c0PvKy 5G4mB/rj01B6PGdEkEcv/eZs67L79jq17cojxx5rOQaENPBRpy9PB4ivqCco1PUr27Xj oQAEpkB2u1Nim/jLEzLiLL4DkcmpEY7rnB0FB9BmZnvhQ7s1gFud0TWPNqHUMoRd3Rpf 48pqIXR6PqtbJn27fHJaQJ/yGoIYXwpH00bsIQsOHxJMKiDIp7RII3B1Mjeh2PhbuL6P 8tGY7jVOaWFfUDSoVh/6FL0S/XxBENWpWxFxJxDrbXWDs7nLrU1EbiJ/J8MQLfhfOjeF cQcQ== X-Gm-Message-State: AO0yUKV8HOb4jVGAmxuM+gh+PcNhEP1L3qG3ExEuTCllF0Kt988EmZnF el8pnSvpFPfC1/O2UtWQMj0= X-Google-Smtp-Source: AK7set9GUlIkvZiMMJHbL1YlDHIQPYuqsE3eGFqhvDr4pSZzxB82JJDY+CxjmHJJWkP5dBcF/eD+Jw== X-Received: by 2002:a62:7911:0:b0:5a9:c16f:b4ea with SMTP id u17-20020a627911000000b005a9c16fb4eamr1495085pfc.7.1676924363589; Mon, 20 Feb 2023 12:19:23 -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 c6-20020a62e806000000b00593e4e6516csm390202pfi.124.2023.02.20.12.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:23 -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 v5 03/14] dma-buf/fence-chain: Add fence deadline support Date: Mon, 20 Feb 2023 12:18:50 -0800 Message-Id: <20230220201916.1822214-4-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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 Mon Feb 20 20:18:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147044 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 10841C64EC7 for ; Mon, 20 Feb 2023 20:19:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232713AbjBTUTh (ORCPT ); Mon, 20 Feb 2023 15:19:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232613AbjBTUT1 (ORCPT ); Mon, 20 Feb 2023 15:19:27 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1EAE1A679; Mon, 20 Feb 2023 12:19:25 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id x20-20020a17090a8a9400b00233ba727724so1637091pjn.1; Mon, 20 Feb 2023 12:19:25 -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=MUhwCn+Xf/Lh0tYXdZ7kyW7NLgJoG2FRHZEn6JIAUnU=; b=TLl/TPdqwtRVyveoqEQwyAPlXFgjLvNAuBIDILQ7Oea8iShNEbj69MwDSh/ZP2fh6c TV1oOrQe0ax0dddlxozQsiJDUBwCnQRl3HXHq47Nn4DMjkNY4G2zL+SVcy36iMieZbup afcG/xfi/AK0Meeb6pxNWibWBy77ENmfnk+NDvcNXQYxyLEBF2gE5SyMvWisXrYlPfWP MTsyf12mxXXsXfO9FE5gvS40BYBJ2pdxeef8KaLJMLJgpTDxzdVKVgB6ALvJC8MEuDJ4 4oYX/Nhw3xsvftd2XfRdtU9Svkyxdl7GrHIR1Fwh1pBSL35Gzh5tgAZR9tpSjJu/Sq+p Dtbg== 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=MUhwCn+Xf/Lh0tYXdZ7kyW7NLgJoG2FRHZEn6JIAUnU=; b=KHrnKazFo8AukGGEGTI++Tzv2FzL+tlXoOtKa7bfy8887/pQ2ePUV+wYV3lzWlj72l hSP1SYYJwd8pPFL18hYZOtOU5vp99H6LaTwFk9VWd+vwYltpECNmgtSwnBW18u0iYOMy OLdeELvYONRJKLwfefugrO1GqW0CjiMjZiuReWRFKUNOLKsJM7cG9zitYnjUu77m/kT1 9G80vnP6zcV7wY6G9xQ3BOhtUj6PECQr3XgogdVzvylHWApawS/ftiOVTrreWiUp3Yig cHvNHDrngKvZvF4sV5ua8gDRXpQ40i7W61g8GkCq2QTPZz8Xs+B+FYI+kFaFcSyEDMoT +ytw== X-Gm-Message-State: AO0yUKWS/2EQRsf2qRFlGXLFG24+yi7axckyEV1ydlvK1NS26utbAtf+ F5mzCrh4uT+ueBZ/ulRZYkk= X-Google-Smtp-Source: AK7set91Mua/G9JK+x+xMWNddOlWiq3csiO2OiGxMIoS16V6T9Bxz3GsDOwmPM60j3SHNpJw0pgOLg== X-Received: by 2002:a17:903:1d2:b0:19a:a815:2868 with SMTP id e18-20020a17090301d200b0019aa8152868mr2217276plh.44.1676924365081; Mon, 20 Feb 2023 12:19:25 -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 je13-20020a170903264d00b0019a74afe97dsm8306264plb.187.2023.02.20.12.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:24 -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 , 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 v5 04/14] dma-buf/dma-resv: Add a way to set fence deadline Date: Mon, 20 Feb 2023 12:18:51 -0800 Message-Id: <20230220201916.1822214-5-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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 Reviewed-by: Christian König --- drivers/dma-buf/dma-resv.c | 22 ++++++++++++++++++++++ include/linux/dma-resv.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index 1c76aed8e262..2a594b754af1 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -684,6 +684,28 @@ 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) + * + * May be called without holding the dma_resv lock. Sets @deadline on + * all fences filtered by @usage. + */ +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 Mon Feb 20 20:18:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147045 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 C50CFC64ED9 for ; Mon, 20 Feb 2023 20:19:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231562AbjBTUTj (ORCPT ); Mon, 20 Feb 2023 15:19:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232663AbjBTUTf (ORCPT ); Mon, 20 Feb 2023 15:19:35 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E29DFEB4F; Mon, 20 Feb 2023 12:19:26 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id nw10-20020a17090b254a00b00233d7314c1cso2645897pjb.5; Mon, 20 Feb 2023 12:19:26 -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=UQ+HtpBiPCHT5rgzWcpe+Ijn6L9dvBBGUTrq3sDHFpM=; b=aBPYkWOPEw5s/QxVkQ4uEzGBQrGpC11xe6a0TdCQnHUz9Lg4Jg4ZFMMUitrcoAklRP uZ25ZVI2ki1L7kvXW8ZHCeL3XRW8vIrmTcvbmLNHTfQfuIhwhq/6KRI51xwTivD8Nwt9 2i8h8Qu/SbG3uQ6z4j5SZbuDmaK23k7eYe2hsQJ2z9WkrYBUlKO5wNm06Ea+NGA6WSEK G765LgG9J/cCilXYb00n6OQwBOVe3BQn33mPy5GrrVirflLyYKBApVrnCE2uGEZz/I22 g1XT4G+hunwHY8lhml2zoNS95+KJAjftv3pBbWw6tX4TsyTFo5pQJjR0y7jExqOC4+RB pkxQ== 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=UQ+HtpBiPCHT5rgzWcpe+Ijn6L9dvBBGUTrq3sDHFpM=; b=GrFMO7cXoWs9wQkQpUY6ULhd8Oaa+JyCO1dnQ6ffP0mXNyis90UFoJkBb0R5F3BG8V 73OPPYLsT67WYo4HsdwEUOlmxAunI5BVv8nkkZFkRqDP6eA2WF4OIk3OwbYs8pGPZ9Nk Wt9hgq4pz/68MfKlq9g7m7ZmprIGJt8yjHCSFPvRsQWcgbTa5tdnpowRdNIopxjPtw+Q rMpY8HEbi3f1q1pAHVvXFIvM/RsbPoo3q/HaabcqQ3Mpql04eTqlz3H99A8cGHUj7aL0 Ddii3Q2RRvdcPHhA4eR5Apj6G0Vx3s8qrfIVgJladCCxLaWOwVhMN1j+GhzHSG5A2K51 xLUQ== X-Gm-Message-State: AO0yUKUK/e/DwZ13Rw/GU76n0+LvLlnLpm7hREtDA6bR8E0lsIikdbSb hwB6SrqZqkNeV4cQ8hWKrbg= X-Google-Smtp-Source: AK7set9EVO1gQGiG3KVtMCHENF5SPFZEN0nVUMY1XWm3OJSiYEagViseS4VaLvzQ2HdMN0PH+F+rPg== X-Received: by 2002:a17:902:d484:b0:19c:1904:4490 with SMTP id c4-20020a170902d48400b0019c19044490mr6008782plg.63.1676924366311; Mon, 20 Feb 2023 12:19:26 -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 17-20020a170902c11100b0019945535973sm8350579pli.63.2023.02.20.12.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:25 -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 v5 05/14] dma-buf/sync_file: Add SET_DEADLINE ioctl Date: Mon, 20 Feb 2023 12:18:52 -0800 Message-Id: <20230220201916.1822214-6-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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 v3: Use u64 value in ns to express deadline. Signed-off-by: Rob Clark --- drivers/dma-buf/sync_file.c | 19 +++++++++++++++++++ include/uapi/linux/sync_file.h | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index af57799c86ce..418021cfb87c 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, ns_to_ktime(ts.deadline_ns)); + + 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..6d2ad4addf1b 100644 --- a/include/uapi/linux/sync_file.h +++ b/include/uapi/linux/sync_file.h @@ -67,6 +67,21 @@ struct sync_file_info { __u64 sync_fence_info; }; +/** + * struct sync_set_deadline - set a deadline hint on a fence + * @deadline_ns: absolute time of the deadline + * @pad: must be zero + * + * The timebase for the deadline is CLOCK_MONOTONIC (same as vblank) + */ +struct sync_set_deadline { + __u64 deadline_ns; + /* Not strictly needed for alignment but gives some possibility + * for future extension: + */ + __u64 pad; +}; + #define SYNC_IOC_MAGIC '>' /** @@ -95,4 +110,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 Mon Feb 20 20:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147046 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 D9CCAC678D5 for ; Mon, 20 Feb 2023 20:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232594AbjBTUTk (ORCPT ); Mon, 20 Feb 2023 15:19:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232674AbjBTUTf (ORCPT ); Mon, 20 Feb 2023 15:19:35 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00A2113D48; Mon, 20 Feb 2023 12:19:27 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id b14-20020a17090a8c8e00b002349579949aso2475375pjo.5; Mon, 20 Feb 2023 12:19:27 -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=qPSgblFxcMDwoNtdY8qW+0LuYLpgnFy45QQcEr2JcOw=; b=b6XsnDqK1olt5qz2T9u3YiOy1VT5RRxz/VMoCYps3Pgrs+exn0Ya8JX+enLUoYcNBj buWfCT4iJPWfewaDPWp/5MvY+8QNicRVOvpZHbzyieCeadRJB6D+ELIdtWQA4vrudB0C Ic8gs+sFUfMRmdGe8U8V9mlHakR00nNgiPRSLRz2wdN0NwK0cO/ZTEM+Dk85lDjnxFGH 4H69GyzuGQ4Yzbn85CZMH0ujDoR4wVYNjPMbCZHKi7GaRLaFXdb2OrikJlOFpEQdeOqM rY/t4VFouvqsEETK+GCENjhhtY9tFNbH5CV48cJKLSsRL+uhx50XjKjLgz+GY+R0oaqk Wy2g== 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=qPSgblFxcMDwoNtdY8qW+0LuYLpgnFy45QQcEr2JcOw=; b=M+EbSZe1g0EiAt6i4BGTDr416db8RR+EyW4N2S7whytxiSWHkjYoeORh4mNGumbljT Xa4+ix0OBLalAHEwffKwxqeAaRE9fu38n3kUcuLdPLCmvnReIKZl0m7jhFhETtgJnf2T LkXfeauU36du/fc+BGnWOcocz9kZS4VfUDAWRRNqfsvOxFBl2jlDgQ4LHhrT9U4mUh3q 8QtVvNcVoXfYb0O03V3I7ZKQeiWHWN7/JabrOLxddWgTSQokv9nLU8EcPUCqVbUPJF93 fSG9ICChadUTs8sfs0VOZARx/yiTyHFUrF3dESozOcoQetVvAs/1t4OjVe5u2zmaT2I8 w6IA== X-Gm-Message-State: AO0yUKWMwDk59K1ge9jTrPAaG6ks9/h8n3NXXzdOOlMpwxYCFT2a8SBR aZ3AG2Cr/Fayny2qfU6RLRk= X-Google-Smtp-Source: AK7set/kLRp8IZ3rKb3WEqYptlfgjeKBGtJDw+/6Vpa1D7As5QAyc9t819GAtY4AWeHTvgf1dPYb+A== X-Received: by 2002:a17:902:ea07:b0:19a:f9b5:2f2f with SMTP id s7-20020a170902ea0700b0019af9b52f2fmr2362963plg.55.1676924367448; Mon, 20 Feb 2023 12:19:27 -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 z18-20020a1709028f9200b00198f2407ea1sm2033972plo.241.2023.02.20.12.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:27 -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 v5 06/14] dma-buf/sync_file: Support (E)POLLPRI Date: Mon, 20 Feb 2023 12:18:53 -0800 Message-Id: <20230220201916.1822214-7-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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 418021cfb87c..cbe96295373b 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 Mon Feb 20 20:18:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147048 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 D7695C64EC7 for ; Mon, 20 Feb 2023 20:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231697AbjBTUTn (ORCPT ); Mon, 20 Feb 2023 15:19:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232693AbjBTUTg (ORCPT ); Mon, 20 Feb 2023 15:19:36 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7431A12BFD; Mon, 20 Feb 2023 12:19:29 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id cb13so1138649pfb.5; Mon, 20 Feb 2023 12:19:29 -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=XiQQqcTshEbLjD8Mc0BqkK6iz8Zi/TK1jh3DESgjpc4=; b=EWlHLC4MR7yCgiQ7t5NjL4rflY/lHTNWITQmEgqG+vD5GKWdxIXDX3riU3EFvd3BNb U06DJbgiE2zvlQKapngeJ+aCSWD2L3tVDQFEvzuGKAyiS+R53gZhemupMklmpwEiliXf K79CAkJxyrcP1HFGivhBxUGLufbemHG0Rv6fJR9huvHeIIM1ILxSQdGZ47psp/nQm3OS RqvRx8Ab3h32aghQWBUmQq9X+DnutjaNE23HkxiQ39VswqnZ2ykZDKEOtU6Y5+0FOsuF x5ah3Uq115bwRKiSBH1iovTN55fLzqQzVRM/EpfOZNdLnmFQQsRkfu/SaQN70OKC2eWa VeMg== 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=XiQQqcTshEbLjD8Mc0BqkK6iz8Zi/TK1jh3DESgjpc4=; b=DsM2SCI/BSs0ApLKZo1l6J3WQu5dKkYGwkPvkhbchrPGOaO+2hRe1AeJBDe1DNvpIR Ahxvof9+SgLIqa1QxkkUqx7ryKTLWSfyEWdNeuQuuHdWcmg/qtUnblfk9XgPU2s0k7bk eor7jI2dZPKFXcoB62bpYbeKMo9Q35z1UqLRfTcjkoLpBXNmfLW5firxlX7WOb++6QwW 7mfJgpL3wVChu9XZJnVUrXTT05MOdkc8zqXTozmv2Ug5ng5CpdxYm9sBP6J/IqTFEtgr Oc3srWESjbVVotK3c9U/ATszFRQyAK5rmLW94J9pduyXIo1NcGELoF5RIKDvRWHrDGRR ZrgQ== X-Gm-Message-State: AO0yUKVuhVh8/YxVETIGa7q/ZmZgjzqNAc1qj6xXfPcCZZh9OFcoRWgI AqptJEOV6d1cEKRDXgsskns= X-Google-Smtp-Source: AK7set8DBuY7ObnW5AgZYvamzQMZH1dc5w9PJC9F+zllVkpDOVshjNN4rL/mls3MjSK/WrgINVYhKg== X-Received: by 2002:a05:6a00:1786:b0:5a9:d0e6:6a85 with SMTP id s6-20020a056a00178600b005a9d0e66a85mr2614276pfg.7.1676924368772; Mon, 20 Feb 2023 12:19:28 -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 4-20020aa79244000000b005a8851e0cddsm1688110pfp.188.2023.02.20.12.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:28 -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 v5 07/14] dma-buf/sw_sync: Add fence deadline support Date: Mon, 20 Feb 2023 12:18:54 -0800 Message-Id: <20230220201916.1822214-8-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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. v2: Switch UABI to express deadline as u64 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..3e2315ee955b 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c @@ -52,12 +52,28 @@ struct sw_sync_create_fence_data { __s32 fence; /* fd of new fence */ }; +/** + * struct sw_sync_get_deadline - get the deadline hint of a sw_sync fence + * @deadline_ns: absolute time of the deadline + * @pad: must be zero + * @fence_fd: the sw_sync fence fd (in) + * + * The timebase for the deadline is CLOCK_MONOTONIC (same as vblank) + */ +struct sw_sync_get_deadline { + __u64 deadline_ns; + __u32 pad; + __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 +187,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 +202,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 +411,37 @@ 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 dma_fence *fence; + struct sync_pt *pt; + + if (copy_from_user(&data, (void __user *)arg, sizeof(data))) + return -EFAULT; + + if (data.deadline_ns || data.pad) + 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; + + + data.deadline_ns = ktime_to_ns(pt->deadline); + + 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 Mon Feb 20 20:18: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: 13147047 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 B7F6FC64ED9 for ; Mon, 20 Feb 2023 20:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232746AbjBTUTm (ORCPT ); Mon, 20 Feb 2023 15:19:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232704AbjBTUTh (ORCPT ); Mon, 20 Feb 2023 15:19:37 -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 BA2241F5C5; Mon, 20 Feb 2023 12:19:30 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id nt5-20020a17090b248500b00237161e33f4so623157pjb.4; Mon, 20 Feb 2023 12:19:30 -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=nN6DNEQkX/s3NAcoshCilQQszrxyjAFA3pfEABOouBtmdv2hr9a8EWn9OyFTTOn1is wsp5iZbsB2B25KAj2t5c+u7DMFzqqtYR6ifa6hmq1+2ig4YFIYh7ikNCdQkej1y054ht QtbZa8qU4DpXxtjE4YpvEqDU8XNluRXrRHDS+d8Rr8Ev56fIug8fBs1kkGVsa2X9kmk+ 9Btdy49CeZA3JhAw0PJCEi7LCLD1/Fgg0Dj4LccvZyA9HioaLw//vp5nqpiWo/PFeROp slfdJyVloTzyreqVmcEzFxyRto/3TANPyM9OEEIWiWHU3qh8dFWAnkt+sK1bRmZs9Dl5 jYYw== 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=AAZgL3KkQ2Q55g9aCBrS5Hph9VttpFItSKnhrrfNxpANnCfGO8hy/0BC6Iwsdg6eYN yD2Npw12SWZUtVYaSqinKRMXx9JUYA4MZbEu9aJ+CNTCKoDtOktI07aF8dzQ19/jy5hx JuX22+ZIhDuPFnrUWCO+pC6na30yjX00DL8xEqEvdQ/+zSpO/QtMX78aY2hy5e2dPAcm YZMQmRwz0WDxD9ffRPSohsb75/f/Mzf7qYscjiMaO7WqtBjmc6amTlJkiHK5J60W9deB 4DZkSus5SwZ1GWwZNdyFYnOU0nB7kcn8fGj7GcIgi6xp/7UzL5newaTmI7RmfrD1N88B lGlw== X-Gm-Message-State: AO0yUKXLmNC1FRV1m+9L/3vkCAnmdrWxsptTR6V0I94cwalVkwfl1gPW XaN5b0WTZbmXSk49Vj6zwxA= X-Google-Smtp-Source: AK7set+10ywClxtJs9TTsbZ74hiuYpYPx64Pje5euev1rRXiuG7LtSR4TdiTx67SOu7mGT/czxhhRw== X-Received: by 2002:a17:903:11c4:b0:19a:a43c:41ae with SMTP id q4-20020a17090311c400b0019aa43c41aemr5454750plh.25.1676924370134; Mon, 20 Feb 2023 12:19:30 -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 p22-20020a170902a41600b001966d94cb2esm3791564plq.288.2023.02.20.12.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:29 -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 v5 08/14] drm/scheduler: Add fence deadline support Date: Mon, 20 Feb 2023 12:18:55 -0800 Message-Id: <20230220201916.1822214-9-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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 Mon Feb 20 20:18:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147049 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 D223AC6FA99 for ; Mon, 20 Feb 2023 20:19:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231797AbjBTUT4 (ORCPT ); Mon, 20 Feb 2023 15:19:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232721AbjBTUTr (ORCPT ); Mon, 20 Feb 2023 15:19:47 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA1020547; Mon, 20 Feb 2023 12:19:36 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id cp9so3603991pjb.0; Mon, 20 Feb 2023 12:19:36 -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=uqyHMdEv/I4h+kB4S5EmXwyYyPXw9FA0QD7a4XeiZZ4=; b=qWxbi7cysynJlROyYqpT1W5K38P/2KBzlq1IDmM8LAsxKTEBy+yKtthSfCwkwQpTch bJssSD7Jm1bOfNrHo2EZ8pl9i75VI9BkwXKX6wx2OWcwSiqz+LFI4ESOB9eMaeaU+Hra UEawNS4Axf9WfdwkAE0wURqqKZ/MzmKm4VHNtQV7Fp0HSwit+2A811AMVbq/tDLcB3tG 0UYa2Z2WB3lgmlP4y39XuJ3tAdT4EzjY/f2FJHue0XlasQa8LkPliR47zFrwyAT1it7j 6zzbs6m7tGkhnFCdkXE42R75YTq2J1CFMceXM51jdtDfP9oSRPYD2AJjWKwMbz8ZDaQz HW5g== 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=uqyHMdEv/I4h+kB4S5EmXwyYyPXw9FA0QD7a4XeiZZ4=; b=CL10t5W6wiNcGehm1/zSyDDwy0fjVL5QVFB+XBzdPISwkmHuCuxZHaIJTfamuiLVy3 jg4CMfu60bS8loMymoL3wNpQYr+TWjGsYtCD+eJolvlyt4Evx998v1N+os5ophW00WKL c6Xgw4RwyTtLezcYE6Xr64Vj1d0SaePyR3q1Trh6pmOLjGP4/QYHzcK8ZFyQPJ+D0YhT b+cshl3pOr+a6GzJObJ4JNrb3mxesne2PsCtsslxVerAGDRbSbePwBGnN5g4qP1OLFbz mb1FSUBlTH5HvjTQGpI/8hWvVNdBZWeOy7uabEB82YJJOAXy+ahUBFc5mPCnGGyNIJUu pQHg== X-Gm-Message-State: AO0yUKWa+2p16YpgtDT0IwyzzoSHnIJv0nDbt5QeoY+I39S8cUI/B+ax 9npRlHXHDgFo9A9lA7RcMZE= X-Google-Smtp-Source: AK7set9MW9Ae7MZ9KibrDVZ+SbelSx7YqcKLkt2u5xbEXakFPUpi+tzyphq21rOe4G4OT1nqIYfOeA== X-Received: by 2002:a17:90b:4f4d:b0:233:e1e6:33dc with SMTP id pj13-20020a17090b4f4d00b00233e1e633dcmr1373625pjb.48.1676924375715; Mon, 20 Feb 2023 12:19:35 -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 go6-20020a17090b03c600b00233afe09177sm1872773pjb.8.2023.02.20.12.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:19:34 -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 v5 12/14] drm/msm: Add deadline based boost support Date: Mon, 20 Feb 2023 12:18:59 -0800 Message-Id: <20230220201916.1822214-13-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-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. v2: rebase Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_fence.c | 74 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/msm/msm_fence.h | 20 +++++++++ 2 files changed, 94 insertions(+) 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 Mon Feb 20 20:19:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13147050 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 B7F44C64EC7 for ; Mon, 20 Feb 2023 20:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232587AbjBTUUm (ORCPT ); Mon, 20 Feb 2023 15:20:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbjBTUU1 (ORCPT ); Mon, 20 Feb 2023 15:20:27 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9B1B21A1C; Mon, 20 Feb 2023 12:20:09 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id k29so1596998pgm.3; Mon, 20 Feb 2023 12:20:09 -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=9VcsUu3unD+maL4g/jB1gMbq//XnoqiDQvEiNIyt7mI=; b=eFd6WKVkDjMERL0NUJwdZTkwaDz0OjPOGjnuwSqBIjiEyMvPenvK4sKtmZyxPWgSI5 WzMJ7uiuRFqsr+eNs7HnTFRMZMbN/YDiqBuD4ndq4yNYXEZLdGcxi3k805YFDaRTM49H btsQGnmcp+Jjet2+wIFLHC8jDiihHqY6cv/dPw9x9644Qa2EUek2cYNr9GJNbS8dgyFQ P4BpZWBP0fPeYBPaJP/C+GnuHA8Ghph1mcX47CION2s+/ZlxKblgjj9wQSBLyzCt5Nee 8vZ4iojT33oWnJ5z8yuQWQAsIzfLIZESfCxDG4TaE7N2JPqd9DRSZuJmNBVAKuuF7rDe FzFg== 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=9VcsUu3unD+maL4g/jB1gMbq//XnoqiDQvEiNIyt7mI=; b=pOxZSKZZCNYl93d22osXo+HFb4ekxazPbUtKJWJ9ZBJsEAYGMqIY0pLv4CJsdu2Qxy 7xdmgYassi/z/Qz9gToGjbxVR1GQPfnvmJJqLYfTqQW6jAh5Aks/jyURMfSmU8JQvuN7 1VoXxf5wqaEBEMjQ5MlUWdIxsXZuOhzWlMDC/pxp8GAi3BMpkka9I9yeo3yFgzr7IfOd 1kzi0ezqW8i7zal2LppwmIvYQbwn+TnXA47NAA9BfBgw8VBSMv66DulnjIxTWUZ2rBZd vWv2Dx1LriMUZtwwulwrJer2Q3jHx9jHvjr1OqtTqWbsIEPAzl9sGcE9zbXYeX7Uuu1F hDvQ== X-Gm-Message-State: AO0yUKUsQZa2mrQsFQK6Cn+TtTY3EQtlZCAoaM3TjpB8WKcl3qT9zK74 NQjeYYyZI/a6UlXvofjE7Uo= X-Google-Smtp-Source: AK7set/lZ+AFzfPQmwQQNW8iN+Fzdh2s6fnv3atcgztBFxVgeLYdWwu6bkkmpStlqHcJMRsJSfDpoA== X-Received: by 2002:a62:184d:0:b0:5a9:fcb0:e8a2 with SMTP id 74-20020a62184d000000b005a9fcb0e8a2mr1540546pfy.11.1676924402380; Mon, 20 Feb 2023 12:20:02 -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 e22-20020a62ee16000000b005a84e660713sm1934218pfi.195.2023.02.20.12.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 12:20:02 -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 v5 14/14] drm/i915: Add deadline based boost support Date: Mon, 20 Feb 2023 12:19:01 -0800 Message-Id: <20230220201916.1822214-15-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220201916.1822214-1-robdclark@gmail.com> References: <20230220201916.1822214-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark v2: rebase Signed-off-by: Rob Clark --- drivers/gpu/drm/i915/i915_request.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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)