for standalone execution

main
Phani 5 years ago
parent 7ce5cf9a6d
commit a231796990

@ -11,12 +11,13 @@ LDFLAGS = -Wl,--export-dynamic -ldl -lm
USE_MEM = USE_MEM_VM USE_MEM = USE_MEM_VM
CFLAGS = ${OPTFLAGS} -D${USE_MEM} -I${INC} -pthread CFLAGS = ${OPTFLAGS} -D${USE_MEM} -I${INC} -pthread
CFLAGS += -DX86_64 CFLAGS += -DX86_64
CFLAGS += -DDEBUG #CFLAGS += -DDEBUG
CFLAGS += -D_GNU_SOURCE CFLAGS += -D_GNU_SOURCE
#CFLAGS += -DNOSTDIO #CFLAGS += -DNOSTDIO
CFLAGS += -DUSE_UVIO CFLAGS += -DSTANDALONE
#CFLAGS += -DUSE_SYSCALL #CFLAGS += -DUSE_UVIO
#CFLAGS += -DPREEMPT_DISABLE CFLAGS += -DUSE_SYSCALL
CFLAGS += -DPREEMPT_DISABLE
MAKE= make --no-print-directory MAKE= make --no-print-directory

@ -26,6 +26,7 @@ usage(char *cmd)
int int
main(int argc, char* argv[]) main(int argc, char* argv[])
{ {
#ifndef STANDALONE
int i = 0, rtthd_ret[SBOX_NCORES] = { 0 }; int i = 0, rtthd_ret[SBOX_NCORES] = { 0 };
pthread_t rtthd[SBOX_NCORES]; pthread_t rtthd[SBOX_NCORES];
@ -97,4 +98,15 @@ main(int argc, char* argv[])
// runtime threads run forever!! so join should not return!! // runtime threads run forever!! so join should not return!!
printf("\nOh no..!! This can't be happening..!!\n"); printf("\nOh no..!! This can't be happening..!!\n");
exit(-1); exit(-1);
#else /* STANDALONE */
arch_context_init(&base_context, 0, 0);
uv_loop_init(&uvio);
/* in current dir! */
struct module *m = module_alloc(argv[1], argv[1], 0, 0, 0, 0, 0, 0);
assert(m);
struct sandbox *s = sandbox_alloc(m, argv[1]);
exit(0);
#endif
} }

@ -108,7 +108,9 @@ module_alloc(char *modname, char *modpath, u32 udp_port, i32 nargs, i32 nrets, u
module_indirect_table = cache_tbl; module_indirect_table = cache_tbl;
mod->udpport = udp_port; mod->udpport = udp_port;
module_add(mod); module_add(mod);
#ifndef STANDALONE
module_io_init(mod); module_io_init(mod);
#endif
return mod; return mod;

@ -106,16 +106,19 @@ sandbox_schedule(void)
void void
sandbox_wakeup(sandbox_t *s) sandbox_wakeup(sandbox_t *s)
{ {
#ifndef STANDALONE
debuglog("[%p: %s]\n", s, s->mod->name); debuglog("[%p: %s]\n", s, s->mod->name);
// perhaps 2 lists in the sandbox to make sure sandbox is either in runlist or waitlist.. // perhaps 2 lists in the sandbox to make sure sandbox is either in runlist or waitlist..
assert(ps_list_singleton_d(s)); assert(ps_list_singleton_d(s));
s->state = SANDBOX_RUNNABLE; s->state = SANDBOX_RUNNABLE;
ps_list_head_append_d(&runq, s); ps_list_head_append_d(&runq, s);
#endif
} }
void void
sandbox_block(void) sandbox_block(void)
{ {
#ifndef STANDALONE
// perhaps 2 lists in the sandbox to make sure sandbox is either in runlist or waitlist.. // perhaps 2 lists in the sandbox to make sure sandbox is either in runlist or waitlist..
softint_disable(); softint_disable();
struct sandbox *c = sandbox_current(); struct sandbox *c = sandbox_current();
@ -125,6 +128,9 @@ sandbox_block(void)
c->state = SANDBOX_BLOCKED; c->state = SANDBOX_BLOCKED;
struct sandbox *s = sandbox_schedule(); struct sandbox *s = sandbox_schedule();
sandbox_switch(s); sandbox_switch(s);
#else
uv_run(runtime_uvio(), UV_RUN_DEFAULT);
#endif
} }
void __attribute__((noinline)) __attribute__((noreturn)) void __attribute__((noinline)) __attribute__((noreturn))
@ -172,6 +178,7 @@ sandbox_run_func(void *data)
void void
sandbox_run(struct sandbox *s) sandbox_run(struct sandbox *s)
{ {
#ifndef STANDALONE
// for now, a pull model... // for now, a pull model...
// sandbox_run adds to the global ready queue.. // sandbox_run adds to the global ready queue..
// each sandboxing thread pulls off of that global ready queue.. // each sandboxing thread pulls off of that global ready queue..
@ -180,12 +187,16 @@ sandbox_run(struct sandbox *s)
pthread_mutex_lock(&glbq_mtx); pthread_mutex_lock(&glbq_mtx);
ps_list_head_append_d(&glbq, s); ps_list_head_append_d(&glbq, s);
pthread_mutex_unlock(&glbq_mtx); pthread_mutex_unlock(&glbq_mtx);
#else
sandbox_switch(s);
#endif
} }
// perhaps respond to request // perhaps respond to request
void void
sandbox_exit(void) sandbox_exit(void)
{ {
#ifndef STANDALONE
struct sandbox *curr = sandbox_current(); struct sandbox *curr = sandbox_current();
assert(curr); assert(curr);
@ -195,6 +206,9 @@ sandbox_exit(void)
curr->state = SANDBOX_RETURNED; curr->state = SANDBOX_RETURNED;
// TODO: free resources here? or only from main? // TODO: free resources here? or only from main?
sandbox_switch(sandbox_schedule()); sandbox_switch(sandbox_schedule());
#else
sandbox_switch(NULL);
#endif
} }
void * void *

Loading…
Cancel
Save