aboutsummaryrefslogtreecommitdiff
path: root/arch/v1/arch.c
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2026-05-25 04:39:17 +0200
committerPaul Oliver <contact@pauloliver.dev>2026-05-25 04:39:17 +0200
commitad21f51f4f14da9b9283fa72f1574cdb7286c4d9 (patch)
treeda4b61ce885c73835ba6a54b34f7d18f126e1a3b /arch/v1/arch.c
parentbe2c37ac8c8e317eb7e05829ff2078c1b3bbce4e (diff)
Reorganizes SQLite database into two (core and arch) tables
Diffstat (limited to 'arch/v1/arch.c')
-rw-r--r--arch/v1/arch.c292
1 files changed, 108 insertions, 184 deletions
diff --git a/arch/v1/arch.c b/arch/v1/arch.c
index ec5d778..9e6f3e6 100644
--- a/arch/v1/arch.c
+++ b/arch/v1/arch.c
@@ -2,23 +2,23 @@
// https://git.pauloliver.dev/salis-v1/about/
enum {
-#define INST(index, label, mnemonic, symbol) label,
- INST_SET
+#define INST(core, pref, index, label, mnemonic, symbol) label,
+ INST_SET(core, pref)
#undef INST
};
#if defined(DATA_PUSH)
-#define ARCH_EVENT_ARRAYS \
- ARCH_EVENT_ARRAY(0, wev) /* write events array*/ \
- ARCH_EVENT_ARRAY(1, xev) /* memory block swap events array */
-#define ARCH_EVENT_ARRAYS_COUNT 2
-
-#define INST_EVENT_ARRAYS \
- INST_EVENT_ARRAY(0, pop) /* instruction population */ \
- INST_EVENT_ARRAY(1, exe) /* instruction executions */ \
- INST_EVENT_ARRAY(2, wrt) /* instruction writes */
+#define INST_EVENT_ARRAYS(core) \
+ INST_EVENT_ARRAY(core, 0, pop) /* instruction population */ \
+ INST_EVENT_ARRAY(core, 1, exe) /* instruction executions */ \
+ INST_EVENT_ARRAY(core, 2, wrt) /* instruction writes */
#define INST_EVENT_ARRAYS_COUNT 3
+#define ARCH_EVENT_ARRAYS(core) \
+ ARCH_EVENT_ARRAY(core, 0, wev) /* write events array*/ \
+ ARCH_EVENT_ARRAY(core, 1, xev) /* memory block swap events array */
+#define ARCH_EVENT_ARRAYS_COUNT 2
+
thrd_t g_arch_eva_thrds[CORES][ARCH_EVENT_ARRAYS_COUNT];
struct DeflateParams g_arch_eva_deflate_params[CORES][ARCH_EVENT_ARRAYS_COUNT];
#endif
@@ -62,9 +62,9 @@ void arch_core_save(FILE *f, const struct Core *core) {
fwrite(&core->wmb0, sizeof(uint64_t), 1, f);
fwrite(&core->wmb1, sizeof(uint64_t), 1, f);
fwrite(&core->wdea, sizeof(uint64_t), 1, f);
-#define ARCH_EVENT_ARRAY(_, ev) \
+#define ARCH_EVENT_ARRAY(core, index, ev) \
fwrite(core->ev##a, sizeof(uint64_t), MVEC_SIZE, f);
- ARCH_EVENT_ARRAYS
+ ARCH_EVENT_ARRAYS(core)
#undef ARCH_EVENT_ARRAY
#else
(void)f;
@@ -84,9 +84,9 @@ void arch_core_load(FILE *f, struct Core *core) {
fread(&core->wmb0, sizeof(uint64_t), 1, f);
fread(&core->wmb1, sizeof(uint64_t), 1, f);
fread(&core->wdea, sizeof(uint64_t), 1, f);
-#define ARCH_EVENT_ARRAY(_, ev) \
+#define ARCH_EVENT_ARRAY(core, index, ev) \
fread(core->ev##a, sizeof(uint64_t), MVEC_SIZE, f);
- ARCH_EVENT_ARRAYS
+ ARCH_EVENT_ARRAYS(core)
#undef ARCH_EVENT_ARRAY
#else
(void)f;
@@ -850,8 +850,8 @@ void arch_validate_proc(const struct Core *core, uint64_t pix) {
wchar_t arch_symbol(uint8_t inst) {
switch (inst % INST_COUNT) {
-#define INST(index, label, mnemonic, symbol) case index: return symbol;
- INST_SET
+#define INST(core, pref, index, label, mnemonic, symbol) case index: return symbol;
+ INST_SET(core, pref)
#undef INST
}
@@ -861,8 +861,8 @@ wchar_t arch_symbol(uint8_t inst) {
const char *arch_mnemonic(uint8_t inst) {
switch (inst % INST_COUNT) {
-#define INST(index, label, mnemonic, symbol) case index: return mnemonic;
- INST_SET
+#define INST(core, pref, index, label, mnemonic, symbol) case index: return mnemonic;
+ INST_SET(core, pref)
#undef INST
}
@@ -882,68 +882,28 @@ void arch_push_data_header(void) {
salis_exec_sql(
0, NULL, NULL,
"create table arch ("
+#define INST(core, pref, index, label, mnemonic, symbol) \
+ #label "_" #pref "_" #core " int not null, "
+#define INST_EVENT_ARRAY(core, index, iv) \
+ INST_SET(core, iv)
+#define ARCH_EVENT_ARRAY(core, index, ev) \
+ #ev "_size_" #core " int not null, " \
+ #ev "_" #core " blob not null, "
#define FOR_CORE(i) \
"cycl_" #i " int not null, " \
"wmb0_" #i " int not null, " \
"wmb1_" #i " int not null, " \
- "wdea_" #i " int not null, "
+ "wdea_" #i " int not null, " \
+ INST_EVENT_ARRAYS(i) \
+ ARCH_EVENT_ARRAYS(i)
FOR_CORES
#undef FOR_CORE
+#undef ARCH_EVENT_ARRAY
+#undef INST_EVENT_ARRAY
+#undef INST
"step int not null"
");"
);
-
- // Instruction events
- char *iprefs[] = { "pop", "exe", "wrt" };
- int iprefs_cnt = sizeof(iprefs) / sizeof(iprefs[0]);
-
- for (int i = 0; i < CORES; ++i) {
- for (int j = 0; j < iprefs_cnt; ++j) {
- g_info("Creating %s_%d table in SQLite database", iprefs[j], i);
- salis_exec_sql(
- 0, NULL, NULL,
- "create table %s_%d ("
-#define FOR_CORE(i) "cycl_" #i " int not null, "
- FOR_CORES
-#undef FOR_CORE
-#define INST(index, label, mnemonic, symbol) #label " int not null, "
- INST_SET
-#undef INST
- "step int not null"
- ");",
- iprefs[j], i
- );
- }
- }
-
- // Memory events
- for (int i = 0; i < CORES; ++i) {
- for (int j = 0; j < ARCH_EVENT_ARRAYS_COUNT; ++j) {
- char *pref = NULL;
-
- switch (j) {
-#define ARCH_EVENT_ARRAY(idx, ev) \
- case idx: pref = #ev; break;
- ARCH_EVENT_ARRAYS
-#undef ARCH_EVENT_ARRAY
- default: assert(false);
- }
-
- g_info("Creating %s_%d table in SQLite database", pref, i);
- salis_exec_sql(
- 0, NULL, NULL,
- "create table %s_%d ("
-#define FOR_CORE(i) "cycl_" #i " int not null, "
- FOR_CORES
-#undef FOR_CORE
- "size int not null, "
- "evts blob not null ,"
- "step int not null"
- ");",
- pref, i
- );
- }
- }
}
#endif
@@ -969,92 +929,20 @@ void arch_push_data_line(void) {
#endif
}
- g_info("Pushing row to arch table in SQLite database");
- salis_exec_sql(
- 0, NULL, NULL,
- "insert into arch ("
-#define FOR_CORE(i) \
- "cycl_" #i ", " \
- "wmb0_" #i ", " \
- "wmb1_" #i ", " \
- "wdea_" #i ", "
- FOR_CORES
-#undef FOR_CORE
- "step"
- ") values ("
-#define FOR_CORE(i) "%ld, %ld, %ld, %ld, "
- FOR_CORES
-#undef FOR_CORE
- "%ld"
- ");",
-#define FOR_CORE(i) \
- g_cores[i].cycl, \
- g_cores[i].wmb0, \
- g_cores[i].wmb1, \
- g_cores[i].wdea,
- FOR_CORES
-#undef FOR_CORE
- g_steps
- );
-
- char *iprefs[] = { "pop", "exe", "wrt" };
- int iprefs_cnt = sizeof(iprefs) / sizeof(iprefs[0]);
-
- for (int i = 0; i < CORES; ++i) {
- for (int j = 0; j < iprefs_cnt; ++j) {
- uint64_t *ia = NULL;
- char *pref = NULL;
-
- switch (j) {
-#define INST_EVENT_ARRAY(idx, iv) \
- case idx: ia = g_cores[i].i##iv; pref = #iv; break;
- INST_EVENT_ARRAYS
-#undef INST_EVENT_ARRAY
- default: assert(false);
- }
-
- g_info("Pushing row to %s_%d table in SQLite database", pref, i);
- salis_exec_sql(
- 0, NULL, NULL,
- "insert into %s_%d ("
-#define FOR_CORE(i) "cycl_" #i ", "
- FOR_CORES
-#undef FOR_CORE
-#define INST(index, label, mnemonic, symbol) #label ", "
- INST_SET
-#undef INST
- "step"
- ") values ("
-#define FOR_CORE(i) "%ld, "
- FOR_CORES
-#undef FOR_CORE
-#define INST(index, label, mnemonic, symbol) "%ld, "
- INST_SET
-#undef INST
- "%ld"
- ");",
- pref, i,
-#define FOR_CORE(i) g_cores[i].cycl,
- FOR_CORES
-#undef FOR_CORE
-#define INST(index, label, mnemonic, symbol) ia[index],
- INST_SET
-#undef INST
- g_steps
- );
- }
- }
-
- // Insert arch-specific memory events
+ // Compress event arrays
// Compression (deflation) is CPU intensive so it is done in parallel
+ memset(&g_arch_eva_deflate_params, 0, sizeof(struct DeflateParams) * CORES * ARCH_EVENT_ARRAYS_COUNT);
+ const void *blobs[CORES][ARCH_EVENT_ARRAYS_COUNT];
+ int blob_sizes[CORES][ARCH_EVENT_ARRAYS_COUNT];
+
for (int i = 0; i < CORES; ++i) {
for (int j = 0; j < ARCH_EVENT_ARRAYS_COUNT; ++j) {
uint64_t *in = NULL;
switch (j) {
-#define ARCH_EVENT_ARRAY(idx, ev) \
- case idx: in = g_cores[i].ev##a; break;
- ARCH_EVENT_ARRAYS
+#define ARCH_EVENT_ARRAY(core, index, ev) \
+ case index: in = g_cores[i].ev##a; break;
+ ARCH_EVENT_ARRAYS(core)
#undef ARCH_EVENT_ARRAY
default: assert(false);
}
@@ -1070,44 +958,80 @@ void arch_push_data_line(void) {
for (int i = 0; i < CORES; ++i) {
for (int j = 0; j < ARCH_EVENT_ARRAYS_COUNT; ++j) {
- char *pref = NULL;
-
- switch (j) {
-#define ARCH_EVENT_ARRAY(idx, ev) \
- case idx: pref = #ev; break;
- ARCH_EVENT_ARRAYS
-#undef ARCH_EVENT_ARRAY
- default: assert(false);
- }
-
thrd_join(g_arch_eva_thrds[i][j], NULL);
- // Insert blob
struct DeflateParams *params = &g_arch_eva_deflate_params[i][j];
- const void *blob = params->out;
- int blob_size = params->strm.total_out;
+ blobs[i][j] = params->out;
+ blob_sizes[i][j] = params->strm.total_out;
+ }
+ }
- g_info("Pushing row to %s_%d table in SQLite database", pref, i);
- salis_exec_sql(
- 1, &blob, &blob_size,
- "insert into %s_%d ("
-#define FOR_CORE(i) "cycl_" #i ", "
- FOR_CORES
+ g_info("Pushing row to arch table in SQLite database");
+ salis_exec_sql(
+ CORES * ARCH_EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes,
+ "insert into arch ("
+#define INST(core, pref, index, label, mnemonic, symbol) \
+ #label "_" #pref "_" #core ", "
+#define INST_EVENT_ARRAY(core, index, iv) \
+ INST_SET(core, iv)
+#define ARCH_EVENT_ARRAY(core, index, ev) \
+ #ev "_size_" #core ", " \
+ #ev "_" #core ", "
+#define FOR_CORE(i) \
+ "cycl_" #i ", " \
+ "wmb0_" #i ", " \
+ "wmb1_" #i ", " \
+ "wdea_" #i ", " \
+ INST_EVENT_ARRAYS(i) \
+ ARCH_EVENT_ARRAYS(i)
+ FOR_CORES
#undef FOR_CORE
- "size, evts, step"
- ") values ("
-#define FOR_CORE(i) "%ld, "
- FOR_CORES
+#undef ARCH_EVENT_ARRAY
+#undef INST_EVENT_ARRAY
+#undef INST
+ "step"
+ ") values ("
+#define INST(core, pref, index, label, mnemonic, symbol) \
+ "%ld, "
+#define INST_EVENT_ARRAY(core, index, iv) \
+ INST_SET(core, iv)
+#define ARCH_EVENT_ARRAY(core, index, ev) \
+ "%ld, ?, "
+#define FOR_CORE(i) \
+ "%ld, %ld, %ld, %ld, " \
+ INST_EVENT_ARRAYS(i) \
+ ARCH_EVENT_ARRAYS(i)
+ FOR_CORES
#undef FOR_CORE
- "%ld, ?, %ld"
- ");",
- pref, i,
-#define FOR_CORE(i) g_cores[i].cycl,
- FOR_CORES
+#undef ARCH_EVENT_ARRAY
+#undef INST_EVENT_ARRAY
+#undef INST
+ "%ld"
+ ");",
+#define INST(core, pref, index, label, mnemonic, symbol) \
+ g_cores[core].i##pref,
+#define INST_EVENT_ARRAY(core, index, iv) \
+ INST_SET(core, iv)
+#define ARCH_EVENT_ARRAY(core, index, ev) \
+ blob_sizes[core][index],
+#define FOR_CORE(i) \
+ g_cores[i].cycl, \
+ g_cores[i].wmb0, \
+ g_cores[i].wmb1, \
+ g_cores[i].wdea, \
+ INST_EVENT_ARRAYS(i) \
+ ARCH_EVENT_ARRAYS(i)
+ FOR_CORES
#undef FOR_CORE
- blob_size, g_steps
- );
+#undef ARCH_EVENT_ARRAY
+#undef INST_EVENT_ARRAY
+#undef INST
+ g_steps
+ );
+ for (int i = 0; i < CORES; ++i) {
+ for (int j = 0; j < ARCH_EVENT_ARRAYS_COUNT; ++j) {
+ struct DeflateParams *params = &g_arch_eva_deflate_params[i][j];
salis_deflate_end(params);
free(params->out);
}
@@ -1125,9 +1049,9 @@ void arch_push_data_line(void) {
core->wmb1 = 0;
core->wdea = 0;
-#define ARCH_EVENT_ARRAY(_, ev) \
+#define ARCH_EVENT_ARRAY(core, index, ev) \
memset(core->ev##a, 0, EVA_SIZE);
- ARCH_EVENT_ARRAYS
+ ARCH_EVENT_ARRAYS(core)
#undef ARCH_EVENT_ARRAY
}
}