From 69b1f94fe8ddcbd1a26f1348f55b92b776c1e0c7 Mon Sep 17 00:00:00 2001 From: phani Date: Fri, 3 Jan 2020 11:29:17 -0500 Subject: [PATCH] scalable sandbox creation in each runtime core --- runtime/Makefile | 1 + runtime/include/sandbox.h | 8 ++++++++ runtime/src/runtime.c | 9 ++++++++- runtime/src/sandbox.c | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/runtime/Makefile b/runtime/Makefile index b479fb6..f0816a8 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -16,6 +16,7 @@ CFLAGS += -D_GNU_SOURCE #CFLAGS += -DNOSTDIO #CFLAGS += -DSTANDALONE CFLAGS += -DUSE_UVIO +CFLAGS += -DSBOX_SCALE_ALLOC #CFLAGS += -DUSE_SYSCALL #CFLAGS += -DPREEMPT_DISABLE CACHE_LINESIZE := $(shell getconf LEVEL1_DCACHE_LINESIZE) diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index aeaaacd..dcf4383 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -77,6 +77,7 @@ struct sandbox { } PAGE_ALIGNED; #ifndef STANDALONE +#ifdef SBOX_SCALE_ALLOC struct sandbox_request { struct module *mod; char *args; @@ -87,6 +88,9 @@ typedef struct sandbox_request sbox_request_t; #else typedef struct sandbox sbox_request_t; #endif +#else +typedef struct sandbox sbox_request_t; +#endif DEQUE_PROTOTYPE(sandbox, sbox_request_t *); @@ -106,6 +110,7 @@ static inline sbox_request_t * sbox_request_alloc(struct module *mod, char *args, int sock, const struct sockaddr *addr) { #ifndef STANDALONE +#ifdef SBOX_SCALE_ALLOC sbox_request_t *s = malloc(sizeof(sbox_request_t)); assert(s); s->mod = mod; @@ -117,6 +122,9 @@ sbox_request_alloc(struct module *mod, char *args, int sock, const struct sockad #else return sandbox_alloc(mod, args, sock, addr); #endif +#else + return sandbox_alloc(mod, args, sock, addr); +#endif } static inline struct sandbox * diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index acda7ca..4d7f7e1 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -48,11 +48,16 @@ sandbox_pull(void) if (!s) break; #ifndef STANDALONE +#ifdef SBOX_SCALE_ALLOC 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); +#else + assert(s->state == SANDBOX_RUNNABLE); + sandbox_local_run(s); +#endif #else assert(s->state == SANDBOX_RUNNABLE); sandbox_local_run(s); @@ -223,7 +228,9 @@ sandbox_run(sbox_request_t *s) // 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); -// s->state = SANDBOX_RUNNABLE; +#ifndef SBOX_SCALE_ALLOC + s->state = SANDBOX_RUNNABLE; +#endif sandbox_deque_push(s); #else sandbox_switch(s); diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 078a27b..3f500ec 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -314,6 +314,10 @@ sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *a arch_context_init(&sb->ctxt, (reg_t)sandbox_entry, (reg_t)(sb->stack_start + sb->stack_size)); #ifdef STANDALONE sandbox_run(sb); +#else +#ifndef SBOX_SCALE_ALLOC + sandbox_run(sb); +#endif #endif return sb;