diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-17 16:54:42 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-17 16:54:42 +0200 |
commit | 89bcc229184341f31d87e6f359731fa12d5b5c5a (patch) | |
tree | 1844ffbd0d5963eccfea10ceb3b29ed4f68a1b08 | |
parent | Test commit (diff) | |
download | wireguard-monolithic-historical-89bcc229184341f31d87e6f359731fa12d5b5c5a.tar.xz wireguard-monolithic-historical-89bcc229184341f31d87e6f359731fa12d5b5c5a.zip |
selftest/mpmc_ring: small restructuring
-rw-r--r-- | src/selftest/mpmc_ring.h | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/selftest/mpmc_ring.h b/src/selftest/mpmc_ring.h index f5f8fcf..c862d78 100644 --- a/src/selftest/mpmc_ring.h +++ b/src/selftest/mpmc_ring.h @@ -20,15 +20,15 @@ #define PER_CONSUMER (ELEMENT_COUNT/THREADS_CONSUMER) #define THREADS_TOTAL (THREADS_PRODUCER + THREADS_CONSUMER) -struct mpmc_ptr_ring *ring __initdata; - struct worker_producer { struct work_struct work; + struct mpmc_ptr_ring *ring; int thread_num; }; struct worker_consumer { struct work_struct work; + struct mpmc_ptr_ring *ring; int thread_num; int64_t total; int64_t count; @@ -37,10 +37,10 @@ struct worker_consumer { static __init void producer_function(struct work_struct *work) { struct worker_producer *td = container_of(work, struct worker_producer, work); - uintptr_t count = (td->thread_num * PER_PRODUCER) + 1; + uintptr_t i; - for (; count <= (td->thread_num + 1) * PER_PRODUCER; ++count) { - while (mpmc_ptr_ring_produce(ring, (void *) count)) { + for (i = td->thread_num * PER_PRODUCER + 1; i <= (td->thread_num + 1) * PER_PRODUCER; ++i) { + while (mpmc_ptr_ring_produce(td->ring, (void *)i)) { schedule(); /*pr_info("We have awoken (producer)");*/ } @@ -54,14 +54,14 @@ static __init void consumer_function(struct work_struct *work) for (i = 0; i < PER_CONSUMER; ++i) { uintptr_t value; - while (!(value = (uintptr_t) mpmc_ptr_ring_consume(ring))) { + while (!(value = (uintptr_t)mpmc_ptr_ring_consume(td->ring))) { schedule(); /*cpu_relax();*/ /*pr_info("We have awoken (consumer)");*/ } td->total += value; - ++(td->count); + ++td->count; } } @@ -70,38 +70,37 @@ bool __init mpmc_ring_selftest(void) struct workqueue_struct *wq; struct worker_producer *producers; struct worker_consumer *consumers; + struct mpmc_ptr_ring ring; int64_t total = 0, count = 0; int i; producers = kmalloc_array(THREADS_PRODUCER, sizeof(*producers), GFP_KERNEL); consumers = kmalloc_array(THREADS_CONSUMER, sizeof(*consumers), GFP_KERNEL); - ring = kmalloc(sizeof(*ring), GFP_KERNEL); - BUG_ON(!ring || !producers || !consumers); - BUG_ON(mpmc_ptr_ring_init(ring, QUEUE_SIZE, GFP_KERNEL)); + BUG_ON(!producers || !consumers); + BUG_ON(mpmc_ptr_ring_init(&ring, QUEUE_SIZE, GFP_KERNEL)); wq = alloc_workqueue("mpmc_ring_selftest", WQ_UNBOUND, 0); for (i = 0; i < THREADS_PRODUCER; ++i) { + producers[i].ring = ˚ producers[i].thread_num = i; INIT_WORK(&producers[i].work, producer_function); queue_work(wq, &producers[i].work); } for (i = 0; i < THREADS_CONSUMER; ++i) { - consumers[i] = (struct worker_consumer) { - .thread_num = i, - .total = 0, - .count = 0, - }; + consumers[i].ring = ˚ + consumers[i].thread_num = i; + consumers[i].total = 0; + consumers[i].count = 0; INIT_WORK(&consumers[i].work, consumer_function); queue_work(wq, &consumers[i].work); } destroy_workqueue(wq); - BUG_ON(!mpmc_ptr_ring_empty(ring)); - mpmc_ptr_ring_cleanup(ring, NULL); - kfree(ring); + BUG_ON(!mpmc_ptr_ring_empty(&ring)); + mpmc_ptr_ring_cleanup(&ring, NULL); for (i = 0; i < THREADS_CONSUMER; ++i) { total += consumers[i].total; |