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

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

208
.vscode/launch.json vendored

@ -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
}
]
}
]
}

@ -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;
}

Binary file not shown.

@ -2,8 +2,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
// 假设的 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;
}

Loading…
Cancel
Save