From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>,
Gustavo Padovan <gustavo@padovan.org>,
Chris Wilson <chris.p.wilson@linux.intel.com>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Subject: [PATCH 3/4] dma-buf/fence-chain: Wait on each tested chain link
Date: Thu, 14 Aug 2025 10:16:14 +0200 [thread overview]
Message-ID: <20250814094824.217142-9-janusz.krzysztofik@linux.intel.com> (raw)
In-Reply-To: <20250814094824.217142-6-janusz.krzysztofik@linux.intel.com>
Userspace may build dma_fence chains of arbitrary length step by step,
e.g. via drm_syncobj IOCTLs, and each step may start waiting on a chain
link it has added. Adjust the wait_* selftests to cover such extreme use
cases.
Having that done, don't enable signaling on each chain link when building
the chain. There is no point in doing that as long as no user is waiting
on the link, and even then, signaling is enabled automatically as soon as
a user starts waiting on the fence. Let individual test cases decide
which links of the chain should be waited on / need signaling enabled.
Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
---
drivers/dma-buf/st-dma-fence-chain.c | 120 ++++++++++++++++++++-------
1 file changed, 91 insertions(+), 29 deletions(-)
diff --git a/drivers/dma-buf/st-dma-fence-chain.c b/drivers/dma-buf/st-dma-fence-chain.c
index bff4192420d8b..0e7a24ed7caeb 100644
--- a/drivers/dma-buf/st-dma-fence-chain.c
+++ b/drivers/dma-buf/st-dma-fence-chain.c
@@ -145,8 +145,6 @@ static int fence_chains_init(struct fence_chains *fc, unsigned int count,
}
fc->tail = fc->chains[i];
-
- dma_fence_enable_sw_signaling(fc->chains[i]);
}
fc->chain_length = i;
@@ -570,23 +568,34 @@ static int __wait_fence_chains(void *arg)
static int wait_forward(void *arg)
{
+ struct task_struct **tsk;
struct fence_chains fc;
- struct task_struct *tsk;
ktime_t dt;
+ int i = 0;
int err;
- int i;
err = fence_chains_init(&fc, CHAIN_SZ, seqno_inc);
if (err)
return err;
- tsk = kthread_run(__wait_fence_chains, fc.tail, "dmabuf/wait");
- if (IS_ERR(tsk)) {
- err = PTR_ERR(tsk);
+ tsk = kmalloc_array(fc.chain_length, sizeof(*tsk), GFP_KERNEL);
+ if (!tsk) {
+ err = -ENOMEM;
goto err;
}
- get_task_struct(tsk);
- yield_to(tsk, true);
+
+ for (i = 0; i < fc.chain_length; i++) {
+ tsk[i] = kthread_run(__wait_fence_chains, fc.chains[i],
+ "dmabuf/wait-%llu", fc.fences[i]->seqno);
+ if (IS_ERR(tsk[i])) {
+ err = PTR_ERR(tsk[i]);
+ pr_err("Reported %d for kthread_run(%llu)!\n",
+ err, fc.fences[i]->seqno);
+ goto err;
+ }
+ get_task_struct(tsk[i]);
+ yield_to(tsk[i], true);
+ }
dt = -ktime_get();
for (i = 0; i < fc.chain_length; i++)
@@ -595,32 +604,53 @@ static int wait_forward(void *arg)
pr_info("%s: %d signals in %llu ns\n", __func__, fc.chain_length, ktime_to_ns(dt));
- err = kthread_stop_put(tsk);
-
err:
+ while (i--) {
+ int tsk_err = kthread_stop_put(tsk[i]);
+
+ if (tsk_err)
+ pr_err("Reported %d for kthread_stop_put(%llu)!\n",
+ tsk_err, fc.fences[i]->seqno);
+
+ if (!err)
+ err = tsk_err;
+ }
+ kfree(tsk);
+
fence_chains_fini(&fc);
return err;
}
static int wait_backward(void *arg)
{
+ struct task_struct **tsk;
struct fence_chains fc;
- struct task_struct *tsk;
ktime_t dt;
+ int i = 0;
int err;
- int i;
err = fence_chains_init(&fc, CHAIN_SZ, seqno_inc);
if (err)
return err;
- tsk = kthread_run(__wait_fence_chains, fc.tail, "dmabuf/wait");
- if (IS_ERR(tsk)) {
- err = PTR_ERR(tsk);
+ tsk = kmalloc_array(fc.chain_length, sizeof(*tsk), GFP_KERNEL);
+ if (!tsk) {
+ err = -ENOMEM;
goto err;
}
- get_task_struct(tsk);
- yield_to(tsk, true);
+
+ for (i = 0; i < fc.chain_length; i++) {
+ tsk[i] = kthread_run(__wait_fence_chains, fc.chains[i],
+ "dmabuf/wait-%llu", fc.fences[i]->seqno);
+ if (IS_ERR(tsk[i])) {
+ err = PTR_ERR(tsk[i]);
+ pr_err("Reported %d for kthread_run(%llu)!\n",
+ err, fc.fences[i]->seqno);
+ goto err;
+ }
+ get_task_struct(tsk[i]);
+ yield_to(tsk[i], true);
+ }
dt = -ktime_get();
for (i = fc.chain_length; i--; )
@@ -629,9 +659,20 @@ static int wait_backward(void *arg)
pr_info("%s: %d signals in %llu ns\n", __func__, fc.chain_length, ktime_to_ns(dt));
- err = kthread_stop_put(tsk);
-
+ i = fc.chain_length;
err:
+ while (i--) {
+ int tsk_err = kthread_stop_put(tsk[i]);
+
+ if (tsk_err)
+ pr_err("Reported %d for kthread_stop_put(%llu)!\n",
+ tsk_err, fc.fences[i]->seqno);
+
+ if (!err)
+ err = tsk_err;
+ }
+ kfree(tsk);
+
fence_chains_fini(&fc);
return err;
}
@@ -654,11 +695,11 @@ static void randomise_fences(struct fence_chains *fc)
static int wait_random(void *arg)
{
+ struct task_struct **tsk;
struct fence_chains fc;
- struct task_struct *tsk;
ktime_t dt;
+ int i = 0;
int err;
- int i;
err = fence_chains_init(&fc, CHAIN_SZ, seqno_inc);
if (err)
@@ -666,13 +707,24 @@ static int wait_random(void *arg)
randomise_fences(&fc);
- tsk = kthread_run(__wait_fence_chains, fc.tail, "dmabuf/wait");
- if (IS_ERR(tsk)) {
- err = PTR_ERR(tsk);
+ tsk = kmalloc_array(fc.chain_length, sizeof(*tsk), GFP_KERNEL);
+ if (!tsk) {
+ err = -ENOMEM;
goto err;
}
- get_task_struct(tsk);
- yield_to(tsk, true);
+
+ for (i = 0; i < fc.chain_length; i++) {
+ tsk[i] = kthread_run(__wait_fence_chains, fc.chains[i],
+ "dmabuf/wait-%llu", fc.fences[i]->seqno);
+ if (IS_ERR(tsk[i])) {
+ err = PTR_ERR(tsk[i]);
+ pr_err("Reported %d for kthread_run(%llu)!\n",
+ err, fc.fences[i]->seqno);
+ goto err;
+ }
+ get_task_struct(tsk[i]);
+ yield_to(tsk[i], true);
+ }
dt = -ktime_get();
for (i = 0; i < fc.chain_length; i++)
@@ -681,9 +733,19 @@ static int wait_random(void *arg)
pr_info("%s: %d signals in %llu ns\n", __func__, fc.chain_length, ktime_to_ns(dt));
- err = kthread_stop_put(tsk);
-
err:
+ while (i--) {
+ int tsk_err = kthread_stop_put(tsk[i]);
+
+ if (tsk_err)
+ pr_err("Reported %d for kthread_stop_put(%llu)!\n",
+ tsk_err, fc.fences[i]->seqno);
+
+ if (!err)
+ err = tsk_err;
+ }
+ kfree(tsk);
+
fence_chains_fini(&fc);
return err;
}
--
2.50.1
next prev parent reply other threads:[~2025-08-14 9:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 8:16 [PATCH 0/4] dma-buf/fence-chain: Speed up processing of rearmed callbacks Janusz Krzysztofik
2025-08-14 8:16 ` [PATCH 1/4] dma-buf/fence-chain: Report time spent in wait_* test cases Janusz Krzysztofik
2025-08-14 8:16 ` [PATCH 2/4] dma-buf/fence-chain: Let test cases decide which fence to wait on Janusz Krzysztofik
2025-08-14 8:16 ` Janusz Krzysztofik [this message]
2025-08-14 8:16 ` [PATCH 4/4] dma-buf/fence-chain: Speed up processing of rearmed callbacks Janusz Krzysztofik
2025-08-14 12:24 ` Christian König
2025-08-18 14:30 ` Janusz Krzysztofik
2025-08-18 14:42 ` Christian König
2025-08-19 9:04 ` Janusz Krzysztofik
2025-08-19 9:15 ` Christian König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250814094824.217142-9-janusz.krzysztofik@linux.intel.com \
--to=janusz.krzysztofik@linux.intel.com \
--cc=chris.p.wilson@linux.intel.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavo@padovan.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®