tree
hwwang 5 months ago
parent 5161282992
commit ef88c3f960

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

@ -11,6 +11,7 @@
#include "hash.h"
extern uint64_t system_start_timestamp;
#define OUPUT_MAX 20;
__thread struct sandbox *worker_thread_current_sandbox = NULL;
@ -150,11 +151,11 @@ current_sandbox_start(void)
//uint64_t current_rs = enqueue_timestamp - system_start_timestamp;
//mem_log("time %lu request id:%d executing, name:%s remaining slack %lu\n", current_rs,
// sandbox->id, sandbox->module->name, sandbox->remaining_slack);
struct sandbox_request *sandbox_request = NULL;
static bool left_output_flag = false;
if (next_module->is_sandboxcreate == false)
{
sandbox_request =
struct sandbox_request *sandbox_request = NULL;
static bool left_output_flag = false;
if (next_module->is_sandboxcreate == false)
{
sandbox_request =
sandbox_request_allocate(next_module, false, sandbox->request_length,
next_module->name, sandbox->client_socket_descriptor,
(const struct sockaddr *)&sandbox->client_address,
@ -177,8 +178,18 @@ current_sandbox_start(void)
{
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);
#ifdef OPT_AVOID_GLOBAL_QUEUE
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
/* 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) {
/* Put the next sandbox to the local run queue to reduce the overhead of the global queue */
@ -197,13 +208,19 @@ current_sandbox_start(void)
#else
/* Add to the Global Sandbox Request Scheduler */
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
/* Remove the client fd from epoll if it is the first sandbox in the chain */
if (sandbox->request_from_outside) {
sandbox_remove_from_epoll(sandbox);
}
sandbox_set_as_returned(sandbox, SANDBOX_RUNNING);
}
} else {
/* Retrieve the result, construct the HTTP response, and send to client */
if (sandbox_send_response(sandbox) < 0) {

@ -1,7 +1,7 @@
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 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)

Binary file not shown.

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

@ -1,8 +1,24 @@
{
"active": true,
"name": "cifar10_1",
"path": "cifar10_wasm.so",
"port": 10000,
"relative-deadline-us": 78574,
"argsize": 1,
"http-req-headers": [],
"http-req-content-type": "image/bmp",
"http-req-size": 4096000,
"http-resp-headers": [],
"http-resp-size": 1024,
"http-resp-content-type": "text/plain",
"tail-module": true
},
{
"active": true,
"name": "resize1",
"path": "resize_wasm.so",
"port": 10000,
"port": 10001,
"relative-deadline-us": 78574,
"argsize": 1,
"http-req-headers": [],
@ -14,32 +30,17 @@
},
{
"active": true,
"name": "png2bmp1",
"path": "C-Image-Manip_wasm.so",
"port": 10001,
"relative-deadline-us": 78574,
"argsize": 1,
"http-req-headers": [],
"http-req-content-type": "image/png",
"http-req-size": 4096000,
"http-resp-headers": [],
"http-resp-size": 4096000,
"http-resp-content-type": "image/bmp"
"active": true,
"name": "resize2",
"path": "resize_wasm.so",
"port": 10002,
"relative-deadline-us": 78574,
"argsize": 1,
"http-req-headers": [],
"http-req-content-type": "image/jpeg",
"http-req-size": 1024000,
"http-resp-headers": [],
"http-resp-size": 1024000,
"http-resp-content-type": "image/png"
},
{
"active": true,
"name": "cifar10_1",
"path": "cifar10_wasm.so",
"port": 10002,
"relative-deadline-us": 78574,
"argsize": 1,
"http-req-headers": [],
"http-req-content-type": "image/bmp",
"http-req-size": 4096000,
"http-resp-headers": [],
"http-resp-size": 1024,
"http-resp-content-type": "text/plain",
"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