chore: rerun formatter

main
Sean McBride 5 years ago
parent c4142c00f1
commit 2220cf34a0

@ -57,14 +57,8 @@ struct module *module_find_by_socket_descriptor(int sock);
static inline void
module_http_info(
struct module *module,
int request_count,
char *request_headers,
char request_content_type[],
int response_count,
char *response_headers,
char response_content_type[])
module_http_info(struct module *module, int request_count, char *request_headers, char request_content_type[],
int response_count, char *response_headers, char response_content_type[])
{
assert(module);
module->request_header_count = request_count;

@ -109,12 +109,7 @@ typedef struct sandbox sandbox_t;
* @return the new sandbox request
**/
static inline sbox_request_t *
sbox_request_alloc(
struct module *module,
char *args,
int sock,
const struct sockaddr *addr,
u64 start_time)
sbox_request_alloc(struct module *module, char *args, int sock, const struct sockaddr *addr, u64 start_time)
{
sbox_request_t *sandbox_request = malloc(sizeof(sbox_request_t));
assert(sandbox_request);

@ -497,8 +497,8 @@ wasm_readv(i32 fd, i32 iov_offset, i32 iovcnt)
if (fd == 0) {
// both 1 and 2 go to client.
int len = 0;
struct wasm_iovec *iov = get_memory_ptr_void(iov_offset, iovcnt * sizeof(struct wasm_iovec));
struct sandbox *s = sandbox_current();
struct wasm_iovec * iov = get_memory_ptr_void(iov_offset, iovcnt * sizeof(struct wasm_iovec));
struct sandbox * s = sandbox_current();
struct http_request *r = &s->http_request;
if (r->bodylen <= 0) return 0;
for (int i = 0; i < iovcnt; i++) {

@ -47,7 +47,9 @@ usage(char *cmd)
* Sets the process data segment (RLIMIT_DATA) and # file descriptors
* (RLIMIT_NOFILE) soft limit to its hard limit (see man getrlimit)
**/
void set_resource_limits_to_max(){
void
set_resource_limits_to_max()
{
struct rlimit resource_limit;
if (getrlimit(RLIMIT_DATA, &resource_limit) < 0) {
perror("getrlimit RLIMIT_DATA");
@ -72,7 +74,9 @@ void set_resource_limits_to_max(){
/**
* Check the number of cores and the compiler flags and allocate available cores
**/
void allocate_available_cores(){
void
allocate_available_cores()
{
// Find the number of processors currently online
total_online_processors = sysconf(_SC_NPROCESSORS_ONLN);
@ -88,8 +92,8 @@ void allocate_available_cores(){
first_worker_processor = 0;
total_worker_processors = 1;
}
debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", total_online_processors, total_worker_processors,
first_worker_processor, MOD_REQ_CORE);
debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", total_online_processors,
total_worker_processors, first_worker_processor, MOD_REQ_CORE);
}
/**
@ -97,7 +101,9 @@ void allocate_available_cores(){
* Otherwise, log to STDOUT
* NOSTIO = No Standard Input/Output?
**/
void process_nostio(){
void
process_nostio()
{
#ifdef NOSTDIO
fclose(stdout);
fclose(stderr);
@ -115,9 +121,12 @@ void process_nostio(){
/**
* Starts all worker threads and sleeps forever on pthread_join, which should never return
**/
void start_worker_threads(){
void
start_worker_threads()
{
for (int i = 0; i < total_worker_processors; i++) {
int ret = pthread_create(&worker_threads[i], NULL, sandbox_run_func, (void *)&worker_threads_argument[i]);
int ret = pthread_create(&worker_threads[i], NULL, sandbox_run_func,
(void *)&worker_threads_argument[i]);
if (ret) {
errno = ret;
perror("pthread_create");

@ -101,7 +101,8 @@ module_server_init(struct module *module)
/**
* Module Mega Setup Function
* Creates a new module, invokes tbl_init_fn to initialize the indirect table, adds it to the module DB, and starts listening for HTTP Requests
* Creates a new module, invokes tbl_init_fn to initialize the indirect table, adds it to the module DB, and starts
*listening for HTTP Requests
*
* @param name
* @param path
@ -114,8 +115,8 @@ module_server_init(struct module *module)
* @returns A new module or NULL in case of failure
**/
struct module *
module_alloc(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_memory, u32 timeout, int port, int request_size,
int response_size)
module_alloc(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_memory, u32 timeout, int port,
int request_size, int response_size)
{
struct module *module = (struct module *)malloc(sizeof(struct module));
if (!module) return NULL;
@ -156,18 +157,20 @@ module_alloc(char *name, char *path, i32 argument_count, u32 stack_size, u32 max
if (response_size == 0) response_size = MOD_REQ_RESP_DEFAULT;
module->max_request_size = request_size;
module->max_response_size = response_size;
module->max_request_or_response_size = round_up_to_page(request_size > response_size ? request_size : response_size);
module->max_request_or_response_size = round_up_to_page(request_size > response_size ? request_size
: response_size);
// module_indirect_table is a thread-local struct
struct indirect_table_entry *cache_tbl = module_indirect_table;
// assumption: All modules are created at program start before we enable preemption or enable the execution of any worker threads
// We are checking that thread-local module_indirect_table is NULL to prove that we aren't yet preempting
// If we want to be able to do this later, we can possibly defer module_table_init until the first invocation
// assumption: All modules are created at program start before we enable preemption or enable the execution of
// any worker threads We are checking that thread-local module_indirect_table is NULL to prove that we aren't
// yet preempting If we want to be able to do this later, we can possibly defer module_table_init until the
// first invocation
assert(cache_tbl == NULL);
// TODO: determine why we have to set the module_indirect_table state before calling table init and then restore the existing value
// What is the relationship between these things?
// TODO: determine why we have to set the module_indirect_table state before calling table init and then restore
// the existing value What is the relationship between these things?
module_indirect_table = module->indirect_table;
module_table_init(module);
module_indirect_table = cache_tbl;

@ -38,13 +38,14 @@ static inline void
sandbox_local_run(struct sandbox *s)
{
assert(ps_list_singleton_d(s));
// fprintf(stderr, "(%d,%lu) %s: run %p, %s\n", sched_getcpu(), pthread_self(), __func__, s, s->module->name);
// fprintf(stderr, "(%d,%lu) %s: run %p, %s\n", sched_getcpu(), pthread_self(), __func__, s,
// s->module->name);
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
* 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
@ -55,7 +56,9 @@ sandbox_pull(void)
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->module, sandbox_request->args, sandbox_request->sock, sandbox_request->addr, sandbox_request->start_time);
struct sandbox *sandbox = sandbox_alloc(sandbox_request->module, sandbox_request->args,
sandbox_request->sock, sandbox_request->addr,
sandbox_request->start_time);
assert(sandbox);
free(sandbox_request);
sandbox->state = SANDBOX_RUNNABLE;
@ -120,7 +123,7 @@ sandbox_schedule(int interrupt)
static inline void
sandbox_local_free(unsigned int number_to_free)
{
for (int i = 0; i < number_to_free; i++){
for (int i = 0; i < number_to_free; i++) {
if (ps_list_head_empty(&local_completion_queue)) break;
struct sandbox *s = ps_list_head_first_d(&local_completion_queue, struct sandbox);
if (!s) break;
@ -296,7 +299,8 @@ sandbox_exit(void)
}
/**
* @brief Execution Loop of the listener core, handles HTTP requests, allocates sandbox request objects, and pushes the sandbox object to the global dequeue
* @brief Execution Loop of the listener core, handles HTTP requests, allocates sandbox request objects, and pushes the
* sandbox object to the global dequeue
* @param d Unknown
* @return NULL
*
@ -331,7 +335,8 @@ runtime_accept_thdfn(void *d)
total_requests++;
printf("Received Request %d at %lu\n", total_requests, start_time);
sbox_request_t *sb = sbox_request_alloc(m, m->name, s, (const struct sockaddr *)&client, start_time);
sbox_request_t *sb = sbox_request_alloc(m, m->name, s, (const struct sockaddr *)&client,
start_time);
assert(sb);
}
}

@ -25,12 +25,12 @@ sandbox_memory_map(struct module *module)
assert(round_up_to_page(sandbox_size) == sandbox_size);
// What does mmap do exactly with fd -1?
void *addr = mmap(NULL, sandbox_size + memory_size + /* guard page */ PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
0);
void *addr = mmap(NULL, sandbox_size + memory_size + /* guard page */ PAGE_SIZE, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (addr == MAP_FAILED) return NULL;
void *addr_rw = mmap(addr, sandbox_size + linear_memory_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1,
0);
void *addr_rw = mmap(addr, sandbox_size + linear_memory_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
if (addr_rw == MAP_FAILED) {
munmap(addr, memory_size + PAGE_SIZE);
return NULL;
@ -256,8 +256,7 @@ sandbox_entry(void)
r = uv_tcp_open((uv_tcp_t *)&curr->cuv, curr->csock);
assert(r == 0);
#endif
if (sandbox_client_request_get() > 0)
{
if (sandbox_client_request_get() > 0) {
curr->rr_data_len = rsp_hdr_len; // TODO: do this on first write to body.
alloc_linear_memory();
// perhaps only initialized for the first instance? or TODO!

@ -70,7 +70,8 @@ util_parse_modules_file_json(char *file_name)
jsmntok_t tokens[MOD_MAX * JSON_ELE_MAX];
// Use Jasmine to parse the JSON
int total_tokens = jsmn_parse(&module_parser, file_buffer, strlen(file_buffer), tokens, sizeof(tokens) / sizeof(tokens[0]));
int total_tokens = jsmn_parse(&module_parser, file_buffer, strlen(file_buffer), tokens,
sizeof(tokens) / sizeof(tokens[0]));
if (total_tokens < 0) {
debuglog("jsmn_parse: invalid JSON?\n");
return -1;
@ -98,14 +99,15 @@ util_parse_modules_file_json(char *file_name)
char request_content_type[HTTP_HEADERVAL_MAXSZ] = { 0 };
char response_content_type[HTTP_HEADERVAL_MAXSZ] = { 0 };
for (; j < ntoks; ) {
for (; j < ntoks;) {
int ntks = 1;
char key[32] = { 0 };
char val[256] = { 0 };
sprintf(val, "%.*s", tokens[j + i + 1].end - tokens[j + i + 1].start,
file_buffer + tokens[j + i + 1].start);
sprintf(key, "%.*s", tokens[j + i].end - tokens[j + i].start, file_buffer + tokens[j + i].start);
sprintf(key, "%.*s", tokens[j + i].end - tokens[j + i].start,
file_buffer + tokens[j + i].start);
if (strcmp(key, "name") == 0) {
strcpy(module_name, val);
} else if (strcmp(key, "path") == 0) {
@ -160,9 +162,11 @@ util_parse_modules_file_json(char *file_name)
if (is_active == 0) continue;
// Allocate a module based on the values from the JSON
struct module *module = module_alloc(module_name, module_path, argument_count, 0, 0, 0, port, request_size, response_size);
struct module *module = module_alloc(module_name, module_path, argument_count, 0, 0, 0, port,
request_size, response_size);
assert(module);
module_http_info(module, request_count, request_headers, request_content_type, response_count, reponse_headers, response_content_type);
module_http_info(module, request_count, request_headers, request_content_type, response_count,
reponse_headers, response_content_type);
module_count++;
free(request_headers);
free(reponse_headers);

Loading…
Cancel
Save