Re: [PATCH 1/2] rust: Add initial interconnect framework abstractions
From: Konrad Dybcio
Date: Wed Jul 23 2025 - 07:37:23 EST
On 7/23/25 12:44 PM, Daniel Sedlak wrote:
> Hi Konrad,
[...]
>> + /// Create a new instance from bits (b) per second
>> + pub const fn from_bits_per_sec(_bps: u32) -> Self {
>> + Self(1)
>> + }
>
> This is a very shady API. If I were to call
>
> let bw = IccBwUnit::from_bits_per_sec(16);
>
> I would expect.
>
> assert_eq!(bw.as_bytes_per_sec(), 2);
>
> But it would fail (assuming that 8 bits = 1 byte), since IccBwUnit::from_bits_per_sec(), always assigns 1.
I followed the C api:
include/linux/interconnect.h
18:#define bps_to_icc(x) (1)
But indeed, something like bw.div_ceil(8) makes more logical sense
>> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
>> index 87bcaa1c6b8a6291e71905e8dde60d945b654b98..60f6ac6e79cce57a8538ea0ad48f34f51af91731 100644
>> --- a/rust/kernel/lib.rs
>> +++ b/rust/kernel/lib.rs
>> @@ -89,6 +89,7 @@
>> pub mod fmt;
>> pub mod fs;
>> pub mod init;
>> +pub mod icc;
>
> Nit: formatting/missing space?
No, it's actually fine.. git decided that context lines shall begin
with a space
Konrad