feat: Assign start_time to sandbox

main
Sean McBride 5 years ago
parent b0434ac941
commit d058f99e0f

@ -80,14 +80,14 @@ struct sandbox_request {
char * args;
int sock;
struct sockaddr *addr;
unsigned long long int start_time_in_cycles;
u64 start_time; // cycles
};
typedef struct sandbox_request sbox_request_t;
DEQUE_PROTOTYPE(sandbox, sbox_request_t *);
// a runtime resource, malloc on this!
struct sandbox *sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *addr);
struct sandbox *sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *addr, u64 start_time);
// should free stack and heap resources.. also any I/O handles.
void sandbox_free(struct sandbox *sbox);
@ -104,7 +104,7 @@ sbox_request_alloc(
char *args,
int sock,
const struct sockaddr *addr,
unsigned long long int start_time_in_cycles)
u64 start_time)
{
// sandbox_alloc seems to be
sbox_request_t *s = malloc(sizeof(sbox_request_t));
@ -113,7 +113,7 @@ sbox_request_alloc(
s->args = args;
s->sock = sock;
s->addr = (struct sockaddr *)addr;
s->start_time_in_cycles = start_time_in_cycles;
s->start_time = start_time;
sandbox_run(s);
return s;
}
@ -239,6 +239,9 @@ sandbox_deque_pop(sbox_request_t **s)
return ret;
}
/**
* @returns A Sandbox Request or NULL
**/
static inline sbox_request_t *
sandbox_deque_steal(void)
{

@ -16,7 +16,7 @@ i32 log_file_descriptor = -1;
u32 total_online_processors = 0;
u32 total_worker_processors = 0;
u32 first_worker_processor = 0;
int worker_threads_argument[SBOX_NCORES] = { 0 }; // This is always empty, as we don't pass an argument
int worker_threads_argument[SBOX_NCORES] = { 0 }; // The worker sets its argument to -1 on error
pthread_t worker_threads[SBOX_NCORES];
static unsigned long long

@ -31,7 +31,7 @@ __thread arch_context_t base_context;
__thread uv_loop_t uvio;
/**
* Append the sandbox to the local_run_queueueue
* Append the sandbox to the local_run_queue
* @param s sandbox to add
*/
static inline void
@ -42,24 +42,28 @@ sandbox_local_run(struct sandbox *s)
ps_list_head_append_d(&local_run_queue, s);
}
/**
* Pulls up to 1..n sandbox requests, allocates them as sandboxes, sets them as runnable and places them on the local runqueue, and then frees the sandbox requests
* The batch size pulled at once is set by SBOX_PULL_MAX
* @return the number of sandbox requests pulled
*/
static inline int
sandbox_pull(void)
{
int n = 0;
while (n < SBOX_PULL_MAX) {
sbox_request_t *s = sandbox_deque_steal();
if (!s) break;
struct sandbox *sb = sandbox_alloc(s->mod, s->args, s->sock, s->addr);
assert(sb);
free(s);
sb->state = SANDBOX_RUNNABLE;
sandbox_local_run(sb);
n++;
int total_sandboxes_pulled = 0;
while (total_sandboxes_pulled < SBOX_PULL_MAX) {
sbox_request_t *sandbox_request;
if ((sandbox_request = sandbox_deque_steal()) == NULL) break;
struct sandbox *sandbox = sandbox_alloc(sandbox_request->mod, sandbox_request->args, sandbox_request->sock, sandbox_request->addr, sandbox_request->start_time);
assert(sandbox);
free(sandbox_request);
sandbox->state = SANDBOX_RUNNABLE;
sandbox_local_run(sandbox);
total_sandboxes_pulled++;
}
return n;
return total_sandboxes_pulled;
}
static __thread unsigned int in_callback;
@ -229,14 +233,15 @@ sandbox_run_func(void *data)
pthread_exit(data);
}
/**
* Push the Sandbox Request to the Global Dequeue
* @param s The sandbox request we're pushing
**/
void
sandbox_run(sbox_request_t *s)
sandbox_run(sbox_request_t *sandbox_request)
{
// for now, a pull model...
// sandbox_run adds to the global ready queue..
// each sandboxing thread pulls off of that global ready queue..
debuglog("[%p: %s]\n", s, s->mod->name);
sandbox_deque_push(s);
debuglog("[%p: %s]\n", sandbox_request, sandbox_request->mod->name);
sandbox_deque_push(sandbox_request);
}
// perhaps respond to request
@ -274,7 +279,7 @@ runtime_accept_thdfn(void *d)
int total_requests = 0;
while (true) {
int ready = epoll_wait(epoll_file_descriptor, epoll_events, EPOLL_MAX, -1);
unsigned long long int start_time_in_cycles = rdtsc();
u64 start_time = rdtsc();
for (int i = 0; i < ready; i++) {
if (epoll_events[i].events & EPOLLERR) {
perror("epoll_wait");
@ -292,10 +297,9 @@ runtime_accept_thdfn(void *d)
assert(0);
}
total_requests++;
printf("Received Request %d at %lld\n", total_requests, start_time_in_cycles);
printf("Received Request %d at %lu\n", total_requests, start_time);
// struct sandbox *sb = sandbox_alloc(m, m->name, s, (const struct sockaddr *)&client);
sbox_request_t *sb = sbox_request_alloc(m, m->name, s, (const struct sockaddr *)&client, start_time_in_cycles);
sbox_request_t *sb = sbox_request_alloc(m, m->name, s, (const struct sockaddr *)&client, start_time);
assert(sb);
}
}

@ -325,7 +325,7 @@ sandbox_entry(void)
}
struct sandbox *
sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *addr)
sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *addr, u64 start_time)
{
if (!module_is_valid(mod)) return NULL;
@ -334,6 +334,9 @@ sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *a
struct sandbox *sb = (struct sandbox *)sandbox_memory_map(mod);
if (!sb) return NULL;
// Assign the start time from the request
sb->start_time = start_time;
// actual module instantiation!
sb->args = (void *)args;
sb->stack_size = mod->stack_size;

@ -212,7 +212,8 @@ parse_sandbox_file_custom(char *filename)
assert(0);
}
sb = sandbox_alloc(mod, args, 0, NULL);
// TODO: Adding 0 as start time to match new signature. Unsure how this function is used... -SPM
sb = sandbox_alloc(mod, args, 0, NULL, 0);
assert(sb);
total_boxes++;
@ -262,7 +263,8 @@ util_parse_sandbox_string_json(struct module *mod, char *str, const struct socka
*(args + ((k - 1) * MOD_ARG_MAX_SZ) + g->end - g->start) = '\0';
}
struct sandbox *sb = sandbox_alloc(mod, args, 0, addr);
// TODO: Adding 0 as start time to match new signature. Unsure how this function is used... -SPM
struct sandbox *sb = sandbox_alloc(mod, args, 0, addr, 0);
assert(sb);
return sb;
@ -296,7 +298,8 @@ util_parse_sandbox_string_custom(struct module *mod, char *str, const struct soc
assert(ntoks < MOD_MAX_ARGS);
}
struct sandbox *sb = sandbox_alloc(mod, args, 0, addr);
// TODO: Adding 0 as start time to match new signature. Unsure how this function is used... -SPM
struct sandbox *sb = sandbox_alloc(mod, args, 0, addr, 0);
assert(sb);
return sb;

Loading…
Cancel
Save