diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2026-05-25 21:36:50 +0200 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2026-05-25 21:38:20 +0200 |
| commit | bace2d7f20acc609d552a80bb018939d5e8afab8 (patch) | |
| tree | 0525710979c3342a2ed74fc675c192cb9b0c7870 /core | |
| parent | 54342ed0cc61585d953183ec29309eb0db846b72 (diff) | |
Save file compression and data aggregation always enabled
Diffstat (limited to 'core')
| -rw-r--r-- | core/compress.c | 2 | ||||
| -rw-r--r-- | core/logger.c | 8 | ||||
| -rw-r--r-- | core/salis.c | 70 | ||||
| -rw-r--r-- | core/sql.c | 6 |
4 files changed, 13 insertions, 73 deletions
diff --git a/core/compress.c b/core/compress.c index 8ef3c41..b45a583 100644 --- a/core/compress.c +++ b/core/compress.c @@ -1,5 +1,3 @@ -#pragma once - #define EVA_SIZE (sizeof(uint64_t) * MVEC_SIZE) struct DeflateParams { diff --git a/core/logger.c b/core/logger.c index 7d5b69e..2c8746f 100644 --- a/core/logger.c +++ b/core/logger.c @@ -81,7 +81,7 @@ void log_msg(enum LogLevel level, bool colored, const char *format, va_list args printf("\r%s\n", buff); } -void log_info(const char *format, ...) { +void log_info_default(const char *format, ...) { assert(format); va_list args; @@ -90,7 +90,7 @@ void log_info(const char *format, ...) { va_end(args); } -void log_warn(const char *format, ...) { +void log_warn_default(const char *format, ...) { assert(format); va_list args; @@ -100,5 +100,5 @@ void log_warn(const char *format, ...) { } // Client may install their own loggers -void (*g_info)(const char *fmt, ...) = log_info; -void (*g_warn)(const char *fmt, ...) = log_warn; +void (*log_info)(const char *fmt, ...) = log_info_default; +void (*log_warn)(const char *fmt, ...) = log_warn_default; diff --git a/core/salis.c b/core/salis.c index abed1ec..d6efcf2 100644 --- a/core/salis.c +++ b/core/salis.c @@ -1,23 +1,16 @@ #include <assert.h> +#include <sqlite3.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <threads.h> -#include "logger.c" - -#if defined(COMPRESS) #include <zlib.h> -#include "compress.c" -#endif -#if defined(DATA_PUSH) -#include <sqlite3.h> -#include <zlib.h> +#include "logger.c" #include "compress.c" #include "sql.c" -#endif #define INST_CAP 0x80 #define INST_MASK 0x7f @@ -25,13 +18,11 @@ #define MALL_FLAG 0x80 #define UINT64_HALF 0x8000000000000000ul -#if defined(DATA_PUSH) #define EVENT_ARRAYS(core) \ EVENT_ARRAY(core, 0, aev) /* allocation events array */ \ EVENT_ARRAY(core, 1, eev) /* executions events array */ \ EVENT_ARRAY(core, 2, bev) /* birth events array */ #define EVENT_ARRAYS_COUNT 3 -#endif struct Proc { #define PROC_FIELD(type, name) type name; @@ -58,7 +49,6 @@ struct Core { uint64_t *ivav; uint8_t *iviv; -#if defined(DATA_PUSH) 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) @@ -71,7 +61,6 @@ struct Core { #define CORE_DATA_FIELD(type, name) type name; CORE_DATA_FIELDS #undef CORE_DATA_FIELD -#endif #define CORE_FIELD(type, name) type name; CORE_FIELDS @@ -92,10 +81,8 @@ const struct Proc g_dead_proc; char g_asav_pbuf[AUTOSAVE_NAME_LEN]; #endif -#if defined(DATA_PUSH) thrd_t g_eva_thrds[CORES][EVENT_ARRAYS_COUNT]; struct DeflateParams g_eva_deflate_params[CORES][EVENT_ARRAYS_COUNT]; -#endif // Each architecture must define these functions #if defined(COMMAND_NEW) @@ -163,19 +150,16 @@ void mvec_alloc(struct Core *core, uint64_t addr) { #if defined(MVEC_LOOP) core->mvec[mvec_loop(addr)] |= MALL_FLAG; -#if defined(DATA_PUSH) + // Record deallocation event ++core->aeva[mvec_loop(addr)]; -#endif #else assert(addr < MVEC_SIZE); core->mvec[addr] |= MALL_FLAG; -#if defined(DATA_PUSH) // Record deallocation event ++core->aeva[addr]; #endif -#endif core->mall++; } @@ -186,19 +170,15 @@ void mvec_free(struct Core *core, uint64_t addr) { #if defined(MVEC_LOOP) core->mvec[mvec_loop(addr)] ^= MALL_FLAG; -#if defined(DATA_PUSH) // Record deallocation event ++core->aeva[mvec_loop(addr)]; -#endif #else assert(addr < MVEC_SIZE); core->mvec[addr] ^= MALL_FLAG; -#if defined(DATA_PUSH) // Record deallocation event ++core->aeva[addr]; #endif -#endif core->mall--; } @@ -379,7 +359,6 @@ void proc_new(struct Core *core, const struct Proc *proc) { core->plst++; memcpy(&core->pvec[core->plst % core->pcap], proc, sizeof(struct Proc)); -#if defined(DATA_PUSH) // Store birth event in database uint64_t child_addr = arch_proc_mb0_addr(core, core->plst); uint64_t child_size = arch_proc_mb0_size(core, core->plst); @@ -392,7 +371,6 @@ void proc_new(struct Core *core, const struct Proc *proc) { ++core->beva[addr]; #endif } -#endif } void proc_kill(struct Core *core) { @@ -441,23 +419,19 @@ void core_save(FILE *f, const struct Core *core) { fwrite(&core->pcur, sizeof(uint64_t), 1, f); fwrite(&core->psli, sizeof(uint64_t), 1, f); fwrite(&core->ivpt, sizeof(uint64_t), 1, f); -#if defined(DATA_PUSH) fwrite(&core->emb0, sizeof(uint64_t), 1, f); fwrite(&core->emb1, sizeof(uint64_t), 1, f); fwrite(&core->eliv, sizeof(uint64_t), 1, f); fwrite(&core->edea, sizeof(uint64_t), 1, f); -#endif fwrite(core->iviv, sizeof(uint8_t), SYNC_INTERVAL, f); fwrite(core->ivav, sizeof(uint64_t), SYNC_INTERVAL, f); fwrite(core->pvec, sizeof(struct Proc), core->pcap, f); fwrite(core->mvec, sizeof(uint8_t), MVEC_SIZE, f); -#if defined(DATA_PUSH) #define EVENT_ARRAY(core, index, ev) \ fwrite(core->ev##a, sizeof(uint64_t), MVEC_SIZE, f); EVENT_ARRAYS(core) #undef EVENT_ARRAY -#endif arch_core_save(f, core); } @@ -531,12 +505,10 @@ void core_load(FILE *f, struct Core *core) { fread(&core->pcur, sizeof(uint64_t), 1, f); fread(&core->psli, sizeof(uint64_t), 1, f); fread(&core->ivpt, sizeof(uint64_t), 1, f); -#if defined(DATA_PUSH) fread(&core->emb0, sizeof(uint64_t), 1, f); fread(&core->emb1, sizeof(uint64_t), 1, f); fread(&core->eliv, sizeof(uint64_t), 1, f); fread(&core->edea, sizeof(uint64_t), 1, f); -#endif core->iviv = calloc(SYNC_INTERVAL, sizeof(uint8_t)); core->ivav = calloc(SYNC_INTERVAL, sizeof(uint64_t)); @@ -550,12 +522,10 @@ void core_load(FILE *f, struct Core *core) { fread(core->ivav, sizeof(uint64_t), SYNC_INTERVAL, f); fread(core->pvec, sizeof(struct Proc), core->pcap, f); fread(core->mvec, sizeof(uint8_t), MVEC_SIZE, f); -#if defined(DATA_PUSH) #define EVENT_ARRAY(core, index, ev) \ fread(core->ev##a, sizeof(uint64_t), MVEC_SIZE, f); EVENT_ARRAYS(core) #undef EVENT_ARRAY -#endif arch_core_load(f, core); } @@ -600,7 +570,6 @@ void core_step(struct Core *core) { if (core->psli != 0) { core_pull_ipcm(core); -#if defined(DATA_PUSH) // Save execution event locations in database assert(mvec_proc_is_live(core, core->pcur)); @@ -623,7 +592,6 @@ void core_step(struct Core *core) { core->eeva[pcur_ip]++; } #endif -#endif arch_proc_step(core, core->pcur); @@ -657,13 +625,9 @@ void core_step(struct Core *core) { // ---------------------------------------------------------------------------- #if defined(COMMAND_NEW) || defined(COMMAND_LOAD) void salis_save(const char *path) { -#if defined(COMPRESS) size_t size = 0; char *in = NULL; FILE *f = open_memstream(&in, &size); -#else - FILE *f = fopen(path, "wb"); -#endif assert(f); @@ -675,7 +639,6 @@ void salis_save(const char *path) { fwrite(&g_syncs, sizeof(uint64_t), 1, f); fclose(f); -#if defined(COMPRESS) assert(size); char *out = malloc(size); assert(out); @@ -699,7 +662,6 @@ void salis_save(const char *path) { free(in); free(out); -#endif } void salis_auto_save(void) { @@ -718,17 +680,16 @@ void salis_auto_save(void) { assert(rem >= 0); assert(rem < AUTOSAVE_NAME_LEN); - g_info("Saving simulation state on step %#lx", g_steps); + log_info("Saving simulation state on step %#lx", g_steps); salis_save(g_asav_pbuf); } #endif -#if defined(DATA_PUSH) #if defined(COMMAND_NEW) void salis_push_data_header(void) { assert(g_sim_db); - g_info("Creating core table in SQLite database"); + log_info("Creating core table in SQLite database"); sql_exec( 0, NULL, NULL, "create table core (" @@ -815,7 +776,7 @@ void salis_push_data_line(void) { } } - g_info("Pushing row to core table in SQLite database"); + log_info("Pushing row to core table in SQLite database"); sql_exec( CORES * EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes, "insert into core (" @@ -897,13 +858,9 @@ void salis_push_data_line(void) { // Push arch-specific data arch_push_data_line(); } -#endif #if defined(COMMAND_NEW) void salis_init(void) { - assert(g_info); - assert(g_warn); - uint64_t seed = SEED; for (int i = 0; i < CORES; ++i) { @@ -914,18 +871,15 @@ void salis_init(void) { salis_auto_save(); #endif -#if defined(DATA_PUSH) // Initialize database sql_open(); salis_push_data_header(); salis_push_data_line(); -#endif } #endif #if defined(COMMAND_LOAD) void salis_load(void) { -#if defined(COMPRESS) FILE *fx = fopen(SIM_PATH, "rb"); assert(fx); @@ -956,9 +910,6 @@ void salis_load(void) { comp_inflate_end(¶ms); FILE *f = fmemopen(out, size, "rb"); -#else - FILE *f = fopen(SIM_PATH, "rb"); -#endif assert(f); @@ -969,15 +920,10 @@ void salis_load(void) { fread(&g_steps, sizeof(uint64_t), 1, f); fread(&g_syncs, sizeof(uint64_t), 1, f); fclose(f); - -#if defined(COMPRESS) free(in); free(out); -#endif -#if defined(DATA_PUSH) sql_open(); -#endif } #endif @@ -1045,11 +991,9 @@ void salis_loop(uint64_t ns, uint64_t dt) { } #endif -#if defined(DATA_PUSH) if (g_steps % DATA_PUSH_INTERVAL == 0) { salis_push_data_line(); } -#endif salis_loop(ns - dt, SYNC_INTERVAL); } @@ -1107,9 +1051,7 @@ void salis_step(uint64_t ns) { } void salis_free(void) { -#if defined(DATA_PUSH) sql_close(); -#endif for (int i = 0; i < CORES; ++i) { arch_core_free(&g_cores[i]); @@ -38,11 +38,11 @@ void sql_exec(int blob_cnt, const void **blobs, const int *blob_sizes, const cha break; } - g_warn("SQLite database returned error %d with message:", sql_res); - g_warn(sqlite3_errmsg(g_sim_db)); + log_warn("SQLite database returned error %d with message:", sql_res); + log_warn(sqlite3_errmsg(g_sim_db)); if (sql_res == SQLITE_BUSY) { - g_info("Will retry query..."); + log_info("Will retry query..."); continue; } |
