]> asedeno.scripts.mit.edu Git - linux.git/commit
libbpf: optimize barrier for XDP socket rings
authorMagnus Karlsson <magnus.karlsson@intel.com>
Tue, 16 Apr 2019 12:58:12 +0000 (14:58 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 17 Apr 2019 03:13:10 +0000 (20:13 -0700)
commit2c5935f1b2b642cee8e1562396ec8a7781fc4c6d
tree851eb8e92dd057e389e6a7b733dbda56f8a1d666
parentb7e3a28019c92ffe1f55de278c5641de33b6259a
libbpf: optimize barrier for XDP socket rings

The full memory barrier in the XDP socket rings on the consumer side
between the load of the data and the store of the consumer ring is
there to protect the store from being executed before the load of the
data. If this was allowed to happen, the producer might overwrite the
data field with a new entry before the consumer got the chance to read
it.

On x86, stores are guaranteed not to be reordered with older loads, so
it does not need a full memory barrier here. A compile time barrier
would be enough. This patch introdcues a new primitive in
libbpf_util.h that implements a new barrier type (libbpf_smp_rwmb)
hindering stores to be reordered with older loads. It is then used in
the XDP socket ring access code in libbpf to improve performance.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf_util.h
tools/lib/bpf/xsk.h