remove redundent comments

main
xiaosuGW 3 years ago
parent 24502d316b
commit 5d77f8efb5

@ -13,7 +13,7 @@ CC=clang
CC_OPTIONS = -O3 -flto -g -pthread -D_GNU_SOURCE CC_OPTIONS = -O3 -flto -g -pthread -D_GNU_SOURCE
# CC_OPTIONS for Debugging # CC_OPTIONS for Debugging
#CC_OPTIONS = -O0 -g -pthread -D_GNU_SOURCE # CC_OPTIONS = -O0 -g -pthread -D_GNU_SOURCE
# CFI Sanitizer # CFI Sanitizer
# CC_OPTIONS = -O0 -g -pthread -D_GNU_SOURCE -flto -fvisibility=default -fsanitize=cfi # CC_OPTIONS = -O0 -g -pthread -D_GNU_SOURCE -flto -fvisibility=default -fsanitize=cfi
@ -91,7 +91,6 @@ CFLAGS += -DUSE_MEM_VM
LDFLAGS += -Wl,--export-dynamic -ldl -lm LDFLAGS += -Wl,--export-dynamic -ldl -lm
LDFLAGS += -Lthirdparty/dist/lib/ LDFLAGS += -Lthirdparty/dist/lib/
INCLUDES += -Iinclude/ -Ithirdparty/dist/include/ INCLUDES += -Iinclude/ -Ithirdparty/dist/include/
INCLUDES += -Iinclude/ -Ithirdparty/ck/include/
# CFILES # CFILES
CFILES += src/*.c CFILES += src/*.c
@ -100,7 +99,6 @@ CFILES += src/libc/*.c
CFILES += src/memory/common.c CFILES += src/memory/common.c
CFILES += src/memory/64bit_nix.c CFILES += src/memory/64bit_nix.c
CFILES += thirdparty/dist/lib/http_parser.o CFILES += thirdparty/dist/lib/http_parser.o
CFILES += thirdparty/dist/lib/libck.a
# Configuring Jasmine # Configuring Jasmine
JSMNCFLAGS += -DJSMN_STATIC JSMNCFLAGS += -DJSMN_STATIC

@ -41,7 +41,7 @@ arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp)
* which defaults to resuming execution of main * which defaults to resuming execution of main
*/ */
static inline int static inline int
arch_context_switch(struct arch_context *a, struct arch_context *b) //save context to a and switch to context b arch_context_switch(struct arch_context *a, struct arch_context *b)
{ {
#ifndef NDEBUG #ifndef NDEBUG
/* /*
@ -61,7 +61,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) //save conte
assert(a != b); assert(a != b);
/* Set any NULLs to worker_thread_base_context to resume execution of main */ /* Set any NULLs to worker_thread_base_context to resume execution of main */
if (a == NULL) a = &worker_thread_base_context; //NULL indicates the main context of the worker thread before running any sandboxs if (a == NULL) a = &worker_thread_base_context;
if (b == NULL) b = &worker_thread_base_context; if (b == NULL) b = &worker_thread_base_context;
/* A Transition {Unused, Running} -> Fast */ /* A Transition {Unused, Running} -> Fast */

@ -143,7 +143,7 @@ sandbox_open_http(struct sandbox *sandbox)
http_parser_init(&sandbox->http_parser, HTTP_REQUEST); http_parser_init(&sandbox->http_parser, HTTP_REQUEST);
/* Set the sandbox as the data the http-parser has access to */ /* Set the sandbox as the data the http-parser has access to */
sandbox->http_parser.data = sandbox; //assign data to sandbox in case to operator it when a callback happended sandbox->http_parser.data = sandbox;
/* Freshly allocated sandbox going runnable for first time, so register client socket with epoll */ /* Freshly allocated sandbox going runnable for first time, so register client socket with epoll */
struct epoll_event accept_evt; struct epoll_event accept_evt;

@ -88,7 +88,6 @@ sandbox_receive_request(struct sandbox *sandbox)
sandbox->request_response_data_length += nparsed; sandbox->request_response_data_length += nparsed;
} }
//http_request_print(&sandbox->http_request);
sandbox->request_length = sandbox->request_response_data_length; sandbox->request_length = sandbox->request_response_data_length;
rc = 0; rc = 0;

