All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-xe] [PATCH] drm/xe/mmio: Make xe_mmio_wait32() aware of interrupts
@ 2023-11-14 22:09 Gustavo Sousa
  2023-11-14 23:29 ` [Intel-xe] ✓ CI.Patch_applied: success for " Patchwork
                   ` (9 more replies)
  0 siblings, 10 replies; 16+ messages in thread
From: Gustavo Sousa @ 2023-11-14 22:09 UTC (permalink / raw)
  To: intel-xe

With the current implementation, a preemption or other kind of interrupt
might happen between xe_mmio_read32() and ktime_get_raw(). Such an
interruption (specially in the case of preemption) might be long enough
to cause a timeout without giving a chance of a new check on the
register value on a next iteration, which would have happened otherwise.

This issue causes some sporadic timeouts in some code paths. As an
example, we were experiencing some rare timeouts when waiting for PLL
unlock for C10/C20 PHYs (see intel_cx0pll_disable()). After debugging,
we found out that the PLL unlock was happening within the expected time
period (20us), which suggested a bug in xe_mmio_wait32().

To fix the issue, ensure that we call ktime_get_raw() to get the current
time before we check the register value. This allows for a last check
after a timeout and covers the case where the it is caused by some
preemption/interrupt.

This change was tested with the aforementioned PLL unlocking code path.
Experiments showed that, before this change, we observed reported
timeouts in 54 of 5000 runs; and, after this change, no timeouts were
reported in 5000 runs.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
---
 drivers/gpu/drm/xe/xe_mmio.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_mmio.h b/drivers/gpu/drm/xe/xe_mmio.h
index ae09f777d711..4d0e816a81ac 100644
--- a/drivers/gpu/drm/xe/xe_mmio.h
+++ b/drivers/gpu/drm/xe/xe_mmio.h
@@ -98,13 +98,22 @@ static inline int xe_mmio_wait32(struct xe_gt *gt, struct xe_reg reg, u32 mask,
 	u32 read;
 
 	for (;;) {
+		cur = ktime_get_raw();
+
+		/*
+		 * Keep the compiler from re-ordering calls to ktime_get_raw()
+		 * and xe_mmio_read32(): reading the current time after reading
+		 * register has the potential for "fake timeouts" due to
+		 * preemption/interrupts in between the two.
+		 */
+		barrier();
+
 		read = xe_mmio_read32(gt, reg);
 		if ((read & mask) == val) {
 			ret = 0;
 			break;
 		}
 
-		cur = ktime_get_raw();
 		if (!ktime_before(cur, end))
 			break;
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-11-17 21:30 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-14 22:09 [Intel-xe] [PATCH] drm/xe/mmio: Make xe_mmio_wait32() aware of interrupts Gustavo Sousa
2023-11-14 23:29 ` [Intel-xe] ✓ CI.Patch_applied: success for " Patchwork
2023-11-14 23:29 ` [Intel-xe] ✓ CI.checkpatch: " Patchwork
2023-11-14 23:30 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-11-14 23:37 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-11-14 23:38 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-11-14 23:39 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-11-15  0:14 ` [Intel-xe] ✓ CI.BAT: " Patchwork
2023-11-15 16:51 ` [Intel-xe] [PATCH] " Lucas De Marchi
2023-11-15 17:58   ` Gustavo Sousa
2023-11-15 18:31     ` Rodrigo Vivi
2023-11-15 20:04     ` Lucas De Marchi
2023-11-16 13:42       ` Gustavo Sousa
2023-11-16 17:56         ` Lucas De Marchi
2023-11-15 22:31 ` [Intel-xe] ✗ CI.Patch_applied: failure for drm/xe/mmio: Make xe_mmio_wait32() aware of interrupts (rev3) Patchwork
2023-11-17 21:30 ` Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.