From 87ba8af8a0251bd8b8955a9dd4127b85881e83e8 Mon Sep 17 00:00:00 2001 From: hwwang Date: Wed, 30 Oct 2024 19:38:37 +0800 Subject: [PATCH] fix time bug --- runtime/Makefile | 4 ++-- runtime/src/listener_thread.c | 5 +++-- runtime/src/module.c | 21 ++++++++++---------- runtime/tests/Makefile | 2 +- runtime/tests/noop/deal_noop.py | 26 ++++++++++++++++++++++++ runtime/tests/noop/main.c | 11 ++++++++++ runtime/tests/noop/noop_average.py | 22 ++++++++++++++++++++ runtime/tests/start_noop1.sh | 32 ++++++++++++++++++++++++++++++ runtime/tests/test_noop1.json | 17 ++++++++++++++++ 9 files changed, 124 insertions(+), 16 deletions(-) create mode 100755 runtime/tests/noop/deal_noop.py create mode 100644 runtime/tests/noop/main.c create mode 100644 runtime/tests/noop/noop_average.py create mode 100755 runtime/tests/start_noop1.sh create mode 100644 runtime/tests/test_noop1.json diff --git a/runtime/Makefile b/runtime/Makefile index bb37fd2..49f2b92 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -59,8 +59,8 @@ CFLAGS += -DLOG_TO_FILE # CFLAGS += -DLOG_PREEMPTION # CFLAGS += -DLOG_MODULE_LOADING # CFLAGS += -DOPT_AVOID_GLOBAL_QUEUE -#CFLAGS += -DLOG_RUNTIME_FILE_LOG -CFLAGS += -DLOG_RUNTIME_MEM_LOG +CFLAGS += -DLOG_RUNTIME_FILE_LOG +#CFLAGS += -DLOG_RUNTIME_MEM_LOG # This dumps per module *.csv files containing the cycle a sandbox has been in RUNNING when each # page is allocated. This helps understand the relationship to memory allocation and execution time. diff --git a/runtime/src/listener_thread.c b/runtime/src/listener_thread.c index 1001597..107b41b 100644 --- a/runtime/src/listener_thread.c +++ b/runtime/src/listener_thread.c @@ -104,7 +104,6 @@ listener_thread_main(void *dummy) */ assert(descriptor_count > 0); - uint64_t request_arrival_timestamp = __getcycles(); for (int i = 0; i < descriptor_count; i++) { /* Check Event to determine if epoll returned an error */ if ((epoll_events[i].events & EPOLLERR) == EPOLLERR) { @@ -222,9 +221,11 @@ listener_thread_main(void *dummy) /* Adding system start timestamp to avoid negative remaining slack in the following update. They are all cycles */ uint64_t remaining_slack = system_start_timestamp + module->relative_deadline - estimated_execution_time; + + uint64_t request_arrival_timestamp = __getcycles(); /* Allocate a Sandbox Request */ struct sandbox_request *sandbox_request = - sandbox_request_allocate(module, true, 0, module->name, client_socket, + sandbox_request_allocate(module, true, 0, module->name, client_socket, (const struct sockaddr *)&client_address, request_arrival_timestamp, request_arrival_timestamp,remaining_slack, work_admitted, NULL, 0); diff --git a/runtime/src/module.c b/runtime/src/module.c index a9bdd19..61e483d 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -412,7 +412,7 @@ module_new_from_json(char *file_name) uint32_t expected_execution_us = 0; int admissions_percentile = 50; bool is_active = false; - bool is_tail_module = false; +// bool is_tail_module = false; int32_t request_count = 0; int32_t response_count = 0; int j = 1; @@ -489,15 +489,15 @@ module_new_from_json(char *file_name) } else { panic("Expected active key to be a JSON boolean, was %s\n", val); } - } else if (strcmp(key, "tail-module") == 0) { - assert(tokens[i + j + 1].type == JSMN_PRIMITIVE); - if (val[0] == 't') { - is_tail_module = true; - } else if (val[0] == 'f') { - is_tail_module = false; - } else { - panic("Expected tail_module key to be a JSON boolean, was %s\n", val); - } + // } else if (strcmp(key, "tail-module") == 0) { + // assert(tokens[i + j + 1].type == JSMN_PRIMITIVE); + // if (val[0] == 't') { + // is_tail_module = true; + // } else if (val[0] == 'f') { + // is_tail_module = false; + // } else { + // panic("Expected tail_module key to be a JSON boolean, was %s\n", val); + // } } else if (strcmp(key, "relative-deadline-us") == 0) { int64_t buffer = strtoll(val, NULL, 10); if (buffer < 0 || buffer > (int64_t)RUNTIME_RELATIVE_DEADLINE_US_MAX) @@ -604,7 +604,6 @@ module_new_from_json(char *file_name) if(next_module_count == 0) { module->next_module_names = NULL; - }else { module->next_module_names = malloc(next_module_count * sizeof(char*)); diff --git a/runtime/tests/Makefile b/runtime/tests/Makefile index 4d15231..eeedfc5 100644 --- a/runtime/tests/Makefile +++ b/runtime/tests/Makefile @@ -2,7 +2,7 @@ include Makefile.inc #TESTS=fibonacci fibonacci2 fibonacci3 big_fibonacci C-Image-Manip empty work work1k work10k work100k work1m forever filesys sockserver sockclient empty TESTS=fibonacci big_fibonacci C-Image-Manip empty work work1k work10k work100k work1m forever filesys sockserver sockclient empty -TESTS2=fibonacciadd mem work3 picinpic +TESTS2=fibonacciadd mem work3 picinpic noop TESTSRT=$(TESTS:%=%_rt) TESTSRT2=$(TESTS2:%=%_rt) diff --git a/runtime/tests/noop/deal_noop.py b/runtime/tests/noop/deal_noop.py new file mode 100755 index 0000000..64b8500 --- /dev/null +++ b/runtime/tests/noop/deal_noop.py @@ -0,0 +1,26 @@ +import sys + +def process_file(input_file, noop_functions): + data = {noop: [] for noop in noop_functions} + + with open(input_file, "r") as infile: + for line in infile: + for noop in noop_functions: + if noop in line: + value = line.split(",")[6] + data[noop].append(value) + + for noop, values in data.items(): + with open(f"{noop}.txt", "w") as outfile: + outfile.write("\n".join(values)) + +if __name__ == "__main__": + noop_functions = ["noop1", "noop2", "noop3", "noop4", "noop5"] + + argv = sys.argv[1:] + if len(argv) < 1: + print("usage:", sys.argv[0], "file_dir percentage") + sys.exit() + + input_file = argv[0] + process_file(input_file, noop_functions) \ No newline at end of file diff --git a/runtime/tests/noop/main.c b/runtime/tests/noop/main.c new file mode 100644 index 0000000..f4c9f1b --- /dev/null +++ b/runtime/tests/noop/main.c @@ -0,0 +1,11 @@ +#include + + +void noop() { + +} + +int main() { + noop(); + return 0; +} \ No newline at end of file diff --git a/runtime/tests/noop/noop_average.py b/runtime/tests/noop/noop_average.py new file mode 100644 index 0000000..1f09682 --- /dev/null +++ b/runtime/tests/noop/noop_average.py @@ -0,0 +1,22 @@ +import os + +def calculate_average(filename): + with open(filename, "r") as file: + values = file.readlines() + values = [int(value.strip()) for value in values] + average = sum(values) / len(values) if values else 0 + return average + +def main(): + noop_functions = ["noop1", "noop2", "noop3", "noop4", "noop5"] + + for noop in noop_functions: + filename = f"{noop}.txt" + if os.path.exists(filename): + average = calculate_average(filename) + print(f"Average for {filename}: {average}") + else: + print(f"{filename} does not exist.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/runtime/tests/start_noop1.sh b/runtime/tests/start_noop1.sh new file mode 100755 index 0000000..09dbee9 --- /dev/null +++ b/runtime/tests/start_noop1.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +function usage { + echo "$0 [perf output file, chain_function_perf.log or single_function_perf.log or opt_function_perf.log]" + exit 1 +} + +if [ $# != 1 ] ; then + usage + exit 1; +fi + +output=$1 + + +declare project_path="$( + cd "$(dirname "$0")/../.." + pwd +)" +echo $project_path +path=`pwd` +#export SLEDGE_DISABLE_PREEMPTION=true +export SLEDGE_CPU_SPEED=2500 +export SLEDGE_SCHEDULER=FIFO +export SLEDGE_SIGALRM_HANDLER=BROADCAST +#export SLEDGE_SIGALRM_HANDLER=TRIAGED +#export SLEDGE_NWORKERS=16 +#export SLEDGE_SCHEDULER=EDF +export SLEDGE_SANDBOX_PERF_LOG=$path/$output +echo $SLEDGE_SANDBOX_PERF_LOG +cd $project_path/runtime/bin +LD_LIBRARY_PATH="$(pwd):$LD_LIBRARY_PATH" ./sledgert ../tests/test_noop1.json \ No newline at end of file diff --git a/runtime/tests/test_noop1.json b/runtime/tests/test_noop1.json new file mode 100644 index 0000000..0ecd344 --- /dev/null +++ b/runtime/tests/test_noop1.json @@ -0,0 +1,17 @@ +{ + "active": true, + "name": "noop1", + "path": "noop_wasm.so", + "port": 10000, + "relative-deadline-us": 0, + "argsize": 0, + "priority": 1, + "pre_module_count": 0, + "next_modules": [], + "http-req-headers": [], + "http-req-content-type": "text/plain", + "http-req-size": 0, + "http-resp-headers": [], + "http-resp-size": 0, + "http-resp-content-type": "text/plain", +} \ No newline at end of file