chore: refactor away DEBUG define

main
Sean McBride 4 years ago
parent 4d2e2641f4
commit 5327ac1e8c

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "debuglog.h"
#include "perf_window.h" #include "perf_window.h"
struct admissions_info { struct admissions_info {

@ -15,7 +15,6 @@
static inline void static inline void
client_socket_close(int client_socket) client_socket_close(int client_socket)
{ {
// debuglog("Closing Socket\n");
if (close(client_socket) < 0) debuglog("Error closing client socket - %s", strerror(errno)); if (close(client_socket) < 0) debuglog("Error closing client socket - %s", strerror(errno));
} }

@ -7,18 +7,20 @@
extern int32_t debuglog_file_descriptor; extern int32_t debuglog_file_descriptor;
#ifdef LOG_TO_FILE #ifdef LOG_TO_FILE
#ifndef DEBUG #ifdef NDEBUG
#error LOG_TO_FILE is only valid if in DEBUG mode #error LOG_TO_FILE is invalid if NDEBUG is set
#endif /* DEBUG */ #endif /* NDEBUG */
#endif /* LOG_TO_FILE */ #endif /* LOG_TO_FILE */
/** /**
* debuglog is a macro that behaves based on the macros DEBUG and LOG_TO_FILE * debuglog is a macro that behaves based on the macros NDEBUG and LOG_TO_FILE
* If DEBUG is not set, debuglog does nothing * If NDEBUG is 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 NDEBUG is not 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 * 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 #ifdef LOG_TO_FILE
#define debuglog(fmt, ...) \ #define debuglog(fmt, ...) \
dprintf(debuglog_file_descriptor, "C: %02d, T: 0x%lx, F: %s> \n\t" fmt "\n", sched_getcpu(), pthread_self(), \ 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__, \ fprintf(stderr, "C: %02d, T: 0x%lx, F: %s> \n\t" fmt "\n", sched_getcpu(), pthread_self(), __func__, \
##__VA_ARGS__); ##__VA_ARGS__);
#endif /* LOG_TO_FILE */ #endif /* LOG_TO_FILE */
#else /* !DEBUG */ #endif /* !NDEBUG */
#define debuglog(fmt, ...)
#endif /* DEBUG */

@ -2,7 +2,7 @@
#include <errno.h> #include <errno.h>
#include "debuglog.h" #include "panic.h"
#include "module.h" #include "module.h"
struct module *module_database_find_by_name(char *name); struct module *module_database_find_by_name(char *name);
@ -30,7 +30,7 @@ module_database_add(struct module *module)
done: done:
return rc; return rc;
err_no_space: err_no_space:
debuglog("Cannot add module. Database is full.\n"); panic("Cannot add module. Database is full.\n");
rc = -ENOSPC; rc = -ENOSPC;
goto done; goto done;
} }

@ -11,7 +11,7 @@
#define LISTENER_THREAD_CORE_ID 0 /* Dedicated Listener Core */ #define LISTENER_THREAD_CORE_ID 0 /* Dedicated Listener Core */
#define LISTENER_THREAD_MAX_EPOLL_EVENTS 128 #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_MAX_SANDBOX_REQUEST_COUNT (1 << 19) /* random! */
#define RUNTIME_READ_WRITE_VECTOR_LENGTH 16 #define RUNTIME_READ_WRITE_VECTOR_LENGTH 16

@ -5,7 +5,6 @@
#include "arch/context.h" #include "arch/context.h"
#include "client_socket.h" #include "client_socket.h"
#include "debuglog.h"
#include "deque.h" #include "deque.h"
#include "http_request.h" #include "http_request.h"
#include "http_response.h" #include "http_response.h"

@ -2,6 +2,7 @@
#include <stdatomic.h> #include <stdatomic.h>
#include "debuglog.h"
#include "likely.h" #include "likely.h"
#include "panic.h" #include "panic.h"

@ -2,6 +2,11 @@
#include "runtime.h" #include "runtime.h"
#ifndef NCORES
#warning "NCORES not defined in Makefile. Defaulting to 2"
#define NCORES 2
#endif
#if NCORES == 1 #if NCORES == 1
#error "RUNTIME MINIMUM REQUIREMENT IS 2 CORES" #error "RUNTIME MINIMUM REQUIREMENT IS 2 CORES"
#endif #endif

@ -1,3 +1,4 @@
#include "debuglog.h"
#include "http.h" #include "http.h"
#include "http_request.h" #include "http_request.h"
#include "http_response.h" #include "http_response.h"

@ -1,5 +1,4 @@
#include "client_socket.h" #include "client_socket.h"
#include "debuglog.h"
#include "local_runqueue_list.h" #include "local_runqueue_list.h"
#include "local_runqueue.h" #include "local_runqueue.h"
#include "global_request_scheduler.h" #include "global_request_scheduler.h"

@ -16,10 +16,8 @@
#include "software_interrupt.h" #include "software_interrupt.h"
#include "worker_thread.h" #include "worker_thread.h"
/* Conditionally used by debuglog when DEBUG is set */ /* Conditionally used by debuglog when NDEBUG is not set */
#ifdef DEBUG
int32_t debuglog_file_descriptor = -1; int32_t debuglog_file_descriptor = -1;
#endif
float runtime_processor_speed_MHz = 0; float runtime_processor_speed_MHz = 0;
uint32_t runtime_total_online_processors = 0; uint32_t runtime_total_online_processors = 0;
@ -41,7 +39,7 @@ int runtime_worker_core_count;
static void static void
runtime_usage(char *cmd) runtime_usage(char *cmd)
{ {
debuglog("%s <modules_file>\n", cmd); printf("%s <modules_file>\n", cmd);
} }
/** /**
@ -80,6 +78,7 @@ runtime_allocate_available_cores()
{ {
/* Find the number of processors currently online */ /* Find the number of processors currently online */
runtime_total_online_processors = sysconf(_SC_NPROCESSORS_ONLN); runtime_total_online_processors = sysconf(_SC_NPROCESSORS_ONLN);
printf("Detected %u cores\n", runtime_total_online_processors);
uint32_t max_possible_workers = runtime_total_online_processors - 1; uint32_t max_possible_workers = runtime_total_online_processors - 1;
if (runtime_total_online_processors < 2) panic("Runtime requires at least two cores!"); 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; runtime_worker_threads_count = max_possible_workers;
} }
debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", printf("Running one listener core at ID %u and %u worker core(s) starting at ID %u\n", LISTENER_THREAD_CORE_ID,
runtime_total_online_processors, runtime_worker_threads_count, runtime_first_worker_processor, runtime_worker_threads_count, runtime_first_worker_processor);
LISTENER_THREAD_CORE_ID);
} }
/** /**
@ -136,7 +134,6 @@ err:
goto done; goto done;
} }
#ifdef DEBUG
/** /**
* Controls the behavior of the debuglog macro defined in types.h * 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. * 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; debuglog_file_descriptor = STDOUT_FILENO;
#endif /* LOG_TO_FILE */ #endif /* LOG_TO_FILE */
} }
#endif /* DEBUG */
/** /**
* Starts all worker threads and sleeps forever on pthread_join, which should never return * Starts all worker threads and sleeps forever on pthread_join, which should never return
@ -165,6 +161,7 @@ runtime_process_debug_log_behavior()
void void
runtime_start_runtime_worker_threads() 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++) { for (int i = 0; i < runtime_worker_threads_count; i++) {
int ret = pthread_create(&runtime_worker_threads[i], NULL, worker_thread_main, int ret = pthread_create(&runtime_worker_threads[i], NULL, worker_thread_main,
(void *)&runtime_worker_threads_argument[i]); (void *)&runtime_worker_threads_argument[i]);
@ -208,10 +205,12 @@ runtime_configure()
} else { } else {
panic("Invalid scheduler policy: %s. Must be {EDF|FIFO}\n", scheduler_policy); 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 */ /* Runtime Perf Log */
char *runtime_sandbox_perf_log_path = getenv("SLEDGE_SANDBOX_PERF_LOG"); char *runtime_sandbox_perf_log_path = getenv("SLEDGE_SANDBOX_PERF_LOG");
if (runtime_sandbox_perf_log_path != NULL) { 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"); runtime_sandbox_perf_log = fopen(runtime_sandbox_perf_log_path, "w");
if (runtime_sandbox_perf_log == NULL) { perror("sandbox perf log"); } if (runtime_sandbox_perf_log == NULL) { perror("sandbox perf log"); }
fprintf(runtime_sandbox_perf_log, fprintf(runtime_sandbox_perf_log,
@ -222,11 +221,9 @@ runtime_configure()
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
#ifdef DEBUG
runtime_process_debug_log_behavior(); runtime_process_debug_log_behavior();
#endif
debuglog("Initializing the runtime\n"); printf("Starting the Sledge runtime\n");
if (argc != 2) { if (argc != 2) {
runtime_usage(argv[0]); runtime_usage(argv[0]);
exit(-1); exit(-1);
@ -237,7 +234,7 @@ main(int argc, char **argv)
runtime_processor_speed_MHz = runtime_get_processor_speed_MHz(); runtime_processor_speed_MHz = runtime_get_processor_speed_MHz();
software_interrupt_interval_duration_in_cycles = (uint64_t)SOFTWARE_INTERRUPT_INTERVAL_DURATION_IN_USEC software_interrupt_interval_duration_in_cycles = (uint64_t)SOFTWARE_INTERRUPT_INTERVAL_DURATION_IN_USEC
* runtime_processor_speed_MHz; * 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_set_resource_limits_to_max();
runtime_allocate_available_cores(); runtime_allocate_available_cores();
@ -248,9 +245,6 @@ main(int argc, char **argv)
#endif #endif
if (module_new_from_json(argv[1])) panic("failed to parse modules file[%s]\n", argv[1]); 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(); listener_thread_initialize();
debuglog("Starting %d worker thread(s)\n", runtime_worker_threads_count);
runtime_start_runtime_worker_threads(); runtime_start_runtime_worker_threads();
} }

@ -190,6 +190,7 @@ listener_thread_main(void *dummy)
void void
listener_thread_initialize(void) listener_thread_initialize(void)
{ {
printf("Starting listener thread\n");
cpu_set_t cs; cpu_set_t cs;
CPU_ZERO(&cs); CPU_ZERO(&cs);

@ -42,7 +42,7 @@ __thread uint64_t worker_thread_start_timestamp;
static inline void static inline void
worker_thread_dump_lock_overhead() worker_thread_dump_lock_overhead()
{ {
#ifdef DEBUG #ifndef NDEBUG
#ifdef LOG_LOCK_OVERHEAD #ifdef LOG_LOCK_OVERHEAD
uint64_t worker_duration = __getcycles() - worker_thread_start_timestamp; uint64_t worker_duration = __getcycles() - worker_thread_start_timestamp;
debuglog("Locks consumed %lu / %lu cycles, or %f%%\n", worker_thread_lock_duration, worker_duration, debuglog("Locks consumed %lu / %lu cycles, or %f%%\n", worker_thread_lock_duration, worker_duration,

Loading…
Cancel
Save