numam-dpdk/app
Mattias Rönnblom 0bee070907 eal: add seqlock
A sequence lock (seqlock) is a synchronization primitive which allows
for data-race free, low-overhead, high-frequency reads, suitable for
data structures shared across many cores and which are updated
relatively infrequently.

A seqlock permits multiple parallel readers. A spinlock is used to
serialize writers. In cases where there is only a single writer, or
writer-writer synchronization is done by some external means, the
"raw" sequence counter type (and accompanying rte_seqcount_*()
functions) may be used instead.

To avoid resource reclamation and other issues, the data protected by
a seqlock is best off being self-contained (i.e., no pointers [except
to constant data]).

One way to think about seqlocks is that they provide means to perform
atomic operations on data objects larger than what the native atomic
machine instructions allow for.

DPDK seqlocks (and the underlying sequence counters) are not
preemption safe on the writer side. A thread preemption affects
performance, not correctness.

A seqlock contains a sequence number, which can be thought of as the
generation of the data it protects.

A reader will
  1. Load the sequence number (sn).
  2. Load, in arbitrary order, the seqlock-protected data.
  3. Load the sn again.
  4. Check if the first and second sn are equal, and even numbered.
     If they are not, discard the loaded data, and restart from 1.

The first three steps need to be ordered using suitable memory fences.

A writer will
  1. Take the spinlock, to serialize writer access.
  2. Load the sn.
  3. Store the original sn + 1 as the new sn.
  4. Perform load and stores to the seqlock-protected data.
  5. Store the original sn + 2 as the new sn.
  6. Release the spinlock.

Proper memory fencing is required to make sure the first sn store, the
data stores, and the second sn store appear to the reader in the
mentioned order.

The sn loads and stores must be atomic, but the data loads and stores
need not be.

The original seqlock design and implementation was done by Stephen
Hemminger. This is an independent implementation, using C11 atomics.

For more information on seqlocks, see
https://en.wikipedia.org/wiki/Seqlock

Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
Reviewed-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
2022-06-07 13:33:14 +02:00
..
dumpcap app/dumpcap: allow help/version without primary process 2022-03-08 09:32:59 +01:00
pdump app/pdump: free mempool at resources cleanup 2022-03-08 00:19:31 +01:00
proc-info fix spelling in comments and strings 2022-01-11 12:16:53 +01:00
test eal: add seqlock 2022-06-07 13:33:14 +02:00
test-acl app/acl: support different formats for IPv6 address 2022-05-30 23:31:37 +02:00
test-bbdev baseband/fpga_5gnr_fec: remove FLR timeout 2022-06-01 16:26:35 +02:00
test-cmdline
test-compress-perf app/compress-perf: fix number of queue pairs to setup 2022-03-04 10:53:09 +01:00
test-crypto-perf app/crypto-perf: allow auth generate followed by encryption 2022-06-01 16:26:36 +02:00
test-eventdev app/eventdev: support asym ops for crypto adapter 2022-06-01 16:26:34 +02:00
test-fib app/fib: fix division by zero 2022-02-11 08:50:13 +01:00
test-flow-perf fix spelling in comments and strings 2022-01-11 12:16:53 +01:00
test-gpudev gpudev: use CPU mapping in communication list 2022-02-22 20:08:52 +01:00
test-pipeline app: remove unneeded atomic header include 2021-11-17 11:07:06 +01:00
test-pmd ethdev: add IPv4/IPv6 ECN header rewrite action 2022-06-02 11:58:38 +02:00
test-regex app/regex: fix number of matches 2022-03-14 12:15:29 +01:00
test-sad
meson.build build: make pdump optional 2021-11-17 12:49:19 +01:00