[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aRb6GPDZo3kaoeKm@google.com>
Date: Fri, 14 Nov 2025 09:44:56 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Tejun Heo <tj@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
Lai Jiangshan <jiangshanlai@...il.com>, Gary Guo <gary@...yguo.net>,
"Björn Roy Baron" <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Daniel Almeida <daniel.almeida@...labora.com>, John Hubbard <jhubbard@...dia.com>,
Philipp Stanner <phasta@...nel.org>, Tamir Duberstein <tamird@...il.com>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, Benno Lossin <lossin@...nel.org>
Subject: Re: [PATCH v2 2/2] rust: workqueue: add creation of workqueues
On Thu, Nov 13, 2025 at 11:52:17AM -0800, Boqun Feng wrote:
> On Thu, Nov 13, 2025 at 10:01:07AM +0000, Alice Ryhl wrote:
> > Creating workqueues is needed by various GPU drivers. Not only does it
> > give you better control over execution, it also allows devices to ensure
> > that all tasks have exited before the device is unbound (or similar) by
> > running the workqueue destructor.
> >
> > A wrapper type Flags is provided for workqueue flags. It allows you to
> > build any valid flag combination, while using a type-level marker for
> > whether WQ_BH is used to prevent invalid flag combinations. The Flags wrapper
> > also forces you to explicitly pick one of percpu, unbound, or bh.
> >
> > Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
> [...]
> > +/// An owned kernel work queue.
> > +///
> > +/// Dropping a workqueue blocks on all pending work.
> > +///
> > +/// # Invariants
> > +///
> > +/// `queue` points at a valid workqueue that is owned by this `OwnedQueue`.
> > +pub struct OwnedQueue {
> > + queue: NonNull<Queue>,
>
> I hope Owned/Ownable can make it just a Owned<Queue> here ;-) And
> that'll make Owned<Queue> automatically Send + Sync. I think it's not a
> rare ask for `OwnedQueue` to be Send + Sync.
Oh yeah it should be Send/Sync.
And hopefully we get Owned eventually.
> > +}
> > +
> > +#[expect(clippy::manual_c_str_literals)]
> > +impl OwnedQueue {
> > + /// Allocates a new workqueue.
> > + ///
> > + /// The provided name is used verbatim as the workqueue name.
> > + ///
> > + /// # Examples
> > + ///
> > + /// ```
> > + /// use kernel::c_str;
> > + /// use kernel::workqueue::{OwnedQueue, Flags};
> > + ///
> > + /// let wq = OwnedQueue::new(c_str!("my-wq"), Flags::unbound().sysfs(), 0)?;
> > + /// wq.try_spawn(
> > + /// GFP_KERNEL,
> > + /// || pr_warn!("Printing from my-wq"),
> > + /// )?;
> > + /// # Ok::<(), Error>(())
> > + /// ```
> > + #[inline]
> > + pub fn new<const BH: bool>(
> > + name: &CStr,
> > + flags: Flags<BH>,
> > + max_active: usize,
>
> Do we need to support `max_active` as `usize` when the underlying C
> code only support i32?
Negative values don't really make sense. But maybe it's a good idea,
yeah.
Alice
Powered by blists - more mailing lists