Re: [PATCH 1/3] rust: completion: implement initial abstraction
From: Benno Lossin
Date: Thu Jun 12 2025 - 07:15:44 EST
On Thu Jun 12, 2025 at 1:06 PM CEST, Danilo Krummrich wrote:
> On Thu, Jun 12, 2025 at 12:53:45PM +0200, Benno Lossin wrote:
>> On Thu Jun 12, 2025 at 12:35 PM CEST, Danilo Krummrich wrote:
>> > On Thu, Jun 12, 2025 at 10:15:55AM +0200, Benno Lossin wrote:
>> >> On Tue Jun 3, 2025 at 10:48 PM CEST, Danilo Krummrich wrote:
>> >> > + /// Signal all tasks waiting on this completion.
>> >> > + ///
>> >> > + /// This method wakes up all tasks waiting on this completion; after this operation the
>> >> > + /// completion is permanently done.
>> >> > + pub fn complete_all(&self) {
>> >> > + // SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
>> >> > + unsafe { bindings::complete_all(self.as_raw()) };
>> >> > + }
>> >> > +
>> >> > + /// Wait for completion of a task.
>> >> > + ///
>> >> > + /// This method waits for the completion of a task; it is not interruptible and there is no
>> >> > + /// timeout.
>> >>
>> >> Another thing that we should document is weather this function returns
>> >> immediately when `complete_all` was already called in the past.
>> >
>> > The details are all documented in [1], which is also linked in the module
>> > documentation of this file.
>> >
>> > [1] https://docs.kernel.org/scheduler/completion.html
>>
>> I dislike that we don't have the docs right there on the function.
>> Following that link, there is also a lot of other stuff there that don't
>> apply to Rust (eg initializing completions, and the
>> wait_for_completion*() variants).
>>
>> After a bit of reading, I found the part that I was looking for (by
>> searching for `complete_all`...):
>>
>> A thread that wants to signal that the conditions for continuation have
>> been achieved calls `complete()` to signal exactly one of the waiters
>> that it can continue:
>>
>> ```c
>> void complete(struct completion *done)
>> ```
>>
>> ... or calls `complete_all()` to signal all current and future waiters:
>>
>> ```c
>> void complete_all(struct completion *done)
>> ```
>>
>> Let's just put this information on the `complete_all` function.
>
> It's already there, no?
>
> "after this operation the completion is permanently done"
The phrasing in the C docs seems more obvious to me "signal to all
current and future waiters". The "permanently done" part is a bit
ambiguous to me.
---
Cheers,
Benno