Re: [PATCH net-next v2 4/6] rust: time: add wrapper for fsleep function
From: FUJITA Tomonori
Date: Wed Oct 09 2024 - 09:29:28 EST
On Mon, 7 Oct 2024 14:24:03 +0200
Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>> +/// Sleeps for a given duration.
>> +///
>> +/// Equivalent to the kernel's [`fsleep`], flexible sleep function,
>> +/// which automatically chooses the best sleep method based on a duration.
>> +///
>> +/// `Delta` must be longer than one microsecond.
>> +///
>> +/// This function can only be used in a nonatomic context.
>> +pub fn fsleep(delta: Delta) {
>> + // SAFETY: FFI call.
>> + unsafe { bindings::fsleep(delta.as_micros() as c_ulong) }
>> +}
>
> This rounds down. Should this round it up to the nearest microsecond
> instead? It's generally said that fsleep should sleep for at least the
> provided duration, but that it may sleep for longer under some
> circumstances. By rounding up, you preserve that guarantee.
I'll round up in the next version.
> Also, the note about always sleeping for "at least" the duration may
> be a good fit for the docs here as well.
I see, will add it.