From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD0CBC126 for ; Sun, 11 Jun 2023 15:49:53 +0000 (UTC) Date: Sun, 11 Jun 2023 15:49:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1686498582; x=1686757782; bh=lUa+nmeI9yRUbuhP+8bRkBfKWC+0PjnP8iKSG3rcCDU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Duv9LGs1zXCAeHvUkMjATp4l0b0KzAFUW0IRfyYYAKz8HsC/QyKACYp+fREYpLrL3 6sQo2gK5KYs2QDQjYsN6w1Liufz0P+foa+/nJGoVRbhd4hBXbvOfuN2yGj0Dptj7UZ ufO68LfLoAqNdoFqc8QUbE03nakZmg9kcQK4YFqtMPex/8Lg+Dk6JrplFVlgjtrm1i mqB4liK2CHBtb6WHdFGLu+aPbr7VVqhuKvq6AEOfytsEmW6ZKd5bmsdvjvcmJPRjR9 szCMsJq49aqJMzaVzHT/LZr8KH/lF/z4doFthVYqqcnpXY0J9bHMwucSPUYXpAQxmb VQ1lmfHsz9SaA== To: Alice Ryhl From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Wedson Almeida Filho , Tejun Heo , Lai Jiangshan , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , linux-kernel@vger.kernel.org, patches@lists.linux.dev, Wedson Almeida Filho , Martin Rodriguez Reboredo Subject: Re: [PATCH v2 4/8] rust: workqueue: define built-in queues Message-ID: In-Reply-To: <20230601134946.3887870-5-aliceryhl@google.com> References: <20230601134946.3887870-1-aliceryhl@google.com> <20230601134946.3887870-5-aliceryhl@google.com> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01.06.23 15:49, Alice Ryhl wrote: > From: Wedson Almeida Filho >=20 > We provide these methods because it lets us access these queues from > Rust without using unsafe code. >=20 > These methods return `&'static Queue`. References annotated with the > 'static lifetime are used when the referent will stay alive forever. > That is ok for these queues because they are global variables and cannot > be destroyed. >=20 > Signed-off-by: Wedson Almeida Filho > Co-developed-by: Alice Ryhl > Signed-off-by: Alice Ryhl > Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Benno Lossin --=20 Cheers, Benno > --- > rust/kernel/workqueue.rs | 65 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 65 insertions(+) >=20 > diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs > index 9c630840039b..e37820f253f6 100644 > --- a/rust/kernel/workqueue.rs > +++ b/rust/kernel/workqueue.rs > @@ -105,3 +105,68 @@ unsafe fn __enqueue(self, queue_work_on: F) -> Se= lf::EnqueueOutput > where > F: FnOnce(*mut bindings::work_struct) -> bool; > } > + > +/// Returns the system work queue (`system_wq`). > +/// > +/// It is the one used by `schedule[_delayed]_work[_on]()`. Multi-CPU mu= lti-threaded. There are > +/// users which expect relatively short queue flush time. > +/// > +/// Callers shouldn't queue work items which can run for too long. > +pub fn system() -> &'static Queue { > + // SAFETY: `system_wq` is a C global, always available. > + unsafe { Queue::from_raw(bindings::system_wq) } > +} > + > +/// Returns the system high-priority work queue (`system_highpri_wq`). > +/// > +/// It is similar to the one returned by [`system`] but for work items w= hich require higher > +/// scheduling priority. > +pub fn system_highpri() -> &'static Queue { > + // SAFETY: `system_highpri_wq` is a C global, always available. > + unsafe { Queue::from_raw(bindings::system_highpri_wq) } > +} > + > +/// Returns the system work queue for potentially long-running work item= s (`system_long_wq`). > +/// > +/// It is similar to the one returned by [`system`] but may host long ru= nning work items. Queue > +/// flushing might take relatively long. > +pub fn system_long() -> &'static Queue { > + // SAFETY: `system_long_wq` is a C global, always available. > + unsafe { Queue::from_raw(bindings::system_long_wq) } > +} > + > +/// Returns the system unbound work queue (`system_unbound_wq`). > +/// > +/// Workers are not bound to any specific CPU, not concurrency managed, = and all queued work items > +/// are executed immediately as long as `max_active` limit is not reache= d and resources are > +/// available. > +pub fn system_unbound() -> &'static Queue { > + // SAFETY: `system_unbound_wq` is a C global, always available. > + unsafe { Queue::from_raw(bindings::system_unbound_wq) } > +} > + > +/// Returns the system freezable work queue (`system_freezable_wq`). > +/// > +/// It is equivalent to the one returned by [`system`] except that it's = freezable. > +pub fn system_freezable() -> &'static Queue { > + // SAFETY: `system_freezable_wq` is a C global, always available. > + unsafe { Queue::from_raw(bindings::system_freezable_wq) } > +} > + > +/// Returns the system power-efficient work queue (`system_power_efficie= nt_wq`). > +/// > +/// It is inclined towards saving power and is converted to "unbound" va= riants if the > +/// `workqueue.power_efficient` kernel parameter is specified; otherwise= , it is similar to the one > +/// returned by [`system`]. > +pub fn system_power_efficient() -> &'static Queue { > + // SAFETY: `system_power_efficient_wq` is a C global, always availab= le. > + unsafe { Queue::from_raw(bindings::system_power_efficient_wq) } > +} > + > +/// Returns the system freezable power-efficient work queue (`system_fre= ezable_power_efficient_wq`). > +/// > +/// It is similar to the one returned by [`system_power_efficient`] exce= pt that is freezable. > +pub fn system_freezable_power_efficient() -> &'static Queue { > + // SAFETY: `system_freezable_power_efficient_wq` is a C global, alwa= ys available. > + unsafe { Queue::from_raw(bindings::system_freezable_power_efficient_= wq) } > +} > -- > 2.41.0.rc0.172.g3f132b7071-goog >=20