From: Dirk Behme <dirk.behme@gmail.com>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>,
rust-for-linux@vger.kernel.org
Cc: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com,
gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, a.hindborg@kernel.org,
aliceryhl@google.com, tmgross@umich.edu
Subject: Re: [PATCH v1] rust: Add pr_*_once macros
Date: Sun, 3 Nov 2024 17:38:10 +0100 [thread overview]
Message-ID: <b9bcc656-7e58-4509-aa2b-6279a72fa9fe@gmail.com> (raw)
In-Reply-To: <20241103030530.76756-1-fujita.tomonori@gmail.com>
On 03.11.24 04:05, FUJITA Tomonori wrote:
> Add Rust version of pr_[emerg|alert|crit|err|warn|notic|info]_once
> functions, which print a message only once.
Maybe it should be mentioned why this is added? Who will use this?
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
> rust/kernel/print.rs | 92 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 92 insertions(+)
>
> diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
> index a28077a7cb30..57dbb45ba5c0 100644
> --- a/rust/kernel/print.rs
> +++ b/rust/kernel/print.rs
> @@ -414,3 +414,95 @@ macro_rules! pr_cont (
> $crate::print_macro!($crate::print::format_strings::CONT, true, $($arg)*)
> )
> );
> +
> +/// Executes code only once if the condition is true.
> +///
> +/// Public but hidden since it should only be used from public macros.
> +#[doc(hidden)]
> +#[macro_export]
> +macro_rules! do_once_lite_if (
> + ($condition:expr, $e:expr) => (
> + {
> + #[link_section = ".data.once"]
> + static ALREADY_DONE: core::sync::atomic::AtomicBool =
> + core::sync::atomic::AtomicBool::new(false);
> + let mut ret = false;
> +
> + if $condition && !ALREADY_DONE.swap(true, core::sync::atomic::Ordering::Relaxed) {
What is '$condition' good for? It looks to me that it is set just to
'true' everywhere below? Could it be dropped?
> + $e;
> + ret = true;
> + }
> + ret
> + }
> + )
> +);
> +
> +/// Prints an emergency-level message (level 0) only once.
> +///
> +/// Equivalent to the kernel's [`pr_emerg_once`] macro.
Here and below:
Would it make sense to use a similar header style like with the
existing pr_*()? And add '# Examples'?
Best regards
Dirk
> +#[macro_export]
> +macro_rules! pr_emerg_once (
> + ($($arg:tt)*) => (
> + $crate::do_once_lite_if!(true, $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_if!(true, $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_if!(true, $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_if!(true, $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_if!(true, $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_if!(true, $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_if!(true, $crate::pr_info!($($arg)*))
> + )
> +);
>
> base-commit: ae7851c29747fa3765ecb722fe722117a346f988
next prev parent reply other threads:[~2024-11-03 16:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-03 3:05 [PATCH v1] rust: Add pr_*_once macros FUJITA Tomonori
2024-11-03 16:38 ` Dirk Behme [this message]
2024-11-04 1:48 ` FUJITA Tomonori
2024-11-03 16:41 ` Miguel Ojeda
2024-11-03 22:29 ` jens.korinth
2024-11-04 2:15 ` FUJITA Tomonori
2024-11-04 6:08 ` Boqun Feng
2024-11-04 2:08 ` FUJITA Tomonori
2024-11-04 15:44 ` Miguel Ojeda
2024-11-04 22:08 ` jens.korinth
2024-11-04 22:20 ` Boqun Feng
2024-11-04 23:33 ` FUJITA Tomonori
2024-11-05 20:20 ` Miguel Ojeda
2024-11-05 23:33 ` FUJITA Tomonori
2024-11-05 20:35 ` Miguel Ojeda
2024-11-05 23:31 ` 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=b9bcc656-7e58-4509-aa2b-6279a72fa9fe@gmail.com \
--to=dirk.behme@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).