Re: [PATCH v1] rust: time: Avoid 64-bit integer division

From: Christian Schrefl
Date: Thu May 01 2025 - 19:39:01 EST


On 02.05.25 1:03 AM, Boqun Feng wrote:
> On Thu, May 01, 2025 at 05:11:44PM +0200, Arnd Bergmann wrote:
>> On Thu, May 1, 2025, at 15:20, Boqun Feng wrote:
>>> On Thu, May 01, 2025 at 06:12:02AM -0700, Boqun Feng wrote:
>>>> On Thu, May 01, 2025 at 10:07:17PM +0900, FUJITA Tomonori wrote:
>>>>> On Thu, 1 May 2025 05:26:54 -0700
>>>>> Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
>>>>>
>>>>>> On Thu, May 01, 2025 at 10:58:18AM +0900, FUJITA Tomonori wrote:
>>>>>>> Avoid 64-bit integer division that 32-bit architectures don't
>>>>>>> implement generally. This uses ktime_to_ms() and ktime_to_us()
>>>>>>> instead.
>>>>>>>
>>>>>>> The timer abstraction needs i64 / u32 division so C's div_s64() can be
>>>>>>> used but ktime_to_ms() and ktime_to_us() provide a simpler solution
>>>>>>> for this timer abstraction problem. On some architectures, there is
>>>>>>> room to optimize the implementation of them, but such optimization can
>>>>>>> be done if and when it becomes necessary.
>>>>>>>
>>>>>>
>>>>>> Nacked-by: Boqun Feng <boqun.feng@xxxxxxxxx>
>>>>>>
>>>>>> As I said a few times, we should rely on compiler's optimization when
>>>>>> available, i.e. it's a problem that ARM compiler doesn't have this
>>>>>> optimization, don't punish other architecture of no reason.
>>
>> What is Arm specific here? I'm not aware of the compiler doing anything
>
> Because Arm is the only 32bit architecture that selects CONFIG_HAVE_RUST
> for non-UML cases, i.e. this is the only 32bit architecture that has
> this problem. If your point is we should do this for all 32bit
> architectures, then I won't disagree. Just s/CONFIG_ARM/CONFIG_32BIT
> then.

I would be for using `CONFIG_32BIT` since from what I understand this
applies to all 32bit architectures. It feels a bit weird to single out
arm just because it is the only one that currently has rust support.

Cheers
Christian

>
> Regards,
> Boqun
>
>> different from the other 32-bit architectures, though most are missing
>> an optimized __arch_xprod_64() and fall back to slightly worse code
>> from the asm-generic version.
>>
>>> Copy-paste errors:
>>>
>>> unsafe { bindings::ktime_to_ms(ns) }
>>>
>>>> }
>>>>
>>>> #[cfg(not(CONFIG_ARM))]
>>>> fn ns_to_ms(ns: i64) -> i64 {
>>>> self.as_nanos() / NSEC_PER_MSEC
>>>
>>> ns / NSEC_PER_MSEC
>>
>> I'm sure this is still broken on all 32-bit targets.
>>
>> Arnd