tree
hwwang 5 months ago
parent 5161282992
commit ef88c3f960

@ -56,18 +56,23 @@
} }
] ]
}, },
{ {
"name": "hash", "name": "tree",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/runtime/Utest_py/hash", "program": "${workspaceFolder}/runtime/bin/sledgert",
"args": ["key1"], "args": [
"${workspaceFolder}/runtime/tests/tree.json"
],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"environment": [], "environment": [],
"externalConsole": false, "externalConsole": false,
"MIMode": "gdb", "MIMode": "gdb",
"sourceFileMap": {
"/sledge/runtime": "${workspaceFolder}/runtime"
},
"envFile": "${workspaceFolder}/.env",
"setupCommands": [ "setupCommands": [
{ {
"description": "Enable pretty-printing for gdb", "description": "Enable pretty-printing for gdb",

@ -11,6 +11,7 @@
#include "hash.h" #include "hash.h"
extern uint64_t system_start_timestamp; extern uint64_t system_start_timestamp;
#define OUPUT_MAX 20;
__thread struct sandbox *worker_thread_current_sandbox = NULL; __thread struct sandbox *worker_thread_current_sandbox = NULL;
@ -177,7 +178,17 @@ current_sandbox_start(void)
{ {
sandbox_request->previous_function_output = pre_func_output; sandbox_request->previous_function_output = pre_func_output;
} }
ssize_t combined_length = sandbox_request->output_length + output_length + 3;
remove_item(sandboxes_request_table, next_module->name); remove_item(sandboxes_request_table, next_module->name);
char *combined_output = (char *)malloc(combined_length);
if (!combined_output) {
fprintf(stderr, "Failed to allocate memory for the combined output: %s\n", strerror(errno));
goto err;
}
strcpy(combined_output, sandbox_request->previous_function_output);
strcat(combined_output, "+");
strcat(combined_output, sandbox_request->previous_function_output2);
sandbox->output_length = combined_length;
#ifdef OPT_AVOID_GLOBAL_QUEUE #ifdef OPT_AVOID_GLOBAL_QUEUE
/* TODO: The running time of the current sandbox contains the next sandbox's initialization time, does it matter? */ /* TODO: The running time of the current sandbox contains the next sandbox's initialization time, does it matter? */
if (sandbox->absolute_deadline == sandbox_request->absolute_deadline) { if (sandbox->absolute_deadline == sandbox_request->absolute_deadline) {
@ -197,13 +208,19 @@ current_sandbox_start(void)
#else #else
/* Add to the Global Sandbox Request Scheduler */ /* Add to the Global Sandbox Request Scheduler */
global_request_scheduler_add(sandbox_request); global_request_scheduler_add(sandbox_request);
if (sandbox_send_response(sandbox) < 0) {
error_message = "Unable to build and send client response\n";
goto err;
};
next_module->is_sandboxcreate = false;
}
#endif #endif
/* Remove the client fd from epoll if it is the first sandbox in the chain */ /* Remove the client fd from epoll if it is the first sandbox in the chain */
if (sandbox->request_from_outside) { if (sandbox->request_from_outside) {
sandbox_remove_from_epoll(sandbox); sandbox_remove_from_epoll(sandbox);
} }
sandbox_set_as_returned(sandbox, SANDBOX_RUNNING); sandbox_set_as_returned(sandbox, SANDBOX_RUNNING);
}
} else { } else {
/* Retrieve the result, construct the HTTP response, and send to client */ /* Retrieve the result, construct the HTTP response, and send to client */
if (sandbox_send_response(sandbox) < 0) { if (sandbox_send_response(sandbox) < 0) {

@ -1,7 +1,7 @@
include Makefile.inc include Makefile.inc
#TESTS=fibonacci fibonacci2 fibonacci3 big_fibonacci C-Image-Manip empty work work1k work10k work100k work1m forever filesys sockserver sockclient empty #TESTS=fibonacci fibonacci2 fibonacci3 big_fibonacci C-Image-Manip empty work work1k work10k work100k work1m forever filesys sockserver sockclient empty
TESTS=fibonacci big_fibonacci C-Image-Manip empty work work1k work10k work100k work1m forever filesys sockserver sockclient empty TESTS=fibonacci big_fibonacci C-Image-Manip empty work work1k work10k work100k work1m forever filesys sockserver sockclient empty tree
TESTSRT=$(TESTS:%=%_rt) TESTSRT=$(TESTS:%=%_rt)

Binary file not shown.

@ -94,85 +94,85 @@ fib(unsigned long int n)
//return 0; //return 0;
//} //}
main(int argc, char **argv) int main(int argc, char **argv)
{ {
unsigned long n = 0, r; unsigned long n = 0, r;
scanf("%lu", &n); scanf("%lu", &n);
FILE *f = stdout; //FILE *f = stdout;
// unsigned long long st = get_time(), en; // unsigned long long st = get_time(), en;
//r = fib(29); r = fib(n);
// en = get_time(); // en = get_time();
switch(n) { // switch(n) {
case 0: { // case 0: {
char array[4 * 1024] = {0}; // char array[4 * 1024] = {0};
memset(array, 'a', 4 * 1024); // memset(array, 'a', 4 * 1024);
array[4 * 1024 - 1] = 0; // array[4 * 1024 - 1] = 0;
//printf("%s\n", array); // //printf("%s\n", array);
fwrite(array, 1, 4 * 1024 - 1, f); // fwrite(array, 1, 4 * 1024 - 1, f);
break; // break;
} // }
case 1: { // case 1: {
char array[100 * 1024] = {'b'}; // char array[100 * 1024] = {'b'};
memset(array, 'b', 100 * 1024); // memset(array, 'b', 100 * 1024);
array[100 * 1024 - 1] = 0; // array[100 * 1024 - 1] = 0;
//printf("%s\n", array); // //printf("%s\n", array);
fwrite(array, 1, 100 * 1024 - 1, f); // fwrite(array, 1, 100 * 1024 - 1, f);
break; // break;
} // }
case 2: { // case 2: {
char array[200 * 1024] = {'c'}; // char array[200 * 1024] = {'c'};
memset(array, 'c', 200 * 1024); // memset(array, 'c', 200 * 1024);
array[200 * 1024 - 1] = 0; // array[200 * 1024 - 1] = 0;
fwrite(array, 1, 200 * 1024 - 1, f); // fwrite(array, 1, 200 * 1024 - 1, f);
//printf("%s\n", array); // //printf("%s\n", array);
break; // break;
} // }
case 4: { // case 4: {
char array[400 * 1024] = {'d'}; // char array[400 * 1024] = {'d'};
memset(array, 'd', 400 * 1024); // memset(array, 'd', 400 * 1024);
array[400 * 1024 - 1] = 0; // array[400 * 1024 - 1] = 0;
fwrite(array, 1, 400 * 1024 - 1, f); // fwrite(array, 1, 400 * 1024 - 1, f);
//printf("%s\n", array); // //printf("%s\n", array);
break; // break;
} // }
case 6: { // case 6: {
char array[600 * 1024] = {'e'}; // char array[600 * 1024] = {'e'};
memset(array, 'e', 600 * 1024); // memset(array, 'e', 600 * 1024);
array[600 * 1024 - 1] = 0; // array[600 * 1024 - 1] = 0;
fwrite(array, 1, 600 * 1024 - 1, f); // fwrite(array, 1, 600 * 1024 - 1, f);
//printf("%s\n", array); // //printf("%s\n", array);
break; // break;
} // }
case 8: { // case 8: {
char array[800 * 1024] = {'f'}; // char array[800 * 1024] = {'f'};
memset(array, 'f', 800 * 1024); // memset(array, 'f', 800 * 1024);
array[800 * 1024 - 1] = 0; // array[800 * 1024 - 1] = 0;
fwrite(array, 1, 800 * 1024 - 1, f); // fwrite(array, 1, 800 * 1024 - 1, f);
//printf("%s\n", array); // //printf("%s\n", array);
break; // break;
} // }
case 10:{ // case 10:{
char array[1000 * 1024] = {'g'}; // char array[1000 * 1024] = {'g'};
memset(array, 'g', 1000 * 1024); // memset(array, 'g', 1000 * 1024);
array[1000 * 1024 - 1] = 0; // array[1000 * 1024 - 1] = 0;
fwrite(array, 1, 1000 * 1024 - 1, f); // fwrite(array, 1, 1000 * 1024 - 1, f);
//printf("%s\n", array); // //printf("%s\n", array);
break; // break;
} // }
default: printf("error input of n\n"); // default: printf("error input of n\n");
} // }
fclose(f); //fclose(f);
//printf("%lu\n", n); //printf("%lu\n", n);
//printf("%lu\n", r); printf("%lu\n", r);
return 0; return 0;
} }

@ -1,45 +1,46 @@
{ {
"active": true, "active": true,
"name": "resize1", "name": "cifar10_1",
"path": "resize_wasm.so", "path": "cifar10_wasm.so",
"port": 10000, "port": 10000,
"relative-deadline-us": 78574, "relative-deadline-us": 78574,
"argsize": 1, "argsize": 1,
"http-req-headers": [], "http-req-headers": [],
"http-req-content-type": "image/jpeg", "http-req-content-type": "image/bmp",
"http-req-size": 1024000, "http-req-size": 4096000,
"http-resp-headers": [], "http-resp-headers": [],
"http-resp-size": 1024000, "http-resp-size": 1024,
"http-resp-content-type": "image/png" "http-resp-content-type": "text/plain",
"tail-module": true
}, },
{ {
"active": true, "active": true,
"name": "png2bmp1", "name": "resize1",
"path": "C-Image-Manip_wasm.so", "path": "resize_wasm.so",
"port": 10001, "port": 10001,
"relative-deadline-us": 78574, "relative-deadline-us": 78574,
"argsize": 1, "argsize": 1,
"http-req-headers": [], "http-req-headers": [],
"http-req-content-type": "image/png", "http-req-content-type": "image/jpeg",
"http-req-size": 4096000, "http-req-size": 1024000,
"http-resp-headers": [], "http-resp-headers": [],
"http-resp-size": 4096000, "http-resp-size": 1024000,
"http-resp-content-type": "image/bmp" "http-resp-content-type": "image/png"
}, },
{ {
"active": true, "active": true,
"name": "cifar10_1", "name": "resize2",
"path": "cifar10_wasm.so", "path": "resize_wasm.so",
"port": 10002, "port": 10002,
"relative-deadline-us": 78574, "relative-deadline-us": 78574,
"argsize": 1, "argsize": 1,
"http-req-headers": [], "http-req-headers": [],
"http-req-content-type": "image/bmp", "http-req-content-type": "image/jpeg",
"http-req-size": 4096000, "http-req-size": 1024000,
"http-resp-headers": [], "http-resp-headers": [],
"http-resp-size": 1024, "http-resp-size": 1024000,
"http-resp-content-type": "text/plain", "http-resp-content-type": "image/png"
"tail-module": true },
}

@ -0,0 +1,16 @@
{
"active": true,
"name": "tree",
"path": "tree_wasm.so",
"port": 10000,
"expected-execution-us": 5000,
"relative-deadline-us": 360000,
"argsize": 1,
"http-req-headers": [],
"http-req-content-type": "text/plain",
"http-req-size": 1024,
"http-resp-headers": [],
"http-resp-size": 1024,
"http-resp-content-type": "text/plain"
}

@ -0,0 +1,63 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX_BUF 300
#define MAX_TOKENS 100
// 修改split_string函数使其返回字符串数组
char **split_string(char *str, int *token_count) {
char **p = malloc(MAX_TOKENS * sizeof(char*));
int i = 0;
char *saveptr;
char *token = strtok_r(str, "++", &saveptr);
while (token != NULL) {
p[i++] = token;
token = strtok_r(NULL, "++", &saveptr);
}
*token_count = i; // 设置token计数
return p;
}
int main(int argc, char **argv) {
char *d = malloc(MAX_BUF + 1);
int r = read(0, d, MAX_BUF);
d[r] = '\0';
// 移除输入中的换行符
if (d[r - 1] == '\n') {
d[r - 1] = '\0';
}
int token_count;
char **tokens = split_string(d, &token_count);
// 确保至少有两个token
if (token_count >= 2) {
char *endptr1, *endptr2;
long num1 = strtol(tokens[0], &endptr1, 10);
long num2 = strtol(tokens[1], &endptr2, 10);
// 检查转换是否成功
if (*endptr1 == '\0' && *endptr2 == '\0') {
long sum = num1 + num2;
printf("the sum is %ld\n", sum);
} else {
if (*endptr1 != '\0') {
return -1;
}
if (*endptr2 != '\0') {
return -1;
}
}
} else {
return -1;
}
free(tokens); // 释放分配的内存
free(d);
return 0;
}

Binary file not shown.
Loading…
Cancel
Save