From: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: adam.miszczak@linux.intel.com, kamil.konieczny@linux.intel.com,
lukasz.laguna@intel.com, zbigniew.kempczynski@intel.com,
Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Subject: [PATCH i-g-t 1/3] lib/xe/xe_spin: fix premature batch exit on BO resubmission
Date: Fri, 31 Jul 2026 16:18:04 +0200 [thread overview]
Message-ID: <20260731141806.890207-2-marcin.bernatowicz@linux.intel.com> (raw)
In-Reply-To: <20260731141806.890207-1-marcin.bernatowicz@linux.intel.com>
COND_BBE reads ticks_delta from memory. When the same BO is resubmitted,
COND_BBE can read the value left by the previous batch(elapsed >= ctx_ticks
at that batch's exit), satisfying the exit condition on the very first loop
iteration before any new elapsed time is stored.
Write sentinel 0 to ticks_delta at batch start and use
MI_SEMAPHORE_WAIT to poll until it is visible in memory before entering
the loop. This guarantees COND_BBE cannot read the stale value from the
previous batch.
Also switch from inverted ticks_delta logic (STOREINV + ~ctx_ticks) to
direct elapsed ticks (STORE + MAD_LT_IDD + ctx_ticks) for readability.
The pad loop between SRM and COND_BBE is removed as it does not help.
Suggested-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Cc: Adam Miszczak <adam.miszczak@linux.intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Lukasz Laguna <lukasz.laguna@intel.com>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
---
lib/xe/xe_spin.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/lib/xe/xe_spin.c b/lib/xe/xe_spin.c
index 874310789..2863d2163 100644
--- a/lib/xe/xe_spin.c
+++ b/lib/xe/xe_spin.c
@@ -52,7 +52,6 @@ void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts)
uint64_t start_addr = opts->addr + offsetof(struct xe_spin, start);
uint64_t end_addr = opts->addr + offsetof(struct xe_spin, end);
uint64_t ticks_delta_addr = opts->addr + offsetof(struct xe_spin, ticks_delta);
- uint64_t pad_addr = opts->addr + offsetof(struct xe_spin, pad);
uint64_t timestamp_addr = opts->addr + offsetof(struct xe_spin, timestamp);
int b = 0;
uint32_t devid;
@@ -77,6 +76,18 @@ void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts)
spin->batch[b++] = start_addr >> 32;
spin->batch[b++] = 0xc0ffee;
+ if (opts->ctx_ticks) {
+ /* Write sentinel and wait until it is visible in memory before loop. */
+ spin->batch[b++] = MI_STORE_DWORD_IMM_GEN4;
+ spin->batch[b++] = ticks_delta_addr;
+ spin->batch[b++] = ticks_delta_addr >> 32;
+ spin->batch[b++] = 0;
+ spin->batch[b++] = MI_SEMAPHORE_WAIT | MI_SEMAPHORE_POLL | MI_SEMAPHORE_SAD_EQ_SDD;
+ spin->batch[b++] = 0;
+ spin->batch[b++] = ticks_delta_addr;
+ spin->batch[b++] = ticks_delta_addr >> 32;
+ }
+
loop_addr = opts->addr + b * sizeof(uint32_t);
if (opts->preempt)
@@ -101,12 +112,12 @@ void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts)
spin->batch[b++] = opts->use_queue_timestamp ? QUEUE_TIMESTAMP : CTX_TIMESTAMP;
spin->batch[b++] = CS_GPR(NOW_TS);
- /* delta = now - start; inverted to match COND_BBE */
+ /* delta = now - start */
spin->batch[b++] = MI_MATH(4);
spin->batch[b++] = MI_MATH_LOAD(MI_MATH_REG_SRCA, MI_MATH_REG(NOW_TS));
spin->batch[b++] = MI_MATH_LOAD(MI_MATH_REG_SRCB, MI_MATH_REG(START_TS));
spin->batch[b++] = MI_MATH_SUB;
- spin->batch[b++] = MI_MATH_STOREINV(MI_MATH_REG(NOW_TS), MI_MATH_REG_ACCU);
+ spin->batch[b++] = MI_MATH_STORE(MI_MATH_REG(NOW_TS), MI_MATH_REG_ACCU);
/* Save delta for reading by COND_BBE */
spin->batch[b++] = MI_STORE_REGISTER_MEM_GEN8 | MI_SRM_CS_MMIO;
@@ -114,17 +125,9 @@ void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts)
spin->batch[b++] = ticks_delta_addr;
spin->batch[b++] = ticks_delta_addr >> 32;
- /* Delay between SRM and COND_BBE to post the writes */
- for (int n = 0; n < 8; n++) {
- spin->batch[b++] = MI_STORE_DWORD_IMM_GEN4;
- spin->batch[b++] = pad_addr;
- spin->batch[b++] = pad_addr >> 32;
- spin->batch[b++] = 0xc0ffee;
- }
-
- /* Break if delta [time elapsed] > ns */
- spin->batch[b++] = MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE | 2;
- spin->batch[b++] = ~(opts->ctx_ticks);
+ /* Break if delta [time elapsed] >= ns */
+ spin->batch[b++] = MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE | MAD_LT_IDD | 2;
+ spin->batch[b++] = opts->ctx_ticks;
spin->batch[b++] = ticks_delta_addr;
spin->batch[b++] = ticks_delta_addr >> 32;
}
--
2.43.0
next prev parent reply other threads:[~2026-07-31 14:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 14:18 [PATCH i-g-t 0/3] gem_wsim: fix batch premature completion Marcin Bernatowicz
2026-07-31 14:18 ` Marcin Bernatowicz [this message]
2026-07-31 15:52 ` [PATCH i-g-t 1/3] lib/xe/xe_spin: fix premature batch exit on BO resubmission Zbigniew Kempczyński
2026-07-31 14:18 ` [PATCH i-g-t 2/3] benchmarks/gem_wsim: fix ticks_delta assertion for non-inverted logic Marcin Bernatowicz
2026-07-31 15:53 ` Zbigniew Kempczyński
2026-07-31 14:18 ` [PATCH i-g-t 3/3] tests/xe_sriov_scheduling: fix ticks_delta check " Marcin Bernatowicz
2026-07-31 15:54 ` Zbigniew Kempczyński
2026-07-31 14:53 ` ✓ Xe.CI.BAT: success for gem_wsim: fix batch premature completion (rev2) Patchwork
2026-07-31 15:25 ` ✓ i915.CI.BAT: " Patchwork
2026-07-31 16:37 ` ✓ Xe.CI.FULL: " Patchwork
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=20260731141806.890207-2-marcin.bernatowicz@linux.intel.com \
--to=marcin.bernatowicz@linux.intel.com \
--cc=adam.miszczak@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=lukasz.laguna@intel.com \
--cc=zbigniew.kempczynski@intel.com \
/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