diff --git a/runtime/include/admissions_info.h b/runtime/include/admissions_info.h index 591cffc..d61ae8c 100644 --- a/runtime/include/admissions_info.h +++ b/runtime/include/admissions_info.h @@ -1,5 +1,6 @@ #pragma once +#include "debuglog.h" #include "perf_window.h" struct admissions_info { diff --git a/runtime/include/client_socket.h b/runtime/include/client_socket.h index a4c60fc..5ca0868 100644 --- a/runtime/include/client_socket.h +++ b/runtime/include/client_socket.h @@ -15,7 +15,6 @@ static inline void client_socket_close(int client_socket) { - // debuglog("Closing Socket\n"); if (close(client_socket) < 0) debuglog("Error closing client socket - %s", strerror(errno)); } diff --git a/runtime/include/debuglog.h b/runtime/include/debuglog.h index 8ff46b6..0b877d0 100644 --- a/runtime/include/debuglog.h +++ b/runtime/include/debuglog.h @@ -7,18 +7,20 @@ extern int32_t debuglog_file_descriptor; #ifdef LOG_TO_FILE -#ifndef DEBUG -#error LOG_TO_FILE is only valid if in DEBUG mode -#endif /* DEBUG */ +#ifdef NDEBUG +#error LOG_TO_FILE is invalid if NDEBUG is set +#endif /* NDEBUG */ #endif /* LOG_TO_FILE */ /** - * debuglog is a macro that behaves based on the macros DEBUG and LOG_TO_FILE - * If DEBUG is not set, debuglog does nothing - * If DEBUG is set and LOG_TO_FILE is set, debuglog prints to the logfile defined in debuglog_file_descriptor - * If DEBUG is set and LOG_TO_FILE is not set, debuglog prints to STDOUT + * debuglog is a macro that behaves based on the macros NDEBUG and LOG_TO_FILE + * If NDEBUG is set, debuglog does nothing + * If NDEBUG is not set and LOG_TO_FILE is set, debuglog prints to the logfile defined in debuglog_file_descriptor + * If NDEBUG is not set and LOG_TO_FILE is not set, debuglog prints to STDERR */ -#ifdef DEBUG +#ifdef NDEBUG +#define debuglog(fmt, ...) +#else /* NDEBUG */ #ifdef LOG_TO_FILE #define debuglog(fmt, ...) \ dprintf(debuglog_file_descriptor, "C: %02d, T: 0x%lx, F: %s> \n\t" fmt "\n", sched_getcpu(), pthread_self(), \ @@ -28,6 +30,4 @@ extern int32_t debuglog_file_descriptor; fprintf(stderr, "C: %02d, T: 0x%lx, F: %s> \n\t" fmt "\n", sched_getcpu(), pthread_self(), __func__, \ ##__VA_ARGS__); #endif /* LOG_TO_FILE */ -#else /* !DEBUG */ -#define debuglog(fmt, ...) -#endif /* DEBUG */ +#endif /* !NDEBUG */ diff --git a/runtime/include/module_database.h b/runtime/include/module_database.h index af5e1cc..e973399 100644 --- a/runtime/include/module_database.h +++ b/runtime/include/module_database.h @@ -2,7 +2,7 @@ #include -#include "debuglog.h" +#include "panic.h" #include "module.h" struct module *module_database_find_by_name(char *name); @@ -30,7 +30,7 @@ module_database_add(struct module *module) done: return rc; err_no_space: - debuglog("Cannot add module. Database is full.\n"); + panic("Cannot add module. Database is full.\n"); rc = -ENOSPC; goto done; } diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 1fe1790..2ac8826 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -11,7 +11,7 @@ #define LISTENER_THREAD_CORE_ID 0 /* Dedicated Listener Core */ #define LISTENER_THREAD_MAX_EPOLL_EVENTS 128 -#define RUNTIME_LOG_FILE "awesome.log" +#define RUNTIME_LOG_FILE "sledge.log" #define RUNTIME_MAX_SANDBOX_REQUEST_COUNT (1 << 19) /* random! */ #define RUNTIME_READ_WRITE_VECTOR_LENGTH 16 diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index c91ae90..bd4f620 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -5,7 +5,6 @@ #include "arch/context.h" #include "client_socket.h" -#include "debuglog.h" #include "deque.h" #include "http_request.h" #include "http_response.h" diff --git a/runtime/include/sandbox_state.h b/runtime/include/sandbox_state.h index 26ee213..8fd4f1a 100644 --- a/runtime/include/sandbox_state.h +++ b/runtime/include/sandbox_state.h @@ -2,6 +2,7 @@ #include +#include "debuglog.h" #include "likely.h" #include "panic.h" diff --git a/runtime/include/worker_thread.h b/runtime/include/worker_thread.h index 5df3f97..4ff06db 100644 --- a/runtime/include/worker_thread.h +++ b/runtime/include/worker_thread.h @@ -2,6 +2,11 @@ #include "runtime.h" +#ifndef NCORES +#warning "NCORES not defined in Makefile. Defaulting to 2" +#define NCORES 2 +#endif + #if NCORES == 1 #error "RUNTIME MINIMUM REQUIREMENT IS 2 CORES" #endif diff --git a/runtime/src/http_parser_settings.c b/runtime/src/http_parser_settings.c index 16ac6ba..f06c52e 100644 --- a/runtime/src/http_parser_settings.c +++ b/runtime/src/http_parser_settings.c @@ -1,3 +1,4 @@ +#include "debuglog.h" #include "http.h" #include "http_request.h" #include "http_response.h" diff --git a/runtime/src/local_runqueue_list.c b/runtime/src/local_runqueue_list.c index ba5e8a1..92b5cc8 100644 --- a/runtime/src/local_runqueue_list.c +++ b/runtime/src/local_runqueue_list.c @@ -1,5 +1,4 @@ #include "client_socket.h" -#include "debuglog.h" #include "local_runqueue_list.h" #include "local_runqueue.h" #include "global_request_scheduler.h" diff --git a/runtime/src/main.c b/runtime/src/main.c index e08db16..faca901 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -16,10 +16,8 @@ #include "software_interrupt.h" #include "worker_thread.h" -/* Conditionally used by debuglog when DEBUG is set */ -#ifdef DEBUG +/* Conditionally used by debuglog when NDEBUG is not set */ int32_t debuglog_file_descriptor = -1; -#endif float runtime_processor_speed_MHz = 0; uint32_t runtime_total_online_processors = 0; @@ -41,7 +39,7 @@ int runtime_worker_core_count; static void runtime_usage(char *cmd) { - debuglog("%s \n", cmd); + printf("%s \n", cmd); } /** @@ -80,7 +78,8 @@ runtime_allocate_available_cores() { /* Find the number of processors currently online */ runtime_total_online_processors = sysconf(_SC_NPROCESSORS_ONLN); - uint32_t max_possible_workers = runtime_total_online_processors - 1; + printf("Detected %u cores\n", runtime_total_online_processors); + uint32_t max_possible_workers = runtime_total_online_processors - 1; if (runtime_total_online_processors < 2) panic("Runtime requires at least two cores!"); @@ -98,9 +97,8 @@ runtime_allocate_available_cores() runtime_worker_threads_count = max_possible_workers; } - debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", - runtime_total_online_processors, runtime_worker_threads_count, runtime_first_worker_processor, - LISTENER_THREAD_CORE_ID); + printf("Running one listener core at ID %u and %u worker core(s) starting at ID %u\n", LISTENER_THREAD_CORE_ID, + runtime_worker_threads_count, runtime_first_worker_processor); } /** @@ -136,7 +134,6 @@ err: goto done; } -#ifdef DEBUG /** * Controls the behavior of the debuglog macro defined in types.h * If LOG_TO_FILE is defined, close stdin, stdout, stderr, and debuglog writes to a logfile named awesome.log. @@ -157,7 +154,6 @@ runtime_process_debug_log_behavior() debuglog_file_descriptor = STDOUT_FILENO; #endif /* LOG_TO_FILE */ } -#endif /* DEBUG */ /** * Starts all worker threads and sleeps forever on pthread_join, which should never return @@ -165,6 +161,7 @@ runtime_process_debug_log_behavior() void runtime_start_runtime_worker_threads() { + printf("Starting %d worker thread(s)\n", runtime_worker_threads_count); for (int i = 0; i < runtime_worker_threads_count; i++) { int ret = pthread_create(&runtime_worker_threads[i], NULL, worker_thread_main, (void *)&runtime_worker_threads_argument[i]); @@ -208,10 +205,12 @@ runtime_configure() } else { panic("Invalid scheduler policy: %s. Must be {EDF|FIFO}\n", scheduler_policy); } + printf("Scheduler Policy: %s\n", print_runtime_scheduler(runtime_scheduler)); /* Runtime Perf Log */ char *runtime_sandbox_perf_log_path = getenv("SLEDGE_SANDBOX_PERF_LOG"); if (runtime_sandbox_perf_log_path != NULL) { + printf("Logging Sandbox Performance to: %s\n", runtime_sandbox_perf_log_path); runtime_sandbox_perf_log = fopen(runtime_sandbox_perf_log_path, "w"); if (runtime_sandbox_perf_log == NULL) { perror("sandbox perf log"); } fprintf(runtime_sandbox_perf_log, @@ -222,11 +221,9 @@ runtime_configure() int main(int argc, char **argv) { -#ifdef DEBUG runtime_process_debug_log_behavior(); -#endif - debuglog("Initializing the runtime\n"); + printf("Starting the Sledge runtime\n"); if (argc != 2) { runtime_usage(argv[0]); exit(-1); @@ -237,7 +234,7 @@ 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; - debuglog("Detected processor speed of %f MHz\n", runtime_processor_speed_MHz); + printf("Detected processor speed of %f MHz\n", runtime_processor_speed_MHz); runtime_set_resource_limits_to_max(); runtime_allocate_available_cores(); @@ -248,9 +245,6 @@ main(int argc, char **argv) #endif if (module_new_from_json(argv[1])) panic("failed to parse modules file[%s]\n", argv[1]); - debuglog("Scheduler Policy: %s\n", print_runtime_scheduler(runtime_scheduler)); - debuglog("Starting listener thread\n"); listener_thread_initialize(); - debuglog("Starting %d worker thread(s)\n", runtime_worker_threads_count); runtime_start_runtime_worker_threads(); } diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index df218f8..28a63f9 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -190,6 +190,7 @@ listener_thread_main(void *dummy) void listener_thread_initialize(void) { + printf("Starting listener thread\n"); cpu_set_t cs; CPU_ZERO(&cs); diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index caea395..2887b5f 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -42,7 +42,7 @@ __thread uint64_t worker_thread_start_timestamp; static inline void worker_thread_dump_lock_overhead() { -#ifdef DEBUG +#ifndef NDEBUG #ifdef LOG_LOCK_OVERHEAD uint64_t worker_duration = __getcycles() - worker_thread_start_timestamp; debuglog("Locks consumed %lu / %lu cycles, or %f%%\n", worker_thread_lock_duration, worker_duration,