aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorThomas Gschwantner <tharre3@gmail.com>2018-06-21 01:00:52 +0200
committerThomas Gschwantner <tharre3@gmail.com>2018-06-22 14:55:44 +0200
commit903df655527e4d1c9a530de28e648fa2b71fb39c (patch)
tree1053012babcefd79f20d6a7ccfbbd7d17b6fee3e /src
parentmpmc_ptr_ring: add {,un}likely() annotations (diff)
downloadwireguard-monolithic-historical-903df655527e4d1c9a530de28e648fa2b71fb39c.tar.xz
wireguard-monolithic-historical-903df655527e4d1c9a530de28e648fa2b71fb39c.zip
Benchmark
Diffstat (limited to 'src')
-rw-r--r--src/mpmc_ptr_ring.h20
-rw-r--r--src/selftest/mpmc_ring.h6
-rwxr-xr-xsrc/tests/netns.sh5
3 files changed, 21 insertions, 10 deletions
diff --git a/src/mpmc_ptr_ring.h b/src/mpmc_ptr_ring.h
index da9393e..9e8b212 100644
--- a/src/mpmc_ptr_ring.h
+++ b/src/mpmc_ptr_ring.h
@@ -44,7 +44,7 @@
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/log2.h>
-#include <linux/processor.h>
+//#include <linux/processor.h>
#include <linux/slab.h>
#include <linux/stddef.h>
@@ -84,7 +84,11 @@ static inline int mpmc_ptr_ring_produce(struct mpmc_ptr_ring *r, void *ptr)
p = atomic_read(&r->producer_head);
for (;;) {
- smp_rmb(); /* TODO */
+ /*
+ * The snapshot of the producer must be up to date with respect
+ * to the consumer.
+ */
+ smp_rmb();
c = atomic_read(&r->consumer_head);
if (likely((p - c) < mask)) {
@@ -93,6 +97,10 @@ static inline int mpmc_ptr_ring_produce(struct mpmc_ptr_ring *r, void *ptr)
} else {
int new_p;
+ /*
+ * Either the buffer is full or our copy of
+ * producer_head is stale.
+ */
smp_rmb();
new_p = atomic_read(&r->producer_head);
@@ -125,9 +133,9 @@ static inline void *mpmc_ptr_ring_consume(struct mpmc_ptr_ring *r)
unsigned int mask = r->mask;
void *element;
- do {
- c = atomic_read(&r->consumer_head);
+ c = atomic_read(&r->consumer_head);
+ do {
/* Fetch consumer_head first. */
smp_rmb();
@@ -203,7 +211,7 @@ static inline void *__mpmc_ptr_ring_peek(struct mpmc_ptr_ring *r)
return NULL;
/* TODO */
- smp_rmb();
+ /*smp_rmb();*/
element = READ_ONCE(r->queue[c & mask]);
@@ -219,7 +227,7 @@ static inline void *__mpmc_ptr_ring_peek(struct mpmc_ptr_ring *r)
*/
static inline void __mpmc_ptr_ring_discard_one(struct mpmc_ptr_ring *r)
{
- smp_mb__before_atomic();
+ /*smp_mb__before_atomic();*/
atomic_inc(&r->consumer_head);
}
diff --git a/src/selftest/mpmc_ring.h b/src/selftest/mpmc_ring.h
index 251456f..624ce22 100644
--- a/src/selftest/mpmc_ring.h
+++ b/src/selftest/mpmc_ring.h
@@ -10,9 +10,9 @@
#include <linux/workqueue.h>
#include <linux/wait.h>
-#define THREADS_PRODUCER 16
-#define THREADS_CONSUMER 16
-#define ELEMENT_COUNT 1000000L /* divisible by threads_{consumer,producer} */
+#define THREADS_PRODUCER 2
+#define THREADS_CONSUMER 2
+#define ELEMENT_COUNT 100000000L /* divisible by threads_{consumer,producer} */
#define QUEUE_SIZE 1024
#define EXPECTED_TOTAL ((ELEMENT_COUNT * (ELEMENT_COUNT + 1)) / 2)
diff --git a/src/tests/netns.sh b/src/tests/netns.sh
index d1950a0..99c0020 100755
--- a/src/tests/netns.sh
+++ b/src/tests/netns.sh
@@ -118,7 +118,10 @@ tests() {
# TCP over IPv4
n2 iperf3 -s -1 -B 192.168.241.2 &
waitiperf $netns2
- n1 iperf3 -Z -t 3 -c 192.168.241.2
+ n1 iperf3 -Z -t 120 -c 192.168.241.2
+
+ sleep 10
+ exit
# TCP over IPv6
n1 iperf3 -s -1 -B fd00::1 &