From: FUJITA Tomonori <fujita.tomonori@gmail.com>
To: alex.gaynor@gmail.com, ojeda@kernel.org
Cc: a.hindborg@kernel.org, aliceryhl@google.com,
bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org,
gary@garyguo.net, lossin@kernel.org,
rust-for-linux@vger.kernel.org, tmgross@umich.edu
Subject: [PATCH v2 0/2] Add support for print exactly once
Date: Wed, 12 Nov 2025 22:16:17 +0900 [thread overview]
Message-ID: <20251112131619.3585510-1-fujita.tomonori@gmail.com> (raw)
This adds the Rust equivalent of the kernel's DO_ONCE_LITE and
pr_*_once macros.
A proposal for this feature was made in the past [1], but it didn't
reach consensus on the implementation and wasn't merged. After reading
the previous discussions, I implemented it using a different approach.
In the previous proposal, a structure equivalent to std::sync::Once
was implemented to realize the DO_ONCE_LITE macro. The approach tried
to provide Once-like semantics by using two atomic values. As pointed
out in the previous review comments, I think this approach tries to
provide more functionality than needed, making it unnecessarily
complex. Also, because data structures in the .data..once section can
be cleared at any time (via debugfs clear_warn_once), an
implementation using two atomics wouldn't work correctly.
Therefore, I decided to drop the idea of emulating Once and took a
minimal approach to implement DO_ONCE_LITE with only one atomic
variable. While it would be possible to implement the feature entirely
as a Rust macro, the functionality that can be implemented as regular
functions has been extracted and implemented as the OnceLite struct
for better code readability.
[1] https://lore.kernel.org/rust-for-linux/20241126-pr_once_macros-v4-0-410b8ca9643e@tuta.io/
v2:
- improve do_once_lite micro syntax
- move once_lite.rs to kernel/sync/
- add comments (including ORDERING)
- fix rustdoc errors
- use vertical layout for imports
v1: https://lore.kernel.org/rust-for-linux/20251105054731.3194118-1-fujita.tomonori@gmail.com/
FUJITA Tomonori (2):
rust: Add support for calling a function exactly once
rust: Add pr_*_once macros
rust/kernel/print.rs | 70 +++++++++++++++++++++++++++++
rust/kernel/sync.rs | 1 +
rust/kernel/sync/once_lite.rs | 83 +++++++++++++++++++++++++++++++++++
3 files changed, 154 insertions(+)
create mode 100644 rust/kernel/sync/once_lite.rs
base-commit: 3b83f5d5e78ac5cddd811a5e431af73959864390
--
2.43.0
next reply other threads:[~2025-11-12 13:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 13:16 FUJITA Tomonori [this message]
2025-11-12 13:16 ` [PATCH v2 1/2] rust: Add support for calling a function exactly once FUJITA Tomonori
2025-11-12 13:16 ` [PATCH v2 2/2] rust: Add pr_*_once macros 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=20251112131619.3585510-1-fujita.tomonori@gmail.com \
--to=fujita.tomonori@gmail.com \
--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=gary@garyguo.net \
--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 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).