* [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev
@ 2026-06-30 21:04 Breno Rodrigues Alves
2026-06-30 21:10 ` Miguel Ojeda
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Breno Rodrigues Alves @ 2026-06-30 21:04 UTC (permalink / raw)
To: alexander.deucher, gregkh, ojeda
Cc: christian.koenig, arnd, rust-for-linux, amd-gfx, linux-kernel,
Breno Rodrigues Alves
This patch introduces an automated indexed state mechanism to optimize
VRAM latency and command loops for the Radeon RX 580 architecture.
Additionally, it provides a converted C-to-Rust sample char driver.
Signed-off-by: Breno Rodrigues Alves <breno3011alves@gmail.com>
---
Documentation/rust/alves_guidelines.rst | 3 ++
drivers/char/Kconfig | 7 +++++
drivers/char/alves_char_dev.rs | 31 +++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/Makefile | 1 +
drivers/gpu/drm/amd/amdgpu/alves_core.rs | 38 ++++++++++++++++++++++++
5 files changed, 80 insertions(+)
create mode 100644 Documentation/rust/alves_guidelines.rst
create mode 100644 drivers/char/alves_char_dev.rs
create mode 100644 drivers/gpu/drm/amd/amdgpu/alves_core.rs
diff --git a/Documentation/rust/alves_guidelines.rst b/Documentation/rust/alves_guidelines.rst
new file mode 100644
index 000000000..f6afa63de
--- /dev/null
+++ b/Documentation/rust/alves_guidelines.rst
@@ -0,0 +1,3 @@
+# Rust for Linux - Core Guidelines
+- Style: Linear, pragmatic, flat, Linus Torvalds style.
+- Constraints: Zero-cost abstractions, strict RAII, no binary bloat.
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 9865227af..ace4df826 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -372,3 +372,10 @@ config ADI
driver include crash and makedumpfile.
endmenu
+config ALVES_CHAR_DEV
+ tristate "Alves C-to-Rust Character Device Driver"
+ depends on RUST
+ help
+ This is a character device driver migrated from C to Rust.
+ It acts as a core showcase of 2% module conversions.
+ Say Y or M here if you want to test the Rust infrastructure.
diff --git a/drivers/char/alves_char_dev.rs b/drivers/char/alves_char_dev.rs
new file mode 100644
index 000000000..5ccb80ea4
--- /dev/null
+++ b/drivers/char/alves_char_dev.rs
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+//! Simple Character Device converted from legacy C to Rust using core Miscdev API.
+
+use kernel::prelude::*;
+use kernel::miscdev;
+
+module! {
+ type: AlvesCharDevice,
+ name: "alves_char_dev",
+ author: "Breno Rodrigues Alves",
+ description: "Pragmatic C-to-Rust converted character device driver",
+ license: "GPL OR MIT",
+}
+
+struct AlvesCharDevice {
+ _dev: miscdev::Registration<AlvesCharDevice>,
+}
+
+#[vtable]
+impl miscdev::Options for AlvesCharDevice {
+ const NAME: \&"static CStr = c_str!("alves_char_dev");
+}
+
+impl kernel::Module for AlvesCharDevice {
+ fn init(module: \&"static ThisModule) -> Result<Self> {
+ pr_info!("Alves C-to-Rust module initialized successfully
+");
+ let dev = miscdev::Registration::new_reg(module)?;
+ Ok(AlvesCharDevice { _dev: dev })
+ }
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile
index ba80542ea..b9f98c3e4 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -349,3 +349,4 @@ include $(AMD_GPU_RAS_FULL_PATH)/Makefile
amdgpu-y += $(AMD_GPU_RAS_FILES)
obj-$(CONFIG_DRM_AMDGPU)+= amdgpu.o
+amdgpu-y += alves_core.o
diff --git a/drivers/gpu/drm/amd/amdgpu/alves_core.rs b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
new file mode 100644
index 000000000..aa436763e
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+//! AMDGPU RX 580 State Optimization Engine (Turing-inspired state machine)
+//!
+//! Copyright (C) 2026 Breno Rodrigues Alves.
+
+use kernel::prelude::*;
+
+#[derive(Copy, Clone, PartialEq, Eq)]
+#[repr(u8)]
+enum GpuState {
+ Idling = 0,
+ LowPower = 1,
+ ComputeActive = 2,
+ VramMaxPerf = 3,
+}
+
+struct Rx580Engine {
+ current_state: GpuState,
+}
+
+impl Rx580Engine {
+ fn transition(&mut self, symbol: u8) {
+ self.current_state = match (self.current_state, symbol) {
+ (GpuState::Idling, 0x01) => GpuState::LowPower,
+ (GpuState::LowPower, 0x02) => GpuState::ComputeActive,
+ (GpuState::ComputeActive, 0x03) => GpuState::VramMaxPerf,
+ (GpuState::VramMaxPerf, 0x00) => GpuState::Idling,
+ (state, _) => state,
+ };
+ }
+}
+
+#[no_mangle]
+pub extern "C" fn amdgpu_rust_rx580_optimize(register_sample: u32) {
+ let mut engine = Rx580Engine { current_state: GpuState::Idling };
+ let symbol = (register_sample \& 0xFF) as u8;
+ engine.transition(symbol);
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev
2026-06-30 21:04 [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev Breno Rodrigues Alves
@ 2026-06-30 21:10 ` Miguel Ojeda
2026-07-01 10:32 ` Greg KH
2026-07-02 18:50 ` Julian Braha
2 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2026-06-30 21:10 UTC (permalink / raw)
To: Breno Rodrigues Alves
Cc: alexander.deucher, gregkh, ojeda, christian.koenig, arnd,
rust-for-linux, amd-gfx, linux-kernel
On Tue, Jun 30, 2026 at 11:04 PM Breno Rodrigues Alves
<breno3011alves@gmail.com> wrote:
>
> diff --git a/Documentation/rust/alves_guidelines.rst b/Documentation/rust/alves_guidelines.rst
> new file mode 100644
> index 000000000..f6afa63de
> --- /dev/null
> +++ b/Documentation/rust/alves_guidelines.rst
> @@ -0,0 +1,3 @@
> +# Rust for Linux - Core Guidelines
> +- Style: Linear, pragmatic, flat, Linus Torvalds style.
> +- Constraints: Zero-cost abstractions, strict RAII, no binary bloat.
What is this? And how is it possible that you changed this file (and
also tested the typo) within minutes of v2 submission?
Is this submission generated with AI? Please see:
https://docs.kernel.org/process/generated-content.html
https://docs.kernel.org/process/coding-assistants.html
Please observe the ~week delay between submissions. Also please add
changelogs for your submissions etc. Please see:
https://docs.kernel.org/process/submitting-patches.html
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev
2026-06-30 21:04 [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev Breno Rodrigues Alves
2026-06-30 21:10 ` Miguel Ojeda
@ 2026-07-01 10:32 ` Greg KH
2026-07-02 18:50 ` Julian Braha
2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-07-01 10:32 UTC (permalink / raw)
To: Breno Rodrigues Alves
Cc: alexander.deucher, ojeda, christian.koenig, arnd, rust-for-linux,
amd-gfx, linux-kernel
On Tue, Jun 30, 2026 at 06:04:45PM -0300, Breno Rodrigues Alves wrote:
> This patch introduces an automated indexed state mechanism to optimize
> VRAM latency and command loops for the Radeon RX 580 architecture.
> Additionally, it provides a converted C-to-Rust sample char driver.
>
> Signed-off-by: Breno Rodrigues Alves <breno3011alves@gmail.com>
> ---
> Documentation/rust/alves_guidelines.rst | 3 ++
> drivers/char/Kconfig | 7 +++++
> drivers/char/alves_char_dev.rs | 31 +++++++++++++++++++
> drivers/gpu/drm/amd/amdgpu/Makefile | 1 +
> drivers/gpu/drm/amd/amdgpu/alves_core.rs | 38 ++++++++++++++++++++++++
> 5 files changed, 80 insertions(+)
> create mode 100644 Documentation/rust/alves_guidelines.rst
> create mode 100644 drivers/char/alves_char_dev.rs
> create mode 100644 drivers/gpu/drm/amd/amdgpu/alves_core.rs
>
> diff --git a/Documentation/rust/alves_guidelines.rst b/Documentation/rust/alves_guidelines.rst
> new file mode 100644
> index 000000000..f6afa63de
> --- /dev/null
> +++ b/Documentation/rust/alves_guidelines.rst
> @@ -0,0 +1,3 @@
> +# Rust for Linux - Core Guidelines
> +- Style: Linear, pragmatic, flat, Linus Torvalds style.
> +- Constraints: Zero-cost abstractions, strict RAII, no binary bloat.
> diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
> index 9865227af..ace4df826 100644
> --- a/drivers/char/Kconfig
> +++ b/drivers/char/Kconfig
> @@ -372,3 +372,10 @@ config ADI
> driver include crash and makedumpfile.
>
> endmenu
> +config ALVES_CHAR_DEV
> + tristate "Alves C-to-Rust Character Device Driver"
> + depends on RUST
> + help
> + This is a character device driver migrated from C to Rust.
> + It acts as a core showcase of 2% module conversions.
> + Say Y or M here if you want to test the Rust infrastructure.
> diff --git a/drivers/char/alves_char_dev.rs b/drivers/char/alves_char_dev.rs
> new file mode 100644
> index 000000000..5ccb80ea4
> --- /dev/null
> +++ b/drivers/char/alves_char_dev.rs
> @@ -0,0 +1,31 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +//! Simple Character Device converted from legacy C to Rust using core Miscdev API.
Where is the original C code?
And what is going to interact with this in userspace? And how?
> +
> +use kernel::prelude::*;
> +use kernel::miscdev;
> +
> +module! {
> + type: AlvesCharDevice,
> + name: "alves_char_dev",
> + author: "Breno Rodrigues Alves",
> + description: "Pragmatic C-to-Rust converted character device driver",
> + license: "GPL OR MIT",
> +}
> +
> +struct AlvesCharDevice {
> + _dev: miscdev::Registration<AlvesCharDevice>,
> +}
> +
> +#[vtable]
> +impl miscdev::Options for AlvesCharDevice {
> + const NAME: \&"static CStr = c_str!("alves_char_dev");
> +}
> +
> +impl kernel::Module for AlvesCharDevice {
> + fn init(module: \&"static ThisModule) -> Result<Self> {
> + pr_info!("Alves C-to-Rust module initialized successfully
> +");
> + let dev = miscdev::Registration::new_reg(module)?;
> + Ok(AlvesCharDevice { _dev: dev })
> + }
> +}
This code doesn't actually do anything at all, how was it tested?
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile
> index ba80542ea..b9f98c3e4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -349,3 +349,4 @@ include $(AMD_GPU_RAS_FULL_PATH)/Makefile
> amdgpu-y += $(AMD_GPU_RAS_FILES)
>
> obj-$(CONFIG_DRM_AMDGPU)+= amdgpu.o
> +amdgpu-y += alves_core.o
> diff --git a/drivers/gpu/drm/amd/amdgpu/alves_core.rs b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
> new file mode 100644
> index 000000000..aa436763e
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
> @@ -0,0 +1,38 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +//! AMDGPU RX 580 State Optimization Engine (Turing-inspired state machine)
> +//!
> +//! Copyright (C) 2026 Breno Rodrigues Alves.
> +
> +use kernel::prelude::*;
> +
> +#[derive(Copy, Clone, PartialEq, Eq)]
> +#[repr(u8)]
> +enum GpuState {
> + Idling = 0,
> + LowPower = 1,
> + ComputeActive = 2,
> + VramMaxPerf = 3,
> +}
> +
> +struct Rx580Engine {
> + current_state: GpuState,
> +}
> +
> +impl Rx580Engine {
> + fn transition(&mut self, symbol: u8) {
> + self.current_state = match (self.current_state, symbol) {
> + (GpuState::Idling, 0x01) => GpuState::LowPower,
> + (GpuState::LowPower, 0x02) => GpuState::ComputeActive,
> + (GpuState::ComputeActive, 0x03) => GpuState::VramMaxPerf,
> + (GpuState::VramMaxPerf, 0x00) => GpuState::Idling,
> + (state, _) => state,
> + };
> + }
> +}
> +
> +#[no_mangle]
> +pub extern "C" fn amdgpu_rust_rx580_optimize(register_sample: u32) {
> + let mut engine = Rx580Engine { current_state: GpuState::Idling };
> + let symbol = (register_sample \& 0xFF) as u8;
> + engine.transition(symbol);
> +}
Same here, this code doesn't do anything that I can tell. How was it
tested?
confused,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev
2026-06-30 21:04 [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev Breno Rodrigues Alves
2026-06-30 21:10 ` Miguel Ojeda
2026-07-01 10:32 ` Greg KH
@ 2026-07-02 18:50 ` Julian Braha
2 siblings, 0 replies; 4+ messages in thread
From: Julian Braha @ 2026-07-02 18:50 UTC (permalink / raw)
To: Breno Rodrigues Alves, alexander.deucher, gregkh, ojeda
Cc: christian.koenig, arnd, rust-for-linux, amd-gfx, linux-kernel
Hi Breno,
On 6/30/26 22:04, Breno Rodrigues Alves wrote:
> This patch introduces an automated indexed state mechanism to optimize
> VRAM latency and command loops for the Radeon RX 580 architecture.
> Additionally, it provides a converted C-to-Rust sample char driver.
>
> Signed-off-by: Breno Rodrigues Alves <breno3011alves@gmail.com>
> ---
In each revision of your patch, could you include the changelog and
links to previous iterations, here below the ---?
- Julian Braha
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-02 18:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 21:04 [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev Breno Rodrigues Alves
2026-06-30 21:10 ` Miguel Ojeda
2026-07-01 10:32 ` Greg KH
2026-07-02 18:50 ` Julian Braha
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox