Skip to contentSkip to conversation

drm/i915/gt: Use poll_timeout_us in place of sliding sleep window

PATCH Superseded Jonathan Cavitt 4 participants 5 messages Jul 6 – Jul 27

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 drm/i915/gt: Use poll_timeout_us in place of sliding sleep window

The functions intel_guc_send_busy_loop and ct_send can theoretically loop forever. In the former case, intel_guc_send_busy_loop can iterate forever if intel_guc_send_nb repeatedly returns -EBUSY. In the latter case, ct_send can loop forever if the guc-to-host or host-to-guc buffers get stuck in a full state.

Rework the functions to use the poll_timeout_us family of functions instead of calculating sleep_period_ms repeatedly. In both cases now, if the loop condition is not met after 10 minutes, the function will report it as a failure.

This also resolves a static analysis issue involving sleep_period_ms overflowing after several shift-left-logical calls.

v2:
- Reduce default sleep/udelay duration (jcavitt)

v3:
- Use atomic in ct_send (jcavitt)

v4:
- Rework ct_send reimplementation to better preserve original logic (Andi)
- Define 10 minutes to remove magic numbers (Krzysztof)

---
 drivers/gpu/drm/i915/gt/uc/intel_guc.h    | 33 +++++----
 drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 90 ++++++++++++++---------
 2 files changed, 71 insertions(+), 52 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +17 -16
index 053780f562c1..2d3adfbcd163 100644
@@ -7,6 +7,7 @@
 #define _INTEL_GUC_H_
 
 #include <linux/delay.h>
+#include <linux/iopoll.h>
 #include <linux/iosys-map.h>
 #include <linux/xarray.h>
 
@@ -354,14 +355,14 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
 				 response_buf, response_buf_size, 0);
 }
 
+#define POLL_TIMEOUT_DUR	(600 * USEC_PER_SEC)
 static inline int intel_guc_send_busy_loop(struct intel_guc *guc,
 					   const u32 *action,
 					   u32 len,
 					   u32 g2h_len_dw,
 					   bool loop)
 {
-	int err;
-	unsigned int sleep_period_ms = 1;
+	int err, timedout;
 	bool not_atomic = !in_atomic() && !irqs_disabled();
 
 	/*
@@ -374,20 +375,20 @@ static inline int intel_guc_send_busy_loop(struct intel_guc *guc,
 	/* No sleeping with spin locks, just busy loop */
 	might_sleep_if(loop && not_atomic);
 
-retry:
-	err = intel_guc_send_nb(guc, action, len, g2h_len_dw);
-	if (unlikely(err == -EBUSY && loop)) {
-		if (likely(not_atomic)) {
-			if (msleep_interruptible(sleep_period_ms))
-				return -EINTR;
-			sleep_period_ms = sleep_period_ms << 1;
-		} else {
-			cpu_relax();
-		}
-		goto retry;
-	}
-
-	return err;
+	if (!loop)
+		return intel_guc_send_nb(guc, action, len, g2h_len_dw);
+
+	if (not_atomic)
+		timedout = poll_timeout_us(err = intel_guc_send_nb(guc, action,
+								   len, g2h_len_dw),
+					   err != -EBUSY, USEC_PER_MSEC,
+					   POLL_TIMEOUT_DUR, false);
+	else
+		timedout = poll_timeout_us_atomic(err = intel_guc_send_nb(guc, action,
+									  len, g2h_len_dw),
+						  err != -EBUSY, USEC_PER_MSEC,
+						  POLL_TIMEOUT_DUR, false);
+	return timedout ?: err;
 }
 
 /* Only call this from the interrupt handler code */
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +54 -36

122 lines not on this page · raw message

Signature · 1 line
2.53.0
#1 lore raw

✗ i915.CI.BAT: failure for drm/i915/gt: Use poll_timeout_us in place of sliding sleep window (rev4)

== Series Details ==

== Series Details ==

