From patchwork Wed May 17 20:31:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 95540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp36799vqo; Wed, 17 May 2023 13:33:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lQImf94WmmlV4BAaCHOro2fsnlCL1RC7SijqrP3+N2uc7TyxdcZJptql8l6AL0oN9pNgC X-Received: by 2002:a17:902:8482:b0:1a6:3799:ec2a with SMTP id c2-20020a170902848200b001a63799ec2amr49701plo.35.1684355602366; Wed, 17 May 2023 13:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684355602; cv=none; d=google.com; s=arc-20160816; b=j+ppd2F6OywCR25M8QAZNnY5mnLtCVdB7iBEUPR3SMAlr2zjfmFQeVhdcM5622Mvsk edO0Ushr+rYe1Fjka0qflXfDIo7Aj4/DLRMu8pbf4JdPtxFNkkOySBEdkGkZDuMCESc+ T5aftMMItXyU1r+JlxiQA8dZEiTU8jvjYsZSKKbvTzfB5BWjDdc3mN5SdgCgNdx5CpPC VnEEJWR0svpqpAThK939KQEwmbaYs7fw3bV1K6YZZYE9om7tWdm62/fFyUIf3ElX7kaU UmiJ/m3sk+McMoEjIQUkKkxWcugccXl5mMiwYVPAfD6bbmbIta11ikYpDJUUo2SUtwq1 qPHw== 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=aOsrinT2/iaeBb0WCg7wbvs+eW6FJ9BpP6VKG3yyBao=; b=InuBUUSNY0h2VJrpsAqop9UrsKtVQPe48fQDkCpI+MENP0HugKhpiQ1FaENnbZ1X54 QTTEW13ybPI1Pyaegut75UYh7yjYpMch2ft4/khxNKEWmklf4njfkUCzNkO9PADwPDH0 YmBOqyV83f9fRmFgBaLYN9LV6OwlAiIfvSw4tnDYx65dCbyC1JI+GKjKJ4m9SUehwTH4 +U2neKHqBNRKVdMdapRXDcoyS93qzLYM8Re8n/JmDYegmRmRl2Yg7eRpFKuDvWh5icQX Oywru87tf/HK7r8hY+0Z4tofI9rKednc1FgJt17ZG5poAdy4UUFqVT0g/bLxPWqLPqpC vk9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=H6PERSAk; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c17-20020a170902d49100b0019b090e497esi23065539plg.298.2023.05.17.13.33.10; Wed, 17 May 2023 13:33:22 -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=H6PERSAk; 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 S229826AbjEQUbr (ORCPT + 99 others); Wed, 17 May 2023 16:31:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbjEQUbf (ORCPT ); Wed, 17 May 2023 16:31:35 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 058FC9037 for ; Wed, 17 May 2023 13:31:33 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id 4fb4d7f45d1cf-50bc456a94dso1283225a12.1 for ; Wed, 17 May 2023 13:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684355491; x=1686947491; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aOsrinT2/iaeBb0WCg7wbvs+eW6FJ9BpP6VKG3yyBao=; b=H6PERSAkTTYE2cWlo4VM3SlqSWM7x5pxRQ0xuWDg3VOBNyhF2hvGKULDhDPgLi2z3g B6Z0eUxWVpg5g5oXZLmaug777isU03Z+nfEJ5ms9qAPmuVNsFW1fc8qMU7nD99034pQy JBR5MzZlyYJrWwX4d7Pd79YdlG1fLg6EbSOgLlcg8D+RArG3dkHGoOpFv7Or62NCvRzf ULBHvzIUC6W1xuBIfvCrqHqTKetHK8rZJFGSh+P0Z8yHzoPYw5anwwjpuCKLIgGlnJaH caRHHNXst0n42JTDJdFiZhG2I1wLxulOebTtWnSeGO+dGTMUCBk6ViszJYZzaZ9AxwrI enWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684355491; x=1686947491; 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=aOsrinT2/iaeBb0WCg7wbvs+eW6FJ9BpP6VKG3yyBao=; b=Z8obwwZ7PrcoKcgeE4UG8PMyK7B/Q+KLfqxr4fxD6ZX5likCybDPRRHqW1OK+OBu9b XkR8ZF6snzxUPe5Qxn1pa6ZvXy73IxG2TZ4ftw0YBPWlHM1zFG+zx32D+Of2JlJw2Xed zFrmygeZzBBktPxfyL8WGu+EKLMzAGSmhsJ6zg++ur2qATNYpPViUmmV9Va/4S63rdeh Fy9zaw4bFQn2sbcfwZTpwX3NjsD8EiAo7raV2GQa27D3480C6nXWU8ndDyE1EgCXkoFF PYzw4xq3fZpVwxPEm4dWskrzgDwLHfAlSWJdnQSrPH2PIJ1zHXEmkH8pT0LXD6OG8sNd Edxg== X-Gm-Message-State: AC+VfDzBp+nQwDAlV1WOP6CeF6b1Crb1EBLsEQm/ovhHIMfgsq16DNRI FJkX17lg1492FQOTwANY6F5sm6njELInyeM= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a50:f610:0:b0:50b:d648:a963 with SMTP id c16-20020a50f610000000b0050bd648a963mr1508053edn.6.1684355491066; Wed, 17 May 2023 13:31:31 -0700 (PDT) Date: Wed, 17 May 2023 20:31:16 +0000 In-Reply-To: <20230517203119.3160435-1-aliceryhl@google.com> Mime-Version: 1.0 References: <20230517203119.3160435-1-aliceryhl@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230517203119.3160435-5-aliceryhl@google.com> Subject: [PATCH v1 4/7] 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_Roy_Baron?= " , Benno Lossin , Alice Ryhl , linux-kernel@vger.kernel.org, patches@lists.linux.dev 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,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766174859861432240?= X-GMAIL-MSGID: =?utf-8?q?1766174859861432240?= 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 e66b6b50dfae..22205d3bda72 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -97,3 +97,68 @@ pub unsafe trait WorkItem { 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) } +}