refactor: implement sandbox request interface

main
Sean McBride 5 years ago
parent 34d91cfa21
commit 6eb5825b55

@ -1,10 +0,0 @@
#ifndef SFRT_SANDBOX_REQUEST_QUEUE_H
#define SFRT_SANDBOX_REQUEST_QUEUE_H
#include <sandbox_request.h>
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 */

@ -0,0 +1,21 @@
#ifndef SFRT_SANDBOX_REQUEST_SCHEDULER_H
#define SFRT_SANDBOX_REQUEST_SCHEDULER_H
#include <sandbox_request.h>
// 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 */

@ -0,0 +1,8 @@
#ifndef SFRT_SANDBOX_REQUEST_SCHEDULER_FIFO_H
#define SFRT_SANDBOX_REQUEST_SCHEDULER_FIFO_H
#include <sandbox_request_scheduler.h>
void sandbox_request_scheduler_fifo_initialize();
#endif /* SFRT_SANDBOX_REQUEST_QUEUE_H */

@ -20,7 +20,7 @@
#include <module.h>
#include <sandbox.h>
#include <sandbox_request.h>
#include <sandbox_request_queue.h>
#include <sandbox_request_scheduler_fifo.h>
#include <software_interrupt.h>
#include <types.h>
@ -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,

@ -0,0 +1,28 @@
#include <sandbox_request_scheduler.h>
// 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();
}

@ -1,56 +1,19 @@
#include <sandbox_request_queue.h>
#include <priority_queue.h>
enum scheduling_policy
{
FIFO,
PS
};
enum scheduling_policy sandbox_request_queue_policy = FIFO;
#include <sandbox_request_scheduler.h>
// 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);
}
Loading…
Cancel
Save