Rust for Linux List
 help / color / mirror / Atom feed
From: FUJITA Tomonori <tomo@flapping.org>
To: aliceryhl@google.com
Cc: tomo@flapping.org, a.hindborg@kernel.org, ojeda@kernel.org,
	acourbot@nvidia.com, anna-maria@linutronix.de,
	bjorn3_gh@protonmail.com, boqun@kernel.org, dakr@kernel.org,
	daniel.almeida@collabora.com, frederic@kernel.org,
	gary@garyguo.net, jstultz@google.com, lossin@kernel.org,
	lyude@redhat.com, sboyd@kernel.org, tamird@kernel.org,
	tglx@kernel.org, tmgross@umich.edu, work@onurozkan.dev,
	rust-for-linux@vger.kernel.org, fujita.tomonori@gmail.com
Subject: Re: [PATCH v2] rust: time: add Delta::to_jiffies_timeout() for timeout conversion
Date: Tue, 08 Sep 2026 22:45:11 +0900 (JST)	[thread overview]
Message-ID: <20260908.224511.1733725108685542391.tomo@flapping.org> (raw)
In-Reply-To: <aqADhk2Z7ynuawJf@google.com>

On Tue, 8 Sep 2026 12:45:58 +0000
Alice Ryhl <aliceryhl@google.com> wrote:

> On Mon, Sep 07, 2026 at 09:35:24PM +0900, FUJITA Tomonori wrote:
>> diff --git a/rust/helpers/math.c b/rust/helpers/math.c
>> new file mode 100644
>> index 000000000000..e2ee29bcce0f
>> --- /dev/null
>> +++ b/rust/helpers/math.c
>> @@ -0,0 +1,8 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +#include <linux/math64.h>
>> +
>> +__rust_helper u64 rust_helper_mul_u64_add_u64_div_u64(u64 a, u64 b, u64 c, u64 d)
>> +{
>> +	return mul_u64_add_u64_div_u64(a, b, c, d);
>> +}
> 
> This looks like it's never an inline function, so I don't think a helper
> is needed.

It's an inline function on x86; arch/x86/include/asm/div64.h.


>> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
>> index 6c0a5e8090d0..8e9c349b1df7 100644
>> --- a/rust/kernel/time.rs
>> +++ b/rust/kernel/time.rs
>> @@ -39,6 +39,10 @@
>>  /// The number of nanoseconds per second.
>>  pub const NSEC_PER_SEC: i64 = bindings::NSEC_PER_SEC as i64;
>>  
>> +/// The C side `MAX_JIFFY_OFFSET`, i.e. `((LONG_MAX >> 1) - 1)`. It is the upper
>> +/// bound the kernel uses for a jiffies span, not a wait-forever value.
>> +const MAX_JIFFY_OFFSET: isize = (isize::MAX >> 1) - 1;
> 
> Should this be:
> 
> const MAX_JIFFY_OFFSET: Jiffies = (isize::MAX >> 1) - 1;
> 
> The Jiffies type alias is always the same as isize, but it may be more
> clear for readers to use Jiffies for the constant.

Jiffies is crate::ffi::c_ulong, i.e. usize, not isize. And it will be
removed; replacing it with Delta<Jiffy> is what the series is for

https://lore.kernel.org/rust-for-linux/20260808062839.1159990-8-tomo@flapping.org/


>> +        // `bindings::HZ` cannot be used here. bindgen keeps the first definition of a
>> +        // macro and ignores a later `#undef`, so `HZ` resolves to `__USER_HZ`, i.e.
>> +        // 100, from `include/uapi/asm-generic/param.h` instead of `CONFIG_HZ`.
>> +        const HZ: u64 = bindings::CONFIG_HZ as u64;
> 
> Sounds very error-prone. Consider fixing this in rust/bindings/lib.rs
> similar to `compat_ptr_ioctl` and then use bindings::HZ here. This will
> reduce the chance of others using bindings::HZ and getting the wrong
> value.

Good idea, thanks. I'll do that in v3: patch 1 fixes bindings::HZ in lib.rs,
and this patch then uses it.


  reply	other threads:[~2026-09-08 13:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 12:35 [PATCH v2] rust: time: add Delta::to_jiffies_timeout() for timeout conversion FUJITA Tomonori
2026-09-08 12:45 ` Alice Ryhl
2026-09-08 13:45   ` FUJITA Tomonori [this message]
2026-09-08 16:42     ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260908.224511.1733725108685542391.tomo@flapping.org \
    --to=tomo@flapping.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=anna-maria@linutronix.de \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=jstultz@google.com \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tamird@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox