aboutsummaryrefslogtreecommitdiff
path: root/core.j2.c
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-11-25 03:20:16 +0100
committerPaul Oliver <contact@pauloliver.dev>2025-11-25 03:20:22 +0100
commitfcf5746e8defdacba2284581a6521f72096891c5 (patch)
treec4403553aa627fc890cfc1b072bea8a471e157e0 /core.j2.c
parenta86ef805982aac5f7de5b5f01b3f6de90dd1030d (diff)
Aggregates data on organisms IO activity
Diffstat (limited to 'core.j2.c')
-rw-r--r--core.j2.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/core.j2.c b/core.j2.c
index 64873d8..45cd8b8 100644
--- a/core.j2.c
+++ b/core.j2.c
@@ -38,7 +38,7 @@ struct Core {
uint64_t *ivav;
uint8_t *iviv;
- // Architectures may provide custom fields
+ // Architecture specific custom fields
{% for type, val in arch_vars.core_fields %}
{{ type }} {{ val }};
{% endfor %}
@@ -70,7 +70,15 @@ void (*g_warn)(const char *fmt, ...);
// Forward declarations
// Each architecture must define these
{% if args.command in ["bench", "new"] and anc_bytes is defined %}
-void arch_anc_init(struct Core *core);
+void arch_core_init(struct Core *core);
+{% endif %}
+
+{% if args.command in ["load", "new"] %}
+void arch_core_save(FILE *f, const struct Core *core);
+{% endif %}
+
+{% if args.command in ["load"] %}
+void arch_core_load(FILE *f, struct Core *core);
{% endif %}
uint64_t arch_proc_mb0_addr(const struct Core *core, uint64_t pix);
@@ -195,25 +203,30 @@ bool mvec_proc_is_live(const struct Core *core, uint64_t pix) {
return pix >= core->pfst && pix <= core->plst;
}
-bool mvec_is_proc_owner(const struct Core *core, uint64_t addr, uint64_t pix) {
+bool mvec_is_in_mb0_of_proc(const struct Core *core, uint64_t addr, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
uint64_t mb0a = arch_proc_mb0_addr(core, pix);
uint64_t mb0s = arch_proc_mb0_size(core, pix);
- if (((addr - mb0a) % {{ mvec_size }}) < mb0s) {
- return true;
- }
+ return ((addr - mb0a) % {{ mvec_size }}) < mb0s;
+}
+
+bool mvec_is_in_mb1_of_proc(const struct Core *core, uint64_t addr, uint64_t pix) {
+ assert(core);
+ assert(mvec_proc_is_live(core, pix));
uint64_t mb1a = arch_proc_mb1_addr(core, pix);
uint64_t mb1s = arch_proc_mb1_size(core, pix);
- if (((addr - mb1a) % {{ mvec_size }}) < mb1s) {
- return true;
- }
+ return ((addr - mb1a) % {{ mvec_size }}) < mb1s;
+}
- return false;
+bool mvec_is_proc_owner(const struct Core *core, uint64_t addr, uint64_t pix) {
+ assert(core);
+ assert(mvec_proc_is_live(core, pix));
+ return mvec_is_in_mb0_of_proc(core, addr, pix) || mvec_is_in_mb1_of_proc(core, addr, pix);
}
uint64_t mvec_get_owner(const struct Core *core, uint64_t addr) {
@@ -360,6 +373,8 @@ void core_save(FILE *f, const struct Core *core) {
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);
+
+ arch_core_save(f, core);
}
{% endif %}
@@ -413,7 +428,7 @@ void core_init(struct Core *core, uint64_t *seed) {
{% if anc_bytes is defined %}
core_assemble_ancestor(core);
- arch_anc_init(core);
+ arch_core_init(core);
{% endif %}
}
{% endif %}
@@ -446,6 +461,8 @@ 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);
+
+ arch_core_load(f, core);
}
{% endif %}