aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorThomas Gschwantner <tharre3@gmail.com>2018-06-04 19:44:17 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-06-04 20:30:02 +0200
commit0df81af3d435aaf29f3dee813c4b30952845e97e (patch)
treea6e00c62082f7b7e206d387428c75e351edcff57
parentWIP8 (diff)
downloadWireGuard-tg/mpmc_ring.tar.xz
WireGuard-tg/mpmc_ring.zip
-rw-r--r--src/mpmc_ring.h26
-rw-r--r--src/receive.c2
-rw-r--r--src/send.c2
3 files changed, 11 insertions, 19 deletions
diff --git a/src/mpmc_ring.h b/src/mpmc_ring.h
index 9ef32ce..280b7f9 100644
--- a/src/mpmc_ring.h
+++ b/src/mpmc_ring.h
@@ -38,7 +38,7 @@
/* http://concurrencykit.org/doc/ck_pr_fence_store_atomic.html */
/* this actually resolves to __asm__ __volatile__("" ::: "memory"); in x86-64 */
/* so basically a compiler barrier? */
-#define ck_pr_fence_store_atomic() smp_mb__before_atomic() /* TODO: probably overkill? */
+#define ck_pr_fence_store_atomic() /*smp_mb__before_atomic()*/ /* TODO: probably overkill? */
/*
* Concurrent ring buffer.
@@ -174,7 +174,7 @@ __always_inline static void *ck_ring_trydequeue_mpmc(struct ck_ring *ring)
if (unlikely(consumer == producer))
return NULL;
- smp_rmb();
+ //smp_rmb();
target = READ_ONCE(ring->queue[consumer]);
@@ -205,7 +205,7 @@ __always_inline static void *ck_ring_dequeue_mpmc(struct ck_ring *ring)
if (unlikely(consumer == producer))
return NULL;
- smp_rmb();
+ //smp_rmb();
target = READ_ONCE(ring->queue[consumer]);
@@ -305,7 +305,7 @@ static __always_inline bool mpmc_ring_empty(struct ck_ring *ring)
smp_rmb();
producer = atomic_read(&ring->p_tail);
- smp_rmb();
+ //smp_rmb();
return producer == consumer;
}
@@ -315,28 +315,20 @@ static __always_inline void mpmc_ring_cleanup(struct ck_ring *ring)
kfree(ring->queue);
}
-static __always_inline bool mpmc_ptr_ring_peek(struct ck_ring *ring, void *data,
- uint size)
+static __always_inline void *mpmc_ptr_ring_peek(struct ck_ring *ring)
{
uint producer, consumer;
- const unsigned int mask = ring->mask;
- void *buffer;
consumer = atomic_read(&ring->c_head);
smp_rmb();
producer = atomic_read(&ring->p_tail);
- smp_rmb();
+ //smp_rmb();
- if (unlikely(producer == consumer)) {
- data = NULL;
- return false;
- }
-
- buffer = (char *)ring->queue + size * (consumer & mask);
- memcpy(data, buffer, size);
+ if (unlikely(producer == consumer))
+ return NULL;
- return true;
+ return ring->queue[consumer];
}
static __always_inline void mpmc_ptr_ring_discard(struct ck_ring *ring)
diff --git a/src/receive.c b/src/receive.c
index b7f14e9..a085049 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -378,7 +378,7 @@ void packet_rx_worker(struct work_struct *work)
bool free;
local_bh_disable();
- while (mpmc_ptr_ring_peek(&queue->ring, &skb, sizeof(struct sk_buff*)) && (state = atomic_read(&PACKET_CB(skb)->state)) != PACKET_STATE_UNCRYPTED) {
+ while ((skb = mpmc_ptr_ring_peek(&queue->ring)) != NULL && (state = atomic_read(&PACKET_CB(skb)->state)) != PACKET_STATE_UNCRYPTED) {
mpmc_ptr_ring_discard(&queue->ring);
peer = PACKET_PEER(skb);
keypair = PACKET_CB(skb)->keypair;
diff --git a/src/send.c b/src/send.c
index 79c5bbe..47abbce 100644
--- a/src/send.c
+++ b/src/send.c
@@ -223,7 +223,7 @@ void packet_tx_worker(struct work_struct *work)
struct sk_buff *first;
enum packet_state state;
- while (mpmc_ptr_ring_peek(&queue->ring, &first, sizeof(struct sk_buff*)) && (state = atomic_read(&PACKET_CB(first)->state)) != PACKET_STATE_UNCRYPTED) {
+ while ((first = mpmc_ptr_ring_peek(&queue->ring)) != NULL && (state = atomic_read(&PACKET_CB(first)->state)) != PACKET_STATE_UNCRYPTED) {
mpmc_ptr_ring_discard(&queue->ring);
peer = PACKET_PEER(first);
keypair = PACKET_CB(first)->keypair;