rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: chenmiao <chenmiao@openatom.club>
Cc: ojeda@kernel.org, "Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Steven Rostedt (Google)" <rostedt@goodmis.org>,
	"open list:RUST" <rust-for-linux@vger.kernel.org>,
	"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rust: kernel: Support more jump_label api
Date: Tue, 4 Nov 2025 14:07:18 +0000	[thread overview]
Message-ID: <aQoIliAbrn0Re7E3@google.com> (raw)
In-Reply-To: <df3a68334760b2b254219a69426982bf858dee39.1762221537.git.chenmiao@openatom.club>

On Tue, Nov 04, 2025 at 02:04:17AM +0000, chenmiao wrote:
> The initial implementation of arch_static_branch was achieved by accessing
> the offset from the original type. However, this approach extended the
> path and introduced redundant calculations when dealing with types like
> `static_key_true/false`, as shown below:
> 
> ```
> static_brach_unlikely(tp, tracepoint, key)
>   => tracepoint->key->key
>   => &tracepoint->key(static_key_false) == &tracepoint->key.key(static_key)
>   => off: tracepoint->key - tracepoint
> ```
> 
> In practice, the implementation of `arch_static_branch` overlooked many
> detailed descriptions. To improve clarity, additional comments have been
> added to the original logic. The approach has been modified to directly
> locate the corresponding `static_key` instead of using offsets, thereby
> reducing  computational overhead.
> 
> If finding the offset from the primitive type is necessary for this
> implementation, I will abandon this change.
> 
> Additionally, support for the `static_branch_enable/disable` APIs has been
> introduced.
> 
> Signed-off-by: chenmiao <chenmiao@openatom.club>

> +    ($basety:ty, $branch:expr, $key:path, $keytyp:ty, $field:ident) => {{
>          let _key: *const $keytyp = ::core::ptr::addr_of!($key);
> -        let _key: *const $crate::bindings::static_key_false = ::core::ptr::addr_of!((*_key).$field);
> +        let _key: *const $basety = ::core::ptr::addr_of!((*_key).$field);
>          let _key: *const $crate::bindings::static_key = _key.cast();
>  
>          #[cfg(not(CONFIG_JUMP_LABEL))]
> @@ -30,7 +71,88 @@ macro_rules! static_branch_unlikely {
>          }
>  
>          #[cfg(CONFIG_JUMP_LABEL)]
> -        $crate::jump_label::arch_static_branch! { $key, $keytyp, $field, false }
> +        {
> +            $crate::jump_label::arch_static_branch! { _key, $branch }
> +        }

So ... this is changing from $key to _key. That's replacing the global
variable with a local variable holding a pointer to the global variable.
However, the arch_static_branch! macro uses the `sym` operand which
requires you to pass it the global directly.

Did you try this code? I don't believe it will work.

Alice

  reply	other threads:[~2025-11-04 14:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-04  2:04 [PATCH] rust: kernel: Support more jump_label api chenmiao
2025-11-04 14:07 ` Alice Ryhl [this message]
2025-11-05 13:28   ` Chen Miao
2025-11-05 13:38     ` Alice Ryhl
2025-11-05 13:55       ` Chen Miao
2025-11-05 14:13         ` Alice Ryhl
2025-11-05 14:16           ` Chen Miao
2025-11-04 14:14 ` Miguel Ojeda
2025-11-05 13:35   ` Chen Miao
2025-11-05 13:40     ` Miguel Ojeda
2025-11-05 13:46       ` Chen Miao
2025-11-05 13:49         ` Miguel Ojeda

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=aQoIliAbrn0Re7E3@google.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=chenmiao@openatom.club \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rostedt@goodmis.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).