From 2f164c34302c6487050d7b55adeb9b13f68c0f9c Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 10 Jul 2020 13:34:42 -0400 Subject: [PATCH] chore: refactor our sandbox_request_t --- runtime/include/global_request_scheduler.h | 10 +++++----- runtime/include/sandbox.h | 8 +++----- runtime/include/sandbox_request.h | 8 +++----- runtime/src/current_sandbox.c | 2 +- runtime/src/global_request_scheduler.c | 10 +++++----- runtime/src/global_request_scheduler_deque.c | 8 ++++---- runtime/src/global_request_scheduler_minheap.c | 6 +++--- runtime/src/libc/uvio.c | 6 +++--- runtime/src/local_runqueue_list.c | 2 +- runtime/src/local_runqueue_minheap.c | 10 +++++----- runtime/src/runtime.c | 2 +- runtime/src/sandbox.c | 4 ++-- runtime/src/worker_thread.c | 4 ++-- 13 files changed, 38 insertions(+), 42 deletions(-) diff --git a/runtime/include/global_request_scheduler.h b/runtime/include/global_request_scheduler.h index 252dde5..f4c1304 100644 --- a/runtime/include/global_request_scheduler.h +++ b/runtime/include/global_request_scheduler.h @@ -3,8 +3,8 @@ #include "sandbox_request.h" /* Returns pointer back if successful, null otherwise */ -typedef sandbox_request_t *(*global_request_scheduler_add_fn_t)(void *); -typedef int (*global_request_scheduler_remove_fn_t)(sandbox_request_t **); +typedef struct sandbox_request *(*global_request_scheduler_add_fn_t)(void *); +typedef int (*global_request_scheduler_remove_fn_t)(struct sandbox_request **); typedef uint64_t (*global_request_scheduler_peek_fn_t)(void); struct global_request_scheduler_config { @@ -16,6 +16,6 @@ struct global_request_scheduler_config { void global_request_scheduler_initialize(struct global_request_scheduler_config *config); -sandbox_request_t *global_request_scheduler_add(sandbox_request_t *); -int global_request_scheduler_remove(sandbox_request_t **); -uint64_t global_request_scheduler_peek(); +struct sandbox_request *global_request_scheduler_add(struct sandbox_request *); +int global_request_scheduler_remove(struct sandbox_request **); +uint64_t global_request_scheduler_peek(); diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index e62d898..082376b 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -75,8 +75,6 @@ struct sandbox { char request_response_data[1]; /* of request_response_data_length, following sandbox mem.. */ } PAGE_ALIGNED; -typedef struct sandbox sandbox_t; - /*************************** * Externs * **************************/ @@ -85,16 +83,16 @@ typedef struct sandbox sandbox_t; extern __thread arch_context_t *worker_thread_next_context; extern void worker_thread_block_current_sandbox(void); -extern void worker_thread_on_sandbox_exit(sandbox_t *sandbox); +extern void worker_thread_on_sandbox_exit(struct sandbox *sandbox); extern void worker_thread_process_io(void); extern void __attribute__((noreturn)) worker_thread_sandbox_switch_preempt(void); -extern void worker_thread_wakeup_sandbox(sandbox_t *sandbox); +extern void worker_thread_wakeup_sandbox(struct sandbox *sandbox); /*************************** * Public API * **************************/ -struct sandbox *sandbox_allocate(sandbox_request_t *sandbox_request); +struct sandbox *sandbox_allocate(struct sandbox_request *sandbox_request); void sandbox_free(struct sandbox *sandbox); void sandbox_main(struct sandbox *sandbox); int sandbox_parse_http_request(struct sandbox *sandbox, size_t length); diff --git a/runtime/include/sandbox_request.h b/runtime/include/sandbox_request.h index d44bea2..44928b9 100644 --- a/runtime/include/sandbox_request.h +++ b/runtime/include/sandbox_request.h @@ -18,9 +18,7 @@ struct sandbox_request { uint64_t absolute_deadline; /* cycles */ }; -typedef struct sandbox_request sandbox_request_t; - -DEQUE_PROTOTYPE(sandbox, sandbox_request_t *); +DEQUE_PROTOTYPE(sandbox, struct sandbox_request *); /** * Allocates a new Sandbox Request and places it on the Global Deque @@ -31,11 +29,11 @@ DEQUE_PROTOTYPE(sandbox, sandbox_request_t *); * @param start_time the timestamp of when we receives the request from the network (in cycles) * @return the new sandbox request */ -static inline sandbox_request_t * +static inline struct sandbox_request * sandbox_request_allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, uint64_t start_time) { - sandbox_request_t *sandbox_request = (sandbox_request_t *)malloc(sizeof(sandbox_request_t)); + struct sandbox_request *sandbox_request = (struct sandbox_request *)malloc(sizeof(struct sandbox_request)); assert(sandbox_request); sandbox_request->module = module; sandbox_request->arguments = arguments; diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index f73cc11..873b900 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -2,7 +2,7 @@ #include "types.h" /* current sandbox that is active.. */ -static __thread sandbox_t *worker_thread_current_sandbox = NULL; +static __thread struct sandbox *worker_thread_current_sandbox = NULL; __thread struct sandbox_context_cache local_sandbox_context_cache = { .linear_memory_start = NULL, diff --git a/runtime/src/global_request_scheduler.c b/runtime/src/global_request_scheduler.c index da0d816..270e8fd 100644 --- a/runtime/src/global_request_scheduler.c +++ b/runtime/src/global_request_scheduler.c @@ -2,14 +2,14 @@ #include "panic.h" /* Default uninitialized implementations of the polymorphic interface */ -__attribute__((noreturn)) static sandbox_request_t * +__attribute__((noreturn)) static struct sandbox_request * uninitialized_add(void *arg) { panic("Global Request Scheduler Add was called before initialization\n"); }; __attribute__((noreturn)) static int -uninitialized_remove(sandbox_request_t **arg) +uninitialized_remove(struct sandbox_request **arg) { panic("Global Request Scheduler Remove was called before initialization\n"); }; @@ -41,8 +41,8 @@ global_request_scheduler_initialize(struct global_request_scheduler_config *conf * Adds a sandbox request to the request scheduler * @param sandbox_request */ -sandbox_request_t * -global_request_scheduler_add(sandbox_request_t *sandbox_request) +struct sandbox_request * +global_request_scheduler_add(struct sandbox_request *sandbox_request) { return global_request_scheduler.add_fn(sandbox_request); } @@ -53,7 +53,7 @@ global_request_scheduler_add(sandbox_request_t *sandbox_request) * @returns 0 if successful, -1 if empty, -2 if unable to take lock or perform atomic operation */ int -global_request_scheduler_remove(sandbox_request_t **removed_sandbox) +global_request_scheduler_remove(struct sandbox_request **removed_sandbox) { return global_request_scheduler.remove_fn(removed_sandbox); } diff --git a/runtime/src/global_request_scheduler_deque.c b/runtime/src/global_request_scheduler_deque.c index 3028fea..b75d167 100644 --- a/runtime/src/global_request_scheduler_deque.c +++ b/runtime/src/global_request_scheduler_deque.c @@ -8,11 +8,11 @@ static pthread_mutex_t global_request_scheduler_deque_mutex = PTHREAD_MUTE * @param sandbox_request * @returns pointer to request if added. NULL otherwise */ -static sandbox_request_t * +static struct sandbox_request * global_request_scheduler_deque_add(void *sandbox_request_raw) { - sandbox_request_t *sandbox_request = (sandbox_request_t *)sandbox_request_raw; - int return_code = 1; + struct sandbox_request *sandbox_request = (struct sandbox_request *)sandbox_request_raw; + int return_code = 1; /* TODO: Running the runtime and listener cores on a single shared core is untested We are unsure if the locking behavior is correct, so there may be deadlocks */ @@ -42,7 +42,7 @@ We are unsure if the locking behavior is correct, so there may be deadlocks */ * @returns 0 if successfully returned a sandbox request, -1 if empty, -2 if atomic instruction unsuccessful */ static int -global_request_scheduler_deque_remove(sandbox_request_t **removed_sandbox_request) +global_request_scheduler_deque_remove(struct sandbox_request **removed_sandbox_request) { int return_code; #if NCORES == 1 diff --git a/runtime/src/global_request_scheduler_minheap.c b/runtime/src/global_request_scheduler_minheap.c index f75bdbd..d7c9219 100644 --- a/runtime/src/global_request_scheduler_minheap.c +++ b/runtime/src/global_request_scheduler_minheap.c @@ -9,7 +9,7 @@ static struct priority_queue global_request_scheduler_minheap; * @param sandbox_request * @returns pointer to request if added. NULL otherwise */ -static sandbox_request_t * +static struct sandbox_request * global_request_scheduler_minheap_add(void *sandbox_request) { int return_code = priority_queue_enqueue(&global_request_scheduler_minheap, sandbox_request); @@ -23,7 +23,7 @@ global_request_scheduler_minheap_add(void *sandbox_request) * @returns 0 if successful, -1 if empty, -2 if unable to take lock or perform atomic operation */ int -global_request_scheduler_minheap_remove(sandbox_request_t **removed_sandbox_request) +global_request_scheduler_minheap_remove(struct sandbox_request **removed_sandbox_request) { return priority_queue_dequeue(&global_request_scheduler_minheap, (void **)removed_sandbox_request); } @@ -43,7 +43,7 @@ global_request_scheduler_minheap_peek(void) uint64_t sandbox_request_get_priority_fn(void *element) { - sandbox_request_t *sandbox_request = (sandbox_request_t *)element; + struct sandbox_request *sandbox_request = (struct sandbox_request *)element; return sandbox_request->absolute_deadline; }; diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index 514c8f8..185ff7d 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -100,7 +100,7 @@ static void wasm_fs_callback(uv_fs_t *req) { debuglog("[%p]\n", req->data); - worker_thread_wakeup_sandbox((sandbox_t *)req->data); + worker_thread_wakeup_sandbox((struct sandbox *)req->data); } // We define our own syscall numbers, because WASM uses x86_64 values even on systems that are not x86_64 @@ -759,7 +759,7 @@ wasm_fchown(int32_t file_descriptor, uint32_t owner, uint32_t group) static void wasm_connection_callback(uv_stream_t *srv, int status) { - sandbox_t *s = srv->data; + struct sandbox *s = srv->data; debuglog(" [%p]\n", s); s->return_value = status; worker_thread_wakeup_sandbox(s); @@ -769,7 +769,7 @@ static void wasm_connect_callback(uv_connect_t *req, int status) { // TODO: how do we use the handle in uv_connect_t ?? - sandbox_t *s = req->data; + struct sandbox *s = req->data; debuglog(" [%p]\n", s); s->return_value = status; worker_thread_wakeup_sandbox(s); diff --git a/runtime/src/local_runqueue_list.c b/runtime/src/local_runqueue_list.c index 7ccbe79..84342c6 100644 --- a/runtime/src/local_runqueue_list.c +++ b/runtime/src/local_runqueue_list.c @@ -45,7 +45,7 @@ local_runqueue_list_get_next() { // If our local runqueue is empty, try to pull and allocate a sandbox request from the global request scheduler if (local_runqueue_is_empty()) { - sandbox_request_t *sandbox_request; + struct sandbox_request *sandbox_request; int return_code = global_request_scheduler_remove(&sandbox_request); if (return_code != 0) return NULL; diff --git a/runtime/src/local_runqueue_minheap.c b/runtime/src/local_runqueue_minheap.c index 337ff24..090d242 100644 --- a/runtime/src/local_runqueue_minheap.c +++ b/runtime/src/local_runqueue_minheap.c @@ -82,8 +82,8 @@ local_runqueue_minheap_get_next() local_runqueue_minheap_add(sandbox); } else if (sandbox_rc == -1) { /* local runqueue was empty, try to pull a sandbox request and return NULL if we're unable to get one */ - sandbox_request_t *sandbox_request; - int sandbox_request_rc = global_request_scheduler_remove(&sandbox_request); + struct sandbox_request *sandbox_request; + int sandbox_request_rc = global_request_scheduler_remove(&sandbox_request); if (sandbox_request_rc != 0) return NULL; sandbox = sandbox_allocate(sandbox_request); @@ -129,10 +129,10 @@ local_runqueue_minheap_preempt(ucontext_t *user_context) if (local_deadline == ULONG_MAX) { assert(local_runqueue_minheap.first_free == 1); }; /* If we're able to get a sandbox request with a tighter deadline, preempt the current context and run it */ - sandbox_request_t *sandbox_request; + struct sandbox_request *sandbox_request; if (global_deadline < local_deadline) { - sandbox_request_t *sandbox_request; - int return_code = global_request_scheduler_remove(&sandbox_request); + struct sandbox_request *sandbox_request; + int return_code = global_request_scheduler_remove(&sandbox_request); // If we were unable to get a sandbox_request, exit if (return_code != 0) goto done; diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index 5968a85..bd1c688 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -95,7 +95,7 @@ listener_thread_main(void *dummy) total_requests++; /* Allocate a Sandbox Request */ - sandbox_request_t *sandbox_request = + struct sandbox_request *sandbox_request = sandbox_request_allocate(module, module->name, socket_descriptor, (const struct sockaddr *)&client_address, start_time); assert(sandbox_request); diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index c5b85c8..901a01d 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -346,7 +346,7 @@ err: } int -sandbox_allocate_stack(sandbox_t *sandbox) +sandbox_allocate_stack(struct sandbox *sandbox) { assert(sandbox); assert(sandbox->module); @@ -365,7 +365,7 @@ err_stack_allocation_failed: } struct sandbox * -sandbox_allocate(sandbox_request_t *sandbox_request) +sandbox_allocate(struct sandbox_request *sandbox_request) { assert(sandbox_request != NULL); assert(sandbox_request->module != NULL); diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index 29e5993..80c2677 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -82,7 +82,7 @@ worker_thread_switch_to_sandbox(struct sandbox *next_sandbox) * @param sandbox the sandbox to check and update if blocked */ void -worker_thread_wakeup_sandbox(sandbox_t *sandbox) +worker_thread_wakeup_sandbox(struct sandbox *sandbox) { software_interrupt_disable(); if (sandbox->state != SANDBOX_BLOCKED) goto done; @@ -219,7 +219,7 @@ worker_thread_main(void *return_code) * TODO: Consider moving this to a future current_sandbox file. This has thus far proven difficult to move */ void -worker_thread_on_sandbox_exit(sandbox_t *exiting_sandbox) +worker_thread_on_sandbox_exit(struct sandbox *exiting_sandbox) { assert(exiting_sandbox);