diff --git a/runtime/include/sandbox_request_queue.h b/runtime/include/sandbox_request_queue.h deleted file mode 100644 index d1ebb43..0000000 --- a/runtime/include/sandbox_request_queue.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SFRT_SANDBOX_REQUEST_QUEUE_H -#define SFRT_SANDBOX_REQUEST_QUEUE_H - -#include - -void sandbox_request_queue_initialize(void); -int sandbox_request_queue_add(sandbox_request_t *); -sandbox_request_t *sandbox_request_queue_remove(void); - -#endif /* SFRT_SANDBOX_REQUEST_QUEUE_H */ \ No newline at end of file diff --git a/runtime/include/sandbox_request_scheduler.h b/runtime/include/sandbox_request_scheduler.h new file mode 100644 index 0000000..fbc3a4a --- /dev/null +++ b/runtime/include/sandbox_request_scheduler.h @@ -0,0 +1,21 @@ +#ifndef SFRT_SANDBOX_REQUEST_SCHEDULER_H +#define SFRT_SANDBOX_REQUEST_SCHEDULER_H + +#include + +// Returns pointer back if successful, null otherwise +typedef sandbox_request_t *(*sandbox_request_scheduler_add_t)(void *); +typedef sandbox_request_t *(*sandbox_request_scheduler_remove_t)(void); + +typedef struct sandbox_request_scheduler_config_t { + sandbox_request_scheduler_add_t add; + sandbox_request_scheduler_remove_t remove; +} sandbox_request_scheduler_config_t; + + +void sandbox_request_scheduler_initialize(sandbox_request_scheduler_config_t *config); + +sandbox_request_t *sandbox_request_scheduler_add(sandbox_request_t *); +sandbox_request_t *sandbox_request_scheduler_remove(); + +#endif /* SFRT_SANDBOX_REQUEST_QUEUE_H */ \ No newline at end of file diff --git a/runtime/include/sandbox_request_scheduler_fifo.h b/runtime/include/sandbox_request_scheduler_fifo.h new file mode 100644 index 0000000..282a9ef --- /dev/null +++ b/runtime/include/sandbox_request_scheduler_fifo.h @@ -0,0 +1,8 @@ +#ifndef SFRT_SANDBOX_REQUEST_SCHEDULER_FIFO_H +#define SFRT_SANDBOX_REQUEST_SCHEDULER_FIFO_H + +#include + +void sandbox_request_scheduler_fifo_initialize(); + +#endif /* SFRT_SANDBOX_REQUEST_QUEUE_H */ \ No newline at end of file diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index 8d22c69..006a51c 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -45,7 +45,7 @@ runtime_initialize(void) assert(runtime_epoll_file_descriptor >= 0); // Allocate and Initialize the global deque - sandbox_request_queue_initialize(); + sandbox_request_scheduler_fifo_initialize(); // Mask Signals software_interrupt_mask_signal(SIGUSR1); @@ -102,7 +102,7 @@ listener_thread_main(void *dummy) sandbox_request_allocate(module, module->name, socket_descriptor, (const struct sockaddr *)&client_address, start_time); assert(sandbox_request); - sandbox_request_queue_add(sandbox_request); + sandbox_request_scheduler_add(sandbox_request); } } @@ -268,7 +268,7 @@ worker_thread_pull_and_process_sandbox_requests(void) while (total_sandboxes_pulled < SANDBOX_PULL_BATCH_SIZE) { sandbox_request_t *sandbox_request; - if ((sandbox_request = sandbox_request_queue_remove()) == NULL) break; + if ((sandbox_request = sandbox_request_scheduler_remove()) == NULL) break; // Actually allocate the sandbox for the requests that we've pulled struct sandbox *sandbox = sandbox_allocate(sandbox_request->module, sandbox_request->arguments, sandbox_request->socket_descriptor, diff --git a/runtime/src/sandbox_request_scheduler.c b/runtime/src/sandbox_request_scheduler.c new file mode 100644 index 0000000..31c9549 --- /dev/null +++ b/runtime/src/sandbox_request_scheduler.c @@ -0,0 +1,28 @@ +#include + + +// The global of our polymorphic interface +sandbox_request_scheduler_config_t sandbox_request_scheduler; + +// Initializes a concrete implementation of the sandbox request scheduler interface +void +sandbox_request_scheduler_initialize(sandbox_request_scheduler_config_t *config) +{ + memcpy(&sandbox_request_scheduler, config, sizeof(sandbox_request_scheduler_config_t)); +} + +// Adds a sandbox request +sandbox_request_t * +sandbox_request_scheduler_add(sandbox_request_t *sandbox_request) +{ + assert(sandbox_request_scheduler.add != NULL); + return sandbox_request_scheduler.add(sandbox_request); +} + +// Removes a sandbox request +sandbox_request_t * +sandbox_request_scheduler_remove() +{ + assert(sandbox_request_scheduler.remove != NULL); + return sandbox_request_scheduler.remove(); +} diff --git a/runtime/src/sandbox_request_queue.c b/runtime/src/sandbox_request_scheduler_fifo.c similarity index 53% rename from runtime/src/sandbox_request_queue.c rename to runtime/src/sandbox_request_scheduler_fifo.c index 89b3fae..d4d04bd 100644 --- a/runtime/src/sandbox_request_queue.c +++ b/runtime/src/sandbox_request_scheduler_fifo.c @@ -1,56 +1,19 @@ -#include -#include - -enum scheduling_policy -{ - FIFO, - PS -}; - -enum scheduling_policy sandbox_request_queue_policy = FIFO; +#include // FIFO Globals -struct deque_sandbox *runtime_global_deque; -pthread_mutex_t runtime_global_deque_mutex = PTHREAD_MUTEX_INITIALIZER; - -// PS Globals -struct priority_queue sandbox_request_queue_ps; - -static inline void -sandbox_request_queue_fifo_initialize(void) -{ - // Allocate and Initialize the global deque - runtime_global_deque = (struct deque_sandbox *)malloc(sizeof(struct deque_sandbox)); - assert(runtime_global_deque); - // Note: Below is a Macro - deque_init_sandbox(runtime_global_deque, RUNTIME_MAX_SANDBOX_REQUEST_COUNT); -} - -static inline void -sandbox_request_queue_ps_initialize(void) -{ - // TODO -} - -void -sandbox_request_queue_initialize(void) -{ - switch (sandbox_request_queue_policy) { - case FIFO: - return sandbox_request_queue_fifo_initialize(); - case PS: - return sandbox_request_queue_ps_initialize(); - } -} +static struct deque_sandbox *runtime_global_deque; +static pthread_mutex_t runtime_global_deque_mutex = PTHREAD_MUTEX_INITIALIZER; /** * Pushes a sandbox request to the global deque * @param sandbox_request + * @returns pointer to request if added. NULL otherwise **/ -static inline int -sandbox_request_queue_fifo_add(sandbox_request_t *sandbox_request) +static sandbox_request_t * +sandbox_request_scheduler_fifo_add(void *sandbox_request_raw) { - int return_code; + sandbox_request_t *sandbox_request = (sandbox_request_t *)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 @@ -61,30 +24,7 @@ sandbox_request_queue_fifo_add(sandbox_request_t *sandbox_request) #if NCORES == 1 pthread_mutex_unlock(&runtime_global_deque_mutex); #endif - - return return_code; -} - -static inline int -sandbox_request_queue_ps_add(sandbox_request_t *sandbox_request) -{ - // TODO - return 0; -} - -/** - * Pushes a sandbox request to the global deque - * @param sandbox_request - **/ -int -sandbox_request_queue_add(sandbox_request_t *sandbox_request) -{ - switch (sandbox_request_queue_policy) { - case FIFO: - return sandbox_request_queue_fifo_add(sandbox_request); - case PS: - return sandbox_request_queue_ps_add(sandbox_request); - } + return (return_code == 0) ? sandbox_request_raw : NULL; } /** @@ -101,10 +41,10 @@ sandbox_request_queue_add(sandbox_request_t *sandbox_request) * * @returns A Sandbox Request or NULL **/ -static inline sandbox_request_t * -sandbox_request_queue_fifo_remove(void) +static sandbox_request_t * +sandbox_request_scheduler_fifo_remove(void) { - sandbox_request_t *sandbox_request = NULL; + sandbox_request_t *sandbox_request; #if NCORES == 1 pthread_mutex_lock(&runtime_global_deque_mutex); @@ -117,21 +57,18 @@ sandbox_request_queue_fifo_remove(void) return sandbox_request; } -static inline sandbox_request_t * -sandbox_request_queue_ps_remove(void) +void +sandbox_request_scheduler_fifo_initialize() { - sandbox_request_t *sandbox_request = NULL; - // TODO - return sandbox_request; -} + // Allocate and Initialize the global deque + runtime_global_deque = (struct deque_sandbox *)malloc(sizeof(struct deque_sandbox)); + assert(runtime_global_deque); + // Note: Below is a Macro + deque_init_sandbox(runtime_global_deque, RUNTIME_MAX_SANDBOX_REQUEST_COUNT); -sandbox_request_t * -sandbox_request_queue_remove(void) -{ - switch (sandbox_request_queue_policy) { - case FIFO: - return sandbox_request_queue_fifo_remove(); - case PS: - return sandbox_request_queue_ps_remove(); - } + // Register Function Pointers for Abstract Scheduling API + sandbox_request_scheduler_config_t config = { .add = sandbox_request_scheduler_fifo_add, + .remove = sandbox_request_scheduler_fifo_remove }; + + sandbox_request_scheduler_initialize(&config); } \ No newline at end of file