@ -25,7 +25,7 @@ struct sandbox_request {
uint64_t absolute_deadline; /* cycles */ uint64_t absolute_deadline; /* cycles */
char * previous_function_output; char * previous_function_output;
ssize_t output_length; ssize_t output_length;
ssize_t pre_request_length; /* previous request length */ ssize_t previous_request_length; /* previous request length */
/* /*
* Unitless estimate of the instantaneous fraction of system capacity required to run the request * Unitless estimate of the instantaneous fraction of system capacity required to run the request
* Calculated by estimated execution time (cycles) * runtime_admissions_granularity / relative deadline (cycles) * Calculated by estimated execution time (cycles) * runtime_admissions_granularity / relative deadline (cycles)
@ -90,7 +90,7 @@ sandbox_request_allocate(struct module *module, bool request_from_outside, ssize
sandbox_request->absolute_deadline = request_arrival_timestamp + module->relative_deadline; sandbox_request->absolute_deadline = request_arrival_timestamp + module->relative_deadline;
sandbox_request->previous_function_output = previous_function_output; sandbox_request->previous_function_output = previous_function_output;
sandbox_request->output_length = output_length; sandbox_request->output_length = output_length;
sandbox_request->pre_request_length = request_length; sandbox_request->previous_request_length = request_length;
/* /*
* Admissions Control State * Admissions Control State

@ -37,7 +37,7 @@ sandbox_set_as_initialized(struct sandbox *sandbox, struct sandbox_request *sand
sandbox->request_from_outside = sandbox_request->request_from_outside; sandbox->request_from_outside = sandbox_request->request_from_outside;
sandbox->previous_function_output = sandbox_request->previous_function_output; sandbox->previous_function_output = sandbox_request->previous_function_output;
sandbox->output_length = sandbox_request->output_length; sandbox->output_length = sandbox_request->output_length;
sandbox->pre_request_length = sandbox_request->pre_request_length; sandbox->previous_request_length = sandbox_request->previous_request_length;
/* Initialize the sandbox's context, stack, and instruction pointer */ /* Initialize the sandbox's context, stack, and instruction pointer */
/* stack_start points to the bottom of the usable stack, so add stack_size to get to top */ /* stack_start points to the bottom of the usable stack, so add stack_size to get to top */
arch_context_init(&sandbox->ctxt, (reg_t)current_sandbox_start, arch_context_init(&sandbox->ctxt, (reg_t)current_sandbox_start,

@ -35,7 +35,7 @@ struct sandbox {
int current_func_index; /* indicate the index of next function in the chain */ int current_func_index; /* indicate the index of next function in the chain */
char * previous_function_output; /* the output of the previous function */ char * previous_function_output; /* the output of the previous function */
ssize_t output_length; /* the length of previous_function_output */ ssize_t output_length; /* the length of previous_function_output */
ssize_t pre_request_length; /* the length of previous_function_output */ ssize_t previosu_request_length; /* the length of previous request */
sandbox_state_t state; sandbox_state_t state;
uint32_t sandbox_size; /* The struct plus enough buffer to hold the request or response (sized off largest) */ uint32_t sandbox_size; /* The struct plus enough buffer to hold the request or response (sized off largest) */
@ -68,7 +68,6 @@ struct sandbox {
uint64_t absolute_deadline; uint64_t absolute_deadline;
uint64_t total_time; /* From Request to Response */ uint64_t total_time; /* From Request to Response */
uint64_t execution_time; /* From running to response */
/* /*
* Unitless estimate of the instantaneous fraction of system capacity required to run the request * Unitless estimate of the instantaneous fraction of system capacity required to run the request

@ -69,24 +69,21 @@ current_sandbox_start(void)
sandbox_initialize_stdio(sandbox); sandbox_initialize_stdio(sandbox);
sandbox_open_http(sandbox);//add IN/OUT event to epoll sandbox_open_http(sandbox);
if (sandbox->request_from_outside) { if (sandbox->request_from_outside) {
if (sandbox_receive_request(sandbox) < 0) {//read data from client socket to get http request, if (sandbox_receive_request(sandbox) < 0) {
//the result populates http_request structure
// if read blocked, then remove the sandbox from the
// local runqueue and pause the sandbox
error_message = "Unable to receive or parse client request\n"; error_message = "Unable to receive or parse client request\n";
goto err; goto err;
}; };
} else { } else {
/* copy previous output to sandbox->request_response_data, as the input for the sandbox.*/ /* copy previous output to sandbox->request_response_data, as the input for the current sandbox.*/
/* let sandbox->http_request->body points to sandbox->request_response_data*/ /* let sandbox->http_request->body points to sandbox->request_response_data*/
assert(sandbox->previous_function_output != NULL); assert(sandbox->previous_function_output != NULL);
memcpy(sandbox->request_response_data, sandbox->previous_function_output, sandbox->output_length); memcpy(sandbox->request_response_data, sandbox->previous_function_output, sandbox->output_length);
sandbox->http_request.body = sandbox->request_response_data; sandbox->http_request.body = sandbox->request_response_data;
sandbox->http_request.body_length = sandbox->output_length; sandbox->http_request.body_length = sandbox->output_length;
sandbox->request_length = sandbox->pre_request_length; sandbox->request_length = sandbox->previous_request_length;
sandbox->request_response_data_length = sandbox->request_length; sandbox->request_response_data_length = sandbox->request_length;
} }
@ -94,7 +91,9 @@ current_sandbox_start(void)
struct module *current_module = sandbox_get_module(sandbox); struct module *current_module = sandbox_get_module(sandbox);
module_initialize_globals(current_module); module_initialize_globals(current_module);
module_initialize_memory(current_module); module_initialize_memory(current_module);
sandbox_setup_arguments(sandbox); //this arguments is not the http body content sandbox_setup_arguments(sandbox);
/* Executing the function */ /* Executing the function */
int32_t argument_count = module_get_argument_count(current_module); int32_t argument_count = module_get_argument_count(current_module);
current_sandbox_enable_preemption(sandbox); current_sandbox_enable_preemption(sandbox);
@ -116,16 +115,16 @@ current_sandbox_start(void)
(const struct sockaddr *)&sandbox->client_address, (const struct sockaddr *)&sandbox->client_address,
sandbox->request_arrival_timestamp, enqueue_timestamp, sandbox->request_arrival_timestamp, enqueue_timestamp,
true, pre_func_output, output_length); true, pre_func_output, output_length);
/* reset the request id to the same as the current request id */ /* TODO: all sandboxs in the chain share the same request id, but sandbox_request_allocate() will busy-wait to generate an unique
id, should we optimize it here?*/
sandbox_request->id = sandbox->id; sandbox_request->id = sandbox->id;
/* Add to the Global Sandbox Request Scheduler */ /* Add to the Global Sandbox Request Scheduler */
global_request_scheduler_add(sandbox_request); global_request_scheduler_add(sandbox_request);
sandbox_remove_from_epoll(sandbox); sandbox_remove_from_epoll(sandbox);
sandbox_set_as_returned(sandbox, SANDBOX_RUNNING); sandbox_set_as_returned(sandbox, SANDBOX_RUNNING);
} else { } else {
/* Retrieve the result, construct the HTTP response, and send to client */ /* Retrieve the result, construct the HTTP response, and send to client */
if (sandbox_send_response(sandbox) < 0) { // if send blocked, remove the sandbox from the local runqueue if (sandbox_send_response(sandbox) < 0) {
// and pause the sandbox
error_message = "Unable to build and send client response\n"; error_message = "Unable to build and send client response\n";
goto err; goto err;
}; };
@ -136,12 +135,12 @@ current_sandbox_start(void)
assert(sandbox->state == SANDBOX_RUNNING); assert(sandbox->state == SANDBOX_RUNNING);
sandbox_close_http(sandbox); sandbox_close_http(sandbox);
sandbox_set_as_returned(sandbox, SANDBOX_RUNNING); //request is completed, remove the sandbox from the local runqueue sandbox_set_as_returned(sandbox, SANDBOX_RUNNING);
} }
done: done:
/* Cleanup connection and exit sandbox */ /* Cleanup connection and exit sandbox */
generic_thread_dump_lock_overhead(); generic_thread_dump_lock_overhead();
scheduler_yield(); //put the sandbox to the complete queue scheduler_yield();
/* This assert prevents a segfault discussed in /* This assert prevents a segfault discussed in
* https://github.com/phanikishoreg/awsm-Serverless-Framework/issues/66 * https://github.com/phanikishoreg/awsm-Serverless-Framework/issues/66

@ -19,6 +19,7 @@ global_request_scheduler_minheap_add(void *sandbox_request)
{ {
assert(sandbox_request); assert(sandbox_request);
assert(global_request_scheduler_minheap); assert(global_request_scheduler_minheap);
/* panic is not applicable here because all worker_threads can add a request to the global queue if it's a chain function */
//if (unlikely(!listener_thread_is_running())) panic("%s is only callable by the listener thread\n", __func__); //if (unlikely(!listener_thread_is_running())) panic("%s is only callable by the listener thread\n", __func__);
int return_code = priority_queue_enqueue(global_request_scheduler_minheap, sandbox_request); int return_code = priority_queue_enqueue(global_request_scheduler_minheap, sandbox_request);

