[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLggkZjUbGxDep1852AbL61ofhf_p2xoZOh87u0boVFUbPw@mail.gmail.com>
Date: Tue, 1 Oct 2024 13:33:27 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: netdev@...r.kernel.org, rust-for-linux@...r.kernel.org, andrew@...n.ch,
hkallweit1@...il.com, tmgross@...ch.edu, ojeda@...nel.org,
alex.gaynor@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me, a.hindborg@...sung.com
Subject: Re: [PATCH net-next v1 1/2] rust: add delay abstraction
On Tue, Oct 1, 2024 at 1:27 PM FUJITA Tomonori
<fujita.tomonori@...il.com> wrote:
>
> Add an abstraction for sleep functions in `include/linux/delay.h` for
> dealing with hardware delays.
>
> The kernel supports several `sleep` functions for handles various
> lengths of delay. This adds fsleep helper function, internally calls
> an appropriate sleep function.
>
> This is used by QT2025 PHY driver to wait until a PHY becomes ready.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
> ---
> rust/bindings/bindings_helper.h | 1 +
> rust/helpers/delay.c | 8 ++++++++
> rust/helpers/helpers.c | 1 +
> rust/kernel/delay.rs | 18 ++++++++++++++++++
> rust/kernel/lib.rs | 1 +
There is already a rust/kernel/time.rs file that this can go in.
> +/// Sleeps for a given duration.
> +///
> +/// Equivalent to the kernel's [`fsleep`] function, internally calls `udelay`,
> +/// `usleep_range`, or `msleep`.
> +///
> +/// This function can only be used in a nonatomic context.
> +pub fn sleep(duration: Duration) {
> + // SAFETY: FFI call.
> + unsafe { bindings::fsleep(duration.as_micros() as c_ulong) }
> +}
We should probably call this `fsleep` to match the C side.
Alice
Powered by blists - more mailing lists