Re: [PATCH v2] rust_binder: use Atomic::add() in BinderStats
From: Alice Ryhl
Date: Sat Oct 31 2026 - 12:13:54 EST
On Sat, Oct 31, 2026 at 4:09 PM Jenhao Chen <jenhaochen@xxxxxxxxxx> wrote:
>
> BinderStats::inc_bc() and BinderStats::inc_br() increment command and
> return statistics counters on every Binder transaction and reply using
> Atomic::fetch_add(1, Relaxed), discarding the returned previous value.
>
> Because the return value of fetch_add() is unused in Rust but must still
> be produced by the underlying value-returning atomic RMW helper
> (atomic_fetch_add_relaxed()), the compiler is forced to emit a
> value-returning atomic operation (LDADD on arm64 with LSE, or LOCK XADD
> on x86) instead of a non-value-returning atomic add (STADD on arm64, or
> LOCK ADD on x86). On arm64 CPUs with LSE, value-returning LDADD requires
> a round-trip response from the L2/interconnect to populate the
> destination register, whereas non-value-returning STADD (encoded as
> LDADD with WZR as the destination register) may be executed as a far
> atomic without waiting for the old value to return to the core.
>
> Switch BinderStats::inc_bc() and BinderStats::inc_br() from
> fetch_add(1, Relaxed) to add(1, Relaxed) so they lower to atomic_add()
> and emit non-value-returning atomic increments. This also matches the C
> Binder driver, which uses atomic_inc() for these statistics counters in
> binder_thread_write() and binder_stat_br().
>
> Reviewed-by: Boqun Feng <boqun@xxxxxxxxxx>
> Reviewed-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>
> Signed-off-by: Jenhao Chen <jenhaochen@xxxxxxxxxx>
Acked-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Greg, please pick this up, thanks!