修改节点扇入时,不用&做分割符,改为增加前四字节作为数据长度

sledge_graph
hwwang 3 months ago
parent 46b4325dba
commit a056d25ff4

@ -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_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

@ -1,7 +1,4 @@
{ {
// 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", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
@ -58,7 +55,9 @@
], ],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"sourceFileMap": {"/sledge/runtime": "${workspaceFolder}/runtime"}, "sourceFileMap": {
"/sledge/runtime": "${workspaceFolder}/runtime"
},
"environment": [], "environment": [],
"externalConsole": false, "externalConsole": false,
"MIMode": "gdb", "MIMode": "gdb",
@ -91,6 +90,25 @@
"ignoreFailures": true "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
}
]
} }
] ]
} }

@ -18,7 +18,7 @@ struct sandbox_pre_functions_output {
char * previous_function_output; char * previous_function_output;
ssize_t output_length; ssize_t output_length;
uint32_t run_priority; uint32_t run_priority;
struct sandbox_pre_functions_output * next; struct sandbox_pre_functions_output* next;
}; };
struct sandbox_request { struct sandbox_request {
uint64_t id; 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 the output of the previous function
* @param output_length the length of the output * @param output_length the length of the output
* @param run_priority the run_priority of the sandbox->module->run_priority * @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 static inline void
pre_functions_output_request_add(struct sandbox_request *request, char *output, ssize_t output_length, uint32_t run_priority) 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 size_t total_length = 0; // Calculate total length without extra for null character
struct sandbox_pre_functions_output *current = request->pre_functions_output; 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) { while (current != NULL) {
total_length += current->output_length; total_length += current->output_length + 4;
current = current->next; current = current->next;
} }
@ -194,15 +209,15 @@ concatenate_outputs(struct sandbox_request *request) {
current = request->pre_functions_output; current = request->pre_functions_output;
while (current != NULL) { while (current != NULL) {
size_t copy_length = current->output_length; size_t copy_length = current->output_length;
if (current->next) {
memcpy(copy_dest, current->previous_function_output, copy_length - 1); *(uint32_t *)copy_dest = (uint32_t)copy_length;
copy_dest[copy_length - 1] = '&'; copy_dest += 4;
copy_dest += copy_length;
} else {
memcpy(copy_dest, current->previous_function_output, copy_length); memcpy(copy_dest, current->previous_function_output, copy_length);
break; copy_dest += copy_length;
}
current = current->next; current = current->next;
} }

Binary file not shown.

@ -2,8 +2,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
// 假设的 Fibonacci 函数实现
unsigned long int fib(unsigned long int n) { unsigned long int fib(unsigned long int n) {
if (n <= 1) return n; if (n <= 1) return n;
return fib(n - 1) + fib(n - 2); return fib(n - 1) + fib(n - 2);
@ -12,26 +12,44 @@ unsigned long int fib(unsigned long int n) {
int main() { int main() {
char buffer[1024]; // Buffer to store input data char buffer[1024]; // Buffer to store input data
// Read data from stdin into buffer
ssize_t bytes_read = read(0, buffer, sizeof(buffer) - 1); ssize_t bytes_read = read(0, buffer, sizeof(buffer) - 1);
if (bytes_read < 0) { if (bytes_read < 0) {
perror("Error reading input"); perror("Error reading input");
return 1; return 1;
} }
buffer[bytes_read] = '\0'; buffer[bytes_read] = '\0'; // Null-terminate the string
// Remove potential newline character at the end of the input // Parse the expected data length from the first 4 bytes for the first number
if (bytes_read > 0 && (buffer[bytes_read - 1] == '\n' || buffer[bytes_read - 1] == '\r')) { if (bytes_read < 4) {
buffer[bytes_read - 1] = '\0'; 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; unsigned long int num1, num2;
char *line = strtok(buffer, "&"); if (sscanf(first_num_start, "%lu", &num1) != 1 || sscanf(second_num_start, "%lu", &num2) != 1) {
char *second_part = strtok(NULL, "&"); // Assume the rest of the string is the second number fprintf(stderr, "Failed to parse the numbers correctly.\n");
return 1;
}
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 fib1 = fib(num1);
unsigned long int fib2 = fib(num2); unsigned long int fib2 = fib(num2);
unsigned long int sum = fib1 + fib2; unsigned long int sum = fib1 + fib2;
@ -42,13 +60,6 @@ int main() {
// Write to stdout // Write to stdout
write(1, output, len); 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);
return 1;
}
return 0; return 0;
} }

Loading…
Cancel
Save