From 5d77f8efb566f8f37b3529f387110ffed57bb7fd Mon Sep 17 00:00:00 2001 From: xiaosuGW Date: Fri, 23 Jul 2021 16:23:50 -0500 Subject: [PATCH] remove redundent comments --- runtime/Makefile | 4 +-- runtime/include/arch/aarch64/context.h | 4 +-- runtime/include/sandbox_functions.h | 2 +- runtime/include/sandbox_receive_request.h | 1 - runtime/include/sandbox_request.h | 4 +-- runtime/include/sandbox_set_as_initialized.h | 2 +- runtime/include/sandbox_types.h | 3 +-- runtime/src/current_sandbox.c | 27 +++++++++---------- .../src/global_request_scheduler_minheap.c | 1 + runtime/src/main.c | 1 - runtime/src/runtime.c | 19 +++++++------ 11 files changed, 31 insertions(+), 37 deletions(-) diff --git a/runtime/Makefile b/runtime/Makefile index af244da..f36e951 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -13,7 +13,7 @@ CC=clang CC_OPTIONS = -O3 -flto -g -pthread -D_GNU_SOURCE # CC_OPTIONS for Debugging -#CC_OPTIONS = -O0 -g -pthread -D_GNU_SOURCE +# CC_OPTIONS = -O0 -g -pthread -D_GNU_SOURCE # CFI Sanitizer # 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 += -Lthirdparty/dist/lib/ INCLUDES += -Iinclude/ -Ithirdparty/dist/include/ -INCLUDES += -Iinclude/ -Ithirdparty/ck/include/ # CFILES CFILES += src/*.c @@ -100,7 +99,6 @@ CFILES += src/libc/*.c CFILES += src/memory/common.c CFILES += src/memory/64bit_nix.c CFILES += thirdparty/dist/lib/http_parser.o -CFILES += thirdparty/dist/lib/libck.a # Configuring Jasmine JSMNCFLAGS += -DJSMN_STATIC diff --git a/runtime/include/arch/aarch64/context.h b/runtime/include/arch/aarch64/context.h index 02397fd..8c85b4a 100644 --- a/runtime/include/arch/aarch64/context.h +++ b/runtime/include/arch/aarch64/context.h @@ -41,7 +41,7 @@ arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp) * which defaults to resuming execution of main */ 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 /* @@ -61,7 +61,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) //save conte assert(a != b); /* 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; /* A Transition {Unused, Running} -> Fast */ diff --git a/runtime/include/sandbox_functions.h b/runtime/include/sandbox_functions.h index 2d39d8a..0e7962c 100644 --- a/runtime/include/sandbox_functions.h +++ b/runtime/include/sandbox_functions.h @@ -143,7 +143,7 @@ sandbox_open_http(struct sandbox *sandbox) http_parser_init(&sandbox->http_parser, HTTP_REQUEST); /* 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 */ struct epoll_event accept_evt; diff --git a/runtime/include/sandbox_receive_request.h b/runtime/include/sandbox_receive_request.h index 79535b1..28686be 100644 --- a/runtime/include/sandbox_receive_request.h +++ b/runtime/include/sandbox_receive_request.h @@ -88,7 +88,6 @@ sandbox_receive_request(struct sandbox *sandbox) sandbox->request_response_data_length += nparsed; } - //http_request_print(&sandbox->http_request); sandbox->request_length = sandbox->request_response_data_length; rc = 0; diff --git a/runtime/include/sandbox_request.h b/runtime/include/sandbox_request.h index 0005dfa..5287ffd 100644 --- a/runtime/include/sandbox_request.h +++ b/runtime/include/sandbox_request.h @@ -25,7 +25,7 @@ struct sandbox_request { uint64_t absolute_deadline; /* cycles */ char * previous_function_output; 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 * 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->previous_function_output = previous_function_output; sandbox_request->output_length = output_length; - sandbox_request->pre_request_length = request_length; + sandbox_request->previous_request_length = request_length; /* * Admissions Control State diff --git a/runtime/include/sandbox_set_as_initialized.h b/runtime/include/sandbox_set_as_initialized.h index 6e66c9a..28ccb19 100644 --- a/runtime/include/sandbox_set_as_initialized.h +++ b/runtime/include/sandbox_set_as_initialized.h @@ -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->previous_function_output = sandbox_request->previous_function_output; 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 */ /* 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, diff --git a/runtime/include/sandbox_types.h b/runtime/include/sandbox_types.h index 9cf510a..9b3f455 100644 --- a/runtime/include/sandbox_types.h +++ b/runtime/include/sandbox_types.h @@ -35,7 +35,7 @@ struct sandbox { int current_func_index; /* indicate the index of next function in the chain */ char * previous_function_output; /* the output of the previous function */ 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; 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 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 diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index bc2acb2..7dcd5d5 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -69,24 +69,21 @@ current_sandbox_start(void) 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_receive_request(sandbox) < 0) {//read data from client socket to get http request, - //the result populates http_request structure - // if read blocked, then remove the sandbox from the - // local runqueue and pause the sandbox + if (sandbox_receive_request(sandbox) < 0) { error_message = "Unable to receive or parse client request\n"; goto err; }; } 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*/ assert(sandbox->previous_function_output != NULL); memcpy(sandbox->request_response_data, sandbox->previous_function_output, sandbox->output_length); sandbox->http_request.body = sandbox->request_response_data; 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; } @@ -94,7 +91,9 @@ current_sandbox_start(void) struct module *current_module = sandbox_get_module(sandbox); module_initialize_globals(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 */ int32_t argument_count = module_get_argument_count(current_module); current_sandbox_enable_preemption(sandbox); @@ -116,16 +115,16 @@ current_sandbox_start(void) (const struct sockaddr *)&sandbox->client_address, sandbox->request_arrival_timestamp, enqueue_timestamp, 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; /* 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_set_as_returned(sandbox, SANDBOX_RUNNING); } else { /* 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 - // and pause the sandbox + if (sandbox_send_response(sandbox) < 0) { error_message = "Unable to build and send client response\n"; goto err; }; @@ -136,12 +135,12 @@ current_sandbox_start(void) assert(sandbox->state == SANDBOX_RUNNING); 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: /* Cleanup connection and exit sandbox */ generic_thread_dump_lock_overhead(); - scheduler_yield(); //put the sandbox to the complete queue + scheduler_yield(); /* This assert prevents a segfault discussed in * https://github.com/phanikishoreg/awsm-Serverless-Framework/issues/66 diff --git a/runtime/src/global_request_scheduler_minheap.c b/runtime/src/global_request_scheduler_minheap.c index d799936..c312405 100644 --- a/runtime/src/global_request_scheduler_minheap.c +++ b/runtime/src/global_request_scheduler_minheap.c @@ -19,6 +19,7 @@ global_request_scheduler_minheap_add(void *sandbox_request) { assert(sandbox_request); 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__); int return_code = priority_queue_enqueue(global_request_scheduler_minheap, sandbox_request); diff --git a/runtime/src/main.c b/runtime/src/main.c index 0729edf..e2101ce 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -226,7 +226,6 @@ runtime_configure() if (runtime_sandbox_perf_log == NULL) { perror("sandbox perf log"); } fprintf(runtime_sandbox_perf_log, "id,function,state,deadline,actual,queued,initializing,runnable," "running,blocked,returned,memory\n"); - fflush(runtime_sandbox_perf_log); } else { printf("\tSandbox Performance Log: Disabled\n"); } diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index bc24bd8..7b061fc 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -65,12 +65,12 @@ runtime_set_resource_limits_to_max() int resource = resources[i]; 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); } else { 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); } else { snprintf(max, uint64_t_max_digits, "%lu", limit.rlim_max); @@ -91,19 +91,18 @@ runtime_set_resource_limits_to_max() void runtime_initialize(void) { - http_total_init(); //initilize http requests/error response counter - sandbox_request_count_initialize(); //initilize sandbox requests counter - sandbox_count_initialize(); //initilize sandbox state counter + http_total_init(); + sandbox_request_count_initialize(); + sandbox_count_initialize(); /* Setup Scheduler */ - scheduler_initialize(); //set function pointers to global_request_scheduler, both EDF and FIFO have a set of functions + scheduler_initialize(); /* Configure Signals */ - signal(SIGPIPE, SIG_IGN); // ignore SIGPIPE - signal(SIGTERM, runtime_cleanup); // call runtime_cleanup when get SIGTERM signal + signal(SIGPIPE, SIG_IGN); + signal(SIGTERM, runtime_cleanup); - http_parser_settings_initialize(); // set function pointers for http parser lib, when get a http message, some callback - // functions will be called + http_parser_settings_initialize(); admissions_control_initialize(); }