* [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout
@ 2026-03-07 20:47 Artem Lytkin
2026-03-08 22:02 ` Claude review: " Claude Code Review Bot
2026-03-08 22:02 ` Claude Code Review Bot
0 siblings, 2 replies; 3+ messages in thread
From: Artem Lytkin @ 2026-03-07 20:47 UTC (permalink / raw)
To: dri-devel; +Cc: daniel.almeida, aliceryhl, dakr, airlied, simona
The Tyr driver uses fixed 100ms sleeps followed by manual register
checks in l2_power_on() and issue_soft_reset(). Both functions have
TODO comments noting that read_poll_timeout() was not yet available
in Rust.
read_poll_timeout() has since been implemented in the kernel (at
rust/kernel/io/poll.rs) and is actively used by other Rust drivers.
Replace the fixed sleeps with proper read_poll_timeout() calls:
- l2_power_on: 100us poll interval, 20ms timeout (matches the C
panthor driver)
- issue_soft_reset: 1ms poll interval, 100ms timeout (the C driver
uses interrupt-driven wait_event_timeout; polling is used here as
the Tyr driver does not yet have IRQ support)
This also changes the error code on timeout from EIO to ETIMEDOUT,
which better reflects the nature of the failure. No callers in the
driver inspect the specific error code.
Signed-off-by: Artem Lytkin <iprintercanon@gmail.com>
---
drivers/gpu/drm/tyr/driver.rs | 27 ++++++++++-----------------
drivers/gpu/drm/tyr/gpu.rs | 21 ++++++++++-----------
2 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 0389c558c036..f54f5f44e923 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -9,6 +9,7 @@
use kernel::devres::Devres;
use kernel::drm;
use kernel::drm::ioctl;
+use kernel::io::poll::read_poll_timeout;
use kernel::new_mutex;
use kernel::of;
use kernel::platform;
@@ -18,7 +19,7 @@
use kernel::sizes::SZ_2M;
use kernel::sync::Arc;
use kernel::sync::Mutex;
-use kernel::time;
+use kernel::time::Delta;
use kernel::types::ARef;
use crate::file::File;
@@ -68,22 +69,14 @@ unsafe impl Sync for TyrData {}
fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
regs::GPU_CMD.write(dev, iomem, regs::GPU_CMD_SOFT_RESET)?;
- // TODO: We cannot poll, as there is no support in Rust currently, so we
- // sleep. Change this when read_poll_timeout() is implemented in Rust.
- kernel::time::delay::fsleep(time::Delta::from_millis(100));
-
- if regs::GPU_IRQ_RAWSTAT.read(dev, iomem)? & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED == 0 {
- dev_err!(dev, "GPU reset failed with errno\n");
- dev_err!(
- dev,
- "GPU_INT_RAWSTAT is {}\n",
- regs::GPU_IRQ_RAWSTAT.read(dev, iomem)?
- );
-
- return Err(EIO);
- }
-
- Ok(())
+ read_poll_timeout(
+ || regs::GPU_IRQ_RAWSTAT.read(dev, iomem),
+ |val| *val & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED != 0,
+ Delta::from_millis(1),
+ Delta::from_millis(100),
+ )
+ .map(|_| ())
+ .inspect_err(|_| dev_err!(dev, "soft reset timed out\n"))
}
kernel::of_device_table!(
diff --git a/drivers/gpu/drm/tyr/gpu.rs b/drivers/gpu/drm/tyr/gpu.rs
index 6c582910dd5d..76dfdef054f1 100644
--- a/drivers/gpu/drm/tyr/gpu.rs
+++ b/drivers/gpu/drm/tyr/gpu.rs
@@ -4,9 +4,10 @@
use kernel::device::Bound;
use kernel::device::Device;
use kernel::devres::Devres;
+use kernel::io::poll::read_poll_timeout;
use kernel::platform;
use kernel::prelude::*;
-use kernel::time;
+use kernel::time::Delta;
use kernel::transmute::AsBytes;
use crate::driver::IoMem;
@@ -206,14 +207,12 @@ fn from(value: u32) -> Self {
pub(crate) fn l2_power_on(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
regs::L2_PWRON_LO.write(dev, iomem, 1)?;
- // TODO: We cannot poll, as there is no support in Rust currently, so we
- // sleep. Change this when read_poll_timeout() is implemented in Rust.
- kernel::time::delay::fsleep(time::Delta::from_millis(100));
-
- if regs::L2_READY_LO.read(dev, iomem)? != 1 {
- dev_err!(dev, "Failed to power on the GPU\n");
- return Err(EIO);
- }
-
- Ok(())
+ read_poll_timeout(
+ || regs::L2_READY_LO.read(dev, iomem),
+ |val| *val == 1,
+ Delta::from_micros(100),
+ Delta::from_millis(20),
+ )
+ .map(|_| ())
+ .inspect_err(|_| dev_err!(dev, "Failed to power on the GPU\n"))
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Claude review: drm/tyr: replace fixed sleeps with read_poll_timeout
2026-03-07 20:47 [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout Artem Lytkin
@ 2026-03-08 22:02 ` Claude Code Review Bot
2026-03-08 22:02 ` Claude Code Review Bot
1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-03-08 22:02 UTC (permalink / raw)
To: dri-devel-reviews
Overall Series Review
Subject: drm/tyr: replace fixed sleeps with read_poll_timeout
Author: Artem Lytkin <iprintercanon@gmail.com>
Patches: 1
Reviewed: 2026-03-09T08:02:33.913687
---
This is a single patch that replaces fixed 100ms sleeps with `read_poll_timeout()` calls in the Tyr (Rust Mali GPU) driver. The change is well-motivated — the TODO comments in the code explicitly asked for this conversion.
**However, this patch is already superseded.** The drm-next tree already contains this exact conversion (the files at `drivers/gpu/drm/tyr/driver.rs` and `drivers/gpu/drm/tyr/gpu.rs` on drm-next already use `poll::read_poll_timeout`). This explains why the patches could not be applied cleanly. The author appears to have developed against an older tree.
Setting aside the already-landed status, the patch is largely correct but has a few minor differences worth noting compared to what actually landed.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Claude review: drm/tyr: replace fixed sleeps with read_poll_timeout
2026-03-07 20:47 [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout Artem Lytkin
2026-03-08 22:02 ` Claude review: " Claude Code Review Bot
@ 2026-03-08 22:02 ` Claude Code Review Bot
1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-03-08 22:02 UTC (permalink / raw)
To: dri-devel-reviews
Patch Review
**Positive aspects:**
- Commit message is well-written with clear rationale and per-function timeout justification.
- The conversion correctly uses the `read_poll_timeout` API, matching its signature (`op`, `cond`, `sleep_delta`, `timeout_delta`).
- Error code change from `EIO` to `ETIMEDOUT` is appropriate (and the commit message correctly notes no callers inspect the specific error code).
**Issues:**
1. **Polling intervals differ from what landed upstream.** For `l2_power_on`, the patch uses:
```rust
Delta::from_micros(100),
Delta::from_millis(20),
```
The commit message says this "matches the C panthor driver," which may be true for the C driver's values, but the version that landed in drm-next uses `Delta::from_millis(1)` / `Delta::from_millis(100)`. The 100µs poll interval is quite aggressive and may cause unnecessary CPU overhead on slow hardware. On the other hand, 20ms total timeout could be too tight for some platforms. The maintainer clearly chose more conservative values.
2. **`.map(|_| ())` pattern vs `?` + `Ok(())`.** The patch uses:
```rust
.map(|_| ())
.inspect_err(|_| dev_err!(dev, "soft reset timed out\n"))
```
The version that landed uses the more idiomatic:
```rust
.inspect_err(|_| dev_err!(dev, "GPU reset failed."))?;
Ok(())
```
The `.map(|_| ())` approach works but is slightly less clear than the `?` + `Ok(())` pattern, which makes the error propagation path more explicit and is a more common Rust idiom.
3. **Trailing `\n` in error messages.** The patch includes `\n` in `dev_err!` strings (e.g., `"soft reset timed out\n"`). The kernel `dev_err!` macro already appends a newline, so the explicit `\n` would result in a double newline. The landed version correctly omits it (e.g., `"GPU reset failed."`).
4. **Lost diagnostic information in `issue_soft_reset`.** The original code printed the raw register value on failure:
```rust
dev_err!(dev, "GPU_INT_RAWSTAT is {}\n",
regs::GPU_IRQ_RAWSTAT.read(dev, iomem)?
);
```
The patch replaces this with just `"soft reset timed out"`, losing useful debug information. While `read_poll_timeout` makes it harder to report the last polled value (since it's consumed internally), this is a minor regression in debuggability.
**Verdict:** The change itself is correct and addresses a real TODO. However, since this work has already landed in drm-next, this patch is moot. If it were being reviewed for merge, the main feedback would be: fix the double-newline issue, consider using `?` + `Ok(())` instead of `.map(|_| ())`, and verify the timeout values are appropriate for all supported platforms.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-08 22:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-07 20:47 [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout Artem Lytkin
2026-03-08 22:02 ` Claude review: " Claude Code Review Bot
2026-03-08 22:02 ` Claude Code Review Bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox