From 788ba6909bad8efa8647a01b20b658703703dc91 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sun, 5 Jul 2020 18:47:41 -0400 Subject: [PATCH] docs: Replace printfs with debuglog --- runtime/src/libc/uvio.c | 15 ++++----------- runtime/src/local_runqueue_list.c | 3 +-- runtime/src/local_runqueue_minheap.c | 6 ++---- runtime/src/main.c | 23 +++++++++-------------- runtime/src/sandbox.c | 18 +++++++----------- runtime/src/worker_thread.c | 4 ++-- 6 files changed, 25 insertions(+), 44 deletions(-) diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index 0691f41..83fc039 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -2,6 +2,7 @@ #include "current_sandbox.h" #include "http_request.h" +#include "panic.h" #include "runtime.h" #include "sandbox.h" #include "types.h" @@ -452,15 +453,8 @@ wasm_mmap(i32 addr, i32 len, i32 prot, i32 flags, i32 file_descriptor, i32 offse { int d = current_sandbox_get_file_descriptor(file_descriptor); if (file_descriptor >= 0) assert(d >= 0); - if (addr != 0) { - printf("parameter void *addr is not supported!\n"); - assert(0); - } - - if (d != -1) { - printf("file mapping is not supported!\n"); - assert(0); - } + if (addr != 0) panic("parameter void *addr is not supported!\n"); + if (d != -1) panic("file mapping is not supported!\n"); assert(len % WASM_PAGE_SIZE == 0); @@ -1151,8 +1145,7 @@ inner_syscall_handler(i32 n, i32 a, i32 b, i32 c, i32 d, i32 e, i32 f) case SYS_RECVFROM: return wasm_recvfrom(a, b, c, d, e, f); } - printf("syscall %d (%d, %d, %d, %d, %d, %d)\n", n, a, b, c, d, e, f); - assert(0); + panic("syscall %d (%d, %d, %d, %d, %d, %d)\n", n, a, b, c, d, e, f); return 0; } diff --git a/runtime/src/local_runqueue_list.c b/runtime/src/local_runqueue_list.c index bea8839..9ecb72e 100644 --- a/runtime/src/local_runqueue_list.c +++ b/runtime/src/local_runqueue_list.c @@ -79,8 +79,7 @@ void local_runqueue_list_append(struct sandbox *sandbox_to_append) { assert(ps_list_singleton_d(sandbox_to_append)); - // fprintf(stderr, "(%d,%lu) %s: run %p, %s\n", sched_getcpu(), pthread_self(), __func__, s, - // s->module->name); + debuglog("(%d,%lu) %s: run %p, %s\n", sched_getcpu(), pthread_self(), __func__, s, s->module->name); ps_list_head_append_d(&local_runqueue_list, sandbox_to_append); } diff --git a/runtime/src/local_runqueue_minheap.c b/runtime/src/local_runqueue_minheap.c index 98ebdcf..23baf23 100644 --- a/runtime/src/local_runqueue_minheap.c +++ b/runtime/src/local_runqueue_minheap.c @@ -137,9 +137,8 @@ local_runqueue_minheap_preempt(ucontext_t *user_context) // If we were unable to get a sandbox_request, exit if (return_code == -1 || return_code == -2) goto done; - printf("Thread %lu Preempted %lu for %lu\n", pthread_self(), local_deadline, - sandbox_request->absolute_deadline); - + debuglog("Thread %lu Preempted %lu for %lu\n", pthread_self(), local_deadline, + sandbox_request->absolute_deadline); /* Allocate the request */ struct sandbox *next_sandbox = sandbox_allocate(sandbox_request); assert(next_sandbox); @@ -147,7 +146,6 @@ local_runqueue_minheap_preempt(ucontext_t *user_context) next_sandbox->state = RUNNABLE; /* Add it to the runqueue */ - printf("adding new sandbox to runqueue\n"); local_runqueue_add(next_sandbox); debuglog("[%p: %s]\n", sandbox, sandbox->module->name); diff --git a/runtime/src/main.c b/runtime/src/main.c index fd9c033..d4054a8 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -9,6 +9,7 @@ #include #include "module.h" +#include "panic.h" #include "runtime.h" #include "sandbox.h" #include "software_interrupt.h" @@ -34,7 +35,6 @@ pthread_t runtime_worker_threads[WORKER_THREAD_CORE_COUNT]; static void runtime_usage(char *cmd) { - printf("%s \n", cmd); debuglog("%s \n", cmd); } @@ -89,9 +89,9 @@ runtime_allocate_available_cores() runtime_first_worker_processor = 0; runtime_total_worker_processors = 1; } - printf("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", - runtime_total_online_processors, runtime_total_worker_processors, runtime_first_worker_processor, - LISTENER_THREAD_CORE_ID); + debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", + runtime_total_online_processors, runtime_total_worker_processors, runtime_first_worker_processor, + LISTENER_THREAD_CORE_ID); } /** @@ -173,7 +173,6 @@ runtime_start_runtime_worker_threads() assert(ret == 0); } debuglog("Sandboxing environment ready!\n"); - printf("aWsm runtime ready!\n"); for (int i = 0; i < runtime_total_worker_processors; i++) { int ret = pthread_join(runtime_worker_threads[i], NULL); @@ -184,7 +183,6 @@ runtime_start_runtime_worker_threads() } } - printf("\nWorker Threads unexpectedly returned!!\n"); exit(-1); } @@ -195,7 +193,7 @@ main(int argc, char **argv) runtime_process_debug_log_behavior(); #endif - printf("Initializing the runtime\n"); + debuglog("Initializing the runtime\n"); if (argc != 2) { runtime_usage(argv[0]); exit(-1); @@ -206,20 +204,17 @@ main(int argc, char **argv) runtime_processor_speed_MHz = runtime_get_processor_speed_MHz(); SOFTWARE_INTERRUPT_INTERVAL_DURATION_IN_CYCLES = (uint64_t)SOFTWARE_INTERRUPT_INTERVAL_DURATION_IN_USEC * runtime_processor_speed_MHz; - printf("Detected processor speed of %f MHz\n", runtime_processor_speed_MHz); + debuglog("Detected processor speed of %f MHz\n", runtime_processor_speed_MHz); runtime_set_resource_limits_to_max(); runtime_allocate_available_cores(); runtime_initialize(); debuglog("Parsing modules file [%s]\n", argv[1]); - if (module_new_from_json(argv[1])) { - printf("failed to parse modules file[%s]\n", argv[1]); - exit(-1); - } + if (module_new_from_json(argv[1])) panic("failed to parse modules file[%s]\n", argv[1]); - printf("Starting listener thread\n"); + debuglog("Starting listener thread\n"); listener_thread_initialize(); - printf("Starting worker threads\n"); + debuglog("Starting worker threads\n"); runtime_start_runtime_worker_threads(); } diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 07216d4..4328242 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -7,6 +7,7 @@ #include "current_sandbox.h" #include "http_parser_settings.h" #include "libuv_callbacks.h" +#include "panic.h" #include "runtime.h" #include "sandbox.h" #include "types.h" @@ -148,8 +149,8 @@ done: sandbox->total_time = end_time - sandbox->start_time; uint64_t total_time_us = sandbox->total_time / runtime_processor_speed_MHz; - printf("%s():%d, %u, %lu\n", sandbox->module->name, sandbox->module->port, - sandbox->module->relative_deadline_us, total_time_us); + debuglog("%s():%d, %u, %lu\n", sandbox->module->name, sandbox->module->port, + sandbox->module->relative_deadline_us, total_time_us); #ifndef USE_HTTP_UVIO int r = send(sandbox->client_socket_descriptor, sandbox->request_response_data, sndsz, 0); @@ -239,7 +240,7 @@ void current_sandbox_main(void) { struct sandbox *sandbox = current_sandbox_get(); - // assert(sandbox != NULL); + assert(sandbox != NULL); assert(sandbox->state == RUNNABLE); assert(!software_interrupt_is_enabled()); @@ -253,7 +254,7 @@ current_sandbox_main(void) /* Parse the request. 1 = Success */ int rc = sandbox_receive_and_parse_client_request(sandbox); - if (rc != 1) goto err; + if (rc != 1) goto done; /* Initialize the module */ struct module *current_module = sandbox_get_module(sandbox); @@ -275,8 +276,6 @@ done: /* Cleanup connection and exit sandbox */ sandbox_close_http(sandbox); worker_thread_on_sandbox_exit(sandbox); -err: - goto done; } /** @@ -335,7 +334,6 @@ set_rw_failed: int rc = munmap(addr, sandbox_size + linear_memory_size + PAGE_SIZE); if (rc == -1) perror("Failed to munmap after fail to set r/w"); alloc_failed: -alloc_too_big: err: perror(error_message); goto done; @@ -460,9 +458,7 @@ done: return; err_free_sandbox_failed: err_free_stack_failed: - /* Inability to free memory is a fatal error */ - perror(error_message); - exit(EXIT_FAILURE); err: - goto done; + /* Errors freeing memory is a fatal error */ + panic(error_message); } diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index e9f84ec..97f4e56 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -67,7 +67,7 @@ worker_thread_switch_to_sandbox(struct sandbox *next_sandbox) if (previous_sandbox != NULL && previous_sandbox->state == RETURNED) { local_completion_queue_add(previous_sandbox); } else if (previous_sandbox != NULL) { - printf("Switched away from sandbox is state %d\n", previous_sandbox->state); + debuglog("Switched away from sandbox is state %d\n", previous_sandbox->state); } software_interrupt_enable(); @@ -84,7 +84,7 @@ worker_thread_wakeup_sandbox(sandbox_t *sandbox) // debuglog("[%p: %s]\n", sandbox, sandbox->module->name); if (sandbox->state == BLOCKED) { sandbox->state = RUNNABLE; - printf("Marking blocked sandbox as runnable\n"); + debuglog("Marking blocked sandbox as runnable\n"); local_runqueue_add(sandbox); } software_interrupt_enable();