@ -226,7 +226,6 @@ runtime_configure()
if (runtime_sandbox_perf_log == NULL) { perror("sandbox perf log"); } if (runtime_sandbox_perf_log == NULL) { perror("sandbox perf log"); }
fprintf(runtime_sandbox_perf_log, "id,function,state,deadline,actual,queued,initializing,runnable," fprintf(runtime_sandbox_perf_log, "id,function,state,deadline,actual,queued,initializing,runnable,"
"running,blocked,returned,memory\n"); "running,blocked,returned,memory\n");
fflush(runtime_sandbox_perf_log);
} else { } else {
printf("\tSandbox Performance Log: Disabled\n"); printf("\tSandbox Performance Log: Disabled\n");
} }

@ -65,12 +65,12 @@ runtime_set_resource_limits_to_max()
int resource = resources[i]; int resource = resources[i];
if (getrlimit(resource, &limit) < 0) panic_err(); if (getrlimit(resource, &limit) < 0) panic_err();
if (limit.rlim_cur == RLIM_INFINITY) { // rlim_cur is soft limit if (limit.rlim_cur == RLIM_INFINITY) {
strncpy(lim, "Infinite", uint64_t_max_digits); strncpy(lim, "Infinite", uint64_t_max_digits);
} else { } else {
snprintf(lim, uint64_t_max_digits, "%lu", limit.rlim_cur); snprintf(lim, uint64_t_max_digits, "%lu", limit.rlim_cur);
} }
if (limit.rlim_max == RLIM_INFINITY) { // rlim_max is hard limit if (limit.rlim_max == RLIM_INFINITY) {
strncpy(max, "Infinite", uint64_t_max_digits); strncpy(max, "Infinite", uint64_t_max_digits);
} else { } else {
snprintf(max, uint64_t_max_digits, "%lu", limit.rlim_max); snprintf(max, uint64_t_max_digits, "%lu", limit.rlim_max);
@ -91,19 +91,18 @@ runtime_set_resource_limits_to_max()
void void
runtime_initialize(void) runtime_initialize(void)
{ {
http_total_init(); //initilize http requests/error response counter http_total_init();
sandbox_request_count_initialize(); //initilize sandbox requests counter sandbox_request_count_initialize();
sandbox_count_initialize(); //initilize sandbox state counter sandbox_count_initialize();
/* Setup Scheduler */ /* Setup Scheduler */
scheduler_initialize(); //set function pointers to global_request_scheduler, both EDF and FIFO have a set of functions scheduler_initialize();
/* Configure Signals */ /* Configure Signals */
signal(SIGPIPE, SIG_IGN); // ignore SIGPIPE signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, runtime_cleanup); // call runtime_cleanup when get SIGTERM signal signal(SIGTERM, runtime_cleanup);
http_parser_settings_initialize(); // set function pointers for http parser lib, when get a http message, some callback http_parser_settings_initialize();
// functions will be called
admissions_control_initialize(); admissions_control_initialize();
} }

Loading…
Cancel
Save