From a61a742245d429b8d085208e249bb3bc80e44fb6 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Tue, 7 Jul 2026 23:30:52 +0200 Subject: data-tests (WIP) --- core/salis.c | 118 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 47 deletions(-) (limited to 'core/salis.c') diff --git a/core/salis.c b/core/salis.c index b7c904b..6f7ffe5 100644 --- a/core/salis.c +++ b/core/salis.c @@ -72,12 +72,17 @@ struct Core { uint64_t *ivav; uint8_t *iviv; + uint64_t amb0; // average size of main memory blocks (rounded) + uint64_t amb1; // average size of child memory blocks (rounded) + uint64_t emb0; // executions within mb0 counter uint64_t emb1; // executions within mb1 counter uint64_t eliv; // executions within not-owned live code counter (parasites) uint64_t edea; // executions within dead code counter -#define EVENT_ARRAY(core, index, ev) uint64_t ev##a[MVEC_SIZE]; +#define EVENT_ARRAY(core, index, ev) \ + uint64_t ev##_blob_size; \ + uint64_t ev##a[MVEC_SIZE]; EVENT_ARRAYS(core) #undef EVENT_ARRAY @@ -147,6 +152,7 @@ const char *arch_mnemonic(uint8_t inst); #if defined(COMMAND_NEW) void arch_push_data_header(void); #endif +void arch_prepare_data_line(void); void arch_push_data_line(FILE *eva_file); // ---------------------------------------------------------------------------- @@ -738,8 +744,8 @@ void salis_push_data_header(void) { "pnum_" #i " int not null, " \ "pfst_" #i " int not null, " \ "plst_" #i " int not null, " \ - "amb0_" #i " real not null, " \ - "amb1_" #i " real not null, " \ + "amb0_" #i " int not null, " \ + "amb1_" #i " int not null, " \ "emb0_" #i " int not null, " \ "emb1_" #i " int not null, " \ "eliv_" #i " int not null, " \ @@ -756,29 +762,46 @@ void salis_push_data_header(void) { } #endif -void salis_push_data_line(void) { - assert(g_sim_db); +void salis_prepare_data_line(void) { + log_info("Preparing data-line for next push"); // Measure average membory block sizes - double amb0[CORES] = { 0 }; - double amb1[CORES] = { 0 }; - for (int i = 0; i < CORES; ++i) { struct Core *core = &g_cores[i]; + double amb0 = 0.; + double amb1 = 0.; for (uint64_t j = core->pfst; j <= core->plst; ++j) { - amb0[i] += (double)arch_proc_mb0_size(core, j); - amb1[i] += (double)arch_proc_mb1_size(core, j); + amb0 += (double)arch_proc_mb0_size(core, j); + amb1 += (double)arch_proc_mb1_size(core, j); } - amb0[i] /= core->pnum; - amb1[i] /= core->pnum; + core->amb0 = (uint64_t)(amb0 / (double)core->pnum); + core->amb1 = (uint64_t)(amb1 / (double)core->pnum); } +} + +void salis_push_data_line(void) { + assert(g_sim_db); // Compress event arrays // Compression (deflation) is CPU intensive so it's done in parallel memset(&g_eva_deflate_params, 0, sizeof(struct DeflateParams) * CORES * EVENT_ARRAYS_COUNT); - uint64_t blob_sizes[CORES][EVENT_ARRAYS_COUNT]; + + int rem = snprintf( + g_eva_pbuf, + EVA_SAVE_NAME_LEN, + "%s/evas-%016lx", + SIM_EVAS, + g_steps + ); + + assert(rem >= 0); + assert(rem < EVA_SAVE_NAME_LEN); + (void)rem; + + log_info("Saving event-array data to file: %s", g_eva_pbuf); + FILE *eva_file = fopen(g_eva_pbuf, "wb"); for (int i = 0; i < CORES; ++i) { for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) { @@ -801,27 +824,22 @@ void salis_push_data_line(void) { } } - int rem = snprintf( - g_eva_pbuf, - EVA_SAVE_NAME_LEN, - "%s/evas-%016lx", - SIM_EDIR, - g_steps - ); - - assert(rem >= 0); - assert(rem < EVA_SAVE_NAME_LEN); - (void)rem; - - log_info("Saving event-array data to file: %s", g_eva_pbuf); - FILE *eva_file = fopen(g_eva_pbuf, "wb"); - for (int i = 0; i < CORES; ++i) { for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) { + uint64_t *blob_size = NULL; + + switch (j) { +#define EVENT_ARRAY(core, index, ev) \ + case index: blob_size = &g_cores[i].ev##_blob_size; break; + EVENT_ARRAYS(core) +#undef EVENT_ARRAY + default: assert(false); + } + thrd_join(g_eva_thrds[i][j], NULL); struct DeflateParams *params = &g_eva_deflate_params[i][j]; - blob_sizes[i][j] = params->strm.total_out; - fwrite(params->out, sizeof(char), blob_sizes[i][j], eva_file); + *blob_size = params->strm.total_out; + if (eva_file) fwrite(params->out, sizeof(char), *blob_size, eva_file); comp_deflate_end(params); free(params->out); } @@ -859,8 +877,8 @@ void salis_push_data_line(void) { "%ld, " \ "%ld, " \ "%ld, " \ - "%f, " \ - "%f, " \ + "%ld, " \ + "%ld, " \ "%ld, " \ "%ld, " \ "%ld, " \ @@ -872,15 +890,15 @@ void salis_push_data_line(void) { "%ld" ");", #define EVENT_ARRAY(core, index, ev) \ - blob_sizes[core][index], + g_cores[core].ev##_blob_size, #define FOR_CORE(i) \ g_cores[i].cycl, \ g_cores[i].mall, \ g_cores[i].pnum, \ g_cores[i].pfst, \ g_cores[i].plst, \ - amb0[i], \ - amb1[i], \ + g_cores[i].amb0, \ + g_cores[i].amb1, \ g_cores[i].emb0, \ g_cores[i].emb1, \ g_cores[i].eliv, \ @@ -896,12 +914,16 @@ void salis_push_data_line(void) { for (int i = 0; i < CORES; ++i) { struct Core *core = &g_cores[i]; + core->amb0 = 0; + core->amb1 = 0; + core->emb0 = 0; core->emb1 = 0; core->eliv = 0; core->edea = 0; #define EVENT_ARRAY(core, index, ev) \ + core->ev##_blob_size = 0; \ memset(core->ev##a, 0, EVENT_ARRAYS_SIZE); EVENT_ARRAYS(core) #undef EVENT_ARRAY @@ -920,14 +942,10 @@ void salis_init(void) { core_init(&g_cores[i], &seed); } -#if defined(COMMAND_NEW) - salis_auto_save(); -#endif - // Initialize database sql_open(); salis_push_data_header(); - salis_push_data_line(); + salis_prepare_data_line(); } #endif @@ -1036,6 +1054,18 @@ void salis_sync(void) { void salis_loop(uint64_t ns, uint64_t dt) { assert(dt); + if (ns) { +#if defined(COMMAND_NEW) || defined(COMMAND_LOAD) + if (g_steps % AUTOSAVE_INTERVAL == 0) { + salis_auto_save(); + } +#endif + + if (g_steps % DATA_PUSH_INTERVAL == 0) { + salis_push_data_line(); + } + } + if (ns < dt) { salis_run_thread(ns); return; @@ -1044,14 +1074,8 @@ void salis_loop(uint64_t ns, uint64_t dt) { salis_run_thread(dt); salis_sync(); -#if defined(COMMAND_NEW) || defined(COMMAND_LOAD) - if (g_steps % AUTOSAVE_INTERVAL == 0) { - salis_auto_save(); - } -#endif - if (g_steps % DATA_PUSH_INTERVAL == 0) { - salis_push_data_line(); + salis_prepare_data_line(); } salis_loop(ns - dt, SYNC_INTERVAL); -- cgit v1.2.1