All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: alex.gaynor@gmail.com, ojeda@kernel.org, a.hindborg@kernel.org,
	aliceryhl@google.com, boqun.feng@gmail.com,
	bjorn3_gh@protonmail.com, dakr@kernel.org, lossin@kernel.org,
	rust-for-linux@vger.kernel.org, tmgross@umich.edu
Subject: Re: [PATCH v3 2/2] rust: Add pr_*_once macros
Date: Tue, 23 Dec 2025 12:06:00 +0000	[thread overview]
Message-ID: <20251223120600.6541cc8f.gary@garyguo.net> (raw)
In-Reply-To: <20251117002452.4068692-3-fujita.tomonori@gmail.com>

On Mon, 17 Nov 2025 09:24:52 +0900
FUJITA Tomonori <fujita.tomonori@gmail.com> wrote:

> Add Rust version of pr_[emerg|alert|crit|err|warn|notic|info]_once
> macros, which print a message only once.
> 
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>

A meta topic about this one.

I think we're adding too many macros with this. In C we had to do this
way because expressive power of mascros are more limited, but I wonder
if we should just add different flavours with macros.

For example, instead of

	pr_warn_once!("foo");

we could do

	pr_warn!(once, "foo");

If we are adding extra tunables, we could do something similar too.
Given all print macros start with a format string, doing this won't create
any ambiguity.

An added benefit is that now you only need to implement the functionality
once in `print_macro!` and all other macros gain the feature, too.

Best,
Gary

> ---
>  rust/kernel/print.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 70 insertions(+)
> 
> diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
> index af32054be5a2..6fd84389a858 100644
> --- a/rust/kernel/print.rs
> +++ b/rust/kernel/print.rs
> @@ -506,3 +506,73 @@ macro_rules! do_once_lite {
>          ONCE.call_once(|| { $($e)* });
>      }};
>  }
> +
> +/// Prints an emergency-level message (level 0) only once.
> +///
> +/// Equivalent to the kernel's `pr_emerg_once` macro.
> +#[macro_export]
> +macro_rules! pr_emerg_once (
> +    ($($arg:tt)*) => (
> +        $crate::do_once_lite! { $crate::pr_emerg!($($arg)*) }
> +    )
> +);
> +
> +/// Prints an alert-level message (level 1) only once.
> +///
> +/// Equivalent to the kernel's `pr_alert_once` macro.
> +#[macro_export]
> +macro_rules! pr_alert_once (
> +    ($($arg:tt)*) => (
> +        $crate::do_once_lite! { $crate::pr_alert!($($arg)*) }
> +    )
> +);
> +
> +/// Prints a critical-level message (level 2) only once.
> +///
> +/// Equivalent to the kernel's `pr_crit_once` macro.
> +#[macro_export]
> +macro_rules! pr_crit_once (
> +    ($($arg:tt)*) => (
> +        $crate::do_once_lite! { $crate::pr_crit!($($arg)*) }
> +    )
> +);
> +
> +/// Prints an error-level message (level 3) only once.
> +///
> +/// Equivalent to the kernel's `pr_err_once` macro.
> +#[macro_export]
> +macro_rules! pr_err_once (
> +    ($($arg:tt)*) => (
> +        $crate::do_once_lite! { $crate::pr_err!($($arg)*) }
> +    )
> +);
> +
> +/// Prints a warning-level message (level 4) only once.
> +///
> +/// Equivalent to the kernel's `pr_warn_once` macro.
> +#[macro_export]
> +macro_rules! pr_warn_once (
> +    ($($arg:tt)*) => (
> +        $crate::do_once_lite! { $crate::pr_warn!($($arg)*) }
> +    )
> +);
> +
> +/// Prints a notice-level message (level 5) only once.
> +///
> +/// Equivalent to the kernel's `pr_notice_once` macro.
> +#[macro_export]
> +macro_rules! pr_notice_once (
> +    ($($arg:tt)*) => (
> +        $crate::do_once_lite! { $crate::pr_notice!($($arg)*) }
> +    )
> +);
> +
> +/// Prints an info-level message (level 6) only once.
> +///
> +/// Equivalent to the kernel's `pr_info_once` macro.
> +#[macro_export]
> +macro_rules! pr_info_once (
> +    ($($arg:tt)*) => (
> +        $crate::do_once_lite! { $crate::pr_info!($($arg)*) }
> +    )
> +);


  reply	other threads:[~2025-12-23 12:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17  0:24 [PATCH v3 0/2] Add support for print exactly once FUJITA Tomonori
2025-11-17  0:24 ` [PATCH v3 1/2] rust: Add support for calling a function " FUJITA Tomonori
2025-12-18 11:38   ` Alice Ryhl
2025-12-23  6:49     ` FUJITA Tomonori
2025-12-23 12:18   ` Gary Guo
2025-12-25  6:14     ` FUJITA Tomonori
2025-11-17  0:24 ` [PATCH v3 2/2] rust: Add pr_*_once macros FUJITA Tomonori
2025-12-23 12:06   ` Gary Guo [this message]
2025-12-25  6:29     ` FUJITA Tomonori
2026-01-13  6:52     ` FUJITA Tomonori
2025-12-18 11:18 ` [PATCH v3 0/2] Add support for print exactly once FUJITA Tomonori
2026-01-30  4:51 ` Miguel Ojeda
2026-01-30 12:34   ` FUJITA Tomonori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251223120600.6541cc8f.gary@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.