Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp844553rwd; Thu, 1 Jun 2023 07:17:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hKiQ6hBtUvQbjUy8Yn0Y5FVIF9Vzd4yrMoFwYKmNpEHol86dtyyJRhm1NikmTdEw4G8TZ X-Received: by 2002:a05:6a20:4392:b0:eb:e2eb:d7ec with SMTP id i18-20020a056a20439200b000ebe2ebd7ecmr6803776pzl.17.1685629054658; Thu, 01 Jun 2023 07:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685629054; cv=none; d=google.com; s=arc-20160816; b=cmAyK8ZatcGryBnvCrS1kT52g2vZS/+17ZydUEebbsviNTaSVO+MsBTZgf6t8yaTpD vsWpYeE/uYMntlwZkhwLynrDM47phgfyVWRBhpukW8CqiCcvvev+cE4c1hAKyKriSl/v Hx0WT69p9QAakFkCH9FYrEFFk8BiIbCD3FPJp5VWFv6m/jE5gNRPGaEee+D18PxaIQuC 2FOL/R7g9B8K3HYHlg7hW4lidh5LkYf1xLAcfs5VyNzPuCI5zHHDjy3KfMo+Z9W5iPc8 rxspf16XYUru7V7HDT95LUHz27ubmi4h8JBpedNpsKS1o9X5pJAnFXHy0xxyeXXNOxP1 rFDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=kFZgiOUIu+kFD/tH5EFpQqSQN/mWPzP02CS5RCs3B9M=; b=KAhcQvN4xVnn8oMLt2e6ukCHRD4cHml/0+tEuFXvUIa/LeIiQ8YMxw/q3grMs1o52+ +yOcISpOUFGm/DM7u5ZkG6qgbG0G9wus7uv1D/CEq7eatUPQV/R9vuCeERqs8j332l8z gsFNFbpSXyumdeUduTD4SehkmrteWrLlmhEHXWkp9AkcEZ2gAFsbYWQ8JHLAzUdFV+uk TwPPuBBDTRv0XGi9X2coVd+GQIhNbCrR0KJbfs9o1S5sKNZqcgcSpuDT+j6M6YwOLMhJ mCAxoaJ3u7KRswqBqA9Jbm9Rk4v6PFsh6T89Mr2cXJcalWxMo4Wn0QZSTNHCq9aKfKeE RR9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=MkzWTGF9; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v67-20020a626146000000b0064d62bda470si321696pfb.302.2023.06.01.07.17.21; Thu, 01 Jun 2023 07:17:34 -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=@google.com header.s=20221208 header.b=MkzWTGF9; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231583AbjFANyD (ORCPT + 99 others); Thu, 1 Jun 2023 09:54:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233016AbjFANyB (ORCPT ); Thu, 1 Jun 2023 09:54:01 -0400 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6778B13D for ; Thu, 1 Jun 2023 06:53:59 -0700 (PDT) Received: by mail-ed1-x54a.google.com with SMTP id 4fb4d7f45d1cf-514b3b99882so706683a12.2 for ; Thu, 01 Jun 2023 06:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685627638; x=1688219638; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kFZgiOUIu+kFD/tH5EFpQqSQN/mWPzP02CS5RCs3B9M=; b=MkzWTGF98V5rWGyl2PEut0MvVD60T25TsJG+nP3EJ0G5Xj9HN/47MO2rJK4nSC8lAD TJvZCwvsHZnHGDFiPXqerEKpexrbHyZ5jkHFur0RTDUcpye/mtH04woakV0u/oTzddFi ErxxJN1cTn+2gjmPjvFwUQd+aIbjKx6adZhQgUS1rFmnHk5ewCWxnCRVk26Do8jsKsXm kwmrZ5wO4mULuKacNSxdAF+hTBRIKHsiOx0dgijn4mDotI5LaPFPj1fzFl3IlRL5TpXy 0qtu9up5ITib15C7+Z77VR0cIS8sBssQbXFZkrc6NmoyqwmKOmd2IQqBo5uEGjolxxCB Nc2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627638; x=1688219638; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kFZgiOUIu+kFD/tH5EFpQqSQN/mWPzP02CS5RCs3B9M=; b=gZh0+JwUIU1KaUqHYgSw6AFokJMqdfcKHBuhpP2FAX9ps1/u5PUOvyc8CdA0zTQEL8 iM/WV+XNDEdL+jCA9MCfA+K7MrxNdSAR1GgdW47kvo9+6VV5OjqcYsSv15pbUC8dP+OK 5iT3R4uY9v+44u9KYzYQTDe/W2StoA1mRm3JSZVXthJVvpS1TrLOWQQF9DpufEOwYwyL 2govK78S5HoAXvJSxmt7ISPpHvSRo0qB/J6sjigBLc24CGJK+VCUxvuJb7GxMK+1Lt7J IYDlR0jixU8PFk72E/gyiJGMlubDwlaZGWToupKtj7uvBwDyy61TmFCsKWqitZUe+Cu2 TujA== X-Gm-Message-State: AC+VfDwof9xGA7G3SV5BN80v5+7Dy0KjQgnsw2k6ej5sOttHGtVxWJis CPFZ6bN2J4ozxBEk1GXjZxilNNwg1/C4ulQ= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a50:f692:0:b0:510:b4dc:165a with SMTP id d18-20020a50f692000000b00510b4dc165amr3036075edn.5.1685627637870; Thu, 01 Jun 2023 06:53:57 -0700 (PDT) Date: Thu, 1 Jun 2023 13:49:42 +0000 In-Reply-To: <20230601134946.3887870-1-aliceryhl@google.com> Mime-Version: 1.0 References: <20230601134946.3887870-1-aliceryhl@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230601134946.3887870-5-aliceryhl@google.com> Subject: [PATCH v2 4/8] rust: workqueue: define built-in queues From: Alice Ryhl To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Wedson Almeida Filho , Tejun Heo , Lai Jiangshan , Alex Gaynor , Boqun Feng , Gary Guo , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Alice Ryhl , linux-kernel@vger.kernel.org, patches@lists.linux.dev, Wedson Almeida Filho , Martin Rodriguez Reboredo Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 From: Wedson Almeida Filho We provide these methods because it lets us access these queues from Rust without using unsafe code. 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. Signed-off-by: Wedson Almeida Filho Co-developed-by: Alice Ryhl Signed-off-by: Alice Ryhl Reviewed-by: Martin Rodriguez Reboredo --- rust/kernel/workqueue.rs | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) 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) -> Self::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 multi-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 which 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 items (`system_long_wq`). +/// +/// It is similar to the one returned by [`system`] but may host long running 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 reached 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_efficient_wq`). +/// +/// It is inclined towards saving power and is converted to "unbound" variants 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 available. + unsafe { Queue::from_raw(bindings::system_power_efficient_wq) } +} + +/// Returns the system freezable power-efficient work queue (`system_freezable_power_efficient_wq`). +/// +/// It is similar to the one returned by [`system_power_efficient`] except that is freezable. +pub fn system_freezable_power_efficient() -> &'static Queue { + // SAFETY: `system_freezable_power_efficient_wq` is a C global, always available. + unsafe { Queue::from_raw(bindings::system_freezable_power_efficient_wq) } +} -- 2.41.0.rc0.172.g3f132b7071-goog