Series: drm/i915/gt: Use poll_timeout_us in place of sliding sleep window (rev4)
URL : https://patchwork.freedesktop.org/series/169454/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_18771 -> Patchwork_169454v4
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_169454v4 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes
introduced in Patchwork_169454v4, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/index.html

Participating hosts (41 -> 40)
------------------------------

Additional (1): bat-adls-6
Missing (2): bat-dg2-13 fi-snb-2520m

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_169454v4:

### IGT changes ###

#### Possible regressions ####

* igt@core_hotunplug@unbind-rebind:
- fi-kbl-8809g: [PASS][1] -> [ABORT][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18771/fi-kbl-8809g/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/fi-kbl-8809g/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_169454v4 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@dmabuf@all-tests:
- bat-adls-6: NOTRUN -> [SKIP][3] ([i915#15931])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@gem_lmem_swapping@parallel-random-engines:
- bat-adls-6: NOTRUN -> [SKIP][4] ([i915#4613]) +3 other tests skip
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@gem_tiled_pread_basic@basic:
- bat-adls-6: NOTRUN -> [SKIP][5] ([i915#15656])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@i915_selftest@live:
- bat-arlh-2: [PASS][6] -> [INCOMPLETE][7] ([i915#16547])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18771/bat-arlh-2/igt@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-arlh-2/igt@[email protected]
- bat-adlp-11: [PASS][8] -> [DMESG-WARN][9] ([i915#16404]) +1 other test dmesg-warn
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18771/bat-adlp-11/igt@[email protected]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adlp-11/igt@[email protected]

* igt@i915_selftest@live@guc_hang:
- bat-arlh-2: [PASS][10] -> [INCOMPLETE][11] ([i915#16376])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18771/bat-arlh-2/igt@i915_selftest@live@guc_hang.html
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-arlh-2/igt@i915_selftest@live@guc_hang.html

* igt@intel_hwmon@hwmon-read:
- bat-adls-6: NOTRUN -> [SKIP][12] ([i915#7707]) +1 other test skip
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy:
- bat-adls-6: NOTRUN -> [SKIP][13] ([i915#4103]) +1 other test skip
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@kms_dsc@dsc-basic:
- bat-adls-6: NOTRUN -> [SKIP][14] ([i915#16361])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@kms_force_connector_basic@force-load-detect:
- bat-adls-6: NOTRUN -> [SKIP][15]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@kms_pm_backlight@basic-brightness:
- bat-adls-6: NOTRUN -> [SKIP][16] ([i915#5354])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@kms_psr@psr-primary-mmap-gtt:
- bat-adls-6: NOTRUN -> [SKIP][17] ([i915#1072] / [i915#9732]) +3 other tests skip
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@kms_setmode@basic-clone-single-crtc:
- bat-adls-6: NOTRUN -> [SKIP][18] ([i915#3555])
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

* igt@prime_vgem@basic-fence-read:
- bat-adls-6: NOTRUN -> [SKIP][19] ([i915#3291]) +2 other tests skip
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-adls-6/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live:
- bat-arls-5: [DMESG-FAIL][20] ([i915#16528]) -> [PASS][21] +1 other test pass
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18771/bat-arls-5/igt@[email protected]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/bat-arls-5/igt@[email protected]

[i915#1072]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/1072
[i915#15656]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15656
[i915#15931]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15931
[i915#16361]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16361
[i915#16376]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16376
[i915#16404]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16404
[i915#16528]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16528
[i915#16547]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16547
[i915#3291]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3291
[i915#3555]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3555
[i915#4103]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4103
[i915#4613]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4613
[i915#5354]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/5354
[i915#7707]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/7707
[i915#9732]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9732

Build changes
-------------

* Linux: CI_DRM_18771 -> Patchwork_169454v4

CI-20190529: 20190529
CI_DRM_18771: 5f3c5d8ad095d09441648d9f564eaee7d9c30bec @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_8990: 8990
Patchwork_169454v4: 5f3c5d8ad095d09441648d9f564eaee7d9c30bec @ git://anongit.freedesktop.org/gfx-ci/linux

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_169454v4/index.html

Reviewed-by on v4 1/1
#2 lore raw
In reply to Jonathan Cavitt

Hi Jonathan,

There was a BAT failure in sound module - I think unrelated to your change.

Quoted 25 lines · Jonathan Cavitt

The functions intel_guc_send_busy_loop and ct_send can theoretically loop forever. In the former case, intel_guc_send_busy_loop can iterate forever if intel_guc_send_nb repeatedly returns -EBUSY. In the latter case, ct_send can loop forever if the guc-to-host or host-to-guc buffers get stuck in a full state.

Rework the functions to use the poll_timeout_us family of functions instead of calculating sleep_period_ms repeatedly. In both cases now, if the loop condition is not met after 10 minutes, the function will report it as a failure.

This also resolves a static analysis issue involving sleep_period_ms overflowing after several shift-left-logical calls.

v2:
- Reduce default sleep/udelay duration (jcavitt)

v3:
- Use atomic in ct_send (jcavitt)

v4:
- Rework ct_send reimplementation to better preserve original logic (Andi)
- Define 10 minutes to remove magic numbers (Krzysztof)

Quoted 5 lines

---

The patch looks good to me:

Signature · 2 lines
Best Regards,
Krzysztof
#3 lore raw
In reply to Jonathan Cavitt

Hi Jonathan,

...

drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 785

Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12 -0
+	/*
+	 * We use a lazy spin wait loop here as we believe that if the CT
+	 * buffers are sized correctly the flow control condition should be
+	 * rare. Reserving the maximum size in the G2H credits as we don't know
+	 * how big the response is going to be.
+	 */
+	timedout = poll_timeout_us_atomic(err = ct_lazy_spin(ct, &request, action,
+							     len, response_buf,
+							     response_buf_size,
+							     status),
+					  err != -EBUSY, USEC_PER_MSEC,
+					  POLL_TIMEOUT_DUR, false);

now poll timeout is not running in atomic context, is there any problem in using simply poll_timeout_us() instead of its _atomic() brother?

Andi

Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6 -0
+
+	/* This is only the case if ct is deadlocked or we time out */
+	if (ct->stall_time != KTIME_MAX)
+		return timedout ?: err;
+
+	/* Otherwise, ct_write failed and we need to clean up */
 	if (unlikely(err))
 		goto unlink;
Signature · 2 lines
-- 
2.53.0
#4 lore raw

-----Original Message-----
From: Andi Shyti <[email protected]>
Sent: Friday, July 24, 2026 5:50 AM
To: Cavitt, Jonathan <[email protected]>
Cc: [email protected]; Zuo, Alex <[email protected]>; [email protected]; Shyti, Andi <[email protected]>; Karas, Krzysztof <[email protected]>
Subject: Re: [PATCH v4] drm/i915/gt: Use poll_timeout_us in place of sliding sleep window

Quoted 5 lines

Hi Jonathan,

...

Quoted 16 lines

drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 785

Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12 -0
+	/*
+	 * We use a lazy spin wait loop here as we believe that if the CT
+	 * buffers are sized correctly the flow control condition should be
+	 * rare. Reserving the maximum size in the G2H credits as we don't know
+	 * how big the response is going to be.
+	 */
+	timedout = poll_timeout_us_atomic(err = ct_lazy_spin(ct, &request, action,
+							     len, response_buf,
+							     response_buf_size,
+							     status),
+					  err != -EBUSY, USEC_PER_MSEC,
+					  POLL_TIMEOUT_DUR, false);

now poll timeout is not running in atomic context, is there any problem in using simply poll_timeout_us() instead of its _atomic() brother?

I... don't know? I guess I can swap it over and we can see if something breaks during CI validation.
-Jonathan Cavitt

Quoted 16 lines

Andi

Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6 -0
+
+	/* This is only the case if ct is deadlocked or we time out */
+	if (ct->stall_time != KTIME_MAX)
+		return timedout ?: err;
+
+	/* Otherwise, ct_write failed and we need to clean up */
 	if (unlikely(err))
 		goto unlink;
Signature · 2 lines
-- 
2.53.0