diff --git a/.vscode/settings.json b/.vscode/settings.json index b18fda0..ee67b69 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,101 +1,102 @@ { "files.associations": { - "*.inc": "cpp", - "arm_nnexamples_cifar10_parameter.h": "c", - "arm_nnexamples_cifar10_weights.h": "c", - "__hash_table": "cpp", - "__split_buffer": "cpp", - "__tree": "cpp", - "array": "cpp", - "bitset": "cpp", - "deque": "cpp", - "dynarray": "cpp", - "simd": "cpp", - "hash_map": "cpp", - "hash_set": "cpp", - "initializer_list": "cpp", - "iterator": "cpp", - "list": "cpp", - "map": "cpp", - "queue": "cpp", - "random": "cpp", - "regex": "cpp", - "set": "cpp", - "stack": "cpp", - "string": "cpp", - "string_view": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "utility": "cpp", - "valarray": "cpp", - "vector": "cpp", - "__locale": "cpp", - "__config": "c", - "*.def": "c", - "mman.h": "c", - "types.h": "c", - "assert.h": "c", - "fstream": "c", - "locale": "c", - "*.tcc": "c", - "sandbox.h": "c", - "runtime.h": "c", - "panic.h": "c", - "ucontext.h": "c", - "stdlib.h": "c", - "pthread.h": "c", - "signal.h": "c", - "current_sandbox.h": "c", - "admissions_control.h": "c", - "sigval_t.h": "c", - "__sigval_t.h": "c", - "sigaction.h": "c", - "string.h": "c", - "errno.h": "c", - "siginfo_t.h": "c", - "features.h": "c", - "time.h": "c", - "local_runqueue_minheap.h": "c", - "global_request_scheduler.h": "c", - "dlfcn.h": "c", - "chrono": "c", - "common.h": "c", - "listener_thread.h": "c", - "http_total.h": "c", - "http_request.h": "c", - "http.h": "c", - "http_parser.h": "c", - "http_parser_settings.h": "c", - "client_socket.h": "c", - "context.h": "c", - "sandbox_types.h": "c", - "sandbox_functions.h": "c", - "ps_list.h": "c", - "module.h": "c", - "local_completion_queue.h": "c", - "local_runqueue.h": "c", - "software_interrupt.h": "c", - "sandbox_set_as_runnable.h": "c", - "sandbox_set_as_complete.h": "c", - "deque.h": "c", - "sandbox_request.h": "c", - "sandbox_send_response.h": "c", - "sandbox_setup_arguments.h": "c", - "worker_thread.h": "c", - "sandbox_set_as_error.h": "c", - "likely.h": "c", - "debuglog.h": "c", - "worker_thread_execute_epoll_loop.h": "c", - "sandbox_set_as_running.h": "c", - "sandbox_summarize_page_allocations.h": "c", - "sandbox_receive_request.h": "c", - "sandbox_state.h": "c", - "stdint.h": "c", - "stdbool.h": "c", - "compare": "c", - "cstdint": "c", - "format": "c" -}, + "*.inc": "cpp", + "arm_nnexamples_cifar10_parameter.h": "c", + "arm_nnexamples_cifar10_weights.h": "c", + "__hash_table": "cpp", + "__split_buffer": "cpp", + "__tree": "cpp", + "array": "cpp", + "bitset": "cpp", + "deque": "cpp", + "dynarray": "cpp", + "simd": "cpp", + "hash_map": "cpp", + "hash_set": "cpp", + "initializer_list": "cpp", + "iterator": "cpp", + "list": "cpp", + "map": "cpp", + "queue": "cpp", + "random": "cpp", + "regex": "cpp", + "set": "cpp", + "stack": "cpp", + "string": "cpp", + "string_view": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "utility": "cpp", + "valarray": "cpp", + "vector": "cpp", + "__locale": "cpp", + "__config": "c", + "*.def": "c", + "mman.h": "c", + "types.h": "c", + "assert.h": "c", + "fstream": "c", + "locale": "c", + "*.tcc": "c", + "sandbox.h": "c", + "runtime.h": "c", + "panic.h": "c", + "ucontext.h": "c", + "stdlib.h": "c", + "pthread.h": "c", + "signal.h": "c", + "current_sandbox.h": "c", + "admissions_control.h": "c", + "sigval_t.h": "c", + "__sigval_t.h": "c", + "sigaction.h": "c", + "string.h": "c", + "errno.h": "c", + "siginfo_t.h": "c", + "features.h": "c", + "time.h": "c", + "local_runqueue_minheap.h": "c", + "global_request_scheduler.h": "c", + "dlfcn.h": "c", + "chrono": "c", + "common.h": "c", + "listener_thread.h": "c", + "http_total.h": "c", + "http_request.h": "c", + "http.h": "c", + "http_parser.h": "c", + "http_parser_settings.h": "c", + "client_socket.h": "c", + "context.h": "c", + "sandbox_types.h": "c", + "sandbox_functions.h": "c", + "ps_list.h": "c", + "module.h": "c", + "local_completion_queue.h": "c", + "local_runqueue.h": "c", + "software_interrupt.h": "c", + "sandbox_set_as_runnable.h": "c", + "sandbox_set_as_complete.h": "c", + "deque.h": "c", + "sandbox_request.h": "c", + "sandbox_send_response.h": "c", + "sandbox_setup_arguments.h": "c", + "worker_thread.h": "c", + "sandbox_set_as_error.h": "c", + "likely.h": "c", + "debuglog.h": "c", + "worker_thread_execute_epoll_loop.h": "c", + "sandbox_set_as_running.h": "c", + "sandbox_summarize_page_allocations.h": "c", + "sandbox_receive_request.h": "c", + "sandbox_state.h": "c", + "stdint.h": "c", + "stdbool.h": "c", + "compare": "c", + "cstdint": "c", + "format": "c", + "jsmn.h": "c" + }, "files.exclude": { "**/.git": true, "**/.svn": true, @@ -203,7 +204,7 @@ "C_Cpp_Runner.useLeakSanitizer": false, "C_Cpp_Runner.showCompilationTime": false, "C_Cpp_Runner.useLinkTimeOptimization": false, -"C_Cpp_Runner.msvcSecureNoWarnings": false, -"git.detectSubmodules": true, -"git.enabled": true -} + "C_Cpp_Runner.msvcSecureNoWarnings": false, + "git.detectSubmodules": true, + "git.enabled": true +} \ No newline at end of file diff --git a/runtime/include/deque.h b/runtime/include/deque.h index 621689b..e4c534a 100644 --- a/runtime/include/deque.h +++ b/runtime/include/deque.h @@ -114,6 +114,12 @@ if (__sync_bool_compare_and_swap(&deque->top, ct, ct + 1) == false) return -EAGAIN; \ \ return 0; \ - } + } \ + static inline bool deque_is_empty_##name(struct deque_##name *q) \ + { \ + long ct = q->top; \ + long cb = q->bottom; \ + return ct >= cb; \ + } #endif /* DEQUE_H */ diff --git a/runtime/include/module.h b/runtime/include/module.h index 9e76905..b039feb 100644 --- a/runtime/include/module.h +++ b/runtime/include/module.h @@ -1,4 +1,4 @@ -#pragma once +#pragma 78once #include #include @@ -20,6 +20,7 @@ #define MODULE_DEFAULT_REQUEST_RESPONSE_SIZE (PAGE_SIZE) + #define MODULE_MAX_ARGUMENT_COUNT 16 #define MODULE_MAX_ARGUMENT_SIZE 64 #define MODULE_MAX_NAME_LENGTH 32 @@ -84,11 +85,8 @@ struct module { /* the left and right children module in the tree */ struct module *left_module; struct module *right_module; - /* the parent moudle info*/ - struct module *parent_module; - { - /* data */ - }; + /* parent moudle or not?*/ + bool *is_parent; }; diff --git a/runtime/include/sandbox_functions.h b/runtime/include/sandbox_functions.h index c282afe..1f0a59e 100644 --- a/runtime/include/sandbox_functions.h +++ b/runtime/include/sandbox_functions.h @@ -225,7 +225,8 @@ sandbox_mem_print_perf(struct sandbox *sandbox) uint64_t blocked_us = sandbox->blocked_duration / runtime_processor_speed_MHz; uint64_t returned_us = sandbox->returned_duration / runtime_processor_speed_MHz; - if (sandbox->module->next_module == NULL) { + //if (sandbox->module->next_module == NULL) { + if(sandbox->module->is_parent) { uint64_t total_time = (sandbox->completion_timestamp - sandbox->request_arrival_timestamp) / runtime_processor_speed_MHz; bool miss_deadline = sandbox->completion_timestamp > sandbox->absolute_deadline ? true : false; uint64_t delayed_us = (sandbox->completion_timestamp - sandbox->absolute_deadline) diff --git a/runtime/src/main.c b/runtime/src/main.c index 557c8d4..e5f8cad 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -352,7 +352,7 @@ main(int argc, char **argv) memset(runtime_worker_threads, 0, sizeof(pthread_t) * RUNTIME_WORKER_THREAD_CORE_COUNT); //runtime_processor_speed_MHz = runtime_get_processor_speed_MHz(); - runtime_processor_speed_MHz = 2600; //this is the default value + runtime_processor_speed_MHz = 2400; //this is the default value char *cpu_speed_MHz_raw = getenv("SLEDGE_CPU_SPEED"); if (cpu_speed_MHz_raw != NULL) { long cpu_speed_MHz = atoi(cpu_speed_MHz_raw); diff --git a/runtime/src/module.c b/runtime/src/module.c index f0810fe..502a91a 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -19,7 +19,8 @@ const int JSON_MAX_ELEMENT_COUNT = 16; const int JSON_MAX_ELEMENT_SIZE = 1024; - +DEQUE_PROTOTYPE(Treequeue,struct module *) +static struct deque_Treequeue *tree_queue; /************************* * Private Static Inline * ************************/ @@ -374,7 +375,26 @@ module_new_from_json(char *file_name) int module_count = 0; char *request_headers = NULL; char *reponse_headers = NULL; - struct module *tail_module = NULL; +/* struct module *tail_module = NULL; + deque_init_Treequeue(tree_queue, total_tokens); + assert(tokens[0].type == JSMN_OBJECT); + + while (deque_is_empty_Treequeue(tree_queue)) + { + Node *current = dequeue(&queue); + + if (is_parent) { + current->left = getNextNode(); + enqueue(&queue, current->left); + } + + if (is_parent) { + current->right = getNextNode(); + enqueue(&queue, current->right); + } + } + }*/ + struct module *nodes[total_tokens]; for (int i = 0; i < total_tokens; i++) { assert(tokens[i].type == JSMN_OBJECT); @@ -454,7 +474,18 @@ 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) { + }else if(strcmp(key,"is_parent") == 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 is-parent 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; @@ -463,7 +494,7 @@ module_new_from_json(char *file_name) } else { panic("Expected tail_module key to be a JSON boolean, was %s\n", val); } - } else if (strcmp(key, "relative-deadline-us") == 0) { + }*/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) panic("Relative-deadline-us must be between 0 and %ld, was %ld\n", @@ -568,15 +599,18 @@ module_new_from_json(char *file_name) if (module == NULL) goto module_new_err; assert(module); - - if (tail_module != NULL) { tail_module->next_module = module; } - tail_module = module; - tail_module->next_module = NULL; - - /* if this is the tail module, reset tail_module to NULL to build another new chain */ - if (is_tail_module) { - tail_module = NULL; - } + if(is_tail_module) module->is_parent == true; + nodes[i] = malloc(sizeof(module)); + nodes[i] = module; + + // if (tail_module != NULL) { tail_module->next_module = module; } + // tail_module = module; + // tail_module->next_module = NULL; + + // /* if this is the tail module, reset tail_module to NULL to build another new chain */ + // if (is_tail_module) { + // tail_module = NULL; + // } module_set_http_info(module, request_count, request_headers, request_content_type, response_count, reponse_headers, response_content_type); @@ -586,7 +620,12 @@ module_new_from_json(char *file_name) free(request_headers); free(reponse_headers); } - + for (int i = 0; i < total_tokens; i++) { + int left_index = 2 * i + 1; + int right_index = 2 * i + 2; + if (left_index < total_tokens) nodes[i]->left_module = nodes[left_index]; + if (right_index < total_tokens) nodes[i]->right_module = nodes[right_index]; + } if (module_count == 0) panic("%s contained no active modules\n", file_name); #ifdef LOG_MODULE_LOADING debuglog("Loaded %d module%s!\n", module_count, module_count > 1 ? "s" : ""); diff --git a/runtime/tree.c b/runtime/tree.c deleted file mode 100644 index d3b5499..0000000 --- a/runtime/tree.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -typedef struct TreeNode { - void (*func)(struct TreeNode *); // 节点的函数 - struct TreeNode *left; // 左子节点 - struct TreeNode *right; // 右子节点 -} TreeNode; -void nodeFunction(TreeNode *node) { - printf("Node function executed: %p\n", (void *)node); -} - -void leafFunction(TreeNode *node) { - printf("Leaf function executed: %p\n", (void *)node); -} -TreeNode *createBinaryTree(int depth) { - if (depth == 0) return NULL; - - TreeNode *node = (TreeNode *)malloc(sizeof(TreeNode)); - node->func = (depth > 1) ? nodeFunction : leafFunction; // 叶节点使用 leafFunction - node->left = createBinaryTree(depth - 1); - node->right = createBinaryTree(depth - 1); - return node; -} -void executeTree(TreeNode *node) { - if (node == NULL) return; - // 首先递归执行左右子节点 - executeTree(node->left); - executeTree(node->right); - // 然后执行当前节点的函数 - node->func(node); -} -void freeTree(TreeNode *node) { - if (node == NULL) return; - freeTree(node->left); - freeTree(node->right); - free(node); -} - -int main() { - // 创建一个深度为 3 的二叉树 - TreeNode *root = createBinaryTree(3); - - // 执行二叉树 - executeTree(root); - - // 释放二叉树占用的内存 - freeTree(root); - return 0; -}