diff options
author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | 2018-05-28 00:40:09 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-04 20:29:48 +0200 |
commit | 0dd372c7488a074ee456f92acc3a45bd351be0a4 (patch) | |
tree | 69fe5048e377c085c5e75f7b37e52ac898cfeb4c /src/receive.c | |
parent | wg-quick: android: change name of intent (diff) | |
download | wireguard-monolithic-historical-0dd372c7488a074ee456f92acc3a45bd351be0a4.tar.xz wireguard-monolithic-historical-0dd372c7488a074ee456f92acc3a45bd351be0a4.zip |
[WIP] Implement a lock-free MPMC ring buffer
TODO: actually use the right memory barriers in the right places
TODO: eliminate false sharing between mpmc_ptr_ring members
TODO: reconsider atomic_long_t vs. atomic_t, vs. the type of size in _init()
TODO: sprinkle likely/unlikely on some branches
FIXME: it still crashes
Diffstat (limited to 'src/receive.c')
-rw-r--r-- | src/receive.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/receive.c b/src/receive.c index 27d3d04..baa41e6 100644 --- a/src/receive.c +++ b/src/receive.c @@ -378,9 +378,8 @@ void packet_rx_worker(struct work_struct *work) bool free; local_bh_disable(); - spin_lock_bh(&queue->ring.consumer_lock); - while ((skb = __ptr_ring_peek(&queue->ring)) != NULL && (state = atomic_read(&PACKET_CB(skb)->state)) != PACKET_STATE_UNCRYPTED) { - __ptr_ring_discard_one(&queue->ring); + while ((skb = __mpmc_ptr_ring_peek(&queue->ring)) != NULL && (state = atomic_read(&PACKET_CB(skb)->state)) != PACKET_STATE_UNCRYPTED) { + __mpmc_ptr_ring_discard_one(&queue->ring); peer = PACKET_PEER(skb); keypair = PACKET_CB(skb)->keypair; free = true; @@ -406,7 +405,6 @@ next: if (unlikely(free)) dev_kfree_skb(skb); } - spin_unlock_bh(&queue->ring.consumer_lock); local_bh_enable(); } @@ -416,7 +414,7 @@ void packet_decrypt_worker(struct work_struct *work) struct sk_buff *skb; bool have_simd = chacha20poly1305_init_simd(); - while ((skb = ptr_ring_consume_bh(&queue->ring)) != NULL) { + while ((skb = mpmc_ptr_ring_consume(&queue->ring)) != NULL) { enum packet_state state = likely(skb_decrypt(skb, &PACKET_CB(skb)->keypair->receiving, have_simd)) ? PACKET_STATE_CRYPTED : PACKET_STATE_DEAD; queue_enqueue_per_peer(&PACKET_PEER(skb)->rx_queue, skb, state); |