chore: Assorted cleanup

main
Sean McBride 5 years ago
parent 9185852236
commit b5e9abced5

@ -63,7 +63,7 @@ To stop the Docker container:
## Running your first serverless function ## Running your first serverless function
An aWsm serverless function consists of a shared library (*.so) and a JSON configuration file that determines how the runtime should execute the serverless function. As an example, here is the configuration file for our sample fibonacci function:. An aWsm serverless function consists of a shared library (\*.so) and a JSON configuration file that determines how the runtime should execute the serverless function. As an example, here is the configuration file for our sample fibonacci function:
```json ```json
{ {

@ -106,14 +106,12 @@ typedef enum
#define MOD_TBL_FN "populate_table" #define MOD_TBL_FN "populate_table"
#define MOD_LIBC_FN "wasmf___init_libc" #define MOD_LIBC_FN "wasmf___init_libc"
#define MOD_MAX_ARGS 16 #define MOD_MAX_ARGS 16 // Max number of arguments
#define MOD_ARG_MAX_SZ 64 #define MOD_ARG_MAX_SZ 64 // Max size of a single argument
#define MOD_MAX 1024 #define MOD_MAX 1024 // Max size of a single module in JSON
#define MOD_NAME_MAX 32 // Max module name length
#define MOD_NAME_MAX 32 #define MOD_PATH_MAX 256 // Max module path length
#define MOD_PATH_MAX 256 #define JSON_ELE_MAX 16 // Max number of elements defined in JSON
#define JSON_ELE_MAX 16
// FIXME: some naive work-stealing here.. // FIXME: some naive work-stealing here..
#define SBOX_PULL_MAX 1 #define SBOX_PULL_MAX 1
@ -143,7 +141,10 @@ typedef enum
#define RDWR_VEC_MAX 16 #define RDWR_VEC_MAX 16
#define MOD_REQ_CORE 0 // Dedicated Listener Core #define MOD_REQ_CORE 0 // Dedicated Listener Core
#define SBOX_NCORES (NCORES > 1 ? NCORES - 1 : NCORES) // If multicore, use all but the dedicated listener core
// If multicore, use all but the dedicated listener core
// If there are fewer cores than this, main dynamically overrides this and uses all available
#define SBOX_NCORES (NCORES > 1 ? NCORES - 1 : NCORES)
#define SBOX_MAX_REQS (1 << 19) // random! #define SBOX_MAX_REQS (1 << 19) // random!
#define SBOX_RESP_STRSZ 32 #define SBOX_RESP_STRSZ 32

@ -43,8 +43,13 @@ usage(char *cmd)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
printf("Starting Awsm\n");
#ifndef STANDALONE #ifndef STANDALONE
int i = 0, rtthd_ret[SBOX_NCORES] = { 0 }; // Array of arguments passed to the start_routine via pthread_create
// This is always empty, as we don't pass an argument
int rtthd_ret[SBOX_NCORES] = { 0 };
// Initialize the array of runtime threads
memset(rtthd, 0, sizeof(pthread_t) * SBOX_NCORES); memset(rtthd, 0, sizeof(pthread_t) * SBOX_NCORES);
if (argc != 2) { if (argc != 2) {
@ -52,6 +57,8 @@ main(int argc, char **argv)
exit(-1); exit(-1);
} }
// Sets the process data segment (RLIMIT_DATA) and # file descriptors
// (RLIMIT_NOFILE) soft limit to its hard limit (see man getrlimit)
struct rlimit r; struct rlimit r;
if (getrlimit(RLIMIT_DATA, &r) < 0) { if (getrlimit(RLIMIT_DATA, &r) < 0) {
perror("getrlimit RLIMIT_DATA"); perror("getrlimit RLIMIT_DATA");
@ -72,7 +79,11 @@ main(int argc, char **argv)
exit(-1); exit(-1);
} }
// Find the number of processors currently online
ncores = sysconf(_SC_NPROCESSORS_ONLN); ncores = sysconf(_SC_NPROCESSORS_ONLN);
// If multicore, we'll pin one core as a listener and run sandbox threads on all others
// If single core, we'll do everything on that one core
if (ncores > 1) { if (ncores > 1) {
u32 x = ncores - 1; u32 x = ncores - 1;
sbox_ncores = SBOX_NCORES; sbox_ncores = SBOX_NCORES;
@ -84,6 +95,8 @@ main(int argc, char **argv)
debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", ncores, sbox_ncores, debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", ncores, sbox_ncores,
sbox_core_st, MOD_REQ_CORE); sbox_core_st, MOD_REQ_CORE);
// If NOSTIO is defined, close stdin, stdout, stderr, and write to logfile named awesome.log. Otherwise, log to STDOUT
// NOSTIO = No Standard Input/Output?
#ifdef NOSTDIO #ifdef NOSTDIO
fclose(stdout); fclose(stdout);
fclose(stderr); fclose(stderr);
@ -98,15 +111,16 @@ main(int argc, char **argv)
#endif #endif
runtime_init(); runtime_init();
debuglog("Parsing modules file [%s]\n", argv[1]); debuglog("Parsing modules file [%s]\n", argv[1]);
if (util_parse_modules_file_json(argv[1])) { if (util_parse_modules_file_json(argv[1])) {
printf("failed to parse modules file[%s]\n", argv[1]); printf("failed to parse modules file[%s]\n", argv[1]);
exit(-1); exit(-1);
} }
runtime_thd_init(); runtime_thd_init();
for (i = 0; i < sbox_ncores; i++) { for (int i = 0; i < sbox_ncores; i++) {
int ret = pthread_create(&rtthd[i], NULL, sandbox_run_func, (void *)&rtthd_ret[i]); int ret = pthread_create(&rtthd[i], NULL, sandbox_run_func, (void *)&rtthd_ret[i]);
if (ret) { if (ret) {
errno = ret; errno = ret;
@ -122,7 +136,7 @@ main(int argc, char **argv)
} }
debuglog("Sandboxing environment ready!\n"); debuglog("Sandboxing environment ready!\n");
for (i = 0; i < sbox_ncores; i++) { for (int i = 0; i < sbox_ncores; i++) {
int ret = pthread_join(rtthd[i], NULL); int ret = pthread_join(rtthd[i], NULL);
if (ret) { if (ret) {
errno = ret; errno = ret;

@ -15,9 +15,8 @@ struct deque_sandbox *glb_dq;
pthread_mutex_t glbq_mtx = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t glbq_mtx = PTHREAD_MUTEX_INITIALIZER;
int epfd; int epfd;
// per-thread (per-core) run and completion queue.. (using doubly-linked-lists) __thread static struct ps_list_head runq; // per-thread(core) run queue (doubly-linked list)
__thread static struct ps_list_head runq; __thread static struct ps_list_head endq; // per-thread(core) completion queue (doubly-linked list)
__thread static struct ps_list_head endq;
// current sandbox that is active.. // current sandbox that is active..
__thread sandbox_t *current_sandbox = NULL; __thread sandbox_t *current_sandbox = NULL;
@ -31,6 +30,10 @@ __thread arch_context_t base_context;
// libuv i/o loop handle per sandboxing thread! // libuv i/o loop handle per sandboxing thread!
__thread uv_loop_t uvio; __thread uv_loop_t uvio;
/**
* Append the sandbox to the runqueue
* @param s sandbox to add
*/
static inline void static inline void
sandbox_local_run(struct sandbox *s) sandbox_local_run(struct sandbox *s)
{ {

Loading…
Cancel
Save