[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250501.223808.669243726185352431.fujita.tomonori@gmail.com>
Date: Thu, 01 May 2025 22:38:08 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: boqun.feng@...il.com
Cc: miguel.ojeda.sandonis@...il.com, fujita.tomonori@...il.com,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
a.hindborg@...sung.com, frederic@...nel.org, lyude@...hat.com,
tglx@...utronix.de, anna-maria@...utronix.de, jstultz@...gle.com,
sboyd@...nel.org, ojeda@...nel.org, alex.gaynor@...il.com,
gary@...yguo.net, bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
aliceryhl@...gle.com, tmgross@...ch.edu, chrisi.schrefl@...il.com,
arnd@...db.de, linux@...linux.org.uk
Subject: Re: [PATCH v1] rust: time: Avoid 64-bit integer division
On Thu, 1 May 2025 06:25:04 -0700
Boqun Feng <boqun.feng@...il.com> wrote:
> On Thu, May 01, 2025 at 03:22:00PM +0200, Miguel Ojeda wrote:
>> On Thu, May 1, 2025 at 3:12 PM Boqun Feng <boqun.feng@...il.com> wrote:
>> >
>> > #[cfg(CONFIG_ARM)]
>> > fn ns_to_ms(ns: i64) -> i64 {
>> >
>> > #[cfg(not(CONFIG_ARM))]
>> > fn ns_to_ms(ns: i64) -> i64 {
>>
>> I think `cfg`s may be better inside, i.e. as local as reasonably
>> possible, so that we share e.g. signature as well as any attributes
>> and docs.
>>
>
> Fair enough.
I'll go with the following.
#[inline]
pub fn as_millis(self) -> i64 {
#[cfg(CONFIG_ARM)]
// SAFETY: It is always safe to call `ktime_to_ms()` with any value.
unsafe {
bindings::ktime_to_ms(self.as_nanos())
}
#[cfg(not(CONFIG_ARM))]
{
self.as_nanos() / NSEC_PER_MSEC
}
}
Powered by blists - more mailing lists