]> Gentwo Git Trees - linux/.git/commit
Avoid memory barrier in read_seqcount() through load acquire sent/20240813-seq_optimize-68c48696c798-v2
authorChristoph Lameter (Ampere) <cl@gentwo.org>
Tue, 13 Aug 2024 18:09:01 +0000 (11:09 -0700)
committerChristoph Lameter <cl@gentwo.org>
Mon, 19 Aug 2024 18:30:25 +0000 (11:30 -0700)
commit289bbcb43968b5438fe127cbd2b3d076b6d400cc
tree50923e0cf7d3094e84a436ca8724fbb1d65af21c
parentb0da640826ba3b6506b4996a6b23a429235e6923
Avoid memory barrier in read_seqcount() through load acquire

Some architectures support load acquire which can save us a memory
barrier and save some cycles.

A typical sequence

do {
seq = read_seqcount_begin(&s);
<something>
} while (read_seqcount_retry(&s, seq);

requires 13 cycles on ARM64 for an empty loop. Two read memory
barriers are needed. One for each of the seqcount_* functions.

We can replace the first read barrier with a load acquire of
the seqcount which saves us one barrier.

On ARM64 doing so reduces the cycle count from 13 to 8.

This is a general improvement for the ARM64 architecture and not
specific to a certain processor. The cycle count here was
obtained on a Neoverse N1 (Ampere Altra).

The ARM documentation states that load acquire is more effective
than a load plus barrier. In general that tends to be true on all
compute platforms that support both.

See (as quoted by Linus Torvalds):
   https://developer.arm.com/documentation/102336/0100/Load-Acquire-and-Store-Release-instructions

 "Weaker ordering requirements that are imposed by Load-Acquire and
  Store-Release instructions allow for micro-architectural
  optimizations, which could reduce some of the performance impacts that
  are otherwise imposed by an explicit memory barrier.

  If the ordering requirement is satisfied using either a Load-Acquire
  or Store-Release, then it would be preferable to use these
  instructions instead of a DMB"

Signed-off-by: Christoph Lameter (Ampere) <cl@gentwo.org>
arch/Kconfig
arch/arm64/Kconfig
include/linux/seqlock.h