From a056d25ff44d74f8833538e2f6bc7ac974f5232e Mon Sep 17 00:00:00 2001 From: hwwang Date: Sun, 18 Aug 2024 17:23:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8A=82=E7=82=B9=E6=89=87?= =?UTF-8?q?=E5=85=A5=E6=97=B6=EF=BC=8C=E4=B8=8D=E7=94=A8&=E5=81=9A?= =?UTF-8?q?=E5=88=86=E5=89=B2=E7=AC=A6=EF=BC=8C=E6=94=B9=E4=B8=BA=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=89=8D=E5=9B=9B=E5=AD=97=E8=8A=82=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- .vscode/launch.json | 208 ++++++++++++++++-------------- runtime/include/sandbox_request.h | 35 +++-- runtime/tests/fibonacciadd/main | Bin 16256 -> 0 bytes runtime/tests/fibonacciadd/main.c | 65 ++++++---- 5 files changed, 178 insertions(+), 134 deletions(-) delete mode 100755 runtime/tests/fibonacciadd/main diff --git a/.env b/.env index 80da153..bacb3d1 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ -LD_LIBRARY_PATH=/home/hai/sledge-old/runtime/bin +LD_LIBRARY_PATH=/home/weihao/sledge/sledge_tree/runtime/bin SLEDGE_SCHEDULER=EDF -SLEDGE_SANDBOX_PERF_LOG=/home/hai/sledge-old/runtime_sandbox_perf_log.log +SLEDGE_SANDBOX_PERF_LOG=/home/weihao/sledge/sledge_tree/runtime_sandbox_perf_log.log diff --git a/.vscode/launch.json b/.vscode/launch.json index 82a7df5..9209453 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,96 +1,114 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Hyde", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/runtime/bin/sledgert", - "args": [ - "${workspaceFolder}/runtime/experiments/applications/ocr/hyde/spec.json" - ], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "envFile": "${workspaceFolder}/.env", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - }, - { - "name": "Preemption", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/runtime/bin/sledgert", - "args": [ - "${workspaceFolder}/runtime/experiments/preemption/spec.json" - ], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "envFile": "${workspaceFolder}/.env", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - }, - { - "name": "graph", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/runtime/bin/sledgert", - "args": [ - "${workspaceFolder}/runtime/tests/graph.json" - ], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "sourceFileMap": {"/sledge/runtime": "${workspaceFolder}/runtime"}, - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "envFile": "${workspaceFolder}/.env", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - }, - { - "name": "utest", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/runtime/utest/map", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "sourceFileMap": {}, - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "envFile": "${workspaceFolder}/.env", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} + "version": "0.2.0", + "configurations": [ + { + "name": "Hyde", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/runtime/bin/sledgert", + "args": [ + "${workspaceFolder}/runtime/experiments/applications/ocr/hyde/spec.json" + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "envFile": "${workspaceFolder}/.env", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "Preemption", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/runtime/bin/sledgert", + "args": [ + "${workspaceFolder}/runtime/experiments/preemption/spec.json" + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "envFile": "${workspaceFolder}/.env", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "graph", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/runtime/bin/sledgert", + "args": [ + "${workspaceFolder}/runtime/tests/graph.json" + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "sourceFileMap": { + "/sledge/runtime": "${workspaceFolder}/runtime" + }, + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "envFile": "${workspaceFolder}/.env", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "utest", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/runtime/utest/map", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "sourceFileMap": {}, + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "envFile": "${workspaceFolder}/.env", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/weihao/sledge/sledge_tree/runtime/tests/noop", + "program": "/home/weihao/sledge/sledge_tree/runtime/tests/noop/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/runtime/include/sandbox_request.h b/runtime/include/sandbox_request.h index d07592c..ec869ec 100644 --- a/runtime/include/sandbox_request.h +++ b/runtime/include/sandbox_request.h @@ -18,7 +18,7 @@ struct sandbox_pre_functions_output { char * previous_function_output; ssize_t output_length; uint32_t run_priority; - struct sandbox_pre_functions_output * next; + struct sandbox_pre_functions_output* next; }; struct sandbox_request { uint64_t id; @@ -127,6 +127,7 @@ sandbox_request_allocate(struct module *module, bool request_from_outside, ssize * @param output the output of the previous function * @param output_length the length of the output * @param run_priority the run_priority of the sandbox->module->run_priority +* The first four bytes of the data represent the length of the data, and the tail character & serves as the delimiter marker **/ static inline void pre_functions_output_request_add(struct sandbox_request *request, char *output, ssize_t output_length, uint32_t run_priority) @@ -179,8 +180,22 @@ concatenate_outputs(struct sandbox_request *request) { size_t total_length = 0; // Calculate total length without extra for null character struct sandbox_pre_functions_output *current = request->pre_functions_output; + if(current && !current->next) + { + char *previous_function_output = (char *)malloc(current->output_length); + if (!previous_function_output) { + panic("Could not allocate memory for concatenated output"); + return; + } + memcpy(previous_function_output, current->previous_function_output, current->output_length); + request->output_length = current->output_length; + request->previous_function_output = previous_function_output; + return; + } + + /* 4 bytes of data represents the length of the data */ while (current != NULL) { - total_length += current->output_length; + total_length += current->output_length + 4; current = current->next; } @@ -194,15 +209,15 @@ concatenate_outputs(struct sandbox_request *request) { current = request->pre_functions_output; while (current != NULL) { + size_t copy_length = current->output_length; - if (current->next) { - memcpy(copy_dest, current->previous_function_output, copy_length - 1); - copy_dest[copy_length - 1] = '&'; - copy_dest += copy_length; - } else { - memcpy(copy_dest, current->previous_function_output, copy_length); - break; - } + + *(uint32_t *)copy_dest = (uint32_t)copy_length; + copy_dest += 4; + + memcpy(copy_dest, current->previous_function_output, copy_length); + copy_dest += copy_length; + current = current->next; } diff --git a/runtime/tests/fibonacciadd/main b/runtime/tests/fibonacciadd/main deleted file mode 100755 index e887a0803e7340314ba08a7be555d96119ba3ecb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16256 zcmeHOYiu0V6~1f7!H|a?NSX&FnNl1`Q8q6pB$PDkBzDFqujbK;s&q2;uH%LEuGyVU zY!txMxXsFJo3^AyRi&m6iAXI~%1fal#552RsYMAtP*5crQ9yQ~;D|m@#A9{0|fJF|Co?!BjRV^c*WqNG%+&nc3OX)Y6E#lQ_*0mRfwH3k3Y zskv$*!t*$4JzATcj6zXy{+u`n4!a{Al~HCN>JMSJp3px z|89}fyp7u%?>uyI{slR`YEdfLvZ8)bD!wq4Oy|26cCB2oa7BGImx(UbU7&s$_|UM~ zuz9CKm;vHAjjE!@l_ehOrn8>x@A*dh#dG`SZ)ltQ)Qz_^Jb$6-(TC@f4fUIR$c75V zlOaMf)hFXaHf}!dMa|_1&n8~zARMnmp}4$^^84V7GQ0(@oITwh%JI~%a{PjE_$R;{ z_yo%q5ar@rHV%LFIQ(RY+pX62+pRV` znNm3?>tt?M*@PX362qjGEV7Q(VJFjITDxqkEt$4c$vYDeletXms#R7l*J`KR)ZT2; zNhornp|nD6*x0;wowYQ2gIBBfYD=Tbz523xWi{{EWW^KN#O`FyNo03yT9?YC6Fcmd z6g9KEBa`NSSgvVVLmX}e#!e;f6_xmlVEno$<2C|K0#JqCQd z95ZQ7`FJGQD`$K>T?=6eGZ1DV%s`ldFau!*!VLVU8F;s5?%&Pcx2nzls+SijW%dm? z6{Ry~@3Yk>bg0tu+d!AghP_(v0uG^v`Y4ntAu3(@0=(^^;)C zV$~xAt45p|NbMe~Bej>7&ezQAA-fZdurFx)$Ok*Lwlj5%1-!g$7q;k7Va7}d+!>I?44-#Hx9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PS#c+1{FUmP9jHf^N4YEyv!i zK;)c!TU)eMjV@QWoDQp%7OdxB8P8a|Q<)Y!WyPILHfP!SF4dap=u9Q>17LJVFZNo-uOH^id)1*i8nWWxbO92p&bw^gHbs0y#xAcLM;Tjol4k#d8^}-A>18r$F-- zSm8%rE1yfy28J>F6TFx=pnqvnx8!mhRc~)-OSbUF2+x%Iq6Q6 z2xGTPj1531QK@LIyTh?tfY^7Tv0ZA|rjf{Ys%SdnB%-_1`DkZ0gIya=w~uPcC$Wbo z8E2|tZSz7JquRXP&b6y(ygQ91Ty(OoW)FUnPG-_$1Pi)sB4v{U*E&;4x5ltjFhC5ze52>RmyCaEUt~*YKisC})!1yn7 zjeZ=8=83qa;5*MP!ToqLPh_>Wl{(?4@u9hy_>Z^mjBKgMe9V=UT7in+Ke+#let-8D zxi1Sx-|v2ZnO_JRV#pZu|04LmVs0n>m-(-tv@i4DVE=9S)7)45WqvHUl9G!;eWa@R z%RDs+j;2K7FY|3dnP0<17Y-+)x&t+uyNbWeR|RF>FZ~xg!Mov4b77HXJ}kJETMG7H zI#5J~aw`5ZKNlQeLuo&F{NH2$wQOflLnwlWT~WX5p_~Q%e*}(lBJsWNC;pz2=O7NF z`zm$9AK>HnH`q_Ghm3qhzWxLsg3j-Mh!uijCm}=@JQDCf!V1Aoaby%f!6yU$2G5HH z{}6a!5kCogJm4?$G(maJ6#L-yL-SBNemVcjU`xhdvM3rhO^N75wE&$3@MXfLwh1^CwZ{N;J#z(SBHV&_VuvhW{5 zL1S0imwCSI|CN2dd|7z$)OzQvu diff --git a/runtime/tests/fibonacciadd/main.c b/runtime/tests/fibonacciadd/main.c index 85cbf92..10f4e7f 100644 --- a/runtime/tests/fibonacciadd/main.c +++ b/runtime/tests/fibonacciadd/main.c @@ -2,8 +2,8 @@ #include #include #include +#include -// 假设的 Fibonacci 函数实现 unsigned long int fib(unsigned long int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); @@ -12,43 +12,54 @@ unsigned long int fib(unsigned long int n) { int main() { char buffer[1024]; // Buffer to store input data - // Read data from stdin into buffer ssize_t bytes_read = read(0, buffer, sizeof(buffer) - 1); if (bytes_read < 0) { perror("Error reading input"); return 1; } - buffer[bytes_read] = '\0'; + buffer[bytes_read] = '\0'; // Null-terminate the string - // Remove potential newline character at the end of the input - if (bytes_read > 0 && (buffer[bytes_read - 1] == '\n' || buffer[bytes_read - 1] == '\r')) { - buffer[bytes_read - 1] = '\0'; + // Parse the expected data length from the first 4 bytes for the first number + if (bytes_read < 4) { + fprintf(stderr, "Input is too short to contain valid data length.\n"); + return 1; + } + + // First number length and number + uint32_t first_num_length; + memcpy(&first_num_length, buffer, sizeof(uint32_t)); + char *first_num_start = buffer + 4; + if (bytes_read < 4 + first_num_length + 4) { // Check if there is enough data for the first number and the second length + fprintf(stderr, "Input does not contain enough data for the first number and the second length.\n"); + return 1; + } + + // Second number length and number + uint32_t second_num_length; + memcpy(&second_num_length, first_num_start + first_num_length, sizeof(uint32_t)); + char *second_num_start = first_num_start + first_num_length + 4; + if (bytes_read < 4 + first_num_length + 4 + second_num_length) { // Check if there is enough data for the second number + fprintf(stderr, "Input does not contain enough data for the second number.\n"); + return 1; } + // Read and calculate Fibonacci numbers unsigned long int num1, num2; - char *line = strtok(buffer, "&"); - char *second_part = strtok(NULL, "&"); // Assume the rest of the string is the second number - - if (line && sscanf(line, "%lu", &num1) == 1 && - second_part && sscanf(second_part, "%lu", &num2) == 1) { - // Calculate Fibonacci numbers and their sum - unsigned long int fib1 = fib(num1); - unsigned long int fib2 = fib(num2); - unsigned long int sum = fib1 + fib2; - - // Prepare output string - char output[1024]; - int len = snprintf(output, sizeof(output), "Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum); - - // Write to stdout - write(1, output, len); - } else { - const char *error_msg = "Invalid input. Please enter two numbers separated by '&'. Your input was: "; - char output_buffer[2048]; // Buffer to hold the error message and user input - int len = snprintf(output_buffer, sizeof(output_buffer), "%s%s\n", error_msg, buffer); - write(1, output_buffer, len); + if (sscanf(first_num_start, "%lu", &num1) != 1 || sscanf(second_num_start, "%lu", &num2) != 1) { + fprintf(stderr, "Failed to parse the numbers correctly.\n"); return 1; } + unsigned long int fib1 = fib(num1); + unsigned long int fib2 = fib(num2); + unsigned long int sum = fib1 + fib2; + + // Prepare output string + char output[1024]; + int len = snprintf(output, sizeof(output), "Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum); + + // Write to stdout + write(1, output, len); + return 0; }