From affe5fbc351db27190cb578208d68f01e75b6884 Mon Sep 17 00:00:00 2001 From: phani Date: Wed, 1 Jan 2020 14:33:12 -0500 Subject: [PATCH] read() chunks fix, other standalone compilation fixes --- runtime/include/http.h | 2 +- runtime/include/types.h | 4 +-- runtime/src/http.c | 4 +++ runtime/src/libc/uvio.c | 7 +++-- runtime/src/sandbox.c | 4 +++ runtime/tests/fibonacci/get_time.h | 44 ++++++++++++++++++++++++++++++ runtime/tests/fibonacci/main.c | 23 ++++++++++++++++ runtime/tests/test_gocr.json | 13 +++++++++ runtime/tests/test_sodlpd.json | 13 +++++++++ runtime/tests/test_sodresize.json | 13 +++++++++ 10 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 runtime/tests/fibonacci/get_time.h create mode 100644 runtime/tests/fibonacci/main.c create mode 100644 runtime/tests/test_gocr.json create mode 100644 runtime/tests/test_sodlpd.json create mode 100644 runtime/tests/test_sodresize.json diff --git a/runtime/include/http.h b/runtime/include/http.h index 3c66f58..04b9e4d 100644 --- a/runtime/include/http.h +++ b/runtime/include/http.h @@ -20,7 +20,7 @@ struct http_request { struct http_header headers[HTTP_HEADERS_MAX]; int nheaders; char *body; - int bodylen; + int bodylen, bodyrlen; // additional for http-parser int last_was_value; int header_end; diff --git a/runtime/include/types.h b/runtime/include/types.h index 8fdbd61..b71f4d5 100644 --- a/runtime/include/types.h +++ b/runtime/include/types.h @@ -56,7 +56,7 @@ typedef uint64_t u64; #define WASM_START_PAGES (1<<8) //16MB #define WASM_MAX_PAGES (1<<15) //4GB -#define WASM_STACK_SIZE (1<<14) // 16KB. +#define WASM_STACK_SIZE (1<<19) // 512KB. #define SBOX_MAX_MEM (1L<<32) // 4GB // These are per module symbols and I'd need to dlsym for each module. instead just use global constants, see above macros. @@ -153,7 +153,7 @@ typedef enum { #define MOD_REQ_RESP_DEFAULT (PAGE_SIZE) #define QUIESCENSE_TIME (1<<20) //cycles! -#define HTTP_HEADERS_MAX 6 +#define HTTP_HEADERS_MAX 16 #define HTTP_HEADER_MAXSZ 32 #define HTTP_HEADERVAL_MAXSZ 64 diff --git a/runtime/src/http.c b/runtime/src/http.c index 0169959..17a3fb4 100644 --- a/runtime/src/http.c +++ b/runtime/src/http.c @@ -57,6 +57,7 @@ http_on_url(http_parser* parser, const char *at, size_t length) static inline int http_on_header_field(http_parser* parser, const char *at, size_t length) { +#ifndef STANDALONE struct sandbox *s = parser->data; struct http_request *r = &s->rqi; @@ -66,6 +67,7 @@ http_on_header_field(http_parser* parser, const char *at, size_t length) r->last_was_value = 0; r->headers[r->nheaders - 1].key = (char *)at; //it is from the sandbox's req_resp_data, should persist. +#endif return 0; } @@ -73,6 +75,7 @@ http_on_header_field(http_parser* parser, const char *at, size_t length) static inline int http_on_header_value(http_parser* parser, const char *at, size_t length) { +#ifndef STANDALONE struct sandbox *s = parser->data; struct http_request *r = &s->rqi; @@ -81,6 +84,7 @@ http_on_header_value(http_parser* parser, const char *at, size_t length) assert(length < HTTP_HEADERVAL_MAXSZ); r->headers[r->nheaders - 1].val = (char *)at; //it is from the sandbox's req_resp_data, should persist. +#endif return 0; } diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index 3bef9c1..e615722 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -67,13 +67,13 @@ wasm_read(i32 filedes, i32 buf_offset, i32 nbyte) char* buf = get_memory_ptr_void(buf_offset, nbyte); return read(filedes, buf, nbyte); #else - // TODO: multiple reads! char* buf = get_memory_ptr_void(buf_offset, nbyte); struct sandbox *s = sandbox_current(); struct http_request *r = &s->rqi; if (r->bodylen <= 0) return 0; int l = nbyte > r->bodylen ? r->bodylen : nbyte; - memcpy(buf, r->body, l); + memcpy(buf, r->body + r->bodyrlen, l); + r->bodyrlen += l; r->bodylen -= l; return l; #endif @@ -488,10 +488,11 @@ wasm_readv(i32 fd, i32 iov_offset, i32 iovcnt) if (l <= 0) break; char *b = get_memory_ptr_void(iov[i].base_offset, iov[i].len); //http request body! - memcpy(b, r->body + len, l); + memcpy(b, r->body + r->bodyrlen + len, l); len += l; r->bodylen -= l; } + r->bodyrlen += len; return len; #endif diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 0d1ba31..89c9751 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -71,6 +71,7 @@ sandbox_args_setup(i32 argc) static inline void sb_read_callback(uv_stream_t *s, ssize_t nr, const uv_buf_t *b) { +#ifndef STANDALONE struct sandbox *c = s->data; if (nr > 0) { @@ -82,6 +83,7 @@ sb_read_callback(uv_stream_t *s, ssize_t nr, const uv_buf_t *b) uv_read_stop(s); sandbox_wakeup(c); +#endif } static inline void @@ -101,6 +103,7 @@ sb_shutdown_callback(uv_shutdown_t *req, int status) static inline void sb_write_callback(uv_write_t *w, int status) { +#ifndef STANDALONE struct sandbox *c = w->data; if (status < 0) { c->cuvsr.data = c; @@ -108,6 +111,7 @@ sb_write_callback(uv_write_t *w, int status) return; } sandbox_wakeup(c); +#endif } static inline void diff --git a/runtime/tests/fibonacci/get_time.h b/runtime/tests/fibonacci/get_time.h new file mode 100644 index 0000000..8312a56 --- /dev/null +++ b/runtime/tests/fibonacci/get_time.h @@ -0,0 +1,44 @@ +#ifndef GET_TIME_H +#define GET_TIME_H + +#include +#include + +#ifndef WASM +#ifndef CPU_FREQ +#define CPU_FREQ 1000 +#endif +#endif + +static unsigned long long +get_time() +{ +#if 0 + unsigned long long int ret = 0; + unsigned int cycles_lo; + unsigned int cycles_hi; + __asm__ volatile ("RDTSC" : "=a" (cycles_lo), "=d" (cycles_hi)); + ret = (unsigned long long int)cycles_hi << 32 | cycles_lo; + + return ret; +#else + struct timeval Tp; + int stat; + stat = gettimeofday (&Tp, NULL); + if (stat != 0) + printf ("Error return from gettimeofday: %d", stat); + return (Tp.tv_sec * 1000000 + Tp.tv_usec); +#endif +} + +static inline void +print_time(unsigned long long s, unsigned long long e) +{ +#if 0 + printf("%llu cycs, %llu us\n", e - s, (e - s) / CPU_FREQ); +#else + fprintf(stderr, "%llu us\n", e - s); +#endif +} + +#endif /* GET_TIME_H */ diff --git a/runtime/tests/fibonacci/main.c b/runtime/tests/fibonacci/main.c new file mode 100644 index 0000000..c622a98 --- /dev/null +++ b/runtime/tests/fibonacci/main.c @@ -0,0 +1,23 @@ +#include +#include "get_time.h" +unsigned long int +fib(unsigned long int n) +{ + if (n <= 1) + return n; + return fib(n-1) + fib(n-2); +} + +int +main(int argc, char **argv) +{ + unsigned long n = 0, r; + scanf("%lu", &n); + unsigned long long st = get_time(), en; + r = fib(n); + en = get_time(); + printf("%lu\n", r); + + print_time(st, en); + return 0; +} diff --git a/runtime/tests/test_gocr.json b/runtime/tests/test_gocr.json new file mode 100644 index 0000000..9587bdb --- /dev/null +++ b/runtime/tests/test_gocr.json @@ -0,0 +1,13 @@ +{ + "active" : "yes", + "name" : "gocr", + "path" : "gocr_wasm.so", + "port" : 10000, + "argsize" : 1, + "http-req-headers" : [ ], + "http-req-content-type" : "image/png", + "http-req-size": 10240, + "http-resp-headers" : [ ], + "http-resp-size" : 128, + "http-resp-content-type" : "text/plain" +} diff --git a/runtime/tests/test_sodlpd.json b/runtime/tests/test_sodlpd.json new file mode 100644 index 0000000..d3eb3d3 --- /dev/null +++ b/runtime/tests/test_sodlpd.json @@ -0,0 +1,13 @@ +{ + "active" : "yes", + "name" : "lpd", + "path" : "lpd_wasm.so", + "port" : 10000, + "argsize" : 1, + "http-req-headers" : [ ], + "http-req-content-type" : "image/jpeg", + "http-req-size": 102400, + "http-resp-headers" : [ ], + "http-resp-size" : 1048576, + "http-resp-content-type" : "image/jpeg" +} diff --git a/runtime/tests/test_sodresize.json b/runtime/tests/test_sodresize.json new file mode 100644 index 0000000..38f7a57 --- /dev/null +++ b/runtime/tests/test_sodresize.json @@ -0,0 +1,13 @@ +{ + "active" : "yes", + "name" : "resize", + "path" : "resize_wasm.so", + "port" : 10000, + "argsize" : 1, + "http-req-headers" : [ ], + "http-req-content-type" : "image/jpeg", + "http-req-size": 102400, + "http-resp-headers" : [ ], + "http-resp-size" : 102400, + "http-resp-content-type" : "image/png" +}