aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/queueing.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-06-07 01:39:08 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2017-09-18 17:38:16 +0200
commit0bc7c9d057d137b72c54d2da7fca522d36128f6a (patch)
tree44b70fb62507849b1e4ef9a2a78bddf9a108165e /src/queueing.c
parentcompat: ensure we can build without compat.h (diff)
downloadwireguard-monolithic-historical-0bc7c9d057d137b72c54d2da7fca522d36128f6a.tar.xz
wireguard-monolithic-historical-0bc7c9d057d137b72c54d2da7fca522d36128f6a.zip
queue: entirely rework parallel system
This removes our dependency on padata and moves to a different mode of multiprocessing that is more efficient. This began as Samuel Holland's GSoC project and was gradually reworked/redesigned/rebased into this present commit, which is a combination of his initial contribution and my subsequent rewriting and redesigning.
Diffstat (limited to 'src/queueing.c')
-rw-r--r--src/queueing.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/queueing.c b/src/queueing.c
new file mode 100644
index 0000000..86e1324
--- /dev/null
+++ b/src/queueing.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */
+
+#include "queueing.h"
+#include <linux/slab.h>
+
+struct kmem_cache *crypt_ctx_cache __read_mostly;
+
+struct multicore_worker __percpu *packet_alloc_percpu_multicore_worker(work_func_t function, void *ptr)
+{
+ int cpu;
+ struct multicore_worker __percpu *worker = alloc_percpu(struct multicore_worker);
+ if (!worker)
+ return NULL;
+ for_each_possible_cpu (cpu) {
+ per_cpu_ptr(worker, cpu)->ptr = ptr;
+ INIT_WORK(&per_cpu_ptr(worker, cpu)->work, function);
+ }
+ return worker;
+}
+
+int packet_queue_init(struct crypt_queue *queue, work_func_t function, bool multicore)
+{
+ INIT_LIST_HEAD(&queue->queue);
+ queue->len = 0;
+ spin_lock_init(&queue->lock);
+ if (multicore) {
+ queue->worker = packet_alloc_percpu_multicore_worker(function, queue);
+ if (!queue->worker)
+ return -ENOMEM;
+ } else
+ INIT_WORK(&queue->work, function);
+ return 0;
+}
+
+int __init init_crypt_ctx_cache(void)
+{
+ crypt_ctx_cache = KMEM_CACHE(crypt_ctx, 0);
+ if (!crypt_ctx_cache)
+ return -ENOMEM;
+ return 0;
+}
+
+void deinit_crypt_ctx_cache(void)
+{
+ kmem_cache_destroy(crypt_ctx_cache);
+}