From 69bdf5b49b68ef5ce8b62992964dee8a0495362b Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 7 Apr 2022 16:32:55 -0400 Subject: [PATCH] feat: grow local runqueue if full --- runtime/src/local_runqueue_minheap.c | 29 ++++++++++++++++++++++++++-- tests/fibonacci/bimodal/Makefile | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/runtime/src/local_runqueue_minheap.c b/runtime/src/local_runqueue_minheap.c index ad3803f..8f3b7b9 100644 --- a/runtime/src/local_runqueue_minheap.c +++ b/runtime/src/local_runqueue_minheap.c @@ -25,6 +25,28 @@ local_runqueue_minheap_is_empty() return priority_queue_length_nolock(local_runqueue_minheap) == 0; } +/** + * Doubles capacity of local runqueue + */ +void +local_runqueue_minheap_grow(void) +{ + assert(local_runqueue_minheap != NULL); + + /* capacity is padded by 1 because idx 0 is padding */ + if (unlikely(local_runqueue_minheap->capacity == 1)) { + debuglog("Growing to 2\n"); + local_runqueue_minheap->capacity++; + } else { + local_runqueue_minheap->capacity = (local_runqueue_minheap->capacity - 1) * 2 + 1; + debuglog("Growing to %zu\n", local_runqueue_minheap->capacity); + } + + local_runqueue_minheap = (struct priority_queue *) + realloc(local_runqueue_minheap, + sizeof(struct priority_queue) + sizeof(void *) * (local_runqueue_minheap->capacity)); +} + /** * Adds a sandbox to the run queue * @param sandbox @@ -34,8 +56,11 @@ void local_runqueue_minheap_add(struct sandbox *sandbox) { int return_code = priority_queue_enqueue_nolock(local_runqueue_minheap, sandbox); - /* TODO: propagate RC to caller. Issue #92 */ - if (return_code == -ENOSPC) panic("Thread Runqueue is full!\n"); + if (unlikely(return_code == -ENOSPC)) { + local_runqueue_minheap_grow(); + return_code = priority_queue_enqueue_nolock(local_runqueue_minheap, sandbox); + if (unlikely(return_code == -ENOSPC)) panic("Thread Runqueue is full!\n"); + } } /** diff --git a/tests/fibonacci/bimodal/Makefile b/tests/fibonacci/bimodal/Makefile index 70b339f..fffbdd7 100644 --- a/tests/fibonacci/bimodal/Makefile +++ b/tests/fibonacci/bimodal/Makefile @@ -45,3 +45,6 @@ client-preempt: client-fib10-multi: hey -z ${DURATION_SEC}s -cpus 4 -c 100 -t 0 -o csv -m GET -d "10\n" "http://${HOSTNAME}:10010" + +client-fib40-multi: + hey -z ${DURATION_SEC}s -cpus 4 -c 100 -t 0 -o csv -m GET -d "40\n" "http://${HOSTNAME}:10040"