Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4507043rwd; Sun, 11 Jun 2023 08:52:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6R72I5QYQjk9RvkNq8OtVW3jKeBqXaqpCbttSxktVTxbWMquXvuxETqJc0JxojsnOzr4Tr X-Received: by 2002:a05:6a20:8f24:b0:107:1805:feea with SMTP id b36-20020a056a208f2400b001071805feeamr8681835pzk.37.1686498751438; Sun, 11 Jun 2023 08:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686498751; cv=none; d=google.com; s=arc-20160816; b=iKWV99iz0crR8xK3jUllpy8IYcsPIiqanp5GLs4zIe8ViTx2OQpdCCTIqnXhWSscS8 iNqgbF1/hMTcEUjW7oWebMkOqq4AS9GcvBVABorTxxRlTFkrEuLl8F9hE3piDBBo3//A hfo7KS/gzaWRyxDjTAstc3Q1itf/oqO2PYne1UR3Ow/C2t2+FnE1OE6RrKtZbhSvdkue GLNQ1hDWXDCI0T/h3Cr4icsUlr5w8ZOP+HZOroW9ffu4uUbZPwIO4isFFlcUP2x6oYHM AiFjEdYKLERlBz9j60ntfD3m3R1ykumFIgbfrggHjzW2/ksnV6qgrHSugpATKtOQxJc0 XHxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=lUa+nmeI9yRUbuhP+8bRkBfKWC+0PjnP8iKSG3rcCDU=; b=sCqVp9V/nTL8V+tL7Q3GZcUaFZ/pBV626hQoF3dj3SG2pejlLxu9HoBdm3v64ELBUy 7285QrXEAhh3PpVinEhaVFYsL+SaAG6ddffI+ySnCzzzxV/zuIJSrqMWDo2lDsmoYuAc 0l7wkNvM2d++SnsfCudYl4Y3qQXx7gfLZTU83rIsCIY3+V2cDvQVWpPfKZb671/fNxxG S/NaJ/b2qim/lqO0+5xR3f3vCFt1Z36OZI4x5JS1dUmQP5VsX3ePw3EBhDQZEsU1I/or RTP7KxFArDbIC9TbhSKmvQTJAaozJXybTJs4ezKsyp6DZc6kJX6DCQylJ8zoXTbZXcYC e63w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Duv9LGs1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a63b205000000b00541710a9d44si1598023pge.114.2023.06.11.08.52.19; Sun, 11 Jun 2023 08:52:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Duv9LGs1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231952AbjFKPtt (ORCPT + 99 others); Sun, 11 Jun 2023 11:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbjFKPts (ORCPT ); Sun, 11 Jun 2023 11:49:48 -0400 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28A1713D for ; Sun, 11 Jun 2023 08:49:44 -0700 (PDT) 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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