From f2853d27836475bca7d79e2917d6489723898bef Mon Sep 17 00:00:00 2001 From: lyuxiaosu Date: Tue, 14 Dec 2021 13:53:39 -0500 Subject: [PATCH] record each thread worker's queuelength when an alarm signal come in --- runtime/include/local_runqueue.h | 2 ++ runtime/src/main.c | 2 +- runtime/src/software_interrupt.c | 13 +++++++++++++ runtime/src/worker_thread.c | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/runtime/include/local_runqueue.h b/runtime/include/local_runqueue.h index 40bf0b2..5a267d2 100644 --- a/runtime/include/local_runqueue.h +++ b/runtime/include/local_runqueue.h @@ -4,6 +4,8 @@ #include "sandbox_types.h" + +#define TEST_RECORDING_BUFFER_LEN 500000 /* Returns pointer back if successful, null otherwise */ typedef void (*local_runqueue_add_fn_t)(struct sandbox *); typedef bool (*local_runqueue_is_empty_fn_t)(void); diff --git a/runtime/src/main.c b/runtime/src/main.c index 46858f4..c92319c 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -356,7 +356,7 @@ main(int argc, char **argv) char *cpu_speed_MHz_raw = getenv("SLEDGE_CPU_SPEED"); if (cpu_speed_MHz_raw != NULL) { long cpu_speed_MHz = atoi(cpu_speed_MHz_raw); - if (unlikely(cpu_speed_MHz < 0)) panic("SLEDGE_CPU_SPEED must be a positive integer, saw %ld\n", cpu_speed_MHz); + if (unlikely(cpu_speed_MHz <= 0)) panic("SLEDGE_CPU_SPEED must be a positive integer, saw %ld\n", cpu_speed_MHz); runtime_processor_speed_MHz = (uint32_t)cpu_speed_MHz; } printf("\tCPU Speed: %u MHz\n", runtime_processor_speed_MHz); diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index 96072d6..b9a07b7 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -31,6 +31,9 @@ static uint64_t software_interrupt_interval_duration_in_cycles; /****************** * Thread Globals * *****************/ +extern __thread uint32_t local_workload_count; +extern __thread int recording_buffer[]; +extern __thread int worker_thread_idx; __thread _Atomic static volatile sig_atomic_t software_interrupt_SIGALRM_kernel_count = 0; __thread _Atomic static volatile sig_atomic_t software_interrupt_SIGALRM_thread_count = 0; @@ -168,6 +171,9 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void switch (signal_type) { case SIGALRM: { + assert(TEST_RECORDING_BUFFER_LEN > software_interrupt_SIGALRM_kernel_count + software_interrupt_SIGALRM_thread_count); + /* record queuelength of the current worker thread */ + recording_buffer[software_interrupt_SIGALRM_kernel_count + software_interrupt_SIGALRM_thread_count] = local_workload_count; sigalrm_propagate_workers(signal_info); if (current_sandbox == NULL || current_sandbox->ctxt.preemptable == false) { /* Cannot preempt, so defer signal @@ -198,8 +204,15 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void goto done; } case SIGINT: { + /* Stop the alarm timer first */ + software_interrupt_disarm_timer(); /* Only the thread that receives SIGINT from the kernel or user space will broadcast SIGINT to other worker threads */ sigint_propagate_workers_listener(signal_info); + mem_log("thread id %d test buffer:",worker_thread_idx); + for(int i = 0; i < software_interrupt_SIGALRM_kernel_count + software_interrupt_SIGALRM_thread_count; i++) { + mem_log("%d ", recording_buffer[i]); + } + mem_log("\n"); dump_log_to_file(); /* terminate itself */ pthread_exit(0); diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index 222624c..10e7e6b 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -21,6 +21,10 @@ * Worker Thread State * **************************/ +extern uint32_t test_recording_buffer_len; +/* test recording buffer for saving queuelength */ +__thread int recording_buffer[TEST_RECORDING_BUFFER_LEN] = {0}; + /* context of the runtime thread before running sandboxes or to resume its "main". */ __thread struct arch_context worker_thread_base_context;