From ffff81957fcf13c83e4aa7649ebde5b6d2132ba7 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 5 May 2021 19:36:05 +0000 Subject: [PATCH] refactor: Decompose perf window header --- runtime/include/perf_window.h | 27 +-------------------------- runtime/include/perf_window_t.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 runtime/include/perf_window_t.h diff --git a/runtime/include/perf_window.h b/runtime/include/perf_window.h index 6b41824..e4ebfc6 100644 --- a/runtime/include/perf_window.h +++ b/runtime/include/perf_window.h @@ -3,35 +3,10 @@ #include #include "lock.h" +#include "perf_window_t.h" #include "runtime.h" #include "worker_thread.h" -/* Should be Power of 2! */ -#define PERF_WINDOW_BUFFER_SIZE 16 - -#if ((PERF_WINDOW_BUFFER_SIZE == 0) || (PERF_WINDOW_BUFFER_SIZE & (PERF_WINDOW_BUFFER_SIZE - 1)) != 0) -#error "PERF_WINDOW_BUFFER_SIZE must be power of 2!" -#endif - -/* - * The by_duration array sorts the last N executions by execution time - * The by_termination array acts as a circular buffer that maps to indices in the by_duration array - * - * by_termination ensures that the when the circular buffer is full, the oldest data in both arrays is - * overwritten, providing a sorted circular buffer - */ -struct execution_node { - uint64_t execution_time; - uint16_t by_termination_idx; /* Reverse idx of the associated by_termination bin. Used for swaps! */ -}; - -struct perf_window { - struct execution_node by_duration[PERF_WINDOW_BUFFER_SIZE]; - uint16_t by_termination[PERF_WINDOW_BUFFER_SIZE]; - uint64_t count; - lock_t lock; -}; - /** * Initializes perf window * @param self diff --git a/runtime/include/perf_window_t.h b/runtime/include/perf_window_t.h new file mode 100644 index 0000000..4d39af4 --- /dev/null +++ b/runtime/include/perf_window_t.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include "lock.h" + +/* Should be Power of 2! */ +#define PERF_WINDOW_BUFFER_SIZE 16 + +#if ((PERF_WINDOW_BUFFER_SIZE == 0) || (PERF_WINDOW_BUFFER_SIZE & (PERF_WINDOW_BUFFER_SIZE - 1)) != 0) +#error "PERF_WINDOW_BUFFER_SIZE must be power of 2!" +#endif + +/* + * The by_duration array sorts the last N executions by execution time + * The by_termination array acts as a circular buffer that maps to indices in the by_duration array + * + * by_termination ensures that the when the circular buffer is full, the oldest data in both arrays is + * overwritten, providing a sorted circular buffer + */ +struct execution_node { + uint64_t execution_time; + uint16_t by_termination_idx; /* Reverse idx of the associated by_termination bin. Used for swaps! */ +}; + +struct perf_window { + struct execution_node by_duration[PERF_WINDOW_BUFFER_SIZE]; + uint16_t by_termination[PERF_WINDOW_BUFFER_SIZE]; + uint64_t count; + lock_t lock; +};