From e898d5ab6922f595c1ccb4e22b36d07f132b9a71 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 29 Jul 2020 13:29:41 -0400 Subject: [PATCH] chore: validate interrupts disabled at spinlock --- runtime/include/runtime.h | 5 +++++ runtime/src/global_request_scheduler_minheap.c | 9 +++++++++ runtime/src/local_runqueue_minheap.c | 7 ++++++- runtime/src/runtime.c | 1 - 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 64ab053..85a0680 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -1,5 +1,6 @@ #pragma once +#include #include /* for epoll_create1(), epoll_ctl(), struct epoll_event */ #include @@ -26,6 +27,10 @@ void stub_init(int32_t offset); unsigned long long __getcycles(void); +/** + * Used to determine if running in the context of a worker thread + * @returns true if worker. false if listener core + */ static inline bool runtime_is_worker() { diff --git a/runtime/src/global_request_scheduler_minheap.c b/runtime/src/global_request_scheduler_minheap.c index d7c9219..c8cc628 100644 --- a/runtime/src/global_request_scheduler_minheap.c +++ b/runtime/src/global_request_scheduler_minheap.c @@ -1,6 +1,9 @@ +#include + #include "global_request_scheduler.h" #include "panic.h" #include "priority_queue.h" +#include "runtime.h" static struct priority_queue global_request_scheduler_minheap; @@ -12,6 +15,11 @@ static struct priority_queue global_request_scheduler_minheap; static struct sandbox_request * global_request_scheduler_minheap_add(void *sandbox_request) { +/* This function is called by both the listener core and workers */ +#ifndef NDEBUG + if (runtime_is_worker()) assert(!software_interrupt_is_enabled()); +#endif + int return_code = priority_queue_enqueue(&global_request_scheduler_minheap, sandbox_request); /* TODO: Propagate -1 to caller */ if (return_code == -1) panic("Request Queue is full\n"); @@ -25,6 +33,7 @@ global_request_scheduler_minheap_add(void *sandbox_request) int global_request_scheduler_minheap_remove(struct sandbox_request **removed_sandbox_request) { + assert(!software_interrupt_is_enabled()); return priority_queue_dequeue(&global_request_scheduler_minheap, (void **)removed_sandbox_request); } diff --git a/runtime/src/local_runqueue_minheap.c b/runtime/src/local_runqueue_minheap.c index 76b12fb..2c7e336 100644 --- a/runtime/src/local_runqueue_minheap.c +++ b/runtime/src/local_runqueue_minheap.c @@ -30,6 +30,8 @@ local_runqueue_minheap_is_empty() void local_runqueue_minheap_add(struct sandbox *sandbox) { + assert(!software_interrupt_is_enabled()); + int return_code = priority_queue_enqueue(&local_runqueue_minheap, sandbox); /* TODO: propagate RC to caller */ if (return_code == -1) panic("Thread Runqueue is full!\n"); @@ -43,6 +45,8 @@ local_runqueue_minheap_add(struct sandbox *sandbox) static int local_runqueue_minheap_remove(struct sandbox **to_remove) { + assert(!software_interrupt_is_enabled()); + return priority_queue_dequeue(&local_runqueue_minheap, (void **)to_remove); } @@ -53,7 +57,9 @@ local_runqueue_minheap_remove(struct sandbox **to_remove) static void local_runqueue_minheap_delete(struct sandbox *sandbox) { + assert(!software_interrupt_is_enabled()); assert(sandbox != NULL); + int rc = priority_queue_delete(&local_runqueue_minheap, sandbox); if (rc == -1) { panic("Tried to delete sandbox %lu from runqueue, but was not present\n", @@ -72,7 +78,6 @@ local_runqueue_minheap_delete(struct sandbox *sandbox) struct sandbox * local_runqueue_minheap_get_next() { - /* Assumption: Software Interrupts are disabed by caller */ assert(!software_interrupt_is_enabled()); struct sandbox * sandbox = NULL; diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index 1f64f10..c4a1291 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -1,4 +1,3 @@ -#include #include #include #include