From 6d7f0b0a746b06a903ec8e14fe14cd0605fb210f Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 16 Jun 2018 04:52:35 +0200 Subject: simd: encapsulate fpu amortization into nice functions --- src/receive.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/receive.c') diff --git a/src/receive.c b/src/receive.c index f33941b..c5062f8 100644 --- a/src/receive.c +++ b/src/receive.c @@ -10,6 +10,7 @@ #include "messages.h" #include "cookie.h" #include "socket.h" +#include "crypto/simd.h" #include #include @@ -418,21 +419,15 @@ void packet_decrypt_worker(struct work_struct *work) { struct crypt_queue *queue = container_of(work, struct multicore_worker, work)->ptr; struct sk_buff *skb; - bool have_simd = chacha20poly1305_init_simd(); + bool have_simd = simd_get(); while ((skb = ptr_ring_consume_bh(&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); - - /* Don't totally kill scheduling latency by keeping preemption disabled forever. */ - if (have_simd && need_resched()) { - chacha20poly1305_deinit_simd(have_simd); - have_simd = chacha20poly1305_init_simd(); - } + have_simd = simd_relax(have_simd); } - chacha20poly1305_deinit_simd(have_simd); + simd_put(have_simd); } static void packet_consume_data(struct wireguard_device *wg, struct sk_buff *skb) -- cgit v1.2.3-59-g8ed1b