Go to file
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
.ci ci: build some job with ASan 2022-05-11 14:05:57 +02:00
.github/workflows ci: build some job with ASan 2022-05-11 14:05:57 +02:00
app eal: add seqlock 2022-06-07 13:33:14 +02:00
buildtools build: fix build on FreeBSD with Meson 0.61.1 2022-03-08 16:37:22 +01:00
config config/arm: disable SVE ACLE for CN10K 2022-06-02 00:36:35 +02:00
devtools ethdev: add telemetry command for module EEPROM 2022-05-31 16:30:30 +02:00
doc eal: add seqlock 2022-06-07 13:33:14 +02:00
drivers dma/idxd: add generic option for queue config 2022-06-07 12:46:12 +02:00
examples examples/pipeline: fix build 2022-06-07 13:12:19 +02:00
kernel kni: fix build 2022-06-06 12:49:51 +02:00
lib eal: add seqlock 2022-06-07 13:33:14 +02:00
license lib: remove librte_ prefix from directory names 2021-04-21 14:04:09 +02:00
usertools usertools/devbind: support virtio block device 2022-06-01 11:50:10 +02:00
.editorconfig devtools: clarify that lines up to 100 characters are ok 2021-11-25 11:51:24 +01:00
.gitattributes
.gitignore doc: add eventdev feature matrices 2021-11-26 16:29:25 +01:00
.travis.yml version: 22.07-rc0 2022-03-21 13:56:40 +01:00
ABI_VERSION version: 22.07-rc0 2022-03-21 13:56:40 +01:00
MAINTAINERS eal: add seqlock 2022-06-07 13:33:14 +02:00
Makefile build: create dummy Makefile 2020-09-07 23:51:57 +02:00
meson_options.txt config: add option for atomic mbuf reference counting 2021-10-25 17:53:30 +02:00
meson.build app/testpmd: register driver specific commands 2022-05-31 17:09:12 +02:00
README license: introduce SPDX identifiers 2018-01-04 22:41:38 +01:00
VERSION version: 22.07-rc0 2022-03-21 13:56:40 +01:00

DPDK is a set of libraries and drivers for fast packet processing.
It supports many processor architectures and both FreeBSD and Linux.

The DPDK uses the Open Source BSD-3-Clause license for the core libraries
and drivers. The kernel components are GPL-2.0 licensed.

Please check the doc directory for release notes,
API documentation, and sample application information.

For questions and usage discussions, subscribe to: users@dpdk.org
Report bugs and issues to the development mailing list: dev@dpdk.org