modify module to tree

main
hwwang 6 months ago
parent 63f689cba7
commit 75bf451df0

@ -1,101 +1,102 @@
{ {
"files.associations": { "files.associations": {
"*.inc": "cpp", "*.inc": "cpp",
"arm_nnexamples_cifar10_parameter.h": "c", "arm_nnexamples_cifar10_parameter.h": "c",
"arm_nnexamples_cifar10_weights.h": "c", "arm_nnexamples_cifar10_weights.h": "c",
"__hash_table": "cpp", "__hash_table": "cpp",
"__split_buffer": "cpp", "__split_buffer": "cpp",
"__tree": "cpp", "__tree": "cpp",
"array": "cpp", "array": "cpp",
"bitset": "cpp", "bitset": "cpp",
"deque": "cpp", "deque": "cpp",
"dynarray": "cpp", "dynarray": "cpp",
"simd": "cpp", "simd": "cpp",
"hash_map": "cpp", "hash_map": "cpp",
"hash_set": "cpp", "hash_set": "cpp",
"initializer_list": "cpp", "initializer_list": "cpp",
"iterator": "cpp", "iterator": "cpp",
"list": "cpp", "list": "cpp",
"map": "cpp", "map": "cpp",
"queue": "cpp", "queue": "cpp",
"random": "cpp", "random": "cpp",
"regex": "cpp", "regex": "cpp",
"set": "cpp", "set": "cpp",
"stack": "cpp", "stack": "cpp",
"string": "cpp", "string": "cpp",
"string_view": "cpp", "string_view": "cpp",
"unordered_map": "cpp", "unordered_map": "cpp",
"unordered_set": "cpp", "unordered_set": "cpp",
"utility": "cpp", "utility": "cpp",
"valarray": "cpp", "valarray": "cpp",
"vector": "cpp", "vector": "cpp",
"__locale": "cpp", "__locale": "cpp",
"__config": "c", "__config": "c",
"*.def": "c", "*.def": "c",
"mman.h": "c", "mman.h": "c",
"types.h": "c", "types.h": "c",
"assert.h": "c", "assert.h": "c",
"fstream": "c", "fstream": "c",
"locale": "c", "locale": "c",
"*.tcc": "c", "*.tcc": "c",
"sandbox.h": "c", "sandbox.h": "c",
"runtime.h": "c", "runtime.h": "c",
"panic.h": "c", "panic.h": "c",
"ucontext.h": "c", "ucontext.h": "c",
"stdlib.h": "c", "stdlib.h": "c",
"pthread.h": "c", "pthread.h": "c",
"signal.h": "c", "signal.h": "c",
"current_sandbox.h": "c", "current_sandbox.h": "c",
"admissions_control.h": "c", "admissions_control.h": "c",
"sigval_t.h": "c", "sigval_t.h": "c",
"__sigval_t.h": "c", "__sigval_t.h": "c",
"sigaction.h": "c", "sigaction.h": "c",
"string.h": "c", "string.h": "c",
"errno.h": "c", "errno.h": "c",
"siginfo_t.h": "c", "siginfo_t.h": "c",
"features.h": "c", "features.h": "c",
"time.h": "c", "time.h": "c",
"local_runqueue_minheap.h": "c", "local_runqueue_minheap.h": "c",
"global_request_scheduler.h": "c", "global_request_scheduler.h": "c",
"dlfcn.h": "c", "dlfcn.h": "c",
"chrono": "c", "chrono": "c",
"common.h": "c", "common.h": "c",
"listener_thread.h": "c", "listener_thread.h": "c",
"http_total.h": "c", "http_total.h": "c",
"http_request.h": "c", "http_request.h": "c",
"http.h": "c", "http.h": "c",
"http_parser.h": "c", "http_parser.h": "c",
"http_parser_settings.h": "c", "http_parser_settings.h": "c",
"client_socket.h": "c", "client_socket.h": "c",
"context.h": "c", "context.h": "c",
"sandbox_types.h": "c", "sandbox_types.h": "c",
"sandbox_functions.h": "c", "sandbox_functions.h": "c",
"ps_list.h": "c", "ps_list.h": "c",
"module.h": "c", "module.h": "c",
"local_completion_queue.h": "c", "local_completion_queue.h": "c",
"local_runqueue.h": "c", "local_runqueue.h": "c",
"software_interrupt.h": "c", "software_interrupt.h": "c",
"sandbox_set_as_runnable.h": "c", "sandbox_set_as_runnable.h": "c",
"sandbox_set_as_complete.h": "c", "sandbox_set_as_complete.h": "c",
"deque.h": "c", "deque.h": "c",
"sandbox_request.h": "c", "sandbox_request.h": "c",
"sandbox_send_response.h": "c", "sandbox_send_response.h": "c",
"sandbox_setup_arguments.h": "c", "sandbox_setup_arguments.h": "c",
"worker_thread.h": "c", "worker_thread.h": "c",
"sandbox_set_as_error.h": "c", "sandbox_set_as_error.h": "c",
"likely.h": "c", "likely.h": "c",
"debuglog.h": "c", "debuglog.h": "c",
"worker_thread_execute_epoll_loop.h": "c", "worker_thread_execute_epoll_loop.h": "c",
"sandbox_set_as_running.h": "c", "sandbox_set_as_running.h": "c",
"sandbox_summarize_page_allocations.h": "c", "sandbox_summarize_page_allocations.h": "c",
"sandbox_receive_request.h": "c", "sandbox_receive_request.h": "c",
"sandbox_state.h": "c", "sandbox_state.h": "c",
"stdint.h": "c", "stdint.h": "c",
"stdbool.h": "c", "stdbool.h": "c",
"compare": "c", "compare": "c",
"cstdint": "c", "cstdint": "c",
"format": "c" "format": "c",
}, "jsmn.h": "c"
},
"files.exclude": { "files.exclude": {
"**/.git": true, "**/.git": true,
"**/.svn": true, "**/.svn": true,
@ -203,7 +204,7 @@
"C_Cpp_Runner.useLeakSanitizer": false, "C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false, "C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false, "C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false, "C_Cpp_Runner.msvcSecureNoWarnings": false,
"git.detectSubmodules": true, "git.detectSubmodules": true,
"git.enabled": true "git.enabled": true
} }

@ -114,6 +114,12 @@
if (__sync_bool_compare_and_swap(&deque->top, ct, ct + 1) == false) return -EAGAIN; \ if (__sync_bool_compare_and_swap(&deque->top, ct, ct + 1) == false) return -EAGAIN; \
\ \
return 0; \ 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 */ #endif /* DEQUE_H */

@ -1,4 +1,4 @@
#pragma once #pragma 78once
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -20,6 +20,7 @@
#define MODULE_DEFAULT_REQUEST_RESPONSE_SIZE (PAGE_SIZE) #define MODULE_DEFAULT_REQUEST_RESPONSE_SIZE (PAGE_SIZE)
#define MODULE_MAX_ARGUMENT_COUNT 16 #define MODULE_MAX_ARGUMENT_COUNT 16
#define MODULE_MAX_ARGUMENT_SIZE 64 #define MODULE_MAX_ARGUMENT_SIZE 64
#define MODULE_MAX_NAME_LENGTH 32 #define MODULE_MAX_NAME_LENGTH 32
@ -84,11 +85,8 @@ struct module {
/* the left and right children module in the tree */ /* the left and right children module in the tree */
struct module *left_module; struct module *left_module;
struct module *right_module; struct module *right_module;
/* the parent moudle info*/ /* parent moudle or not?*/
struct module *parent_module; bool *is_parent;
{
/* data */
};
}; };

@ -225,7 +225,8 @@ sandbox_mem_print_perf(struct sandbox *sandbox)
uint64_t blocked_us = sandbox->blocked_duration / runtime_processor_speed_MHz; uint64_t blocked_us = sandbox->blocked_duration / runtime_processor_speed_MHz;
uint64_t returned_us = sandbox->returned_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; 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; bool miss_deadline = sandbox->completion_timestamp > sandbox->absolute_deadline ? true : false;
uint64_t delayed_us = (sandbox->completion_timestamp - sandbox->absolute_deadline) uint64_t delayed_us = (sandbox->completion_timestamp - sandbox->absolute_deadline)

@ -352,7 +352,7 @@ main(int argc, char **argv)
memset(runtime_worker_threads, 0, sizeof(pthread_t) * RUNTIME_WORKER_THREAD_CORE_COUNT); 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 = 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"); char *cpu_speed_MHz_raw = getenv("SLEDGE_CPU_SPEED");
if (cpu_speed_MHz_raw != NULL) { if (cpu_speed_MHz_raw != NULL) {
long cpu_speed_MHz = atoi(cpu_speed_MHz_raw); long cpu_speed_MHz = atoi(cpu_speed_MHz_raw);

@ -19,7 +19,8 @@
const int JSON_MAX_ELEMENT_COUNT = 16; const int JSON_MAX_ELEMENT_COUNT = 16;
const int JSON_MAX_ELEMENT_SIZE = 1024; const int JSON_MAX_ELEMENT_SIZE = 1024;
DEQUE_PROTOTYPE(Treequeue,struct module *)
static struct deque_Treequeue *tree_queue;
/************************* /*************************
* Private Static Inline * * Private Static Inline *
************************/ ************************/
@ -374,7 +375,26 @@ module_new_from_json(char *file_name)
int module_count = 0; int module_count = 0;
char *request_headers = NULL; char *request_headers = NULL;
char *reponse_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++) { for (int i = 0; i < total_tokens; i++) {
assert(tokens[i].type == JSMN_OBJECT); assert(tokens[i].type == JSMN_OBJECT);
@ -454,7 +474,18 @@ module_new_from_json(char *file_name)
} else { } else {
panic("Expected active key to be a JSON boolean, was %s\n", val); 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); assert(tokens[i + j + 1].type == JSMN_PRIMITIVE);
if (val[0] == 't') { if (val[0] == 't') {
is_tail_module = true; is_tail_module = true;
@ -463,7 +494,7 @@ module_new_from_json(char *file_name)
} else { } else {
panic("Expected tail_module key to be a JSON boolean, was %s\n", val); 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); int64_t buffer = strtoll(val, NULL, 10);
if (buffer < 0 || buffer > (int64_t)RUNTIME_RELATIVE_DEADLINE_US_MAX) if (buffer < 0 || buffer > (int64_t)RUNTIME_RELATIVE_DEADLINE_US_MAX)
panic("Relative-deadline-us must be between 0 and %ld, was %ld\n", 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; if (module == NULL) goto module_new_err;
assert(module); assert(module);
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; } // if (tail_module != NULL) { tail_module->next_module = module; }
tail_module = module; // tail_module = module;
tail_module->next_module = NULL; // tail_module->next_module = NULL;
/* if this is the tail module, reset tail_module to NULL to build another new chain */ // /* if this is the tail module, reset tail_module to NULL to build another new chain */
if (is_tail_module) { // if (is_tail_module) {
tail_module = NULL; // tail_module = NULL;
} // }
module_set_http_info(module, request_count, request_headers, request_content_type, module_set_http_info(module, request_count, request_headers, request_content_type,
response_count, reponse_headers, response_content_type); response_count, reponse_headers, response_content_type);
@ -586,7 +620,12 @@ module_new_from_json(char *file_name)
free(request_headers); free(request_headers);
free(reponse_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); if (module_count == 0) panic("%s contained no active modules\n", file_name);
#ifdef LOG_MODULE_LOADING #ifdef LOG_MODULE_LOADING
debuglog("Loaded %d module%s!\n", module_count, module_count > 1 ? "s" : ""); debuglog("Loaded %d module%s!\n", module_count, module_count > 1 ? "s" : "");

@ -1,50 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
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;
}
Loading…
Cancel
Save