From 6f7ce4063f8fb991e6fefddc8d77f3aa105d8efc Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Fri, 10 Nov 2023 15:27:55 +0100 Subject: [PATCH] Enable all models if the require key is missing Allows programs to update to a new libovni library without breaking the instrumentation. Only until the first call to ovni_thread_require() the models are enabled on demand. --- src/emu/model.c | 7 +++--- src/rt/ovni.c | 42 ++++++++++++-------------------- test/emu/common/instr.h | 1 + test/emu/nosv/multiple-segment.c | 1 + 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/emu/model.c b/src/emu/model.c index 90db93e..ba82912 100644 --- a/src/emu/model.c +++ b/src/emu/model.c @@ -198,14 +198,13 @@ model_version_probe(struct model_spec *spec, struct emu *emu) return -1; } - /* The ovni.require key is mandatory */ JSON_Object *require = json_object_dotget_object(t->meta, "ovni.require"); if (require == NULL) { - err("missing 'ovni.require' key in metadata"); - return -1; + warn("missing 'ovni.require' key, enabling all models"); + enable = 1; + break; } - /* But not all threads need to have this model */ const char *req_version = json_object_get_string(require, spec->name); if (req_version == NULL) continue; diff --git a/src/rt/ovni.c b/src/rt/ovni.c index 42924de..65b06e7 100644 --- a/src/rt/ovni.c +++ b/src/rt/ovni.c @@ -464,29 +464,6 @@ thread_metadata_store(void) die("failed to write thread metadata"); } -static void -thread_require_unsafe(const char *model, const char *version) -{ - int parsedver[3]; - if (version_parse(version, parsedver) != 0) - die("failed to parse provided version \"%s\"", version); - - /* Store into metadata */ - JSON_Object *meta = json_value_get_object(rthread.meta); - - if (meta == NULL) - die("json_value_get_object failed"); - - char dotpath[128]; - if (snprintf(dotpath, 128, "ovni.require.%s", model) >= 128) - die("model name too long"); - - /* TODO: What if is already set? */ - - if (json_object_dotset_string(meta, dotpath, version) != 0) - die("json_object_dotset_string failed"); -} - void ovni_thread_require(const char *model, const char *version) { @@ -507,7 +484,22 @@ ovni_thread_require(const char *model, const char *version) if (version == NULL) die("version string is NULL"); - thread_require_unsafe(model, version); + int parsedver[3]; + if (version_parse(version, parsedver) != 0) + die("failed to parse provided version \"%s\"", version); + + /* Store into metadata */ + JSON_Object *meta = json_value_get_object(rthread.meta); + + if (meta == NULL) + die("json_value_get_object failed"); + + char dotpath[128]; + if (snprintf(dotpath, 128, "ovni.require.%s", model) >= 128) + die("model name too long"); + + if (json_object_dotset_string(meta, dotpath, version) != 0) + die("json_object_dotset_string failed"); } static void @@ -526,8 +518,6 @@ thread_metadata_populate(void) if (json_object_dotset_string(meta, "ovni.lib.commit", OVNI_GIT_COMMIT) != 0) die("json_object_dotset_string failed"); - - thread_require_unsafe("ovni", "1.0.0"); } static void diff --git a/test/emu/common/instr.h b/test/emu/common/instr.h index 7701a6e..37c05c8 100644 --- a/test/emu/common/instr.h +++ b/test/emu/common/instr.h @@ -111,6 +111,7 @@ instr_start(int rank, int nranks) dbg("thread %d has cpu %d (ncpus=%d)", get_tid(), curcpu, nranks); + instr_require("ovni"); instr_thread_execute(curcpu, -1, 0); } diff --git a/test/emu/nosv/multiple-segment.c b/test/emu/nosv/multiple-segment.c index 2b721be..4c597c4 100644 --- a/test/emu/nosv/multiple-segment.c +++ b/test/emu/nosv/multiple-segment.c @@ -46,6 +46,7 @@ main(void) int lcpu = rank % N; ovni_thread_init(get_tid()); + instr_require("ovni"); instr_nosv_init(); instr_thread_execute(lcpu, -1, 0);