Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1060921rwb; Thu, 10 Nov 2022 10:38:38 -0800 (PST) X-Google-Smtp-Source: AMsMyM4RpwL+DrS9xxghPmqUSZ/8aEbDpvmpBXEQJGm7NGK13UoXolX57u1hYtalO23n/He/lXcQ X-Received: by 2002:a17:90a:ba98:b0:20a:e24d:5e32 with SMTP id t24-20020a17090aba9800b0020ae24d5e32mr1704090pjr.138.1668105518391; Thu, 10 Nov 2022 10:38:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668105518; cv=none; d=google.com; s=arc-20160816; b=eVtc5MPW7ulE0dJrFpyccKihEHfGpBxea3aPg/5cs6HqjcWiqpz2RYg2aVpo58Z6mR ACtfexLgq2ClaoFTYRkx52INsml+nEFby+LiFdIrOvn3xHblEfGV0/5p7KEUmYPMCDGq lYcFfCwjfiswyHvpbCO/bh3aQpRG2nBzfMsxxcSfwDcT8BlOvJ0zubEBURsYnBOMEMoQ Kg0vWmg70OI098+n74zx0GtyoS3huJuv9H3FkM8gsDESiFvmsadgPqhZ5w0DPjewpsFr q7hp5+77qk3PRNgBj15qkVRe4PpW1cFMOWeKdsse7MZGek2M6OQJzGdu+Y5AxYJTtFeX lwDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=QjhrCoZQO78aH1Eq+NZaqmtVo4jyNmaRL9pB6MFNrko=; b=N/R1cwwaQSsLLmUGWvAl+h7i6ZsbC2U/I4YLimuXFYBbhWnGLhheDpq4TZuAO+IWs7 WXlTTux5WgJzehjsc7Uq/u3Wd11vA/regGVXDtCCPSSWmVW3cZz77qkeTk0EZC1ezyHI sdFCekMyREbxezpJfIlsvvslnkM9q4ZqZGyNE5Ul7B1o8yNINnuNzIWoVJW16bAEXW1e LjARi0Al1Fpm3WkF5Wns0UvgXHtWSJATYjQ5G8hm1w47/s267X9XGMV9eVegBJ0XFoDh Inv+I+GBiR4GwLh5lOsGD2144FDJzU+d2nQKeFz3dZAhih1Q4xVLoTqLK1paNww/ilVu ujuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dnw0bXKF; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d13-20020a63d70d000000b0046fb2a4c0c8si21508099pgg.146.2022.11.10.10.38.25; Thu, 10 Nov 2022 10:38:38 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=dnw0bXKF; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231535AbiKJSMb (ORCPT + 93 others); Thu, 10 Nov 2022 13:12:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbiKJSM3 (ORCPT ); Thu, 10 Nov 2022 13:12:29 -0500 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C801AB1E8; Thu, 10 Nov 2022 10:12:26 -0800 (PST) Received: by mail-qv1-xf35.google.com with SMTP id n18so1921112qvt.11; Thu, 10 Nov 2022 10:12:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=QjhrCoZQO78aH1Eq+NZaqmtVo4jyNmaRL9pB6MFNrko=; b=dnw0bXKFNPNx7KYtv9J8mc7BNylOSoCT51+8cGLEs3/wfBuCYMroRZdfmembhmFYRu Ftwqcsw52BRG8H3AZ0SkHBwiPjvm8YOXrPPJ625R7TbcO8hLkN7JiCZc2oSv4pbA1ydj zUdcYhiFrbEBuGE4w90UTJ1jPNPgu1O7rXVa/z7ykJpIIk52ngH71q+qpyqkosuf1a47 lJSjaFEiIokN2Drndlv21/sKRAIYvbcXoQ0LWQ2pAxAi6tqJibUA4HQPjfW3L/QUGzfU gha9ddCSr1Y8WlN6+ig0aMk/RP4an2H215sqazYi9PVw6U7nqEqW7+M4YBNfj/q2/9+K pqGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QjhrCoZQO78aH1Eq+NZaqmtVo4jyNmaRL9pB6MFNrko=; b=3KB+SBA9NOsIo/uwHMV9zNIhYEiBekCimZeKkKXxNvbQ9+0qNhTNR2wjSY32HifJ2P uPh6mE1g3gu0FLVbv7zxHn8PrSpM0DRj4RAPCFiHDo2AFnE+QIuWGWwqKs6Zf7nd4Syy BHaPsdXdt1qajOoyM0d+c3/DuqQV0fPiLAKjv4XK+JaTpM/dn5Xcux4IZHApvuVRWBAf CInlOP1Fq0qUXSVtSo4VGPhIWn2OZD1ot6eFks7831Z3cgJ0bu7vXagf/1x6wNA1rfGW cfelMfLMLDPmq7Bbp55fvh/y/GMf7nOMbtYgS3WQDKtBV43MZLVP5GmNoo3oeMYsomrC x4Rw== X-Gm-Message-State: ACrzQf3uyYrDGx47m6gEmWRDKtGsyDWAgcx+XCOarLDau+L/WGR/RSQz 14qA5qWJfeDELcyVr5vqZbw= X-Received: by 2002:a05:6214:4005:b0:4bb:9c0f:bcaa with SMTP id kd5-20020a056214400500b004bb9c0fbcaamr61963356qvb.42.1668103945670; Thu, 10 Nov 2022 10:12:25 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id j67-20020a378746000000b006fa5815b88dsm13005395qkd.88.2022.11.10.10.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 10:12:25 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id DB08827C005B; Thu, 10 Nov 2022 13:12:24 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 10 Nov 2022 13:12:24 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrfeeggdduudduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeekheefledtgfekleelueekudeiudekffevlefhkeelueeitefhgeeigfef jeekgfenucffohhmrghinhepkhgvrhhnvghlrdhorhhgpdhruhhsthdqlhgrnhhgrdhorh hgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsgho qhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqd dujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihm vgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 10 Nov 2022 13:12:24 -0500 (EST) Date: Thu, 10 Nov 2022 10:12:23 -0800 From: Boqun Feng To: Miguel Ojeda Cc: Wedson Almeida Filho , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Adam Bratschi-Kaye Subject: Re: [PATCH v1 02/28] rust: print: add more `pr_*!` levels Message-ID: References: <20221110164152.26136-1-ojeda@kernel.org> <20221110164152.26136-3-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221110164152.26136-3-ojeda@kernel.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Thu, Nov 10, 2022 at 05:41:14PM +0100, Miguel Ojeda wrote: > Currently, only `pr_info!` (for the minimal sample) and > `pr_emerg!` (for the panic handler) are there. > > Add the other levels as new macros, i.e. `pr_alert!`, `pr_crit!`, > `pr_err!`, `pr_warn!`, `pr_notice!` and `pr_debug!`. > > Co-developed-by: Adam Bratschi-Kaye > Signed-off-by: Adam Bratschi-Kaye > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Co-developed-by: Gary Guo > Signed-off-by: Gary Guo > Signed-off-by: Miguel Ojeda Reviewed-by: Boqun Feng Regards, Boqun > --- > rust/kernel/prelude.rs | 2 +- > rust/kernel/print.rs | 154 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 155 insertions(+), 1 deletion(-) > > diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs > index f8219285d8c0..6a1c6b38327f 100644 > --- a/rust/kernel/prelude.rs > +++ b/rust/kernel/prelude.rs > @@ -17,7 +17,7 @@ pub use alloc::{boxed::Box, vec::Vec}; > > pub use macros::module; > > -pub use super::{pr_emerg, pr_info}; > +pub use super::{pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr_notice, pr_warn}; > > pub use super::error::{Error, Result}; > > diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs > index 55db5a1ba752..694f51c6da5c 100644 > --- a/rust/kernel/print.rs > +++ b/rust/kernel/print.rs > @@ -74,7 +74,13 @@ pub mod format_strings { > // Furthermore, `static` instead of `const` is used to share the strings > // for all the kernel. > pub static EMERG: [u8; LENGTH] = generate(false, bindings::KERN_EMERG); > + pub static ALERT: [u8; LENGTH] = generate(false, bindings::KERN_ALERT); > + pub static CRIT: [u8; LENGTH] = generate(false, bindings::KERN_CRIT); > + pub static ERR: [u8; LENGTH] = generate(false, bindings::KERN_ERR); > + pub static WARNING: [u8; LENGTH] = generate(false, bindings::KERN_WARNING); > + pub static NOTICE: [u8; LENGTH] = generate(false, bindings::KERN_NOTICE); > pub static INFO: [u8; LENGTH] = generate(false, bindings::KERN_INFO); > + pub static DEBUG: [u8; LENGTH] = generate(false, bindings::KERN_DEBUG); > } > > /// Prints a message via the kernel's [`_printk`]. > @@ -172,6 +178,126 @@ macro_rules! pr_emerg ( > ) > ); > > +/// Prints an alert-level message (level 1). > +/// > +/// Use this level if action must be taken immediately. > +/// > +/// Equivalent to the kernel's [`pr_alert`] macro. > +/// > +/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and > +/// `alloc::format!` for information about the formatting syntax. > +/// > +/// [`pr_alert`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_alert > +/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html > +/// > +/// # Examples > +/// > +/// ``` > +/// pr_alert!("hello {}\n", "there"); > +/// ``` > +#[macro_export] > +macro_rules! pr_alert ( > + ($($arg:tt)*) => ( > + $crate::print_macro!($crate::print::format_strings::ALERT, $($arg)*) > + ) > +); > + > +/// Prints a critical-level message (level 2). > +/// > +/// Use this level for critical conditions. > +/// > +/// Equivalent to the kernel's [`pr_crit`] macro. > +/// > +/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and > +/// `alloc::format!` for information about the formatting syntax. > +/// > +/// [`pr_crit`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_crit > +/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html > +/// > +/// # Examples > +/// > +/// ``` > +/// pr_crit!("hello {}\n", "there"); > +/// ``` > +#[macro_export] > +macro_rules! pr_crit ( > + ($($arg:tt)*) => ( > + $crate::print_macro!($crate::print::format_strings::CRIT, $($arg)*) > + ) > +); > + > +/// Prints an error-level message (level 3). > +/// > +/// Use this level for error conditions. > +/// > +/// Equivalent to the kernel's [`pr_err`] macro. > +/// > +/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and > +/// `alloc::format!` for information about the formatting syntax. > +/// > +/// [`pr_err`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_err > +/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html > +/// > +/// # Examples > +/// > +/// ``` > +/// pr_err!("hello {}\n", "there"); > +/// ``` > +#[macro_export] > +macro_rules! pr_err ( > + ($($arg:tt)*) => ( > + $crate::print_macro!($crate::print::format_strings::ERR, $($arg)*) > + ) > +); > + > +/// Prints a warning-level message (level 4). > +/// > +/// Use this level for warning conditions. > +/// > +/// Equivalent to the kernel's [`pr_warn`] macro. > +/// > +/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and > +/// `alloc::format!` for information about the formatting syntax. > +/// > +/// [`pr_warn`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_warn > +/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html > +/// > +/// # Examples > +/// > +/// ``` > +/// pr_warn!("hello {}\n", "there"); > +/// ``` > +#[macro_export] > +macro_rules! pr_warn ( > + ($($arg:tt)*) => ( > + $crate::print_macro!($crate::print::format_strings::WARNING, $($arg)*) > + ) > +); > + > +/// Prints a notice-level message (level 5). > +/// > +/// Use this level for normal but significant conditions. > +/// > +/// Equivalent to the kernel's [`pr_notice`] macro. > +/// > +/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and > +/// `alloc::format!` for information about the formatting syntax. > +/// > +/// [`pr_notice`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_notice > +/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html > +/// > +/// # Examples > +/// > +/// ``` > +/// pr_notice!("hello {}\n", "there"); > +/// ``` > +#[macro_export] > +macro_rules! pr_notice ( > + ($($arg:tt)*) => ( > + $crate::print_macro!($crate::print::format_strings::NOTICE, $($arg)*) > + ) > +); > + > /// Prints an info-level message (level 6). > /// > /// Use this level for informational messages. > @@ -196,3 +322,31 @@ macro_rules! pr_info ( > $crate::print_macro!($crate::print::format_strings::INFO, $($arg)*) > ) > ); > + > +/// Prints a debug-level message (level 7). > +/// > +/// Use this level for debug messages. > +/// > +/// Equivalent to the kernel's [`pr_debug`] macro, except that it doesn't support dynamic debug > +/// yet. > +/// > +/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and > +/// `alloc::format!` for information about the formatting syntax. > +/// > +/// [`pr_debug`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_debug > +/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html > +/// > +/// # Examples > +/// > +/// ``` > +/// pr_debug!("hello {}\n", "there"); > +/// ``` > +#[macro_export] > +#[doc(alias = "print")] > +macro_rules! pr_debug ( > + ($($arg:tt)*) => ( > + if cfg!(debug_assertions) { > + $crate::print_macro!($crate::print::format_strings::DEBUG, $($arg)*) > + } > + ) > +); > -- > 2.38.1 >