numam-dpdk/lib
Gavin Hu 86757c2c3e ring/c11: keep deterministic order allowing retry to work
Use case scenario:
1) Thread 1 is enqueuing. It reads prod.head and gets stalled for some
   reasons (running out of cpu time, preempted,...)
2) Thread 2 is enqueuing. It succeeds in enqueuing and moves prod.head
   forward.
3) Thread 3 is dequeuing. It succeeds in dequeuing and moves the cons.tail
   beyond the prod.head read by thread 1.
4) Thread 1 is re-scheduled. It reads cons.tail.

cpu1(producer)      cpu2(producer)          cpu3(consumer)
load r->prod.head
    ^               load r->prod.head
    |               load r->cons.tail
    |               store r->prod.head(+n)
  stalled           <-- enqueue ----->
    |               store r->prod.tail(+n)
    |                                        load r->cons.head
    |                                        load r->prod.tail
    |                                        store r->cons.head(+n)
    |                                        <...dequeue.....>
    v                                        store r->cons.tail(+n)
load r->cons.tail

For thread 1, the __atomic_compare_exchange_n detects the outdated
prod.head and retry the flow with the new one. This retry flow works ok on
strong ordering platform(eg:x86). But for weak ordering platforms(arm,
ppc), loading cons.tail and prod.head might be re-ordered, prod.head is new
but cons.tail becomes too old, the retry flow, based on the detection of
outdated head, does not trigger as expected, thus the outdate cons.tail
causes wrong free_entries.

Similarly, for dequeuing, outdated prod.tail leads to wrong avail_entries.

The fix is to keep the deterministic order of two loads allowing the retry
to work.

Run the ring perf test on the following testbed:
HW: ThunderX2 B0 CPU CN9975 v2.0, 2 sockets, 28core, 4 threads/core, 2.5GHz
OS: Ubuntu 16.04.5 LTS, Kernel: 4.15.0-36-generic
DPDK: 18.08, Configuration: arm64-armv8a-linuxapp-gcc
gcc: 8.1.0
$sudo ./test/test/test -l 16-19,44-47,72-75,100-103 -n 4 \
--socket-mem=1024 -- -i

Without the patch:
*** Testing using two physical cores ***
SP/SC bulk enq/dequeue (size: 8): 5.64
MP/MC bulk enq/dequeue (size: 8): 9.58
SP/SC bulk enq/dequeue (size: 32): 1.98
MP/MC bulk enq/dequeue (size: 32): 2.30

With the patch:
*** Testing using two physical cores ***
SP/SC bulk enq/dequeue (size: 8): 5.75
MP/MC bulk enq/dequeue (size: 8): 10.18
SP/SC bulk enq/dequeue (size: 32): 1.80
MP/MC bulk enq/dequeue (size: 32): 2.34

The results showed the thread fence degrade the performance slightly, but
it is required for correctness.

Fixes: 39368ebfc6 ("ring: introduce C11 memory model barrier option")
Cc: stable@dpdk.org

Signed-off-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Steve Capper <steve.capper@arm.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
2018-11-13 16:57:58 +01:00
..
librte_acl lib: fix shifting 32-bit signed variable 31 times 2018-11-06 01:14:05 +01:00
librte_bbdev remove useless constructor headers 2018-07-12 00:00:35 +02:00
librte_bitratestats bitrate: add sanity check on parameters 2018-07-26 20:07:57 +02:00
librte_bpf bpf: fix a typo 2018-10-25 11:27:49 +02:00
librte_cfgfile build: replace license text with SPDX tag 2018-01-30 21:58:59 +01:00
librte_cmdline ethdev: support MAC address as iterator filter 2018-10-26 22:14:06 +02:00
librte_compat buildtools: change license to SPDX 2018-07-26 22:45:17 +02:00
librte_compressdev compressdev: fix op allocation 2018-11-02 12:25:39 +01:00
librte_cryptodev lib: reduce global variable usage 2018-10-29 02:34:27 +01:00
librte_distributor build: set compat lib as universal dependency 2018-01-30 21:59:00 +01:00
librte_eal eal: fix build 2018-11-12 13:27:02 +01:00
librte_efd build: replace license text with SPDX tag 2018-01-30 21:58:59 +01:00
librte_ethdev ethdev: remove experimental tag for iterator API 2018-11-06 01:14:04 +01:00
librte_eventdev lib: reduce global variable usage 2018-10-29 02:34:27 +01:00
librte_flow_classify flow_classify: do not check for invalid socket ID 2018-10-11 10:37:45 +02:00
librte_gro build: replace license text with SPDX tag 2018-01-30 21:58:59 +01:00
librte_gso gso: support UDP/IPv4 fragmentation 2018-07-11 23:45:20 +02:00
librte_hash hash: remove unnecessary pause 2018-10-26 22:01:37 +02:00
librte_ip_frag ip_frag: use key length for key comparison 2018-11-06 01:58:11 +01:00
librte_jobstats build: replace license text with SPDX tag 2018-01-30 21:58:59 +01:00
librte_kni kni: add function to set link state on kernel interface 2018-10-26 19:46:15 +02:00
librte_kvargs kvargs: support list value 2018-10-26 22:14:06 +02:00
librte_latencystats latency: fix timestamp marking and latency calculation 2018-10-25 10:30:13 +02:00
librte_lpm lpm6: add incremental update on delete 2018-09-19 17:11:37 +02:00
librte_mbuf ethdev: support metadata as flow rule criteria 2018-10-26 22:14:05 +02:00
librte_member remove useless constructor headers 2018-07-12 00:00:35 +02:00
librte_mempool malloc: add function to check if socket is external 2018-10-11 11:11:25 +02:00
librte_meter meter: remove experimental tag from profile API 2018-08-06 01:15:11 +02:00
librte_metrics metrics: disallow null as metric name 2018-07-26 20:30:18 +02:00
librte_net lib: fix shifting 32-bit signed variable 31 times 2018-11-06 01:14:05 +01:00
librte_pci use SPDX tag for 6WIND copyrighted files 2018-05-25 10:47:06 +02:00
librte_pdump mk: build with _GNU_SOURCE defined by default 2018-10-22 11:28:27 +02:00
librte_pipeline pipeline: add table action for packet decap 2018-10-12 19:33:34 +02:00
librte_port port: add symmetric crypto 2018-10-12 19:33:02 +02:00
librte_power power: fix traffic aware build 2018-10-26 14:51:36 +02:00
librte_rawdev lib: reduce global variable usage 2018-10-29 02:34:27 +01:00
librte_reorder build: replace license text with SPDX tag 2018-01-30 21:58:59 +01:00
librte_ring ring/c11: keep deterministic order allowing retry to work 2018-11-13 16:57:58 +01:00
librte_sched mk: build with _GNU_SOURCE defined by default 2018-10-22 11:28:27 +02:00
librte_security security: support PDCP 2018-10-24 15:12:33 +02:00
librte_table lib/librte_table: add hash function headers 2018-10-12 17:58:53 +02:00
librte_telemetry build: add dependency on telemetry to apps with meson 2018-10-27 15:21:33 +02:00
librte_timer eal: make semantics of lcore role function more intuitive 2018-04-26 16:58:18 +02:00
librte_vhost vhost: fix possible out of bound access 2018-11-06 01:14:23 +01:00
Makefile telemetry: introduce infrastructure 2018-10-27 15:18:20 +02:00
meson.build build: change default driver installation directory 2018-10-27 23:22:12 +02:00