netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	rust-for-linux@vger.kernel.org, "Gary Guo" <gary@garyguo.net>,
	"Alice Ryhl" <aliceryhl@google.com>,
	me@kloenk.dev, daniel.almeida@collabora.com,
	linux-kernel@vger.kernel.org, Netdev <netdev@vger.kernel.org>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Anna-Maria Gleixner" <anna-maria@linutronix.de>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"John Stultz" <jstultz@google.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Benjamin Segall" <bsegall@google.com>,
	"Mel Gorman" <mgorman@suse.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	tgunders@redhat.com, david.laight.linux@gmail.com,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Jocelyn Falempe" <jfalempe@redhat.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Christian Schrefl" <chrisi.schrefl@gmail.com>,
	"Linus Walleij" <linus.walleij@linaro.org>
Subject: Re: [PATCH v15 5/6] rust: time: Add wrapper for fsleep() function
Date: Tue, 29 Apr 2025 10:15:18 -0700	[thread overview]
Message-ID: <6811092a.050a0220.27f104.5603@mx.google.com> (raw)
In-Reply-To: <1b9e8761-b71f-4015-bf7d-29072b02f2ac@app.fastmail.com>

On Tue, Apr 29, 2025 at 06:11:02PM +0200, Arnd Bergmann wrote:
> On Tue, Apr 29, 2025, at 18:03, Boqun Feng wrote:
> > On Tue, Apr 29, 2025, at 8:51 AM, Arnd Bergmann wrote:
> >> On Tue, Apr 29, 2025, at 15:17, FUJITA Tomonori wrote:
> >>> On Mon, 28 Apr 2025 20:16:47 +0200 Andreas Hindborg <a.hindborg@kernel.org> wrote:
> >>>      /// Return the number of milliseconds in the [`Delta`].
> >>>      #[inline]
> >>> -    pub const fn as_millis(self) -> i64 {
> >>> -        self.as_nanos() / NSEC_PER_MSEC
> >>> +    pub fn as_millis(self) -> i64 {
> >>> +        math64::div64_s64(self.as_nanos(), NSEC_PER_MSEC)
> >>>      }
> >>>  }
> >>
> >> I think simply calling ktime_to_ms()/ktime_to_us() should result
> >> in reasonably efficient code, since the C version is able to
> >> convert the constant divisor into a multiply/shift operation.
> >>
> >
> > Well, before we jump into this, I would like to understand why
> > this is not optimized with multiply/shift operations on arm in
> > Rust code. Ideally all the dividing constants cases should not
> > need to call a C function.
> 
> I think it's just because nobody has rewritten the
> macros from include/asm-generic/div64.h into rust code.
> 
> The compiler could do the same transformation, but they
> generally just fall back to calling a libgcc function.
> 

FWIW, I found this:

	https://github.com/llvm/llvm-project/issues/63731

seems a WIP though.

Would it make sense if we rely on compiler optimization when it's
avaiable (for x86_64, arm64, riscv, etc), and only call ktime_to_ms() if
not? The downside of calling ktime_to_ms() are:

* it's a call function, and cannot be inlined with LTO or INLINE_HELPER:

	https://lore.kernel.org/all/20250319205141.3528424-1-gary@garyguo.net/

* it doesn't provide the overflow checking even if
  CONFIG_RUST_OVERFLOW_CHECKS=y

Thoughts?

Regards,
Boqun

>      Arnd

  reply	other threads:[~2025-04-29 17:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23 19:28 [PATCH v15 0/6] rust: Add IO polling FUJITA Tomonori
2025-04-23 19:28 ` [PATCH v15 1/6] rust: hrtimer: Add Ktime temporarily FUJITA Tomonori
2025-04-23 19:28 ` [PATCH v15 2/6] rust: time: Add PartialEq/Eq/PartialOrd/Ord trait to Ktime FUJITA Tomonori
2025-04-23 19:28 ` [PATCH v15 3/6] rust: time: Introduce Delta type FUJITA Tomonori
2025-04-23 19:28 ` [PATCH v15 4/6] rust: time: Introduce Instant type FUJITA Tomonori
2025-04-23 19:28 ` [PATCH v15 5/6] rust: time: Add wrapper for fsleep() function FUJITA Tomonori
2025-04-28 18:16   ` Andreas Hindborg
2025-04-29 13:17     ` FUJITA Tomonori
2025-04-29 14:16       ` Christian Schrefl
2025-04-29 14:31         ` Russell King (Oracle)
2025-04-29 14:35       ` Miguel Ojeda
2025-04-30 13:51         ` FUJITA Tomonori
2025-04-30 14:50           ` Boqun Feng
2025-04-30 16:43           ` Christian Schrefl
2025-04-29 15:51       ` Arnd Bergmann
2025-04-29 16:03         ` Boqun Feng
2025-04-29 16:11           ` Arnd Bergmann
2025-04-29 17:15             ` Boqun Feng [this message]
2025-04-29 18:33               ` Arnd Bergmann
2025-04-29 19:14                 ` Boqun Feng
2025-04-29 19:27                   ` Boqun Feng
2025-04-23 19:28 ` [PATCH v15 6/6] MAINTAINERS: rust: Add a new section for all of the time stuff FUJITA Tomonori
2025-04-30 10:40 ` [PATCH v15 0/6] rust: Add IO polling Andreas Hindborg

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=6811092a.050a0220.27f104.5603@mx.google.com \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=andrew@lunn.ch \
    --cc=anna-maria@linutronix.de \
    --cc=arnd@arndb.de \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=bsegall@google.com \
    --cc=chrisi.schrefl@gmail.com \
    --cc=daniel.almeida@collabora.com \
    --cc=david.laight.linux@gmail.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=hkallweit1@gmail.com \
    --cc=jfalempe@redhat.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=me@kloenk.dev \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tgunders@redhat.com \
    --cc=tmgross@umich.edu \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).